@@ -2617,6 +2617,28 @@ static int pci_qdev_find_recursive(PCIBus *bus,
return -EINVAL;
}
+int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot, uint32_t virt_func,
+ PCIDevice **pci_dev)
+{
+ PCIHostState *host_bridge;
+ PCIDevice *d;
+ int devfn;
+ int rc = -ENODEV;
+
+ QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
+ for(devfn = 0; devfn < ARRAY_SIZE(host_bridge->bus->devices); devfn++) {
+ d = host_bridge->bus->devices[devfn];
+ if (d && d->devfn == PCI_DEVFN(virt_slot, virt_func) &&
+ pci_bus_num(pci_get_bus(d)) == virt_bus) {
+ *pci_dev = d;
+ rc = 0;
+ break;
+ }
+ }
+ }
+ return rc;
+}
+
int pci_qdev_find_device(const char *id, PCIDevice **pdev)
{
PCIHostState *host_bridge;
@@ -366,6 +366,8 @@ const char *pci_root_bus_path(PCIDevice *dev);
bool pci_bus_bypass_iommu(PCIBus *bus);
PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
int pci_qdev_find_device(const char *id, PCIDevice **pdev);
+int pci_qdev_get_device(uint32_t virt_bus, uint32_t virt_slot,
+ uint32_t virt_func, PCIDevice **pci_dev);
void pci_bus_get_w64_range(PCIBus *bus, Range *range);
void pci_device_deassert_intx(PCIDevice *dev);
Introduce a helper function to get PCIDevice from qdev pci notation. Signed-off-by: Julia Zhang <julia.zhang@amd.com> --- hw/pci/pci.c | 22 ++++++++++++++++++++++ include/hw/pci/pci.h | 2 ++ 2 files changed, 24 insertions(+)