|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 02/18] pci: Use pci_sbdf_t in pci_add_device()
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
v3: Don't adjust adjacent code.
---
xen/arch/x86/physdev.c | 6 +++---
xen/drivers/passthrough/pci.c | 36 +++++++++++++++++------------------
xen/drivers/pci/physdev.c | 3 ++-
xen/include/xen/pci.h | 4 ++--
4 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c
index 5bbcf3b530..60c02076d6 100644
--- a/xen/arch/x86/physdev.c
+++ b/xen/arch/x86/physdev.c
@@ -472,7 +472,7 @@ 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 +503,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 0adf573150..3038827e28 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -662,12 +662,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.fn;
const char *type;
int ret;
@@ -680,17 +679,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;
@@ -701,16 +700,15 @@ 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;
@@ -729,14 +727,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 */;
@@ -750,18 +748,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) ?
@@ -772,7 +770,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);
@@ -818,14 +816,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 d46501b884..46735a5fc9 100644
--- a/xen/drivers/pci/physdev.c
+++ b/xen/drivers/pci/physdev.c
@@ -50,7 +50,8 @@ 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 ade882caee..26c0c6e449 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -229,8 +229,8 @@ 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(u16 seg, u8 bus, u8 devfn);
int pci_ro_device(int seg, int bus, int devfn);
int pci_hide_device(unsigned int seg, unsigned int bus, unsigned int devfn);
--
2.54.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |