From: Kevin O'Connor Date: Fri, 5 Dec 2008 00:39:10 +0000 (-0500) Subject: Don't allow start_bdf with new auto max bus detection code. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=4132e0213ea9b168dd619ca76f1f1bf075d1f4a4;p=seabios.git Don't allow start_bdf with new auto max bus detection code. It's not valid to set a "start bdf" when search for a device now, because we wont be able to properly detect the maximum bus unless we start at the beginning. Change callers that need to resume a search to use foreachpci() macro. Update all callers so that they don't pass in the now unused start_bdf. --- diff --git a/src/acpi.c b/src/acpi.c index a1c8b82..46aff4a 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -282,8 +282,8 @@ void acpi_bios_init(void) dprintf(3, "init ACPI tables\n"); // This code is hardcoded for PIIX4 Power Management device. - int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3 - , 0); + int bdf = pci_find_device(PCI_VENDOR_ID_INTEL + , PCI_DEVICE_ID_INTEL_82371AB_3); if (bdf < 0) // Device not found return; diff --git a/src/ata.c b/src/ata.c index a33b830..77f5e34 100644 --- a/src/ata.c +++ b/src/ata.c @@ -895,7 +895,7 @@ ata_init() // Scan PCI bus for ATA adapters int count=0; int bdf, max; - foreachpci(bdf, max, 0) { + foreachpci(bdf, max) { if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE) continue; diff --git a/src/optionroms.c b/src/optionroms.c index 8888aa5..32a1f95 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -303,7 +303,7 @@ optionrom_setup() } else { // Find and deploy PCI roms. int bdf, max; - foreachpci(bdf, max, 0) { + foreachpci(bdf, max) { u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE); if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA) continue; @@ -361,7 +361,7 @@ vga_setup() next_rom += ALIGN(rom->size * 512, OPTION_ROM_ALIGN); } else { // Find and deploy PCI VGA rom. - int bdf = pci_find_class(PCI_CLASS_DISPLAY_VGA, 0); + int bdf = pci_find_class(PCI_CLASS_DISPLAY_VGA); if (bdf < 0) // Device not found return; diff --git a/src/pci.c b/src/pci.c index 20838bf..5e8d7bb 100644 --- a/src/pci.c +++ b/src/pci.c @@ -88,11 +88,11 @@ pci_next(int bdf, int *pmax) // Search for a device with the specified vendor and device ids. int -pci_find_device(u16 vendid, u16 devid, int start_bdf) +pci_find_device(u16 vendid, u16 devid) { u32 id = (devid << 16) | vendid; int bdf, max; - foreachpci(bdf, max, start_bdf) { + foreachpci(bdf, max) { u32 v = pci_config_readl(bdf, PCI_VENDOR_ID); if (v != id) continue; @@ -102,27 +102,12 @@ pci_find_device(u16 vendid, u16 devid, int start_bdf) return -1; } -// Search for a device with the specified class id and prog-if. -int -pci_find_classprog(u32 classprog, int start_bdf) -{ - int bdf, max; - foreachpci(bdf, max, start_bdf) { - u32 v = pci_config_readl(bdf, PCI_CLASS_REVISION); - if ((v>>8) != classprog) - continue; - // Found it. - return bdf; - } - return -1; -} - // Search for a device with the specified class id. int -pci_find_class(u16 classid, int start_bdf) +pci_find_class(u16 classid) { int bdf, max; - foreachpci(bdf, max, start_bdf) { + foreachpci(bdf, max) { u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE); if (v != classid) continue; diff --git a/src/pci.h b/src/pci.h index fc39fa0..6623fd9 100644 --- a/src/pci.h +++ b/src/pci.h @@ -23,14 +23,13 @@ u32 pci_config_readl(u16 bdf, u32 addr); u16 pci_config_readw(u16 bdf, u32 addr); u8 pci_config_readb(u16 bdf, u32 addr); -int pci_find_device(u16 vendid, u16 devid, int start_bdf); -int pci_find_classprog(u32 classprog, int start_bdf); -int pci_find_class(u16 classid, int start_bdf); +int pci_find_device(u16 vendid, u16 devid); +int pci_find_class(u16 classid); int pci_next(int bdf, int *pmax); -#define foreachpci(BDF, MAX, START) \ - for (MAX=0x0100, BDF=pci_next((START), &MAX) \ - ; BDF >= 0 \ +#define foreachpci(BDF, MAX) \ + for (MAX=0x0100, BDF=pci_next(0, &MAX) \ + ; BDF >= 0 \ ; BDF=pci_next(BDF+1, &MAX)) // pirtable.c diff --git a/src/pcibios.c b/src/pcibios.c index 93cdc46..e310b18 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -10,6 +10,7 @@ #include "pci.h" // pci_config_readl #include "bregs.h" // struct bregs #include "biosvar.h" // GET_EBDA +#include "pci_regs.h" // PCI_VENDOR_ID #define RET_FUNC_NOT_SUPPORTED 0x81 #define RET_BAD_VENDOR_ID 0x83 @@ -22,7 +23,7 @@ handle_1ab101(struct bregs *regs) { // Find max bus. int bdf, max; - foreachpci(bdf, max, 0) { + foreachpci(bdf, max) { } regs->al = 0x01; // Flags - "Config Mechanism #1" supported. @@ -38,36 +39,40 @@ handle_1ab101(struct bregs *regs) static void handle_1ab102(struct bregs *regs) { - int bdf = -1; + u32 id = (regs->cx << 16) | regs->dx; int count = regs->si; - do { - bdf = pci_find_device(regs->dx, regs->cx, bdf+1); - if (bdf < 0) { - set_code_fail(regs, RET_DEVICE_NOT_FOUND); - return; - } - } while (count--); - - regs->bx = bdf; - set_code_success(regs); + int bdf, max; + foreachpci(bdf, max) { + u32 v = pci_config_readl(bdf, PCI_VENDOR_ID); + if (v != id) + continue; + if (count--) + continue; + regs->bx = bdf; + set_code_success(regs); + return; + } + set_code_fail(regs, RET_DEVICE_NOT_FOUND); } // find class code static void handle_1ab103(struct bregs *regs) { - int bdf = -1; int count = regs->si; - do { - bdf = pci_find_classprog(regs->ecx, bdf+1); - if (bdf < 0) { - set_code_fail(regs, RET_DEVICE_NOT_FOUND); - return; - } - } while (count--); - - regs->bx = bdf; - set_code_success(regs); + u32 classprog = regs->ecx; + int bdf, max; + foreachpci(bdf, max) { + u32 v = pci_config_readl(bdf, PCI_CLASS_REVISION); + if ((v>>8) != classprog) + continue; + if (count--) + continue; + regs->bx = bdf; + set_code_success(regs); + return; + } + set_code_fail(regs, RET_DEVICE_NOT_FOUND); } // read configuration byte diff --git a/src/pciinit.c b/src/pciinit.c index 28bee74..643e027 100644 --- a/src/pciinit.c +++ b/src/pciinit.c @@ -203,10 +203,10 @@ pci_bios_setup(void) pci_bios_bigmem_addr = 0x90000000; int bdf, max; - foreachpci(bdf, max, 0) { + foreachpci(bdf, max) { pci_bios_init_bridges(bdf); } - foreachpci(bdf, max, 0) { + foreachpci(bdf, max) { pci_bios_init_device(bdf); } } diff --git a/src/shadow.c b/src/shadow.c index 1631954..4e13922 100644 --- a/src/shadow.c +++ b/src/shadow.c @@ -39,7 +39,7 @@ make_bios_writable() dprintf(3, "enabling shadow ram\n"); // Locate chip controlling ram shadowing. - int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, 0); + int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441); if (bdf < 0) { dprintf(1, "Unable to unlock ram - bridge not found\n"); return; @@ -74,7 +74,7 @@ make_bios_readonly() dprintf(3, "locking shadow ram\n"); - int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, 0); + int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441); if (bdf < 0) { dprintf(1, "Unable to lock ram - bridge not found\n"); return; diff --git a/src/smm.c b/src/smm.c index b2140b4..dda8d5d 100644 --- a/src/smm.c +++ b/src/smm.c @@ -83,13 +83,13 @@ smm_init() dprintf(3, "init smm\n"); // This code is hardcoded for PIIX4 Power Management device. - int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3 - , 0); + int bdf = pci_find_device(PCI_VENDOR_ID_INTEL + , PCI_DEVICE_ID_INTEL_82371AB_3); if (bdf < 0) // Device not found return; - int i440_bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441 - , 0); + int i440_bdf = pci_find_device(PCI_VENDOR_ID_INTEL + , PCI_DEVICE_ID_INTEL_82441); if (i440_bdf < 0) return;