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.
dprintf(3, "init ACPI tables\n");
// This code is hardcoded for PIIX4 Power Management device.
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;
if (bdf < 0)
// Device not found
return;
// Scan PCI bus for ATA adapters
int count=0;
int bdf, max;
// Scan PCI bus for ATA adapters
int count=0;
int bdf, max;
- foreachpci(bdf, max, 0) {
if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE)
continue;
if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE)
continue;
} else {
// Find and deploy PCI roms.
int bdf, max;
} else {
// Find and deploy PCI roms.
int bdf, max;
- foreachpci(bdf, max, 0) {
u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA)
continue;
u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA)
continue;
next_rom += ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
} else {
// Find and deploy PCI VGA rom.
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;
if (bdf < 0)
// Device not found
return;
// Search for a device with the specified vendor and device ids.
int
// 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;
{
u32 id = (devid << 16) | vendid;
int bdf, max;
- foreachpci(bdf, max, start_bdf) {
u32 v = pci_config_readl(bdf, PCI_VENDOR_ID);
if (v != id)
continue;
u32 v = pci_config_readl(bdf, PCI_VENDOR_ID);
if (v != id)
continue;
-// 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
// Search for a device with the specified class id.
int
-pci_find_class(u16 classid, int start_bdf)
+pci_find_class(u16 classid)
- foreachpci(bdf, max, start_bdf) {
u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
if (v != classid)
continue;
u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
if (v != classid)
continue;
u16 pci_config_readw(u16 bdf, u32 addr);
u8 pci_config_readb(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);
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
; BDF=pci_next(BDF+1, &MAX))
// pirtable.c
#include "pci.h" // pci_config_readl
#include "bregs.h" // struct bregs
#include "biosvar.h" // GET_EBDA
#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
#define RET_FUNC_NOT_SUPPORTED 0x81
#define RET_BAD_VENDOR_ID 0x83
{
// Find max bus.
int bdf, max;
{
// Find max bus.
int bdf, max;
- foreachpci(bdf, max, 0) {
}
regs->al = 0x01; // Flags - "Config Mechanism #1" supported.
}
regs->al = 0x01; // Flags - "Config Mechanism #1" supported.
static void
handle_1ab102(struct bregs *regs)
{
static void
handle_1ab102(struct bregs *regs)
{
+ u32 id = (regs->cx << 16) | regs->dx;
- 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)
{
}
// find class code
static void
handle_1ab103(struct bregs *regs)
{
- 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
}
// read configuration byte
pci_bios_bigmem_addr = 0x90000000;
int bdf, max;
pci_bios_bigmem_addr = 0x90000000;
int bdf, max;
- foreachpci(bdf, max, 0) {
pci_bios_init_bridges(bdf);
}
pci_bios_init_bridges(bdf);
}
- foreachpci(bdf, max, 0) {
pci_bios_init_device(bdf);
}
}
pci_bios_init_device(bdf);
}
}
dprintf(3, "enabling shadow ram\n");
// Locate chip controlling ram shadowing.
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;
if (bdf < 0) {
dprintf(1, "Unable to unlock ram - bridge not found\n");
return;
dprintf(3, "locking shadow ram\n");
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;
if (bdf < 0) {
dprintf(1, "Unable to lock ram - bridge not found\n");
return;
dprintf(3, "init smm\n");
// This code is hardcoded for PIIX4 Power Management device.
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;
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;
if (i440_bdf < 0)
return;