From: "Jan Beulich" Subject: [PATCH 08/11] VT-d: cleanup ATS code Date: Wed, 09 Mar 2011 12:29:25 +0000 Message-ID: <4D7780B50200007800035841@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part95B9A2B5.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part95B9A2B5.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Rather than having per-architecture stubs when ATS support is not implemented, simply provide inline functions in the common header for that case. Signed-off-by: Jan Beulich --- 2011-01-17.orig/xen/drivers/passthrough/vtd/extern.h +++ 2011-01-17/xen/drivers/passthrough/vtd/extern.h @@ -24,7 +24,6 @@ #include "dmar.h" #include =20 -extern bool_t ats_enabled; extern bool_t rwbf_quirk; =20 void print_iommu_regs(struct acpi_drhd_unit *drhd); @@ -56,17 +55,50 @@ struct iommu * ioapic_to_iommu(unsigned=20 struct acpi_drhd_unit * ioapic_to_drhd(unsigned int apic_id); struct acpi_drhd_unit * iommu_to_drhd(struct iommu *iommu); struct acpi_rhsa_unit * drhd_to_rhsa(struct acpi_drhd_unit *drhd); + +#ifdef CONFIG_X86_64 +extern bool_t ats_enabled; + struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu); =20 int ats_device(int seg, int bus, int devfn); int enable_ats_device(int seg, int bus, int devfn); -int disable_ats_device(int seg, int bus, int devfn); +void disable_ats_device(int seg, int bus, int devfn); int invalidate_ats_tcs(struct iommu *iommu); =20 -int qinval_device_iotlb(struct iommu *iommu, - u32 max_invs_pend, u16 sid, u16 size, u64 addr); int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type); +#else +#define ats_enabled 0 + +static inline struct acpi_drhd_unit *find_ats_dev_drhd(struct iommu = *iommu) +{ + return NULL; +} + +static inline int ats_device(int seg, int bus, int devfn) +{ + return 0; +} +static inline int enable_ats_device(int seg, int bus, int devfn) +{ + BUG(); + return -ENOSYS; +} +static inline void disable_ats_device(int seg, int bus, int devfn) +{ + BUG(); +} + +static inline int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 = addr, + unsigned int size_order, u64 type) +{ + return 0; +} +#endif + +int qinval_device_iotlb(struct iommu *iommu, + u32 max_invs_pend, u16 sid, u16 size, u64 addr); =20 unsigned int get_cache_line_size(void); void cacheline_flush(char *); --- 2011-01-17.orig/xen/drivers/passthrough/vtd/ia64/Makefile +++ 2011-01-17/xen/drivers/passthrough/vtd/ia64/Makefile @@ -1,2 +1 @@ obj-y +=3D vtd.o -obj-y +=3D ats.o --- 2011-01-17.orig/xen/drivers/passthrough/vtd/ia64/ats.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2006, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify = it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License = for - * more details. - * - * You should have received a copy of the GNU General Public License = along with - * this program; if not, write to the Free Software Foundation, Inc., 59 = Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. - * - * Author: Allen Kay - */ - -#include -#include -#include -#include -#include -#include -#include "../iommu.h" -#include "../dmar.h" -#include "../vtd.h" -#include "../extern.h" - -struct pci_ats_dev; - -bool_t __read_mostly ats_enabled =3D 0; - -struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu) -{ - return NULL; -} - -int ats_device(int seg, int bus, int devfn) -{ - return 0; -} - -int enable_ats_device(int seg, int bus, int devfn) -{ - return 0; -} - -int disable_ats_device(int seg, int bus, int devfn) -{ - return 0; -} - -int dev_invalidate_iotlb(struct iommu *iommu, u16 did, - u64 addr, unsigned int size_order, u64 type) -{ - return 0; -} --- 2011-01-17.orig/xen/drivers/passthrough/vtd/x86/Makefile +++ 2011-01-17/xen/drivers/passthrough/vtd/x86/Makefile @@ -1,2 +1,2 @@ obj-y +=3D vtd.o -obj-y +=3D ats.o +obj-$(CONFIG_X86_64) +=3D ats.o --- 2011-01-17.orig/xen/drivers/passthrough/vtd/x86/ats.c +++ 2011-01-17/xen/drivers/passthrough/vtd/x86/ats.c @@ -127,23 +127,11 @@ int enable_ats_device(int seg, int bus,=20 u32 value; int pos; =20 - if ( !acpi_find_matched_atsr_unit(bus, devfn) ) - { - dprintk(XENLOG_WARNING VTDPREFIX, - "cannot find matched atsr for %x:%x.%x\n", - bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); - return 0; - } - pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); - if ( !pos ) - { - dprintk(XENLOG_ERR VTDPREFIX, "ats capability not found %x:%x.%x\n= ", - bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); - return 0; - } - else - dprintk(XENLOG_ERR VTDPREFIX, "ats capability found %x:%x.%x\n", + BUG_ON(!pos); + + if ( iommu_verbose ) + dprintk(XENLOG_INFO VTDPREFIX, "%x:%x.%x: ATS capability = found\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); =20 /* BUGBUG: add back seg when multi-seg platform support is enabled */ @@ -189,16 +177,14 @@ int enable_ats_device(int seg, int bus,=20 return pos; } =20 -int disable_ats_device(int seg, int bus, int devfn) +void disable_ats_device(int seg, int bus, int devfn) { - struct list_head *pdev_list, *tmp; struct pci_ats_dev *pdev; u32 value; int pos; =20 pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); - if ( !pos ) - return 0; + BUG_ON(!pos); =20 /* BUGBUG: add back seg when multi-seg platform support is enabled */ value =3D pci_conf_read16(bus, PCI_SLOT(devfn), @@ -207,9 +193,8 @@ int disable_ats_device(int seg, int bus, pci_conf_write16(bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pos + ATS_REG_CTL, value); =20 - list_for_each_safe( pdev_list, tmp, &ats_devices ) + list_for_each_entry ( pdev, &ats_devices, list ) { - pdev =3D list_entry(pdev_list, struct pci_ats_dev, list); if ( pdev->bus =3D=3D bus && pdev->devfn =3D=3D devfn ) { list_del(&pdev->list); @@ -221,8 +206,6 @@ int disable_ats_device(int seg, int bus, if ( iommu_verbose ) dprintk(XENLOG_INFO VTDPREFIX, "%x:%x.%x: ATS is disabled\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); - - return 0; } =20 =20 @@ -257,10 +240,7 @@ out: if ( ctxt_entry ) unmap_vtd_domain_page(ctxt_entry); =20 - if ( found ) - return 1; - - return 0; + return found; } =20 int dev_invalidate_iotlb(struct iommu *iommu, u16 did, --=__Part95B9A2B5.0__= Content-Type: text/plain; name="vtd-ats-cleanup.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vtd-ats-cleanup.patch" Rather than having per-architecture stubs when ATS support is not=0Aimpleme= nted, simply provide inline functions in the common header for=0Athat = case.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = 2011-01-17.orig/xen/drivers/passthrough/vtd/extern.h=0A+++ 2011-01-17/xen/d= rivers/passthrough/vtd/extern.h=0A@@ -24,7 +24,6 @@=0A #include "dmar.h"=0A= #include =0A =0A-extern bool_t ats_enabled;=0A extern = bool_t rwbf_quirk;=0A =0A void print_iommu_regs(struct acpi_drhd_unit = *drhd);=0A@@ -56,17 +55,50 @@ struct iommu * ioapic_to_iommu(unsigned =0A = struct acpi_drhd_unit * ioapic_to_drhd(unsigned int apic_id);=0A struct = acpi_drhd_unit * iommu_to_drhd(struct iommu *iommu);=0A struct acpi_rhsa_un= it * drhd_to_rhsa(struct acpi_drhd_unit *drhd);=0A+=0A+#ifdef CONFIG_X86_64= =0A+extern bool_t ats_enabled;=0A+=0A struct acpi_drhd_unit * find_ats_dev_= drhd(struct iommu *iommu);=0A =0A int ats_device(int seg, int bus, int = devfn);=0A int enable_ats_device(int seg, int bus, int devfn);=0A-int = disable_ats_device(int seg, int bus, int devfn);=0A+void disable_ats_device= (int seg, int bus, int devfn);=0A int invalidate_ats_tcs(struct iommu = *iommu);=0A =0A-int qinval_device_iotlb(struct iommu *iommu,=0A- = u32 max_invs_pend, u16 sid, u16 size, u64 addr);=0A int = dev_invalidate_iotlb(struct iommu *iommu, u16 did,=0A = u64 addr, unsigned int size_order, u64 type);=0A+#else=0A+#define = ats_enabled 0=0A+=0A+static inline struct acpi_drhd_unit *find_ats_dev_drhd= (struct iommu *iommu)=0A+{=0A+ return NULL;=0A+}=0A+=0A+static inline = int ats_device(int seg, int bus, int devfn)=0A+{=0A+ return 0;=0A+}=0A+s= tatic inline int enable_ats_device(int seg, int bus, int devfn)=0A+{=0A+ = BUG();=0A+ return -ENOSYS;=0A+}=0A+static inline void disable_ats_devic= e(int seg, int bus, int devfn)=0A+{=0A+ BUG();=0A+}=0A+=0A+static = inline int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 = addr,=0A+ unsigned int size_order, = u64 type)=0A+{=0A+ return 0;=0A+}=0A+#endif=0A+=0A+int qinval_device_iot= lb(struct iommu *iommu,=0A+ u32 max_invs_pend, u16 = sid, u16 size, u64 addr);=0A =0A unsigned int get_cache_line_size(void);=0A= void cacheline_flush(char *);=0A--- 2011-01-17.orig/xen/drivers/passthroug= h/vtd/ia64/Makefile=0A+++ 2011-01-17/xen/drivers/passthrough/vtd/ia64/Makef= ile=0A@@ -1,2 +1 @@=0A obj-y +=3D vtd.o=0A-obj-y +=3D ats.o=0A--- = 2011-01-17.orig/xen/drivers/passthrough/vtd/ia64/ats.c=0A+++ /dev/null=0A@@= -1,59 +0,0 @@=0A-/*=0A- * Copyright (c) 2006, Intel Corporation.=0A- = *=0A- * This program is free software; you can redistribute it and/or = modify it=0A- * under the terms and conditions of the GNU General Public = License,=0A- * version 2, as published by the Free Software Foundation.=0A-= *=0A- * This program is distributed in the hope it will be useful, but = WITHOUT=0A- * ANY WARRANTY; without even the implied warranty of MERCHANTAB= ILITY or=0A- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General = Public License for=0A- * more details.=0A- *=0A- * You should have = received a copy of the GNU General Public License along with=0A- * this = program; if not, write to the Free Software Foundation, Inc., 59 Temple=0A-= * Place - Suite 330, Boston, MA 02111-1307 USA.=0A- *=0A- * Author: Allen = Kay =0A- */=0A-=0A-#include =0A-#includ= e =0A-#include =0A-#include =0A-#includ= e =0A-#include =0A-#include "../iommu.h"=0A-#inc= lude "../dmar.h"=0A-#include "../vtd.h"=0A-#include "../extern.h"=0A-=0A-st= ruct pci_ats_dev;=0A-=0A-bool_t __read_mostly ats_enabled =3D 0;=0A-=0A-str= uct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu)=0A-{=0A- = return NULL;=0A-}=0A-=0A-int ats_device(int seg, int bus, int devfn)=0A-{= =0A- return 0;=0A-}=0A-=0A-int enable_ats_device(int seg, int bus, int = devfn)=0A-{=0A- return 0;=0A-}=0A-=0A-int disable_ats_device(int seg, = int bus, int devfn)=0A-{=0A- return 0;=0A-}=0A-=0A-int dev_invalidate_io= tlb(struct iommu *iommu, u16 did,=0A- u64 addr, unsigned int size_order,= u64 type)=0A-{=0A- return 0;=0A-}=0A--- 2011-01-17.orig/xen/drivers/pas= sthrough/vtd/x86/Makefile=0A+++ 2011-01-17/xen/drivers/passthrough/vtd/x86/= Makefile=0A@@ -1,2 +1,2 @@=0A obj-y +=3D vtd.o=0A-obj-y +=3D ats.o=0A+obj-$= (CONFIG_X86_64) +=3D ats.o=0A--- 2011-01-17.orig/xen/drivers/passthrough/vt= d/x86/ats.c=0A+++ 2011-01-17/xen/drivers/passthrough/vtd/x86/ats.c=0A@@ = -127,23 +127,11 @@ int enable_ats_device(int seg, int bus, =0A u32 = value;=0A int pos;=0A =0A- if ( !acpi_find_matched_atsr_unit(bus, = devfn) )=0A- {=0A- dprintk(XENLOG_WARNING VTDPREFIX,=0A- = "cannot find matched atsr for %x:%x.%x\n",=0A- bus, = PCI_SLOT(devfn), PCI_FUNC(devfn));=0A- return 0;=0A- }=0A-=0A = pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS);=0A- = if ( !pos )=0A- {=0A- dprintk(XENLOG_ERR VTDPREFIX, "ats = capability not found %x:%x.%x\n",=0A- bus, PCI_SLOT(devfn), = PCI_FUNC(devfn));=0A- return 0;=0A- }=0A- else=0A- = dprintk(XENLOG_ERR VTDPREFIX, "ats capability found %x:%x.%x\n",=0A+ = BUG_ON(!pos);=0A+=0A+ if ( iommu_verbose )=0A+ dprintk(XENLOG_INF= O VTDPREFIX, "%x:%x.%x: ATS capability found\n",=0A bus, = PCI_SLOT(devfn), PCI_FUNC(devfn));=0A =0A /* BUGBUG: add back seg when = multi-seg platform support is enabled */=0A@@ -189,16 +177,14 @@ int = enable_ats_device(int seg, int bus, =0A return pos;=0A }=0A =0A-int = disable_ats_device(int seg, int bus, int devfn)=0A+void disable_ats_device(= int seg, int bus, int devfn)=0A {=0A- struct list_head *pdev_list, = *tmp;=0A struct pci_ats_dev *pdev;=0A u32 value;=0A int = pos;=0A =0A pos =3D pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CA= P_ID_ATS);=0A- if ( !pos )=0A- return 0;=0A+ BUG_ON(!pos);=0A = =0A /* BUGBUG: add back seg when multi-seg platform support is enabled = */=0A value =3D pci_conf_read16(bus, PCI_SLOT(devfn),=0A@@ -207,9 = +193,8 @@ int disable_ats_device(int seg, int bus,=0A pci_conf_write16(= bus, PCI_SLOT(devfn), PCI_FUNC(devfn),=0A pos + = ATS_REG_CTL, value);=0A =0A- list_for_each_safe( pdev_list, tmp, = &ats_devices )=0A+ list_for_each_entry ( pdev, &ats_devices, list )=0A = {=0A- pdev =3D list_entry(pdev_list, struct pci_ats_dev, = list);=0A if ( pdev->bus =3D=3D bus && pdev->devfn =3D=3D devfn = )=0A {=0A list_del(&pdev->list);=0A@@ -221,8 +206,6 @@ = int disable_ats_device(int seg, int bus,=0A if ( iommu_verbose )=0A = dprintk(XENLOG_INFO VTDPREFIX, "%x:%x.%x: ATS is disabled\n",=0A = bus, PCI_SLOT(devfn), PCI_FUNC(devfn));=0A-=0A- return 0;=0A = }=0A =0A =0A@@ -257,10 +240,7 @@ out:=0A if ( ctxt_entry )=0A = unmap_vtd_domain_page(ctxt_entry);=0A =0A- if ( found )=0A- = return 1;=0A-=0A- return 0;=0A+ return found;=0A }=0A =0A int = dev_invalidate_iotlb(struct iommu *iommu, u16 did,=0A --=__Part95B9A2B5.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part95B9A2B5.0__=--