20#include <aquila/errno.h>
25#define PIO_MAX_RETRIES 5
29#define PIO_MAX_SECTORS 256
56 size_t _count = count;
61 if ((err = ata_poll(drive, 1))) {
66 printk(
"ata: retrying...\n");
68 for (
int i = 0; i < 5; ++i)
82 if (ata_poll(drive, 0))
112 if (ata_poll(drive, 1))
return -EIO;
119 if (ata_poll(drive, 0))
return -EIO;
136 return ata_poll(drive, 0) ? -EIO : 0;
static void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
Writes an 8-, 16- or 32-bit register.
#define __outsw(port, count, buf)
#define __insw(port, count, buf)
void ata_select_drive(struct ata_drive *drive, uint32_t mode)
Selects a drive on its channel, for an addressing mode, if it isn't selected so already,...
void ata_setup(struct ata_drive *drive, uint64_t lba, size_t count)
Writes the registers of a command on count sectors from lba: the drive, the address and the count.
void ata_reset(struct ata_drive *drive)
Resets both drives on a drive's channel, and waits until they are done.
void pio_init(struct ata_drive *drive)
Sets a drive up for PIO, and resets its channel.
#define ATA_CMD_CACHE_FLUSH
#define ATA_CMD_CACHE_FLUSH_EXT
#define ATA_CMD_READ_SECTORS
#define ATA_CMD_WRITE_SECTORS_EXT
#define ATA_CMD_READ_SECTORS_EXT
#define ATA_CMD_WRITE_SECTORS
static ssize_t pio_read(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Reads count sectors from lba on, PIO_MAX_SECTORS per command.
static ssize_t pio_write_sectors(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Writes up to PIO_MAX_SECTORS sectors with one command.
static ssize_t pio_read_sectors(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Reads up to PIO_MAX_SECTORS sectors with one command, trying it again a few times if the drive aborts...
static int pio_flush(struct ata_drive *drive)
Has the drive write what its cache holds to the disk.
static ssize_t pio_write(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Writes count sectors from lba on, PIO_MAX_SECTORS per command.
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
unsigned long long int uint64_t
unsigned short int uint16_t
ssize_t(*) read(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
int(*) flush(struct ata_drive *drive)
ssize_t(*) write(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)