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

[PATCH v2 10/15] pci: Use pci_sbdf_t in pci_add_device()



Also take the opportunity to avoid refetching sbdf from pdev
since we already have it now.

No functional change intended.

Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
 xen/arch/x86/physdev.c        |  7 ++++---
 xen/drivers/passthrough/pci.c | 35 ++++++++++++++++-------------------
 xen/drivers/pci/physdev.c     |  2 +-
 xen/include/xen/pci.h         |  3 +--
 4 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c
index a62087b780..d7e62f63c5 100644
--- a/xen/arch/x86/physdev.c
+++ b/xen/arch/x86/physdev.c
@@ -472,7 +472,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) 
arg)
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(0, manage_pci.bus, manage_pci.devfn,
+        ret = pci_add_device(PCI_SBDF(0, manage_pci.bus,
+                                      manage_pci.devfn),
                              NULL, NUMA_NO_NODE);
         break;
     }
@@ -503,8 +504,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) 
arg)
         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(0, manage_pci_ext.bus,
-                             manage_pci_ext.devfn,
+        ret = pci_add_device(PCI_SBDF(0, manage_pci_ext.bus,
+                                      manage_pci_ext.devfn),
                              &pdev_info, NUMA_NO_NODE);
         break;
     }
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 3be0772107..17a4931229 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -661,12 +661,11 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned 
int pos,
     return is64bits ? 2 : 1;
 }
 
-int pci_add_device(u16 seg, u8 bus, u8 devfn,
-                   const struct pci_dev_info *info, nodeid_t node)
+int pci_add_device(pci_sbdf_t sbdf, const struct pci_dev_info *info, nodeid_t 
node)
 {
     struct pci_seg *pseg;
     struct pci_dev *pdev;
-    unsigned int slot = PCI_SLOT(devfn), func = PCI_FUNC(devfn);
+    unsigned int slot = sbdf.devfn, func = sbdf.devfn;
     const char *type;
     int ret;
 
@@ -679,17 +678,17 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
     else
         type = "device";
 
-    ret = xsm_resource_plug_pci(XSM_PRIV, (seg << 16) | (bus << 8) | devfn);
+    ret = xsm_resource_plug_pci(XSM_PRIV, sbdf.sbdf);
     if ( ret )
         return ret;
 
     ret = -ENOMEM;
 
     pcidevs_lock();
-    pseg = alloc_pseg(seg);
+    pseg = alloc_pseg(sbdf.seg);
     if ( !pseg )
         goto out;
-    pdev = alloc_pdev(pseg, bus, devfn);
+    pdev = alloc_pdev(pseg, sbdf.bus, sbdf.devfn);
     if ( !pdev )
         goto out;
 
@@ -700,16 +699,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
         pdev->info = *info;
         if ( pdev->info.is_virtfn )
         {
-            struct pci_dev *pf_pdev =
-                pci_get_pdev(NULL, PCI_SBDF(seg, info->physfn.bus,
-                                            info->physfn.devfn));
+            pci_sbdf_t pf_sbdf = PCI_SBDF(sbdf.seg, info->physfn.bus, 
info->physfn.devfn);
+            struct pci_dev *pf_pdev = pci_get_pdev(NULL, pf_sbdf);
 
             if ( !pf_pdev )
             {
                 printk(XENLOG_WARNING
                        "Attempted to add SR-IOV VF %pp without PF %pp\n",
-                       &pdev->sbdf,
-                       &PCI_SBDF(seg, info->physfn.bus, info->physfn.devfn));
+                       &sbdf, &pf_sbdf);
                 free_pdev(pseg, pdev);
                 ret = -ENODEV;
                 goto out;
@@ -728,14 +725,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
             if ( !pdev->ext_cfg )
                 printk(XENLOG_WARNING
                        "%pp: VF without extended config space?\n",
-                       &pdev->sbdf);
+                       &sbdf);
         }
     }
 
     if ( !pdev->info.is_virtfn && !pdev->physfn.vf_rlen[0] )
     {
         unsigned int pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
-        uint16_t ctrl = pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_CTRL);
+        uint16_t ctrl = pci_conf_read16(sbdf, pos + PCI_SRIOV_CTRL);
 
         if ( !pos )
             /* Nothing */;
@@ -749,18 +746,18 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
             for ( i = 0; i < PCI_SRIOV_NUM_BARS; )
             {
                 unsigned int idx = pos + PCI_SRIOV_BAR + i * 4;
-                uint32_t bar = pci_conf_read32(pdev->sbdf, idx);
+                uint32_t bar = pci_conf_read32(sbdf, idx);
 
                 if ( (bar & PCI_BASE_ADDRESS_SPACE) ==
                      PCI_BASE_ADDRESS_SPACE_IO )
                 {
                     printk(XENLOG_WARNING
                            "SR-IOV device %pp with vf BAR%u in IO space\n",
-                           &pdev->sbdf, i);
+                           &sbdf, i);
                     ++i;
                     continue;
                 }
-                ret = pci_size_mem_bar(pdev->sbdf, idx, NULL,
+                ret = pci_size_mem_bar(sbdf, idx, NULL,
                                        &pdev->physfn.vf_rlen[i],
                                        PCI_BAR_VF |
                                        ((i == PCI_SRIOV_NUM_BARS - 1) ?
@@ -771,7 +768,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
         }
         else
             printk(XENLOG_WARNING "SR-IOV device %pp has its virtual"
-                   " functions already enabled (%04x)\n", &pdev->sbdf, ctrl);
+                   " functions already enabled (%04x)\n", &sbdf, ctrl);
     }
 
     check_pdev(pdev);
@@ -817,14 +814,14 @@ out:
     pcidevs_unlock();
     if ( !ret )
     {
-        printk(XENLOG_DEBUG "PCI add %s %pp\n", type, &pdev->sbdf);
+        printk(XENLOG_DEBUG "PCI add %s %pp\n", type, &sbdf);
         while ( pdev->phantom_stride )
         {
             func += pdev->phantom_stride;
             if ( PCI_SLOT(func) )
                 break;
             printk(XENLOG_DEBUG "PCI phantom %pp\n",
-                   &PCI_SBDF(seg, bus, slot, func));
+                   &PCI_SBDF(sbdf.seg, sbdf.bus, slot, func));
         }
     }
     return ret;
diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c
index 3f5989dca6..17cb27be0a 100644
--- a/xen/drivers/pci/physdev.c
+++ b/xen/drivers/pci/physdev.c
@@ -50,7 +50,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) 
arg)
         }
 #endif
 
-        ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, node);
+        ret = pci_add_device(PCI_SBDF(add.seg, add.bus, add.devfn), 
&pdev_info, node);
         break;
     }
 
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index be8c72f055..c065b2cd5c 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -229,8 +229,7 @@ void setup_hwdom_pci_devices(struct domain *d,
 int pci_release_devices(struct domain *d);
 int pci_add_segment(u16 seg);
 const unsigned long *pci_get_ro_map(u16 seg);
-int pci_add_device(u16 seg, u8 bus, u8 devfn,
-                   const struct pci_dev_info *info, nodeid_t node);
+int pci_add_device(pci_sbdf_t sbdf, const struct pci_dev_info *info, nodeid_t 
node);
 int pci_remove_device(pci_sbdf_t sbdf);
 int pci_ro_device(pci_sbdf_t sbdf);
 int pci_hide_device(pci_sbdf_t sbdf);
-- 
2.54.0



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

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