Wait for RDY bit when resetting ata hard drives.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 13 Jun 2008 02:29:30 +0000 (22:29 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 13 Jun 2008 02:29:30 +0000 (22:29 -0400)
If the reset doesn't wait for RDY, apparently irqs can get generated
    later in the boot which can confuse the OS.

src/ata.c

index 62f55d1f0fac9faa84e8f039f191ca1d914bd631..998576cd519c773140549f99bd236705ad0a5c28 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -132,6 +132,15 @@ ata_reset(int driveid)
     // select device
     outb(slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0, iobase1+ATA_CB_DH);
     msleep(50);
+    u8 sc = inb(iobase1+ATA_CB_SC);
+    u8 sn = inb(iobase1+ATA_CB_SN);
+
+    // For predetermined ATA drives - wait for ready.
+    if (sc==0x01 && sn==0x01) {
+        u8 type=GET_EBDA(ata.devices[driveid].type);
+        if (type == ATA_TYPE_ATA)
+            await_ide(NOT_BSY_RDY, iobase1, IDE_TIMEOUT);
+    }
 
     // 8.2.1 (h) -- wait for not BSY
     status = await_ide(NOT_BSY, iobase1, IDE_TIMEOUT);