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

[Xen-changelog] [xen-unstable] PCI: consolidate interface for adding devices



# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxxxx>
# Date 1311081248 -3600
# Node ID 4dc6a9ba90d60fdf0cc0898fc9a8fe84ae9030fc
# Parent  b3434f24b0827c5ef34e4b4a72893288e2ffbe40
PCI: consolidate interface for adding devices

The functionality of pci_add_device_ext() can be easily folded into
pci_add_device(), and eliminates the need to change two functions for
future adjustments.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>
---


diff -r b3434f24b082 -r 4dc6a9ba90d6 xen/arch/ia64/xen/hypercall.c
--- a/xen/arch/ia64/xen/hypercall.c     Tue Jul 19 14:13:01 2011 +0100
+++ b/xen/arch/ia64/xen/hypercall.c     Tue Jul 19 14:14:08 2011 +0100
@@ -665,8 +665,8 @@
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
-            break;
+        ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
+        break;
     }
 
     case PHYSDEVOP_manage_pci_remove: {
@@ -698,10 +698,10 @@
         pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
         pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
-        ret = pci_add_device_ext(manage_pci_ext.bus,
-                                 manage_pci_ext.devfn,
-                                 &pdev_info);
-            break;
+        ret = pci_add_device(manage_pci_ext.bus,
+                             manage_pci_ext.devfn,
+                             &pdev_info);
+        break;
     }
 
     default:
diff -r b3434f24b082 -r 4dc6a9ba90d6 xen/arch/x86/physdev.c
--- a/xen/arch/x86/physdev.c    Tue Jul 19 14:13:01 2011 +0100
+++ b/xen/arch/x86/physdev.c    Tue Jul 19 14:14:08 2011 +0100
@@ -479,7 +479,7 @@
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
+        ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
         break;
     }
 
@@ -516,9 +516,9 @@
         pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
         pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
-        ret = pci_add_device_ext(manage_pci_ext.bus,
-                                 manage_pci_ext.devfn,
-                                 &pdev_info);
+        ret = pci_add_device(manage_pci_ext.bus,
+                             manage_pci_ext.devfn,
+                             &pdev_info);
         break;
     }
 
diff -r b3434f24b082 -r 4dc6a9ba90d6 xen/drivers/passthrough/pci.c
--- a/xen/drivers/passthrough/pci.c     Tue Jul 19 14:13:01 2011 +0100
+++ b/xen/drivers/passthrough/pci.c     Tue Jul 19 14:14:08 2011 +0100
@@ -143,16 +143,29 @@
     pci_conf_write16(bus, dev, func, pos + PCI_ACS_CTRL, ctrl);
 }
 
-int pci_add_device(u8 bus, u8 devfn)
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *info)
 {
     struct pci_dev *pdev;
+    const char *pdev_type;
     int ret = -ENOMEM;
 
+    if (!info)
+        pdev_type = "device";
+    else if (info->is_extfn)
+        pdev_type = "extended function";
+    else if (info->is_virtfn)
+        pdev_type = "virtual function";
+    else
+        return -EINVAL;
+
     spin_lock(&pcidevs_lock);
     pdev = alloc_pdev(bus, devfn);
     if ( !pdev )
         goto out;
 
+    if ( info )
+        pdev->info = *info;
+
     ret = 0;
     if ( !pdev->domain )
     {
@@ -170,8 +183,8 @@
 
 out:
     spin_unlock(&pcidevs_lock);
-    printk(XENLOG_DEBUG "PCI add device %02x:%02x.%x\n", bus,
-           PCI_SLOT(devfn), PCI_FUNC(devfn));
+    printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
+           bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
     return ret;
 }
 
@@ -198,51 +211,6 @@
     return ret;
 }
 
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info)
-{
-    int ret;
-    char *pdev_type;
-    struct pci_dev *pdev;
-
-    if (info->is_extfn)
-        pdev_type = "Extended Function";
-    else if (info->is_virtfn)
-        pdev_type = "Virtual Function";
-    else
-        return -EINVAL;
-
-
-    ret = -ENOMEM;
-    spin_lock(&pcidevs_lock);
-    pdev = alloc_pdev(bus, devfn);
-    if ( !pdev )
-        goto out;
-
-    pdev->info = *info;
-
-    ret = 0;
-    if ( !pdev->domain )
-    {
-        pdev->domain = dom0;
-        ret = iommu_add_device(pdev);
-        if ( ret )
-        {
-            pdev->domain = NULL;
-            goto out;
-        }
-
-        list_add(&pdev->domain_list, &dom0->arch.pdev_list);
-        pci_enable_acs(pdev);
-    }
-
-out:
-    spin_unlock(&pcidevs_lock);
-    printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
-           bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
-
-    return ret;
-}
-
 static int pci_clean_dpci_irq(struct domain *d,
                               struct hvm_pirq_dpci *pirq_dpci, void *arg)
 {
diff -r b3434f24b082 -r 4dc6a9ba90d6 xen/include/xen/pci.h
--- a/xen/include/xen/pci.h     Tue Jul 19 14:13:01 2011 +0100
+++ b/xen/include/xen/pci.h     Tue Jul 19 14:14:08 2011 +0100
@@ -86,9 +86,8 @@
 struct pci_dev *pci_lock_domain_pdev(struct domain *d, int bus, int devfn);
 
 void pci_release_devices(struct domain *d);
-int pci_add_device(u8 bus, u8 devfn);
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *);
 int pci_remove_device(u8 bus, u8 devfn);
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info);
 struct pci_dev *pci_get_pdev(int bus, int devfn);
 struct pci_dev *pci_get_pdev_by_domain(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®.