Use READ 10 commands
This commit is contained in:
parent
bce02a8aaf
commit
0efafa34c7
26
atapi_imp.h
26
atapi_imp.h
@ -156,15 +156,21 @@ static int ata_device_detect(struct ata_device * dev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _read_12 = 1;
|
||||
|
||||
static void ata_device_read_sector_atapi(struct ata_device * dev, uint32_t lba, uint8_t * buf) {
|
||||
|
||||
if (!dev->is_atapi) return;
|
||||
|
||||
|
||||
uint16_t bus = dev->io_base;
|
||||
|
||||
_try_again:
|
||||
outportb(dev->io_base + ATA_REG_HDDEVSEL, 0xA0 | dev->slave << 4);
|
||||
ata_io_wait(dev);
|
||||
|
||||
print_hex(dev->atapi_sector_size);
|
||||
|
||||
outportb(bus + ATA_REG_FEATURES, 0x00);
|
||||
outportb(bus + ATA_REG_LBA1, dev->atapi_sector_size & 0xFF);
|
||||
outportb(bus + ATA_REG_LBA2, dev->atapi_sector_size >> 8);
|
||||
@ -178,7 +184,7 @@ static void ata_device_read_sector_atapi(struct ata_device * dev, uint32_t lba,
|
||||
}
|
||||
|
||||
atapi_command_t command;
|
||||
command.command_bytes[0] = 0xA8;
|
||||
command.command_bytes[0] = _read_12 ? 0xA8 : 0x28;
|
||||
command.command_bytes[1] = 0;
|
||||
command.command_bytes[2] = (lba >> 0x18) & 0xFF;
|
||||
command.command_bytes[3] = (lba >> 0x10) & 0xFF;
|
||||
@ -186,8 +192,8 @@ static void ata_device_read_sector_atapi(struct ata_device * dev, uint32_t lba,
|
||||
command.command_bytes[5] = (lba >> 0x00) & 0xFF;
|
||||
command.command_bytes[6] = 0;
|
||||
command.command_bytes[7] = 0;
|
||||
command.command_bytes[8] = 0; /* bit 0 = PMI (0, last sector) */
|
||||
command.command_bytes[9] = 1; /* control */
|
||||
command.command_bytes[8] = _read_12 ? 0 : 1; /* bit 0 = PMI (0, last sector) */
|
||||
command.command_bytes[9] = _read_12 ? 1 : 0; /* control */
|
||||
command.command_bytes[10] = 0;
|
||||
command.command_bytes[11] = 0;
|
||||
|
||||
@ -195,15 +201,18 @@ static void ata_device_read_sector_atapi(struct ata_device * dev, uint32_t lba,
|
||||
outports(bus, command.command_words[i]);
|
||||
}
|
||||
|
||||
print("sending\n");
|
||||
|
||||
while (1) {
|
||||
uint8_t status = inportb(dev->io_base + ATA_REG_STATUS);
|
||||
if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup;
|
||||
if ((status & ATA_SR_ERR)) goto atapi_error_on_read_setup_cmd;
|
||||
if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRQ)) break;
|
||||
}
|
||||
|
||||
uint16_t size_to_read = inportb(bus + ATA_REG_LBA2) << 8;
|
||||
size_to_read = size_to_read | inportb(bus + ATA_REG_LBA1);
|
||||
|
||||
print("reading\n");
|
||||
|
||||
inportsm(bus,buf,size_to_read/2);
|
||||
|
||||
@ -213,11 +222,20 @@ static void ata_device_read_sector_atapi(struct ata_device * dev, uint32_t lba,
|
||||
if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY)) break;
|
||||
}
|
||||
|
||||
print("read done\n");
|
||||
return;
|
||||
|
||||
atapi_error_on_read_setup:
|
||||
print("error on setup\n");
|
||||
return;
|
||||
atapi_error_on_read_setup_cmd:
|
||||
if (_read_12) {
|
||||
_read_12 = 0;
|
||||
print("trying again\n");
|
||||
goto _try_again;
|
||||
}
|
||||
print("error on cmd\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user