diff options
Diffstat (limited to 'src/kernel/fs/ata_pio.c')
-rw-r--r-- | src/kernel/fs/ata_pio.c | 122 |
1 files changed, 63 insertions, 59 deletions
diff --git a/src/kernel/fs/ata_pio.c b/src/kernel/fs/ata_pio.c index d3544ba..78cf7ac 100644 --- a/src/kernel/fs/ata_pio.c +++ b/src/kernel/fs/ata_pio.c @@ -3,123 +3,127 @@ #include <kernel/fs/ata_pio.h> #include <kernel/interrupts/interrupts.h> -struct ATA_INTERFACE *new_ATA(uint8_t master, uint16_t portBase) { - struct ATA_INTERFACE *ret = kmalloc(sizeof(struct ATA_INTERFACE)); +struct ata_interface *new_ata(uint8_t master, uint16_t port_base) +{ + struct ata_interface *ret = kmalloc(sizeof(struct ata_interface)); ret->master = master; - ret->dataPort = portBase; - ret->errorPort = portBase + 0x1; - ret->sectorCountPort = portBase + 0x2; - ret->lbaLowPort = portBase + 0x3; - ret->lbaMidPort = portBase + 0x4; - ret->lbaHiPort = portBase + 0x5; - ret->devicePort = portBase + 0x6; - ret->commandPort = portBase + 0x7; - ret->controlPort = portBase + 0x206; - - // isr_ignore(0x06); + ret->data_port = port_base; + ret->error_port = port_base + 0x1; + ret->sector_count_port = port_base + 0x2; + ret->lba_low_port = port_base + 0x3; + ret->lba_mid_port = port_base + 0x4; + ret->lba_high_port = port_base + 0x5; + ret->device_port = port_base + 0x6; + ret->command_port = port_base + 0x7; + ret->control_port = port_base + 0x206; + // isr_ignore(0x2E); // isr_ignore(0x2F); return ret; } -uint8_t ATA_identify(struct ATA_INTERFACE *iface, uint16_t *retdata) { - send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0); - send_b(iface->controlPort, 0); +uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data) +{ + outb(interface->device_port, interface->master ? 0xA0 : 0xB0); + outb(interface->control_port, 0); - send_b(iface->devicePort, 0xA0); - uint8_t status = receive_b(iface->commandPort); + outb(interface->device_port, 0xA0); + uint8_t status = inb(interface->command_port); if (status == 0xFF) return 1; - send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0); - send_b(iface->sectorCountPort, 0); - send_b(iface->lbaLowPort, 0); - send_b(iface->lbaMidPort, 0); - send_b(iface->lbaHiPort, 0); - send_b(iface->commandPort, 0xEC); // Identify command + outb(interface->device_port, interface->master ? 0xA0 : 0xB0); + outb(interface->sector_count_port, 0); + outb(interface->lba_low_port, 0); + outb(interface->lba_mid_port, 0); + outb(interface->lba_high_port, 0); + outb(interface->command_port, 0xEC); // Identify command - status = receive_b(iface->commandPort); + status = inb(interface->command_port); if (!status) return 1; while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01)) { - status = receive_b(iface->commandPort); + status = inb(interface->command_port); } if (status & 0x01) return 1; - for (int i = 0; i < 256; i++) retdata[i] = receive_w(iface->dataPort); + for (int i = 0; i < 256; i++) ret_data[i] = inw(interface->data_port); return 0; } -uint8_t *ATA_read28(struct ATA_INTERFACE *iface, uint32_t sector) { +uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector) +{ if (sector > 0x0FFFFFFF) return 0; - send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); + outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); - uint8_t status; - for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort); + uint8_t status = 0; + for (int i = 0; i < 5; i++) status = inb(interface->command_port); if (status == 0xFF) return 0; - send_b(iface->errorPort, 0); - send_b(iface->sectorCountPort, 1); - send_b(iface->lbaLowPort, sector & 0x000000FF); - send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8); - send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16); - send_b(iface->commandPort, 0x20); // Read command + outb(interface->error_port, 0); + outb(interface->sector_count_port, 1); + outb(interface->lba_low_port, sector & 0x000000FF); + outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8); + outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16); + outb(interface->command_port, 0x20); // Read command - status = receive_b(iface->commandPort); - while ((status & 0x80) && !(status & 0x01)) status = receive_b(iface->commandPort); + status = inb(interface->command_port); + while ((status & 0x80) && !(status & 0x01)) status = inb(interface->command_port); uint8_t *ret = kmalloc(BYTES_PER_SECTOR); for (int i = 0; i < BYTES_PER_SECTOR; i += 2) { - uint16_t data = receive_w(iface->dataPort); + uint16_t data = inw(interface->data_port); ret[i] = data & 0xFF; ret[i + 1] = (data >> 8) & 0xFF; } return ret; } -uint8_t ATA_write28(struct ATA_INTERFACE *iface, uint32_t sector, uint8_t *contents) { +uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint8_t *contents) +{ if (sector > 0x0FFFFFFF) return 1; - asm volatile ("cli"); + asm ("cli"); - send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); + outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24)); - uint8_t status; - for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort); + uint8_t status = 0; + for (int i = 0; i < 5; i++) status = inb(interface->command_port); if (status == 0xFF) return 1; - send_b(iface->errorPort, 0); - send_b(iface->sectorCountPort, 1); - send_b(iface->lbaLowPort, sector & 0x000000FF); - send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8); - send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16); - send_b(iface->commandPort, 0x30); // Write command + outb(interface->error_port, 0); + outb(interface->sector_count_port, 1); + outb(interface->lba_low_port, sector & 0x000000FF); + outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8); + outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16); + outb(interface->command_port, 0x30); // Write command - while ((status & 0x80) || !(status & 0x08)) status = receive_b(iface->commandPort); + while ((status & 0x80) || !(status & 0x08)) status = inb(interface->command_port); if (status & (0x01 || 0x20)) return 2; for (int i = 0; i < BYTES_PER_SECTOR; i += 2) { uint16_t data = contents[i]; data |= ((uint16_t) contents[i + 1]) << 8; - send_w(iface->dataPort, data); + outw(interface->data_port, data); } - send_b(iface->commandPort, 0xE7); // Flush command + outb(interface->command_port, 0xE7); // Flush command - for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort); + for (int i = 0; i < 5; i++) status = inb(interface->command_port); if (!status) return 3; while ((status & 0x80) && !(status & 0x01)) { - status = receive_b(iface->commandPort); + status = inb(interface->command_port); } return 0; } -uint8_t ATA_clear28(struct ATA_INTERFACE *iface, uint32_t sector) { - uint8_t emptysector[512] = {0}; - return ATA_write28(iface, sector, emptysector); +uint8_t ata_clear28(struct ata_interface *interface, uint32_t sector) +{ + uint8_t empty_sector[512] = {0}; + return ata_write28(interface, sector, empty_sector); }
\ No newline at end of file |