Commit 3ae806189842c70cf47e041b3c498c65683e5a21
1 parent
f029bd94
qemu: add pci helper functions (Marcelo Tosatti)
Add pci_find_bus/pci_find_device to be used by PCI hotplug. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6592 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
26 additions
and
0 deletions
hw/pci.c
... | ... | @@ -711,6 +711,26 @@ static void pci_bridge_write_config(PCIDevice *d, |
711 | 711 | pci_default_write_config(d, address, val, len); |
712 | 712 | } |
713 | 713 | |
714 | +PCIBus *pci_find_bus(int bus_num) | |
715 | +{ | |
716 | + PCIBus *bus = first_bus; | |
717 | + | |
718 | + while (bus && bus->bus_num != bus_num) | |
719 | + bus = bus->next; | |
720 | + | |
721 | + return bus; | |
722 | +} | |
723 | + | |
724 | +PCIDevice *pci_find_device(int bus_num, int slot, int function) | |
725 | +{ | |
726 | + PCIBus *bus = pci_find_bus(bus_num); | |
727 | + | |
728 | + if (!bus) | |
729 | + return NULL; | |
730 | + | |
731 | + return bus->devices[PCI_DEVFN(slot, function)]; | |
732 | +} | |
733 | + | |
714 | 734 | PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, |
715 | 735 | pci_map_irq_fn map_irq, const char *name) |
716 | 736 | { | ... | ... |
hw/pci.h
... | ... | @@ -8,6 +8,10 @@ |
8 | 8 | |
9 | 9 | extern target_phys_addr_t pci_mem_base; |
10 | 10 | |
11 | +#define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) | |
12 | +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) | |
13 | +#define PCI_FUNC(devfn) ((devfn) & 0x07) | |
14 | + | |
11 | 15 | /* Device classes and subclasses */ |
12 | 16 | |
13 | 17 | #define PCI_CLASS_STORAGE_SCSI 0x0100 |
... | ... | @@ -222,6 +226,8 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len); |
222 | 226 | uint32_t pci_data_read(void *opaque, uint32_t addr, int len); |
223 | 227 | int pci_bus_num(PCIBus *s); |
224 | 228 | void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d)); |
229 | +PCIBus *pci_find_bus(int bus_num); | |
230 | +PCIDevice *pci_find_device(int bus_num, int slot, int function); | |
225 | 231 | |
226 | 232 | void pci_info(void); |
227 | 233 | PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, | ... | ... |