|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] PCI: pass pdev to pci_find_{,next_}ext_capability()
commit c1f0c432627473e1f3e6a3fd54449b199a819cc0
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Jan 13 12:41:36 2026 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Jan 13 12:41:36 2026 +0100
PCI: pass pdev to pci_find_{,next_}ext_capability()
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>
Reviewed-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
xen/arch/x86/msi.c | 2 +-
xen/drivers/passthrough/ats.c | 2 +-
xen/drivers/passthrough/ats.h | 4 ++--
xen/drivers/passthrough/pci.c | 5 ++---
xen/drivers/passthrough/vtd/iommu.c | 2 +-
xen/drivers/passthrough/vtd/quirks.c | 6 +++---
xen/drivers/pci/pci.c | 16 +++++++++-------
xen/drivers/vpci/rebar.c | 2 +-
xen/drivers/vpci/vpci.c | 6 +++---
xen/include/xen/pci.h | 6 ++++--
10 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index c1667c197c..57ad5002c5 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -676,7 +676,7 @@ static uint64_t read_pci_mem_bar(const struct pci_dev
*pdev, uint8_t bir,
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);
diff --git a/xen/drivers/passthrough/ats.c b/xen/drivers/passthrough/ats.c
index c20bfc8ee7..cb8268adea 100644
--- a/xen/drivers/passthrough/ats.c
+++ b/xen/drivers/passthrough/ats.c
@@ -24,7 +24,7 @@ boolean_param("ats", ats_enabled);
int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list)
{
uint16_t value;
- unsigned int pos = pci_find_ext_capability(pdev->sbdf, PCI_EXT_CAP_ID_ATS);
+ unsigned int pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
BUG_ON(!pos);
diff --git a/xen/drivers/passthrough/ats.h b/xen/drivers/passthrough/ats.h
index 2da255dabe..279936dcf0 100644
--- a/xen/drivers/passthrough/ats.h
+++ b/xen/drivers/passthrough/ats.h
@@ -32,7 +32,7 @@ static inline int pci_ats_enabled(const struct pci_dev *pdev)
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 struct pci_dev *pdev)
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 */
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 52c22fa50c..e42fee009c 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -581,7 +581,7 @@ static void pci_enable_acs(struct pci_dev *pdev)
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;
@@ -722,8 +722,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
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 )
diff --git a/xen/drivers/passthrough/vtd/iommu.c
b/xen/drivers/passthrough/vtd/iommu.c
index e7049456bf..3d6f787b3c 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1477,7 +1477,7 @@ static int ats_device(const struct pci_dev *pdev,
!acpi_find_matched_atsr_unit(pdev) )
return 0;
- 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 )
drhd->iommu->flush_dev_iotlb = true;
diff --git a/xen/drivers/passthrough/vtd/quirks.c
b/xen/drivers/passthrough/vtd/quirks.c
index 0a10a46d90..796b164115 100644
--- 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 *pdev)
/* 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 *pdev)
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;
diff --git a/xen/drivers/pci/pci.c b/xen/drivers/pci/pci.c
index e1ddde90eb..572cb9b21c 100644
--- a/xen/drivers/pci/pci.c
+++ b/xen/drivers/pci/pci.c
@@ -89,9 +89,10 @@ unsigned int pci_find_next_cap(pci_sbdf_t sbdf, unsigned int
pos,
* 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_sbdf_t sbdf,
unsigned int cap)
* 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_capability(pci_sbdf_t sbdf,
unsigned int start,
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;
}
diff --git a/xen/drivers/vpci/rebar.c b/xen/drivers/vpci/rebar.c
index 3c18792d9b..63510c337a 100644
--- a/xen/drivers/vpci/rebar.c
+++ b/xen/drivers/vpci/rebar.c
@@ -53,7 +53,7 @@ static int cf_check init_rebar(struct pci_dev *pdev)
{
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 )
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index c824bf8a8a..d76b81e04b 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -196,7 +196,7 @@ static struct vpci_register
*vpci_get_previous_ext_cap_register(
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 pci_dev *pdev)
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 *pdev)
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);
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 130c2a8c1a..d0521c5085 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -260,8 +260,10 @@ unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf,
unsigned int pos,
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);
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |