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 <blauwirbel@gmail.com>
This commit is contained in:
		
							parent
							
								
									e1c6bbabee
								
							
						
					
					
						commit
						c021f8e65f
					
				
							
								
								
									
										24
									
								
								hw/pci.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								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 "}, "
 | 
					        "'io_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "}, "
 | 
				
			||||||
        "'memory_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "}, "
 | 
					        "'memory_range': { 'base': %" PRId64 ", 'limit': %" PRId64 "}, "
 | 
				
			||||||
        "'prefetchable_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],
 | 
					        dev->config[PCI_SUBORDINATE_BUS],
 | 
				
			||||||
        pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO),
 | 
					        pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO),
 | 
				
			||||||
        pci_bridge_get_limit(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_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY |
 | 
				
			||||||
                                PCI_BASE_ADDRESS_MEM_PREFETCH));
 | 
					                                PCI_BASE_ADDRESS_MEM_PREFETCH));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (dev->config[0x19] != 0) {
 | 
					        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 = qobject_to_qdict(pci_bridge);
 | 
				
			||||||
                qdict_put_obj(qdict, "devices",
 | 
					                qdict_put_obj(qdict, "devices",
 | 
				
			||||||
                          pci_get_devices_list(bus, dev->config[0x19]));
 | 
					                              pci_get_devices_list(child_bus,
 | 
				
			||||||
 | 
					                                                   dev->config[PCI_SECONDARY_BUS]));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        qdict = qobject_to_qdict(obj);
 | 
					        qdict = qobject_to_qdict(obj);
 | 
				
			||||||
        qdict_put_obj(qdict, "pci_bridge", pci_bridge);
 | 
					        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 *pci_find_bus(PCIBus *bus, int bus_num)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PCIBus *sec;
 | 
					    PCIBus *sec, *ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!bus)
 | 
					    if (!bus)
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
@ -1553,11 +1557,13 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* try child bus */
 | 
					    /* try child bus */
 | 
				
			||||||
    QLIST_FOREACH(sec, &bus->child, sibling) {
 | 
					    QLIST_FOREACH(sec, &bus->child, sibling) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!bus->parent_dev /* pci host bridge */
 | 
					        if (!bus->parent_dev /* pci host bridge */
 | 
				
			||||||
            || (pci_bus_num(sec) <= bus_num &&
 | 
					            || (pci_bus_num(sec) >= bus_num &&
 | 
				
			||||||
                bus->parent_dev->config[PCI_SUBORDINATE_BUS])) {
 | 
					                bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS]) ) {
 | 
				
			||||||
            return pci_find_bus(sec, bus_num);
 | 
					            ret = pci_find_bus(sec, bus_num);
 | 
				
			||||||
 | 
					            if (ret) {
 | 
				
			||||||
 | 
					                return ret;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user