pci: introduce a helper function to convert qdev id to PCIDevice
This patch introduce a helper function to get PCIDevice from qdev id. This function will be used later. Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
a2ee6b4fcb
commit
f3006dd1e6
35
hw/pci.c
35
hw/pci.c
@ -2027,3 +2027,38 @@ static char *pcibus_get_dev_path(DeviceState *dev)
|
|||||||
return strdup(path);
|
return strdup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pci_qdev_find_recursive(PCIBus *bus,
|
||||||
|
const char *id, PCIDevice **pdev)
|
||||||
|
{
|
||||||
|
DeviceState *qdev = qdev_find_recursive(&bus->qbus, id);
|
||||||
|
if (!qdev) {
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roughly check if given qdev is pci device */
|
||||||
|
if (qdev->info->init == &pci_qdev_init &&
|
||||||
|
qdev->parent_bus->info == &pci_bus_info) {
|
||||||
|
*pdev = DO_UPCAST(PCIDevice, qdev, qdev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pci_qdev_find_device(const char *id, PCIDevice **pdev)
|
||||||
|
{
|
||||||
|
struct PCIHostBus *host;
|
||||||
|
int rc = -ENODEV;
|
||||||
|
|
||||||
|
QLIST_FOREACH(host, &host_buses, next) {
|
||||||
|
int tmp = pci_qdev_find_recursive(host->bus, id, pdev);
|
||||||
|
if (!tmp) {
|
||||||
|
rc = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (tmp != -ENODEV) {
|
||||||
|
rc = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
1
hw/pci.h
1
hw/pci.h
@ -252,6 +252,7 @@ PCIBus *pci_find_root_bus(int domain);
|
|||||||
int pci_find_domain(const PCIBus *bus);
|
int pci_find_domain(const PCIBus *bus);
|
||||||
PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
|
PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
|
||||||
PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function);
|
PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function);
|
||||||
|
int pci_qdev_find_device(const char *id, PCIDevice **pdev);
|
||||||
PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
|
PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
|
||||||
|
|
||||||
int pci_parse_devaddr(const char *addr, int *domp, int *busp,
|
int pci_parse_devaddr(const char *addr, int *domp, int *busp,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user