aboutsummaryrefslogtreecommitdiff
path: root/src/pci.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2011-07-02 14:49:41 -0400
committerKevin O'Connor <kevin@koconnor.net>2011-07-02 23:38:36 -0400
commit2b333e4bef018de86f010b25829742d1dcd60a0d (patch)
treebd1a34243cebecfc384215f6bf1408be263a604a /src/pci.c
parent0f654a976b9ec8d0346249f8aacc5fbd7d40e946 (diff)
downloadseabios-hppa-2b333e4bef018de86f010b25829742d1dcd60a0d.zip
seabios-hppa-2b333e4bef018de86f010b25829742d1dcd60a0d.tar.gz
seabios-hppa-2b333e4bef018de86f010b25829742d1dcd60a0d.tar.bz2
Rename foreachbdf_in_bus to foreachbdf and simplify it.
Now that all callers of foreachbdf have been converted to foreachbdf_in_bus, simplify the pci_next() code - it no longer needs to track PCI bridges. Also, rename the remaining users of foreachbdf_in_bus to foreachbdf.
Diffstat (limited to 'src/pci.c')
-rw-r--r--src/pci.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/pci.c b/src/pci.c
index ebc6f91..0de8ec5 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -59,48 +59,30 @@ pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on)
// Helper function for foreachbdf() macro - return next device
int
-pci_next(int bdf, int *pmax)
+pci_next(int bdf, int bus)
{
- if (pci_bdf_to_fn(bdf) == 1
- && (pci_config_readb(bdf-1, PCI_HEADER_TYPE) & 0x80) == 0)
+ if (pci_bdf_to_fn(bdf) == 0
+ && (pci_config_readb(bdf, PCI_HEADER_TYPE) & 0x80) == 0)
// Last found device wasn't a multi-function device - skip to
// the next device.
- bdf += 7;
+ bdf += 8;
+ else
+ bdf += 1;
- int max = *pmax;
for (;;) {
- if (bdf >= max) {
- if (CONFIG_PCI_ROOT1 && bdf <= (CONFIG_PCI_ROOT1 << 8))
- bdf = CONFIG_PCI_ROOT1 << 8;
- else if (CONFIG_PCI_ROOT2 && bdf <= (CONFIG_PCI_ROOT2 << 8))
- bdf = CONFIG_PCI_ROOT2 << 8;
- else
- return -1;
- *pmax = max = bdf + 0x0100;
- }
+ if (pci_bdf_to_bus(bdf) != bus)
+ return -1;
u16 v = pci_config_readw(bdf, PCI_VENDOR_ID);
if (v != 0x0000 && v != 0xffff)
// Device is present.
- break;
+ return bdf;
if (pci_bdf_to_fn(bdf) == 0)
bdf += 8;
else
bdf += 1;
}
-
- // Check if found device is a bridge.
- u32 v = pci_config_readb(bdf, PCI_HEADER_TYPE);
- v &= 0x7f;
- if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) {
- v = pci_config_readl(bdf, PCI_PRIMARY_BUS);
- int newmax = (v & 0xff00) + 0x0100;
- if (newmax > max)
- *pmax = newmax;
- }
-
- return bdf;
}
struct pci_device *PCIDevices;
@@ -122,8 +104,8 @@ pci_probe(void)
int bus = -1, lastbus = 0, rootbuses = 0, count=0;
while (bus < MaxPCIBus) {
bus++;
- int bdf, max;
- foreachbdf_in_bus(bdf, max, bus) {
+ int bdf;
+ foreachbdf(bdf, bus) {
// Create new pci_device struct and add to list.
struct pci_device *dev = malloc_tmp(sizeof(*dev));
if (!dev) {