4 int pci_probe(pci_probe_fn_t probe, void *data)
12 for (bus = 0; bus < 0x100; bus++)
13 for (dev = 0; dev < 0x20; dev++)
15 if (pci_read32(bus, dev, 0, 0) == 0xFFFFFFFF)
17 for (fn = 0; fn < 8; fn++)
21 if (pci_read32(bus, dev, fn, 0) == 0xFFFFFFFF)
24 if ((fn != 0) && !(pci_read8(bus, dev, 0, 0x0E) & 0x80))
30 pdev.vid = pci_read16(bus, dev, fn, 0);
31 pdev.did = pci_read16(bus, dev, fn, 2);
33 for (bar = 0; bar < 6; bar++)
35 unsigned long bardat = pci_read32(bus, dev, fn, 0x10 + bar*4);
38 pdev.bars[bar].type = PCI_BAR_NONE;
43 pdev.bars[bar].type = PCI_BAR_IO;
44 pdev.bars[bar].addr = bardat & ~0x3;
46 pdev.bars[bar].prefetchable = (bardat >> 3) & 1;
47 switch ((bardat >> 1) & 0x3)
50 pdev.bars[bar].type = PCI_BAR_MEMORY32;
51 pdev.bars[bar].addr = bardat & ~0xF;
54 pdev.bars[bar].type = PCI_BAR_MEMORY64;
56 pdev.bars[bar].type = PCI_BAR_NONE;
59 pdev.bars[bar].type = PCI_BAR_NONE;
65 devsfound += probe(&pdev, data);
72 static int _enumfn(pci_dev_t *pdev, void *data)
76 outputf("Found device: %02x:%02x.%1x: %04X:%04X",
77 pdev->bus, pdev->dev, pdev->fn,
78 pdev->vid, pdev->did);
79 for (bar = 0; bar < 6; bar++)
81 switch (pdev->bars[bar].type)
84 outputf(" BAR %d: I/O, Addr %04x", bar, pdev->bars[bar].addr);
86 case PCI_BAR_MEMORY32:
87 outputf(" BAR %d: Mem32, Addr %04x", bar, pdev->bars[bar].addr);
89 case PCI_BAR_MEMORY64:
90 outputf(" BAR %d: Mem64, Addr %04x", bar, pdev->bars[bar].addr);
101 pci_probe(_enumfn, 0x0);
104 static int _probefn(pci_dev_t *dev, void *d)
106 pci_driver_t *driver = d;
109 for (i = 0; i < driver->id_count; i++)
110 if ((dev->vid == driver->ids[i].vid) && (dev->did == driver->ids[i].did))
112 outputf("Probing PCI device: %s", driver->ids[i].name ? driver->ids[i].name : driver->name);
113 return driver->probe(dev, d);
118 int pci_probe_driver(pci_driver_t driver)
120 return pci_probe(_probefn, &driver);