Only support IDE devices with pci class of PCI_CLASS_STORAGE_IDE.
Devices of class PCI_CLASS_STORAGE_OTHER may work with some devices,
but they are just as likely to cause a crash with other devices.
diff --git a/src/ata.c b/src/ata.c
index 2e7c4cc..a33b830 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -893,18 +893,11 @@
}
// Scan PCI bus for ATA adapters
- int count=0, bdf=-1;
- u16 classid = PCI_CLASS_STORAGE_OTHER; // SATA first
- while (count<CONFIG_MAX_ATA_INTERFACES-1) {
- bdf = pci_find_class(classid, bdf+1);
- if (bdf < 0) {
- if (classid == PCI_CLASS_STORAGE_IDE)
- // Done
- break;
- classid = PCI_CLASS_STORAGE_IDE; // PATA controllers
- bdf = -1;
+ int count=0;
+ int bdf, max;
+ foreachpci(bdf, max, 0) {
+ if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE)
continue;
- }
u8 irq = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
SET_EBDA(ata.channels[count].irq, irq);
@@ -913,7 +906,7 @@
u8 prog_if = pci_config_readb(bdf, PCI_CLASS_PROG);
u32 port1, port2;
- if (classid != PCI_CLASS_STORAGE_IDE || prog_if & 1) {
+ if (prog_if & 1) {
port1 = pci_config_readl(bdf, PCI_BASE_ADDRESS_0) & ~3;
port2 = pci_config_readl(bdf, PCI_BASE_ADDRESS_1) & ~3;
} else {
@@ -922,19 +915,19 @@
}
SET_EBDA(ata.channels[count].iobase1, port1);
SET_EBDA(ata.channels[count].iobase2, port2);
- dprintf(1, "ATA controller %d at %x/%x (dev %x class %x/%x)\n"
- , count, port1, port2, bdf, classid, prog_if);
+ dprintf(1, "ATA controller %d at %x/%x (dev %x prog_if %x)\n"
+ , count, port1, port2, bdf, prog_if);
count++;
- if (classid != PCI_CLASS_STORAGE_IDE || prog_if & 4) {
+ if (prog_if & 4) {
port1 = pci_config_readl(bdf, PCI_BASE_ADDRESS_2) & ~3;
port2 = pci_config_readl(bdf, PCI_BASE_ADDRESS_3) & ~3;
} else {
port1 = 0x170;
port2 = 0x370;
}
- dprintf(1, "ATA controller %d at %x/%x (dev %x class %x/%x)\n"
- , count, port1, port2, bdf, classid, prog_if);
+ dprintf(1, "ATA controller %d at %x/%x (dev %x prog_if %x)\n"
+ , count, port1, port2, bdf, prog_if);
SET_EBDA(ata.channels[count].iobase1, port1);
SET_EBDA(ata.channels[count].iobase2, port2);
count++;