VT-d/ATS: cleanup
authorJan Beulich <jbeulich@suse.com>
Wed, 2 Nov 2011 12:51:28 +0000 (13:51 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 2 Nov 2011 12:51:28 +0000 (13:51 +0100)
- make acpi_find_matched_atsr_unit() consistent with
  acpi_find_matched_drhd_unit() (and constify their parameter)
- make ats_device() take a struct pci_dev * instead of seg:bus:devfn
  and additionally the matching DRHD (as its callers already worked
  that out)
- remove a stale prototype

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: "Kay, Allen M" <allen.m.kay@intel.com>
xen/drivers/passthrough/vtd/dmar.c
xen/drivers/passthrough/vtd/dmar.h
xen/drivers/passthrough/vtd/extern.h
xen/drivers/passthrough/vtd/iommu.c
xen/drivers/passthrough/vtd/x86/ats.c

index 0b1665bf1ab5acbe9b0fb9de1bfe4c58dcf9d8b3..f1eed5067941ea1906632f934ae203e3ae903bdf 100644 (file)
@@ -160,7 +160,7 @@ static int __init acpi_register_atsr_unit(struct acpi_atsr_unit *atsr)
     return 0;
 }
 
-struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev)
+struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
 {
     u8 bus, devfn;
     struct acpi_drhd_unit *drhd;
@@ -204,17 +204,17 @@ struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev)
     return include_all;
 }
 
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn)
+struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *pdev)
 {
     struct acpi_atsr_unit *atsr;
     struct acpi_atsr_unit *all_ports = NULL;
 
     list_for_each_entry ( atsr, &acpi_atsr_units, list )
     {
-        if ( atsr->segment != seg )
+        if ( atsr->segment != pdev->seg )
             continue;
 
-        if ( test_bit(bus, atsr->scope.buses) )
+        if ( test_bit(pdev->bus, atsr->scope.buses) )
             return atsr;
 
         if ( atsr->all_ports )
index d9ec9783ee2f1b3383d9ece23beaf71f27784d8d..61017f5c3ed08110407249341541ea910d193495 100644 (file)
@@ -86,8 +86,8 @@ struct acpi_rhsa_unit {
         for (idx = 0; (bdf = rmrr->scope.devices[idx]) && \
                  idx < rmrr->scope.devices_cnt; idx++)
 
-struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev);
-struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u16 seg, u8 bus, u8 devfn);
+struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *);
+struct acpi_atsr_unit *acpi_find_matched_atsr_unit(const struct pci_dev *);
 
 #define DMAR_TYPE 1
 #define RMRR_TYPE 2
index 23d599530a6a7a1764405e03c19011d395303019..fe27f1a9b7ec827cdcf8f676bb4cb634cb69cf1a 100644 (file)
@@ -61,10 +61,9 @@ extern bool_t ats_enabled;
 
 struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu);
 
-int ats_device(int seg, int bus, int devfn);
+int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *);
 int enable_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);
 
 int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
                          u64 addr, unsigned int size_order, u64 type);
@@ -76,7 +75,8 @@ 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)
+static inline int ats_device(const struct pci_dev *pdev,
+                             const struct acpi_drhd_unit *drhd)
 {
     return 0;
 }
index 8f8f12f55085b726e6d4b661f68cd5780285941c..d10a4f770f4538ba3bd1b01fdad5648cf4f1fc41 100644 (file)
@@ -1410,7 +1410,7 @@ static int domain_context_mapping(
                     domain->domain_id, seg, bus,
                     PCI_SLOT(devfn), PCI_FUNC(devfn));
         ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn);
-        if ( !ret && ats_device(seg, bus, devfn) )
+        if ( !ret && ats_device(pdev, drhd) > 0 )
             enable_ats_device(seg, bus, devfn);
 
         break;
@@ -1541,7 +1541,7 @@ static int domain_context_unmap(
                     domain->domain_id, seg, bus,
                     PCI_SLOT(devfn), PCI_FUNC(devfn));
         ret = domain_context_unmap_one(domain, iommu, bus, devfn);
-        if ( !ret && ats_device(seg, bus, devfn) )
+        if ( !ret && ats_device(pdev, drhd) > 0 )
             disable_ats_device(seg, bus, devfn);
 
         break;
index 43f3e759893f5d57526c59e3d799eed3ebf5f5be..e77448c58524181a0432bd77e0caf56cddbdf7eb 100644 (file)
@@ -83,40 +83,32 @@ struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu)
     return NULL;
 }
 
-int ats_device(int seg, int bus, int devfn)
+int ats_device(const struct pci_dev *pdev, const struct acpi_drhd_unit *drhd)
 {
-    struct acpi_drhd_unit *drhd, *ats_drhd, *new_drhd;
-    struct pci_dev *pdev;
-    int pos = 0;
+    struct acpi_drhd_unit *ats_drhd;
+    int pos;
 
     if ( !ats_enabled || !iommu_qinval )
         return 0;
 
-    pdev = pci_get_pdev(seg, bus, devfn);
-    if ( !pdev )
-        return 0;
-
-    drhd = acpi_find_matched_drhd_unit(pdev);
-    if ( !drhd )
-        return 0;
-
     if ( !ecap_queued_inval(drhd->iommu->ecap) ||
          !ecap_dev_iotlb(drhd->iommu->ecap) )
         return 0;
 
-    if ( !acpi_find_matched_atsr_unit(seg, bus, devfn) )
+    if ( !acpi_find_matched_atsr_unit(pdev) )
         return 0;
 
     ats_drhd = find_ats_dev_drhd(drhd->iommu);
-    pos = pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS);
+    pos = pci_find_ext_capability(pdev->seg, pdev->bus, pdev->devfn,
+                                  PCI_EXT_CAP_ID_ATS);
 
     if ( pos && (ats_drhd == NULL) )
     {
-        new_drhd = xmalloc(struct acpi_drhd_unit);
-        if ( !new_drhd )
-            return 0;
-        memcpy(new_drhd, drhd, sizeof(struct acpi_drhd_unit));
-        list_add_tail(&new_drhd->list, &ats_dev_drhd_units);
+        ats_drhd = xmalloc(struct acpi_drhd_unit);
+        if ( !ats_drhd )
+            return -ENOMEM;
+        *ats_drhd = *drhd;
+        list_add_tail(&ats_drhd->list, &ats_dev_drhd_units);
     }
     return pos;
 }