diff options
author | Jordan Crouse <jordan.crouse@amd.com> | 2008-10-20 16:52:06 +0000 |
---|---|---|
committer | Jordan Crouse <jordan.crouse@amd.com> | 2008-10-20 16:52:06 +0000 |
commit | 6744231197b38bfc27c43b9cc95d25b6f8595d95 (patch) | |
tree | 83629ae9bbd2a195e528ceca0b2d8c016ee0d181 | |
parent | 20c9cf12a4a8bc2a7939e7bbf490324984f5b055 (diff) |
[PATCH] libpayload: Fix the PCI search function
Remove a possiblity for evil recusion and fix the function and slot
definition in the PCI search loop
Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3674 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
-rw-r--r-- | payloads/libpayload/drivers/pci.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/payloads/libpayload/drivers/pci.c b/payloads/libpayload/drivers/pci.c index be92613e88..31b29f86de 100644 --- a/payloads/libpayload/drivers/pci.c +++ b/payloads/libpayload/drivers/pci.c @@ -75,27 +75,36 @@ static int find_on_bus(int bus, unsigned short vid, unsigned short did, unsigned char hdr; for (devfn = 0; devfn < 0x100; devfn++) { - val = pci_read_config32(PCI_DEV(bus, PCI_SLOT(devfn), - PCI_FUNC(devfn)), REG_VENDOR_ID); + int func = devfn & 0x7; + int slot = (devfn >> 3) & 0x1f; + + val = pci_read_config32(PCI_DEV(bus, slot, func), + REG_VENDOR_ID); if (val == 0xffffffff || val == 0x00000000 || val == 0x0000ffff || val == 0xffff0000) continue; if (val == ((did << 16) | vid)) { - *dev = PCI_DEV(bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + *dev = PCI_DEV(bus, slot, func); return 1; } - hdr = pci_read_config8(PCI_DEV(bus, PCI_SLOT(devfn), - PCI_FUNC(devfn)), REG_HEADER_TYPE); + hdr = pci_read_config8(PCI_DEV(bus, slot, func), + REG_HEADER_TYPE); hdr &= 0x7F; if (hdr == HEADER_TYPE_BRIDGE || hdr == HEADER_TYPE_CARDBUS) { unsigned int busses; - busses = pci_read_config32(PCI_DEV(bus, PCI_SLOT(devfn), - PCI_FUNC(devfn)), REG_PRIMARY_BUS); - if (find_on_bus((busses >> 8) & 0xFF, vid, did, dev)) + busses = pci_read_config32(PCI_DEV(bus, slot, func), + REG_PRIMARY_BUS); + busses = (busses >> 8) & 0xFF; + + /* Avoid recursion if the new bus is the same as + * the old bus (insert lame The Who joke here) */ + + if ((busses != bus) && + find_on_bus(busses, vid, did, dev)) return 1; } } |