Only support IDE devices with pci class of PCI_CLASS_STORAGE_IDE.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 5 Dec 2008 00:22:49 +0000 (19:22 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 5 Dec 2008 00:22:49 +0000 (19:22 -0500)
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.

src/ata.c

index 2e7c4cc22260bcbb638b6e65b1408bf3c79f01a2..a33b83052d6b9f9e5ff437c99450717f4ee3b92b 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -893,18 +893,11 @@ ata_init()
     }
 
     // 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 @@ ata_init()
         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 @@ ata_init()
         }
         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++;