summary refs log tree commit diff stats
path: root/hw/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/pci.c')
-rw-r--r--hw/pci.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 023f7b6f4a..2aeaf75a10 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1299,7 +1299,7 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         "'io_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "}, "
         "'memory_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "}, "
         "'prefetchable_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "} }",
-        dev->config[0x19], dev->config[PCI_SECONDARY_BUS],
+        dev->config[PCI_PRIMARY_BUS], dev->config[PCI_SECONDARY_BUS],
         dev->config[PCI_SUBORDINATE_BUS],
         pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO),
         pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO),
@@ -1310,12 +1310,16 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY |
                                 PCI_BASE_ADDRESS_MEM_PREFETCH));
 
-        if (dev->config[0x19] != 0) {
-            qdict = qobject_to_qdict(pci_bridge);
-            qdict_put_obj(qdict, "devices",
-                          pci_get_devices_list(bus, dev->config[0x19]));
-        }
+        if (dev->config[PCI_SECONDARY_BUS] != 0) {
+            PCIBus *child_bus = pci_find_bus(bus, dev->config[PCI_SECONDARY_BUS]);
 
+            if (child_bus) {
+                qdict = qobject_to_qdict(pci_bridge);
+                qdict_put_obj(qdict, "devices",
+                              pci_get_devices_list(child_bus,
+                                                   dev->config[PCI_SECONDARY_BUS]));
+            }
+        }
         qdict = qobject_to_qdict(obj);
         qdict_put_obj(qdict, "pci_bridge", pci_bridge);
     }
@@ -1542,7 +1546,7 @@ static void pci_bridge_write_config(PCIDevice *d,
 
 PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
 {
-    PCIBus *sec;
+    PCIBus *sec, *ret;
 
     if (!bus)
         return NULL;
@@ -1553,11 +1557,13 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
 
     /* try child bus */
     QLIST_FOREACH(sec, &bus->child, sibling) {
-
         if (!bus->parent_dev /* pci host bridge */
-            || (pci_bus_num(sec) <= bus_num &&
-                bus->parent_dev->config[PCI_SUBORDINATE_BUS])) {
-            return pci_find_bus(sec, bus_num);
+            || (pci_bus_num(sec) >= bus_num &&
+                bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS]) ) {
+            ret = pci_find_bus(sec, bus_num);
+            if (ret) {
+                return ret;
+            }
         }
     }