From 8f9073449acb6cc882423fd3a3302247ed922d0b Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Mon, 25 Aug 2008 05:11:59 +0000 Subject: [PATCH] Fix a simply bug in the find device function. Signed-off-by: Ronald G. Minnich Acked-by: Ronald G. Minnich git-svn-id: svn://coreboot.org/repository/coreboot-v3@821 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- arch/x86/pci_ops_conf1.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/pci_ops_conf1.c b/arch/x86/pci_ops_conf1.c index 1263ed029c..6d54ad8750 100644 --- a/arch/x86/pci_ops_conf1.c +++ b/arch/x86/pci_ops_conf1.c @@ -119,7 +119,8 @@ int pci_conf1_find_on_bus(u16 bus, u16 vid, u16 did, u32 *busdevfn) u8 hdr; int bdf = bus << 16; - /* skip over all the function sin a device -- multifunction devices always have one vendor */ + /* skip over all the functions in a device -- + * multifunction devices always have one vendor */ for (devfn = 0; devfn < 0x100; devfn += 8) { u32 confaddr = bdf | (devfn << 8); val = pci_conf1_read_config32(confaddr, PCI_VENDOR_ID); @@ -127,7 +128,6 @@ int pci_conf1_find_on_bus(u16 bus, u16 vid, u16 did, u32 *busdevfn) if (val == 0xffffffff || val == 0x00000000 || val == 0x0000ffff || val == 0xffff0000) continue; - if (val == ((did << 16) | vid)) { *busdevfn = confaddr; return 1; @@ -135,10 +135,16 @@ int pci_conf1_find_on_bus(u16 bus, u16 vid, u16 did, u32 *busdevfn) hdr = pci_conf1_read_config8(confaddr, PCI_HEADER_TYPE); hdr &= 0x7F; - if (hdr == PCI_HEADER_TYPE_BRIDGE || hdr == PCI_HEADER_TYPE_CARDBUS) { unsigned int busses; busses = pci_conf1_read_config32(confaddr, PCI_PRIMARY_BUS); + /* We should never see a value of 0. + * this can happen if we run this before + * things are set up (which we have to be able to do + * in stage 0 + */ + if (! busses) + continue; if (pci_conf1_find_on_bus((busses >> 8) & 0xFF, vid, did, busdevfn)) return 1; }