aboutsummaryrefslogtreecommitdiff
path: root/hw/pci.c
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2010-12-24 12:14:13 +0900
committerMichael S. Tsirkin <mst@redhat.com>2010-12-24 10:35:30 +0200
commitf3006dd1e60af3765c501a082d621f947d6e5974 (patch)
tree3b42c8ec696f6d6763f7e139b0de502c9ac4f6f5 /hw/pci.c
parenta2ee6b4fcb3e2f2f5d60211ce0f734c61f8e0e30 (diff)
downloadqemu-f3006dd1e60af3765c501a082d621f947d6e5974.zip
qemu-f3006dd1e60af3765c501a082d621f947d6e5974.tar.gz
qemu-f3006dd1e60af3765c501a082d621f947d6e5974.tar.bz2
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>
Diffstat (limited to 'hw/pci.c')
-rw-r--r--hw/pci.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/hw/pci.c b/hw/pci.c
index eb21848..44bb3b9 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -2027,3 +2027,38 @@ static char *pcibus_get_dev_path(DeviceState *dev)
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;
+}