aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2011-06-20 22:23:02 -0400
committerKevin O'Connor <kevin@koconnor.net>2011-06-20 23:58:04 -0400
commit9931bccc3ea5419c6797d0803621c512c7f92224 (patch)
treec49982d96d973ca8599bbbcfd946fd838ca906da
parent9cb49921878e3b74646c93a3d91dd51ff68a3b59 (diff)
downloadseabios-9931bccc3ea5419c6797d0803621c512c7f92224.zip
seabios-9931bccc3ea5419c6797d0803621c512c7f92224.tar.gz
seabios-9931bccc3ea5419c6797d0803621c512c7f92224.tar.bz2
Convert USB detection code to use struct pci_device.
-rw-r--r--src/pci.h3
-rw-r--r--src/usb.c41
2 files changed, 21 insertions, 23 deletions
diff --git a/src/pci.h b/src/pci.h
index a214bb1..7aa2dfe 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -52,6 +52,9 @@ struct pci_device {
extern struct pci_device *PCIDevices;
extern int MaxPCIBus;
void pci_probe(void);
+static inline u32 pci_classprog(struct pci_device *pci) {
+ return (pci->class << 8) | pci->prog_if;
+}
#define foreachpci(PCI) \
for (PCI=PCIDevices; PCI; PCI=PCI->next)
diff --git a/src/usb.c b/src/usb.c
index 454e2d4..26d1017 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -5,7 +5,7 @@
// This file may be distributed under the terms of the GNU LGPLv3 license.
#include "util.h" // dprintf
-#include "pci.h" // foreachbdf
+#include "pci.h" // foreachpci
#include "config.h" // CONFIG_*
#include "pci_regs.h" // PCI_CLASS_REVISION
#include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI
@@ -428,46 +428,41 @@ usb_setup(void)
dprintf(3, "init usb\n");
// Look for USB controllers
- int ehcibdf = -1;
int count = 0;
- int bdf, max;
- foreachbdf(bdf, max) {
- u32 code = pci_config_readl(bdf, PCI_CLASS_REVISION) >> 8;
-
- if (code >> 8 != PCI_CLASS_SERIAL_USB)
+ struct pci_device *ehcipci = PCIDevices;
+ struct pci_device *pci;
+ foreachpci(pci) {
+ if (pci->class != PCI_CLASS_SERIAL_USB)
continue;
- if (bdf > ehcibdf) {
+ if (pci->bdf >= ehcipci->bdf) {
// Check to see if this device has an ehci controller
- ehcibdf = bdf;
- u32 ehcicode = code;
int found = 0;
+ ehcipci = pci;
for (;;) {
- if (ehcicode == PCI_CLASS_SERIAL_USB_EHCI) {
+ if (pci_classprog(ehcipci) == PCI_CLASS_SERIAL_USB_EHCI) {
// Found an ehci controller.
- int ret = ehci_init(ehcibdf, count++, bdf);
+ int ret = ehci_init(ehcipci->bdf, count++, pci->bdf);
if (ret)
// Error
break;
count += found;
- bdf = ehcibdf;
- code = 0;
+ pci = ehcipci;
break;
}
- if (ehcicode >> 8 == PCI_CLASS_SERIAL_USB)
+ if (ehcipci->class == PCI_CLASS_SERIAL_USB)
found++;
- ehcibdf = pci_next(ehcibdf+1, &max);
- if (ehcibdf < 0
- || pci_bdf_to_busdev(ehcibdf) != pci_bdf_to_busdev(bdf))
+ ehcipci = ehcipci->next;
+ if (!ehcipci || (pci_bdf_to_busdev(ehcipci->bdf)
+ != pci_bdf_to_busdev(pci->bdf)))
// No ehci controller found.
break;
- ehcicode = pci_config_readl(ehcibdf, PCI_CLASS_REVISION) >> 8;
}
}
- if (code == PCI_CLASS_SERIAL_USB_UHCI)
- uhci_init(bdf, count++);
- else if (code == PCI_CLASS_SERIAL_USB_OHCI)
- ohci_init(bdf, count++);
+ if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_UHCI)
+ uhci_init(pci->bdf, count++);
+ else if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_OHCI)
+ ohci_init(pci->bdf, count++);
}
}