[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] amd-iov: eliminate open-coded PCI bus scan



# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1292320421 0
# Node ID 72326371ae8106b91da0ca6b0436dd2b6478b7a7
# Parent  fd4cbfbbd83e6091a343844eae1da1468f54b72b
amd-iov: eliminate open-coded PCI bus scan

Instead, use scan_pci_devices() just like VT-d does. This at once
allows making {alloc,free}_pdev() static.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>
---
 xen/drivers/passthrough/amd/pci_amd_iommu.c |   45 +++++++++++-----------------
 xen/drivers/passthrough/pci.c               |    7 +---
 xen/include/xen/pci.h                       |    2 -
 3 files changed, 21 insertions(+), 33 deletions(-)

diff -r fd4cbfbbd83e -r 72326371ae81 xen/drivers/passthrough/amd/pci_amd_iommu.c
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c       Tue Dec 14 09:52:57 
2010 +0000
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c       Tue Dec 14 09:53:41 
2010 +0000
@@ -121,38 +121,28 @@ static void __init amd_iommu_setup_dom0_
 {
     struct amd_iommu *iommu;
     struct pci_dev *pdev;
-    int bus, dev, func;
-    u32 l;
-    int bdf;
+    int bus, devfn, bdf;
 
     spin_lock(&pcidevs_lock);
     for ( bus = 0; bus < 256; bus++ )
     {
-        for ( dev = 0; dev < 32; dev++ )
+        for ( devfn = 0; devfn < 256; devfn++ )
         {
-            for ( func = 0; func < 8; func++ )
-            {
-                l = pci_conf_read32(bus, dev, func, PCI_VENDOR_ID);
-                /* some broken boards return 0 or ~0 if a slot is empty: */
-                if ( (l == 0xffffffff) || (l == 0x00000000) ||
-                     (l == 0x0000ffff) || (l == 0xffff0000) )
-                    continue;
-
-                pdev = alloc_pdev(bus, PCI_DEVFN(dev, func));
-                pdev->domain = d;
-                list_add(&pdev->domain_list, &d->arch.pdev_list);
-
-                bdf = (bus << 8) | pdev->devfn;
-                iommu = find_iommu_for_device(bdf);
-
-                if ( !iommu )
-                {
-                    AMD_IOMMU_DEBUG("Fail to find iommu for device"
-                        "%02x:%02x.%x\n", bus, dev, func);
-                    continue;
-                }
+            pdev = pci_get_pdev(bus, devfn);
+            if ( !pdev )
+                continue;
+
+            pdev->domain = d;
+            list_add(&pdev->domain_list, &d->arch.pdev_list);
+
+            bdf = (bus << 8) | devfn;
+            iommu = find_iommu_for_device(bdf);
+
+            if ( likely(iommu != NULL) )
                 amd_iommu_setup_domain_device(d, iommu, bdf);
-            }
+            else
+                AMD_IOMMU_DEBUG("No iommu for device %02x:%02x.%x\n",
+                                bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
         }
     }
     spin_unlock(&pcidevs_lock);
@@ -173,7 +163,8 @@ int __init amd_iov_detect(void)
         printk("Error initialization\n");
         return -ENODEV;
     }
-    return 0;
+
+    return scan_pci_devices();
 }
 
 static int allocate_domain_resources(struct hvm_iommu *hd)
diff -r fd4cbfbbd83e -r 72326371ae81 xen/drivers/passthrough/pci.c
--- a/xen/drivers/passthrough/pci.c     Tue Dec 14 09:52:57 2010 +0000
+++ b/xen/drivers/passthrough/pci.c     Tue Dec 14 09:53:41 2010 +0000
@@ -43,7 +43,7 @@ static struct {
 /* bus2bridge_lock protects bus2bridge array */
 static DEFINE_SPINLOCK(bus2bridge_lock);
 
-struct pci_dev *alloc_pdev(u8 bus, u8 devfn)
+static struct pci_dev *alloc_pdev(u8 bus, u8 devfn)
 {
     struct pci_dev *pdev;
 
@@ -66,7 +66,7 @@ struct pci_dev *alloc_pdev(u8 bus, u8 de
     return pdev;
 }
 
-void free_pdev(struct pci_dev *pdev)
+static void free_pdev(struct pci_dev *pdev)
 {
     list_del(&pdev->alldevs_list);
     xfree(pdev);
@@ -383,8 +383,7 @@ int pci_device_detect(u8 bus, u8 dev, u8
 
 /*
  * scan pci devices to add all existed PCI devices to alldevs_list,
- * and setup pci hierarchy in array bus2bridge. This function is only
- * called in VT-d hardware setup
+ * and setup pci hierarchy in array bus2bridge.
  */
 int __init scan_pci_devices(void)
 {
diff -r fd4cbfbbd83e -r 72326371ae81 xen/include/xen/pci.h
--- a/xen/include/xen/pci.h     Tue Dec 14 09:52:57 2010 +0000
+++ b/xen/include/xen/pci.h     Tue Dec 14 09:53:41 2010 +0000
@@ -82,8 +82,6 @@ int scan_pci_devices(void);
 int scan_pci_devices(void);
 int pdev_type(u8 bus, u8 devfn);
 int find_upstream_bridge(u8 *bus, u8 *devfn, u8 *secbus);
-struct pci_dev *alloc_pdev(u8 bus, u8 devfn);
-void free_pdev(struct pci_dev *pdev);
 struct pci_dev *pci_lock_pdev(int bus, int devfn);
 struct pci_dev *pci_lock_domain_pdev(struct domain *d, int bus, int devfn);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.