This new API pci_early_find_devices() is derived from the generic version of pci_find_devices() with modifications required in the early phase (like hose, config space access routines).
Signed-off-by: Bin Meng <bmeng...@gmail.com> --- arch/x86/cpu/pci.c | 41 +++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/pci.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/arch/x86/cpu/pci.c b/arch/x86/cpu/pci.c index 1eee08b..cdfb981 100644 --- a/arch/x86/cpu/pci.c +++ b/arch/x86/cpu/pci.c @@ -111,3 +111,44 @@ void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value) { pci_hose_write_config_dword(get_hose(), dev, where, value); } + +pci_dev_t pci_early_find_devices(struct pci_device_id *ids, int index) +{ + struct pci_controller *hose = gd->arch.hose; + u16 vendor, device; + u8 header_type; + pci_dev_t bdf; + int i, bus, found_multi = 0; + + for (bus = hose->first_busno; bus <= hose->last_busno; bus++) + for (bdf = PCI_BDF(bus, 0, 0); + bdf < PCI_BDF(bus + 1, 0, 0); + bdf += PCI_BDF(0, 0, 1)) { + if (pci_skip_dev(hose, bdf)) + continue; + + if (!PCI_FUNC(bdf)) { + header_type = pci_read_config8(bdf, + PCI_HEADER_TYPE); + + found_multi = header_type & 0x80; + } else { + if (!found_multi) + continue; + } + + vendor = pci_read_config16(bdf, PCI_VENDOR_ID); + device = pci_read_config16(bdf, PCI_DEVICE_ID); + + for (i = 0; ids[i].vendor != 0; i++) { + if (vendor == ids[i].vendor && + device == ids[i].device) { + if (index <= 0) + return bdf; + index--; + } + } + } + + return -1; +} diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h index ac1a808..a3550fb 100644 --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -49,4 +49,6 @@ void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value); void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value); void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value); +pci_dev_t pci_early_find_devices(struct pci_device_id *ids, int index); + #endif -- 1.8.2.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot