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

[PATCH 4/6] PCI: pass pdev to pci_find_{,next_}ext_capability()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 6 Jan 2026 14:49:15 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Delivery-date: Tue, 06 Jan 2026 13:49:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This is in preparation of using attributes recorded for devices.
Additionally locating (extended) capabilities of non-devices (e.g. phantom
functions) makes no sense.

While there also eliminate open-coding of PCI_CFG_SPACE_SIZE in adjacent
code.

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

--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -676,7 +676,7 @@ static uint64_t read_pci_mem_bar(const s
         unsigned int pos;
         uint16_t ctrl, num_vf, offset, stride;
 
-        pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_SRIOV);
+        pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
         ctrl = pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_CTRL);
         num_vf = pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_NUM_VF);
         offset = pci_conf_read16(pdev->sbdf, pos + PCI_SRIOV_VF_OFFSET);
--- a/xen/drivers/passthrough/ats.c
+++ b/xen/drivers/passthrough/ats.c
@@ -26,7 +26,7 @@ int enable_ats_device(struct pci_dev *pd
     u32 value;
     int pos;
 
-    pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS);
+    pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
     BUG_ON(!pos);
 
     if ( iommu_verbose )
--- a/xen/drivers/passthrough/ats.h
+++ b/xen/drivers/passthrough/ats.h
@@ -32,7 +32,7 @@ static inline int pci_ats_enabled(const
     u32 value;
     int pos;
 
-    pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS);
+    pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
     BUG_ON(!pos);
 
     value = pci_conf_read16(pdev->sbdf, pos + ATS_REG_CTL);
@@ -45,7 +45,7 @@ static inline int pci_ats_device(const s
     if ( !ats_enabled )
         return 0;
 
-    return pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS);
+    return pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
 }
 
 #endif /* DRIVERS__PASSTHROUGH__ATS_H */
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -641,7 +641,7 @@ static void pci_enable_acs(struct pci_de
     if ( !is_iommu_enabled(pdev->domain) )
         return;
 
-    pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ACS);
+    pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
     if (!pos)
         return;
 
