static void
ata_scan(void)
{
- if (CONFIG_QEMU && !PCIDevices) {
+ if (CONFIG_QEMU && hlist_empty(&PCIDevices)) {
// No PCI devices found - probably a QEMU "-M isapc" machine.
// Try using ISA ports for ATA controllers.
init_controller(NULL, IRQ_ATA1
// PCI bus
struct mpt_bus *buses = (void*)cpu, *bus = buses;
- if (PCIDevices) {
+ if (!hlist_empty(&PCIDevices)) {
memset(bus, 0, sizeof(*bus));
bus->type = MPT_TYPE_BUS;
bus->busid = 0;
}
}
-struct pci_device *PCIDevices VARVERIFY32INIT;
+struct hlist_head PCIDevices VARVERIFY32INIT;
int MaxPCIBus VARFSEG;
// Check if PCI is available at all
dprintf(3, "PCI probe\n");
struct pci_device *busdevs[256];
memset(busdevs, 0, sizeof(busdevs));
- struct pci_device **pprev = &PCIDevices;
+ struct hlist_node **pprev = &PCIDevices.first;
int extraroots = romfile_loadint("etc/extra-pci-roots", 0);
int bus = -1, lastbus = 0, rootbuses = 0, count=0;
while (bus < 0xff && (bus < MaxPCIBus || rootbuses < extraroots)) {
return;
}
memset(dev, 0, sizeof(*dev));
- *pprev = dev;
- pprev = &dev->next;
+ hlist_add(&dev->node, pprev);
count++;
// Find parent device.
#define __PCI_H
#include "types.h" // u32
+#include "list.h" // hlist_node
#define PCI_ROM_SLOT 6
#define PCI_NUM_REGIONS 7
struct pci_device {
u16 bdf;
u8 rootbus;
- struct pci_device *next;
+ struct hlist_node node;
struct pci_device *parent;
// Configuration space device information
};
extern u64 pcimem_start, pcimem_end;
extern u64 pcimem64_start, pcimem64_end;
-extern struct pci_device *PCIDevices;
+extern struct hlist_head PCIDevices;
extern int MaxPCIBus;
int pci_probe_host(void);
void pci_probe_devices(void);
return (pci->class << 8) | pci->prog_if;
}
-#define foreachpci(PCI) \
- for (PCI=PCIDevices; PCI; PCI=PCI->next)
+#define foreachpci(PCI) \
+ hlist_for_each_entry(PCI, &PCIDevices, node)
int pci_next(int bdf, int bus);
#define foreachbdf(BDF, BUS) \
cntl->companion[count++] = comppci;
else if (pci_classprog(comppci) == PCI_CLASS_SERIAL_USB_OHCI)
cntl->companion[count++] = comppci;
- comppci = comppci->next;
+ comppci = container_of(comppci->node.next, struct pci_device, node);
}
run_thread(configure_ehci, cntl);
// Look for USB controllers
int count = 0;
- struct pci_device *ehcipci = PCIDevices;
- struct pci_device *pci;
+ struct pci_device *pci, *ehcipci = NULL;
foreachpci(pci) {
if (pci->class != PCI_CLASS_SERIAL_USB)
continue;
- if (pci->bdf >= ehcipci->bdf) {
+ if (!ehcipci || pci->bdf >= ehcipci->bdf) {
// Check to see if this device has an ehci controller
int found = 0;
ehcipci = pci;
}
if (ehcipci->class == PCI_CLASS_SERIAL_USB)
found++;
- ehcipci = ehcipci->next;
+ ehcipci = container_of(
+ ehcipci->node.next, struct pci_device, node);
if (!ehcipci || (pci_bdf_to_busdev(ehcipci->bdf)
!= pci_bdf_to_busdev(pci->bdf)))
// No ehci controller found.