From db03d5db185430812775f0075a18da459b96a019 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 21 Jun 2008 11:55:29 -0400 Subject: [PATCH] PCI fixes Only set the PIR table signature and checksum in the init function - that way, if it is disabled at runtime (eg, due to coreboot) then it wont be found by the OS. Fix parameter swap bug in handle_1ab102. Add support for more than one bus in pci scanning code (but only have 1 bus for now). --- src/pci.c | 55 ++++++++++++++++++++++++++++---------------------- src/pcibios.c | 2 +- src/pirtable.c | 5 ++--- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/pci.c b/src/pci.c index c688dac..e704444 100644 --- a/src/pci.c +++ b/src/pci.c @@ -7,6 +7,9 @@ #include "pci.h" // PCIDevice #include "ioport.h" // outl +#include "util.h" // dprintf + +#define MAX_BUS 1 void pci_config_writel(PCIDevice d, u32 addr, u32 val) { @@ -53,20 +56,22 @@ u8 pci_config_readb(PCIDevice d, u32 addr) int pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev) { - int devfn; + int devfn, bus; u32 id = (devid << 16) | vendid; - for (devfn=0; devfn<0x100; devfn++) { - PCIDevice d = pci_bd(0, devfn); - u32 v = pci_config_readl(d, 0x00); - if (v != id) - continue; - if (index) { - index--; - continue; + for (bus=0; bus < MAX_BUS; bus++) { + for (devfn=0; devfn<0x100; devfn++) { + PCIDevice d = pci_bd(bus, devfn); + u32 v = pci_config_readl(d, 0x00); + if (v != id) + continue; + if (index) { + index--; + continue; + } + // Found it. + *dev = d; + return 0; } - // Found it. - *dev = d; - return 0; } return -1; } @@ -74,20 +79,22 @@ pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev) int pci_find_class(u32 classid, int index, PCIDevice *dev) { - int devfn; + int devfn, bus; u32 id = classid << 8; - for (devfn=0; devfn<0x100; devfn++) { - PCIDevice d = pci_bd(0, devfn); - u32 v = pci_config_readl(d, 0x08); - if (v != id) - continue; - if (index) { - index--; - continue; + for (bus=0; bus < MAX_BUS; bus++) { + for (devfn=0; devfn<0x100; devfn++) { + PCIDevice d = pci_bd(bus, devfn); + u32 v = pci_config_readl(d, 0x08); + if (v != id) + continue; + if (index) { + index--; + continue; + } + // Found it. + *dev = d; + return 0; } - // Found it. - *dev = d; - return 0; } return -1; } diff --git a/src/pcibios.c b/src/pcibios.c index 1ab72f4..436c106 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -32,7 +32,7 @@ static void handle_1ab102(struct bregs *regs) { PCIDevice d; - int ret = pci_find_device(regs->cx, regs->dx, regs->si, &d); + int ret = pci_find_device(regs->dx, regs->cx, regs->si, &d); if (ret) { set_code_fail(regs, RET_DEVICE_NOT_FOUND); return; diff --git a/src/pirtable.c b/src/pirtable.c index c20a169..433b889 100644 --- a/src/pirtable.c +++ b/src/pirtable.c @@ -11,15 +11,13 @@ struct pir_table { struct pir_header pir; struct pir_slot slots[6]; -} PACKED PIR_TABLE VISIBLE16 __attribute__((aligned(16))) = { +} PACKED PIR_TABLE __attribute__((aligned(16))) = { #if CONFIG_PIRTABLE .pir = { - .signature = PIR_SIGNATURE, .version = 0x0100, .size = sizeof(struct pir_table), .router_devfunc = 0x08, .compatible_devid = 0x122e8086, - .checksum = 0x37, // XXX - should auto calculate }, .slots = { { @@ -93,6 +91,7 @@ create_pirtable() if (! CONFIG_PIRTABLE) return; + PIR_TABLE.pir.signature = PIR_SIGNATURE; PIR_TABLE.pir.checksum = -checksum((u8*)&PIR_TABLE, sizeof(PIR_TABLE)); SET_EBDA(pir_loc, (u32)&PIR_TABLE); } -- 2.25.1