diff options
-rw-r--r-- | hw/pci.c | 20 | ||||
-rw-r--r-- | hw/pci.h | 6 |
2 files changed, 26 insertions, 0 deletions
@@ -711,6 +711,26 @@ static void pci_bridge_write_config(PCIDevice *d, pci_default_write_config(d, address, val, len); } +PCIBus *pci_find_bus(int bus_num) +{ + PCIBus *bus = first_bus; + + while (bus && bus->bus_num != bus_num) + bus = bus->next; + + return bus; +} + +PCIDevice *pci_find_device(int bus_num, int slot, int function) +{ + PCIBus *bus = pci_find_bus(bus_num); + + if (!bus) + return NULL; + + return bus->devices[PCI_DEVFN(slot, function)]; +} + PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, pci_map_irq_fn map_irq, const char *name) { @@ -8,6 +8,10 @@ extern target_phys_addr_t pci_mem_base; +#define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) +#define PCI_FUNC(devfn) ((devfn) & 0x07) + /* Device classes and subclasses */ #define PCI_CLASS_STORAGE_SCSI 0x0100 @@ -222,6 +226,8 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len); uint32_t pci_data_read(void *opaque, uint32_t addr, int len); int pci_bus_num(PCIBus *s); void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d)); +PCIBus *pci_find_bus(int bus_num); +PCIDevice *pci_find_device(int bus_num, int slot, int function); void pci_info(void); PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, |