From: Blue Swirl Date: Sat, 6 Feb 2010 09:20:13 +0000 (+0000) Subject: PCI: fix multiple bridge problems X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c021f8e65f5009a5ab5711d9d5326fcab553ef1c;p=qemu.git PCI: fix multiple bridge problems When several PCI bridges were in use, monitor command "info pci" would enter into infinite loop. Buses behind the bridge were not discoverable because secondary and subordinate bus numbers were not used properly. Other buses were not found because bus search terminated on first miss. Signed-off-by: Blue Swirl --- 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; + } } }