From efde609a28f860fb1df2b0c6fe56ebd68a051f10 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 12 Mar 2008 20:33:15 -0400 Subject: Use 32bit absolute pointers for buffers in ATA code. Using 32bit pointers makes the code a little simpler. It also allows the code to be used from 32 bit mode. It does require all callers to encode the segment/offset into an absolute address. The ins/outs functions also need to know how to convert from 32bit back to segment/offset addresses. The change also includes a minor cleanup of the macros in farptr.h. --- src/ata.c | 59 +++++++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'src/ata.c') diff --git a/src/ata.c b/src/ata.c index 3aea3ad..2e44d41 100644 --- a/src/ata.c +++ b/src/ata.c @@ -186,10 +186,10 @@ send_cmd(struct ata_pio_command *cmd) int ata_transfer(struct ata_pio_command *cmd) { - DEBUGF("ata_transfer id=%d cmd=%d lba=%d count=%d seg=%x off=%x\n" + DEBUGF("ata_transfer id=%d cmd=%d lba=%d count=%d buf=%p\n" , cmd->biosid, cmd->command , (cmd->lba_high << 16) | (cmd->lba_mid << 8) | cmd->lba_low - , cmd->sector_count, cmd->segment, cmd->offset); + , cmd->sector_count, cmd->far_buffer); // Reset count of transferred data SET_EBDA(ata.trsfsectors,0); @@ -208,34 +208,28 @@ ata_transfer(struct ata_pio_command *cmd) irq_enable(); - u16 segment = cmd->segment; - u16 offset = cmd->offset; u8 current = 0; u16 count = cmd->sector_count; u8 status; + void *far_buffer = cmd->far_buffer; for (;;) { - if (offset >= 0xf800) { - offset -= 0x800; - segment += 0x80; - } - if (iswrite) { // Write data to controller - DEBUGF("Write sector id=%d dest=%x:%x\n", biosid, segment, offset); + DEBUGF("Write sector id=%d dest=%p\n", biosid, far_buffer); if (mode == ATA_MODE_PIO32) - outsl_seg(iobase1, segment, offset, 512 / 4); + outsl_far(iobase1, far_buffer, 512 / 4); else - outsw_seg(iobase1, segment, offset, 512 / 2); + outsw_far(iobase1, far_buffer, 512 / 2); } else { // Read data from controller - DEBUGF("Read sector id=%d dest=%x:%x\n", biosid, segment, offset); + DEBUGF("Read sector id=%d dest=%p\n", biosid, far_buffer); if (mode == ATA_MODE_PIO32) - insl_seg(iobase1, segment, offset, 512 / 4); + insl_far(iobase1, far_buffer, 512 / 4); else - insw_seg(iobase1, segment, offset, 512 / 2); + insw_far(iobase1, far_buffer, 512 / 2); await_ide(NOT_BSY, iobase1, IDE_TIMEOUT); } - offset += 512; + far_buffer += 512; current++; SET_EBDA(ata.trsfsectors,current); @@ -280,12 +274,10 @@ ata_transfer(struct ata_pio_command *cmd) // 4 : not ready int ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen - , u16 header, u32 length, u16 bufseg, u16 bufoff) + , u16 header, u32 length, void *far_buffer) { - DEBUGF("ata_cmd_packet d=%d cmdlen=%d h=%d l=%d" - " seg=%x off=%x\n" - , biosid, cmdlen, header, length - , bufseg, bufoff); + DEBUGF("ata_cmd_packet d=%d cmdlen=%d h=%d l=%d buf=%p\n" + , biosid, cmdlen, header, length, far_buffer); u8 channel = biosid / 2; u8 slave = biosid % 2; @@ -321,7 +313,7 @@ ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen irq_enable(); // Send command to device - outsw_seg(iobase1, GET_SEG(SS), (u32)cmdbuf, cmdlen / 2); + outsw_far(iobase1, MAKE_32_PTR(GET_SEG(SS), (u32)cmdbuf), cmdlen / 2); u8 status; u16 loops = 0; @@ -346,10 +338,6 @@ ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen return 3; } - // Normalize address - bufseg += (bufoff / 16); - bufoff %= 16; - // Get the byte count u16 lcount = (((u16)(inb(iobase1 + ATA_CB_CH))<<8) + inb(iobase1 + ATA_CB_CL)); @@ -378,9 +366,8 @@ ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen // Save byte count u16 count = lcount; - DEBUGF("Trying to read %04x bytes (%04x %04x %04x) " - , lbefore+lcount+lafter, lbefore, lcount, lafter); - DEBUGF("to 0x%04x:0x%04x\n", bufseg, bufoff); + DEBUGF("Trying to read %04x bytes (%04x %04x %04x) to %p\n" + , lbefore+lcount+lafter, lbefore, lcount, lafter, far_buffer); // If counts not dividable by 4, use 16bits mode u8 lmode = mode; @@ -410,9 +397,9 @@ ata_cmd_packet(u16 biosid, u8 *cmdbuf, u8 cmdlen inw(iobase1); if (lmode == ATA_MODE_PIO32) - insl_seg(iobase1, bufseg, bufoff, lcount); + insl_far(iobase1, far_buffer, lcount); else - insw_seg(iobase1, bufseg, bufoff, lcount); + insw_far(iobase1, far_buffer, lcount); for (i=0; i