diff --git a/k/atapi.c b/k/atapi.c index 3d03630..d03e709 100644 --- a/k/atapi.c +++ b/k/atapi.c @@ -24,7 +24,7 @@ static void wait_device_selection(uint16_t drive) inb(drive); } -static uint8_t is_atapi_driver(uint16_t bus, uint8_t slave) +static uint8_t is_atapi_drive(uint16_t bus, uint8_t slave) { static uint8_t atapi_sig[] = { ATAPI_SIG_SC, ATAPI_SIG_LBA_LO, ATAPI_SIG_LBA_MI, ATAPI_SIG_LBA_HI }; @@ -61,15 +61,31 @@ static uint8_t is_atapi_driver(uint16_t bus, uint8_t slave) void discover_atapi_drive(void) { - // primary_reg + /* primary_reg */ outb(PRIMARY_DCR, SRST); outb(PRIMARY_DCR, INTERRUPT_DISABLE); + // master_port select_drive(PRIMARY_REG, ATA_PORT_MASTER); wait_device_selection(PRIMARY_REG); - is_atapi_driver(PRIMARY_REG, ATA_PORT_MASTER); + is_atapi_drive(PRIMARY_REG, ATA_PORT_MASTER); - // secondary_reg + // slave port + select_drive(PRIMARY_REG, ATA_PORT_SLAVE); + wait_device_selection(PRIMARY_REG); + is_atapi_drive(PRIMARY_REG, ATA_PORT_SLAVE); + + /* secondary_reg */ outb(SECONDARY_DCR, SRST); outb(SECONDARY_DCR, INTERRUPT_DISABLE); + + // master_port + select_drive(SECONDARY_REG, ATA_PORT_MASTER); + wait_device_selection(SECONDARY_REG); + is_atapi_drive(SECONDARY_REG, ATA_PORT_MASTER); + + // slave port + select_drive(SECONDARY_REG, ATA_PORT_SLAVE); + wait_device_selection(SECONDARY_REG); + is_atapi_drive(SECONDARY_REG, ATA_PORT_SLAVE); }