@@ -787,8 +787,7 @@ int pci_add_device(u16 seg, u8 bus, u8 d
 
     if ( !pdev->info.is_virtfn && !pdev->physfn.vf_rlen[0] )
     {
-        unsigned int pos = pci_find_ext_capability(pdev->sbdf,
-                                                   PCI_EXT_CAP_ID_SRIOV);
+        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);
 
         if ( !pos )
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -62,7 +62,7 @@ int ats_device(const struct pci_dev *pde
         return 0;
 
     ats_drhd = find_ats_dev_drhd(drhd->iommu);
-    pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS);
+    pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
 
     if ( pos && (ats_drhd == NULL) )
     {
--- a/xen/drivers/passthrough/vtd/quirks.c
+++ b/xen/drivers/passthrough/vtd/quirks.c
@@ -531,10 +531,10 @@ void pci_vtd_quirk(const struct pci_dev
     /* Sandybridge-EP (Romley) */
     case 0x3c00: /* host bridge */
     case 0x3c01 ... 0x3c0b: /* root ports */
-        pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ERR);
+        pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
         if ( !pos )
         {
-            pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_VNDR);
+            pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_VNDR);
             while ( pos )
             {
                 val = pci_conf_read32(pdev->sbdf, pos + PCI_VNDR_HEADER);
@@ -543,7 +543,7 @@ void pci_vtd_quirk(const struct pci_dev
                     pos += PCI_VNDR_HEADER;
                     break;
                 }
-                pos = pci_find_next_ext_capability(pdev->sbdf, pos,
+                pos = pci_find_next_ext_capability(pdev, pos,
                                                    PCI_EXT_CAP_ID_VNDR);
             }
             ff = 0;
--- a/xen/drivers/pci/pci.c
+++ b/xen/drivers/pci/pci.c
@@ -89,9 +89,10 @@ unsigned int pci_find_next_cap(pci_sbdf_
  * within the device's PCI configuration space or 0 if the device does
  * not support it.
  */
-unsigned int pci_find_ext_capability(pci_sbdf_t sbdf, unsigned int cap)
+unsigned int pci_find_ext_capability(const struct pci_dev *pdev,
+                                     unsigned int cap)
 {
-    return pci_find_next_ext_capability(sbdf, 0, cap);
+    return pci_find_next_ext_capability(pdev, 0, cap);
 }
 
 /**
@@ -104,14 +105,15 @@ unsigned int pci_find_ext_capability(pci
  * within the device's PCI configuration space or 0 if the device does
  * not support it.
  */
-unsigned int pci_find_next_ext_capability(pci_sbdf_t sbdf, unsigned int start,
+unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev,
+                                          unsigned int start,
                                           unsigned int cap)
 {
     u32 header;
     int ttl = 480; /* 3840 bytes, minimum 8 bytes per capability */
-    unsigned int pos = max(start, 0x100U);
+    unsigned int pos = max(start, PCI_CFG_SPACE_SIZE + 0U);
 
-    header = pci_conf_read32(sbdf, pos);
+    header = pci_conf_read32(pdev->sbdf, pos);
 
     /*
      * If we have no capabilities, this is indicated by cap ID,
@@ -125,9 +127,9 @@ unsigned int pci_find_next_ext_capabilit
         if ( PCI_EXT_CAP_ID(header) == cap && pos != start )
             return pos;
         pos = PCI_EXT_CAP_NEXT(header);
-        if ( pos < 0x100 )
+        if ( pos < PCI_CFG_SPACE_SIZE )
             break;
-        header = pci_conf_read32(sbdf, pos);
+        header = pci_conf_read32(pdev->sbdf, pos);
     }
     return 0;
 }
--- a/xen/drivers/vpci/rebar.c
+++ b/xen/drivers/vpci/rebar.c
@@ -53,7 +53,7 @@ static int cf_check init_rebar(struct pc
 {
     uint32_t ctrl;
     unsigned int nbars;
-    unsigned int rebar_offset = pci_find_ext_capability(pdev->sbdf,
+    unsigned int rebar_offset = pci_find_ext_capability(pdev,
                                                         PCI_EXT_CAP_ID_REBAR);
 
     if ( !rebar_offset )
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -196,7 +196,7 @@ static struct vpci_register *vpci_get_pr
 static int vpci_ext_capability_hide(
     const struct pci_dev *pdev, unsigned int cap)
 {
-    const unsigned int offset = pci_find_ext_capability(pdev->sbdf, cap);
+    const unsigned int offset = pci_find_ext_capability(pdev, cap);
     struct vpci_register *r, *prev_r;
     struct vpci *vpci = pdev->vpci;
     uint32_t header, pre_header;
@@ -264,7 +264,7 @@ static int vpci_init_capabilities(struct
         if ( !is_ext )
             pos = pci_find_cap_offset(pdev->sbdf, cap);
         else if ( is_hardware_domain(pdev->domain) )
-            pos = pci_find_ext_capability(pdev->sbdf, cap);
+            pos = pci_find_ext_capability(pdev, cap);
 
         if ( !pos )
             continue;
@@ -333,7 +333,7 @@ void vpci_deassign_device(struct pci_dev
         if ( !capability->is_ext )
             pos = pci_find_cap_offset(pdev->sbdf, cap);
         else if ( is_hardware_domain(pdev->domain) )
-            pos = pci_find_ext_capability(pdev->sbdf, cap);
+            pos = pci_find_ext_capability(pdev, cap);
         if ( pos )
         {
             int rc = capability->cleanup(pdev, false);
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -263,8 +263,10 @@ unsigned int pci_find_next_cap_ttl(pci_s
                                    unsigned int *ttl);
 unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int pos,
                                unsigned int cap);
-unsigned int pci_find_ext_capability(pci_sbdf_t sbdf, unsigned int cap);
-unsigned int pci_find_next_ext_capability(pci_sbdf_t sbdf, unsigned int start,
+unsigned int pci_find_ext_capability(const struct pci_dev *pdev,
+                                     unsigned int cap);
+unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev,
+                                          unsigned int start,
                                           unsigned int cap);
 const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p,
                       unsigned int *dev_p, unsigned int *func_p);




 


Rackspace

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