Use LBA disk access methods always; don't use CHS methods.
authorKevin O'Connor <kevin@koconnor.net>
Thu, 13 Mar 2008 23:09:49 +0000 (19:09 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 13 Mar 2008 23:09:49 +0000 (19:09 -0400)
Using CHS is dependent on the drive type, not the request type.  So,
old code was not correct.  It is simpler to just always use LBA.

src/ata.c
src/ata.h
src/disk.c

index cbd61d9..95cf1a5 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -546,9 +546,9 @@ ata_detect()
             SET_EBDA(ata.devices[device].device,ATA_DEVICE_HD);
             SET_EBDA(ata.devices[device].mode, ATA_MODE_PIO16);
 
             SET_EBDA(ata.devices[device].device,ATA_DEVICE_HD);
             SET_EBDA(ata.devices[device].mode, ATA_MODE_PIO16);
 
-            u16 ret = ata_cmd_data_chs(device, ATA_CMD_IDENTIFY_DEVICE
-                                       , 0, 0, 1, 1
-                                       , MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
+            u16 ret = ata_cmd_data(device, ATA_CMD_IDENTIFY_DEVICE
+                                   , 1, 1
+                                   , MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
             if (ret)
                 BX_PANIC("ata-detect: Failed to detect ATA device\n");
 
             if (ret)
                 BX_PANIC("ata-detect: Failed to detect ATA device\n");
 
@@ -650,9 +650,9 @@ ata_detect()
             SET_EBDA(ata.devices[device].device,ATA_DEVICE_CDROM);
             SET_EBDA(ata.devices[device].mode, ATA_MODE_PIO16);
 
             SET_EBDA(ata.devices[device].device,ATA_DEVICE_CDROM);
             SET_EBDA(ata.devices[device].mode, ATA_MODE_PIO16);
 
-            u16 ret = ata_cmd_data_chs(device, ATA_CMD_IDENTIFY_DEVICE_PACKET
-                                       , 0, 0, 1, 1
-                                       , MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
+            u16 ret = ata_cmd_data(device, ATA_CMD_IDENTIFY_DEVICE_PACKET
+                                   , 1, 1
+                                   , MAKE_32_PTR(GET_SEG(SS), (u32)buffer));
             if (ret != 0)
                 BX_PANIC("ata-detect: Failed to detect ATAPI device\n");
 
             if (ret != 0)
                 BX_PANIC("ata-detect: Failed to detect ATAPI device\n");
 
index 8d7c508..af64e1a 100644 (file)
--- a/src/ata.h
+++ b/src/ata.h
@@ -68,24 +68,4 @@ ata_cmd_data(u16 biosid, u16 command, u32 lba, u16 count, void *far_buffer)
     return ata_transfer(&cmd);
 }
 
     return ata_transfer(&cmd);
 }
 
-static inline int
-ata_cmd_data_chs(u16 biosid, u16 command, u16 cyl, u16 head, u16 sect, u16 count
-                 , void *far_buffer)
-{
-    u8 slave   = biosid % 2;
-
-    struct ata_pio_command cmd;
-    cmd.far_buffer = far_buffer;
-    cmd.biosid = biosid;
-
-    cmd.sector_count = count & 0xff;
-    cmd.feature = 0;
-    cmd.lba_low = sect;
-    cmd.lba_mid = cyl;
-    cmd.lba_high = cyl >> 8;
-    cmd.device = (slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) | (head & 0xff);
-    cmd.command = command;
-    return ata_transfer(&cmd);
-}
-
 #endif /* __ATA_H */
 #endif /* __ATA_H */
index 0ccbe42..3cf0ced 100644 (file)
@@ -54,8 +54,6 @@ basic_access(struct bregs *regs, u8 device, u16 command)
     u16 nlc   = GET_EBDA(ata.devices[device].lchs.cylinders);
     u16 nlh   = GET_EBDA(ata.devices[device].lchs.heads);
     u16 nlspt = GET_EBDA(ata.devices[device].lchs.spt);
     u16 nlc   = GET_EBDA(ata.devices[device].lchs.cylinders);
     u16 nlh   = GET_EBDA(ata.devices[device].lchs.heads);
     u16 nlspt = GET_EBDA(ata.devices[device].lchs.spt);
-    u16 nph   = GET_EBDA(ata.devices[device].pchs.heads);
-    u16 npspt = GET_EBDA(ata.devices[device].pchs.spt);
 
     // sanity check on cyl heads, sec
     if (cylinder >= nlc || head >= nlh || sector > nlspt) {
 
     // sanity check on cyl heads, sec
     if (cylinder >= nlc || head >= nlh || sector > nlspt) {
@@ -75,23 +73,12 @@ basic_access(struct bregs *regs, u8 device, u16 command)
     u16 segment = regs->es;
     u16 offset  = regs->bx;
 
     u16 segment = regs->es;
     u16 offset  = regs->bx;
 
-    irq_enable();
-
-    u8 status;
-    u32 lba;
-    if (nph != nlh || npspt != nlspt) {
-        // translate lchs to lba
-        lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
+    // translate lchs to lba
+    u32 lba = (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt)
                + (u32)sector - 1);
                + (u32)sector - 1);
-        status = ata_cmd_data(device, command, lba, count
-                              , MAKE_32_PTR(segment, offset));
-    } else {
-        // XXX - see if lba access can always be used.
-        status = ata_cmd_data_chs(device, command
-                                  , cylinder, head, sector, count
-                                  , MAKE_32_PTR(segment, offset));
-    }
-
+    irq_enable();
+    u8 status = ata_cmd_data(device, command, lba, count
+                             , MAKE_32_PTR(segment, offset));
     irq_disable();
 
     // Set nb of sector transferred
     irq_disable();
 
     // Set nb of sector transferred