|
AquilaOS documentation
How it works, and its code
|
Go to the source code of this file.
Data Structures | |
| struct | ata_channel |
| An IDE channel, with the master and slave drives on it. More... | |
| struct | ata_drive |
| A drive on a channel. More... | |
Functions | |
| static const char * | ata_error_string (uint8_t err) |
| Returns the name of an error, from the error register. | |
| static void | ata_wait (struct ata_drive *drive) |
| Waits about 400 ns, as a drive needs after a command, by reading the alternate status register four times. | |
| static int | ata_poll (struct ata_drive *drive, int advanced_check) |
| Waits until a drive is done with what it was doing (BSY clears). | |
| void | ata_reset (struct ata_drive *drive) |
| Resets both drives on a drive's channel, and waits until they are done. | |
| 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, and waits for the drive to take it. | |
| 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 | pio_init (struct ata_drive *drive) |
| Sets a drive up for PIO, and resets its channel. | |
| int | dma_init (struct ata_drive *drive) |
| Sets a drive up for DMA, if both the drive and its channel's controller can do it. | |
| void | dma_irq (struct ata_channel *channel) |
| Handles a channel's interrupt. | |
| #define ATA_CAP_DMA 0x100 |
Definition at line 95 of file ata.h.
Referenced by dma_init().
| #define ATA_CAP_LBA 0x200 |
Definition at line 96 of file ata.h.
Referenced by pio_read_sectors(), and pio_write_sectors().
| #define ATA_CMD_CACHE_FLUSH 0xE7 |
Definition at line 53 of file ata.h.
Referenced by pio_flush().
| #define ATA_CMD_CACHE_FLUSH_EXT 0xEA |
Definition at line 54 of file ata.h.
Referenced by pio_flush().
| #define ATA_CMD_IDENTIFY 0xEC |
Definition at line 57 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_CMD_IDENTIFY_PACKET 0xA1 |
Definition at line 56 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_CMD_READ_DMA 0xC8 |
Definition at line 49 of file ata.h.
Referenced by dma_transfer().
| #define ATA_CMD_READ_DMA_EXT 0x25 |
Definition at line 50 of file ata.h.
Referenced by dma_transfer().
| #define ATA_CMD_READ_SECTORS 0x20 |
Definition at line 45 of file ata.h.
Referenced by pio_read_sectors().
| #define ATA_CMD_READ_SECTORS_EXT 0x24 |
Definition at line 46 of file ata.h.
Referenced by pio_read_sectors().
| #define ATA_CMD_RESET 0x04 |
Definition at line 44 of file ata.h.
Referenced by ata_reset().
| #define ATA_CMD_WRITE_DMA 0xCA |
Definition at line 51 of file ata.h.
Referenced by dma_transfer().
| #define ATA_CMD_WRITE_DMA_EXT 0x35 |
Definition at line 52 of file ata.h.
Referenced by dma_transfer().
| #define ATA_CMD_WRITE_SECTORS 0x30 |
Definition at line 47 of file ata.h.
Referenced by pio_write_sectors().
| #define ATA_CMD_WRITE_SECTORS_EXT 0x34 |
Definition at line 48 of file ata.h.
Referenced by pio_write_sectors().
| #define ATA_ERROR_ABRT 0x004 |
Definition at line 77 of file ata.h.
Referenced by ata_error_string(), and ata_poll().
| #define ATA_ERROR_AMNF 0x001 |
Definition at line 79 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_BBK 0x080 |
Definition at line 72 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_IDNF 0x010 |
Definition at line 75 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_MC 0x020 |
Definition at line 74 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_MCR 0x008 |
Definition at line 76 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_TK0NF 0x002 |
Definition at line 78 of file ata.h.
Referenced by ata_error_string().
| #define ATA_ERROR_UNC 0x040 |
Definition at line 73 of file ata.h.
Referenced by ata_error_string().
| #define ATA_IDENT_CAPABILITIES 98 |
Definition at line 88 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_IDENT_COMMANDSETS 164 |
Definition at line 91 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_IDENT_DEVICETYPE 0 |
Definition at line 82 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_IDENT_MAX_LBA 120 |
Definition at line 90 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_IDENT_MAX_LBA_EXT 200 |
Definition at line 92 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_IDENT_MODEL 54 |
Definition at line 87 of file ata.h.
Referenced by ata_detect_drive().
| #define ATA_MODE_LBA28 0x20 |
Definition at line 100 of file ata.h.
Referenced by ata_detect_drive(), and ata_select_drive().
| #define ATA_MODE_LBA48 0x40 |
Definition at line 101 of file ata.h.
Referenced by ata_detect_drive(), ata_select_drive(), ata_setup(), dma_transfer(), pio_flush(), pio_read_sectors(), and pio_write_sectors().
| #define ATA_PIO_PRI_PORT_BASE 0x1F0 |
Definition at line 19 of file ata.h.
Referenced by ata_probe().
| #define ATA_PIO_PRI_PORT_CONTROL 0x3F6 |
Definition at line 20 of file ata.h.
Referenced by ata_probe().
| #define ATA_PIO_SEC_PORT_BASE 0x170 |
Definition at line 21 of file ata.h.
Referenced by ata_probe().
| #define ATA_PIO_SEC_PORT_CONTROL 0x376 |
Definition at line 22 of file ata.h.
Referenced by ata_probe().
| #define ATA_REG_CMD 0x07 |
Definition at line 33 of file ata.h.
Referenced by ata_detect_drive(), dma_transfer(), pio_flush(), pio_read_sectors(), and pio_write_sectors().
| #define ATA_REG_DATA 0x00 |
Definition at line 25 of file ata.h.
Referenced by ata_detect_drive(), pio_read_sectors(), and pio_write_sectors().
| #define ATA_REG_ERROR 0x01 |
Definition at line 26 of file ata.h.
Referenced by ata_poll(), and ata_setup().
| #define ATA_REG_HDDEVSEL 0x06 |
Definition at line 32 of file ata.h.
Referenced by ata_reset(), ata_select_drive(), and ata_setup().
| #define ATA_REG_LBA0 0x03 |
Definition at line 29 of file ata.h.
Referenced by ata_setup().
| #define ATA_REG_LBA1 0x04 |
Definition at line 30 of file ata.h.
Referenced by ata_detect_drive(), ata_drive_present(), and ata_setup().
| #define ATA_REG_LBA2 0x05 |
Definition at line 31 of file ata.h.
Referenced by ata_detect_drive(), ata_drive_present(), and ata_setup().
| #define ATA_REG_SECCOUNT0 0x02 |
Definition at line 28 of file ata.h.
Referenced by ata_setup().
| #define ATA_REG_STATUS 0x07 |
Definition at line 34 of file ata.h.
Referenced by ata_detect_drive(), ata_drive_present(), ata_poll(), dma_complete(), and dma_irq().
| #define ATA_STATUS_BSY 0x80 |
Definition at line 62 of file ata.h.
Referenced by ata_drive_present(), ata_poll(), and ata_reset().
| #define ATA_STATUS_DF 0x20 |
Definition at line 64 of file ata.h.
Referenced by ata_poll(), and dma_transfer().
| #define ATA_STATUS_DRDY 0x40 |
Definition at line 63 of file ata.h.
Referenced by ata_drive_present().
| #define ATA_STATUS_DRQ 0x08 |
Definition at line 66 of file ata.h.
Referenced by ata_poll().
| #define ATA_STATUS_ERR 0x01 |
Definition at line 69 of file ata.h.
Referenced by ata_poll(), and dma_transfer().
| #define ATA_TIMEOUT 1000000 |
Definition at line 180 of file ata.h.
Referenced by ata_poll(), and ata_reset().
| #define ATADEV_NOTFOUND 0x001 |
Definition at line 12 of file ata.h.
Referenced by ata_detect_drive(), and ata_probe().
| #define ATADEV_PATA 0x002 |
Definition at line 13 of file ata.h.
Referenced by ata_detect_drive(), and ata_probe().
| #define ATADEV_PATAPI 0x004 |
Definition at line 15 of file ata.h.
Referenced by ata_detect_drive(), and ata_probe().
| #define ATADEV_SATA 0x003 |
Definition at line 14 of file ata.h.
Referenced by ata_detect_drive(), and ata_probe().
| #define ATADEV_SATAPI 0x005 |
Definition at line 16 of file ata.h.
Referenced by ata_detect_drive(), and ata_probe().
| #define ATADEV_UNKNOWN 0x000 |
Definition at line 11 of file ata.h.
Referenced by ata_detect_drive().
|
static |
Returns the name of an error, from the error register.
Definition at line 153 of file ata.h.
References ATA_ERROR_ABRT, ATA_ERROR_AMNF, ATA_ERROR_BBK, ATA_ERROR_IDNF, ATA_ERROR_MC, ATA_ERROR_MCR, ata_error_string(), ATA_ERROR_TK0NF, and ATA_ERROR_UNC.
Referenced by ata_error_string(), and ata_poll().
|
static |
Waits until a drive is done with what it was doing (BSY clears).
With advanced_check, it also checks that the drive is ready for data (DRQ) and not in error. Returns 0, -ETIMEDOUT if the drive stays busy, -EAGAIN if it aborted the command (which may be tried again), or -EIO for any other error.
Definition at line 189 of file ata.h.
References ATA_ERROR_ABRT, ata_error_string(), ATA_REG_ERROR, ATA_REG_STATUS, ATA_STATUS_BSY, ATA_STATUS_DF, ATA_STATUS_DRQ, ATA_STATUS_ERR, ATA_TIMEOUT, ata_wait(), ata_drive::base, io_in8(), and printk().
| void ata_reset | ( | struct ata_drive * | drive | ) |
Resets both drives on a drive's channel, and waits until they are done.
| drive | a drive on the channel |
Definition at line 97 of file ata.c.
References ATA_CMD_RESET, ATA_REG_HDDEVSEL, ata_reset(), ATA_STATUS_BSY, ATA_TIMEOUT, ata_drive::base, ata_drive::ctrl, io_in8(), io_out8(), last_selected_drive, last_selected_mode, and NULL.
Referenced by ata_detect_drive(), ata_reset(), and pio_init().
Selects a drive on its channel, for an addressing mode, if it isn't selected so already, and waits for the drive to take it.
| drive | the drive |
| mode | the addressing mode (ATA_MODE_*), or 0 to detect it |
Definition at line 126 of file ata.c.
References ATA_MODE_LBA28, ATA_MODE_LBA48, ATA_REG_HDDEVSEL, ata_select_drive(), ata_drive::base, io_out8(), last_selected_drive, last_selected_mode, ata_drive::mode, and ata_drive::slave.
Referenced by ata_detect_drive(), ata_select_drive(), ata_setup(), and pio_flush().
Writes the registers of a command on count sectors from lba: the drive, the address and the count.
The command itself is sent after.
| drive | the drive |
| lba | the first sector |
| count | how many sectors |
Definition at line 155 of file ata.c.
References ATA_MODE_LBA48, ATA_REG_ERROR, ATA_REG_HDDEVSEL, ATA_REG_LBA0, ATA_REG_LBA1, ATA_REG_LBA2, ATA_REG_SECCOUNT0, ata_select_drive(), ata_setup(), ata_drive::base, io_out8(), ata_drive::mode, and ata_drive::slave.
Referenced by ata_setup(), dma_transfer(), pio_read_sectors(), and pio_write_sectors().
|
static |
Waits about 400 ns, as a drive needs after a command, by reading the alternate status register four times.
Definition at line 170 of file ata.h.
References ata_drive::ctrl, and io_in8().
Referenced by ata_poll().
| int dma_init | ( | struct ata_drive * | drive | ) |
Sets a drive up for DMA, if both the drive and its channel's controller can do it.
| drive | the drive |
Definition at line 195 of file dma.c.
References ioaddr::addr, ATA_CAP_DMA, ata_channel::bm, ata_drive::capabilities, ata_drive::channel, dma_init(), dma_read(), dma_write(), ata_drive::read, and ata_drive::write.
Referenced by ata_probe(), and dma_init().
| void dma_irq | ( | struct ata_channel * | ch | ) |
Handles a channel's interrupt.
If it ends a DMA transfer, the request waiting for it wakes up; otherwise (PIO polls) reading the drive's status acknowledges it.
| ch | the channel |
Definition at line 76 of file dma.c.
References ioaddr::addr, ATA_REG_STATUS, ata_channel::base, ata_channel::bm, BM_ST_IRQ, BM_STATUS, dma_complete(), dma_irq(), io_in8(), ata_channel::irq_wait, and waitq_wakeup_nopoll().
| void pio_init | ( | struct ata_drive * | drive | ) |
Sets a drive up for PIO, and resets its channel.
| drive | the drive |
Definition at line 182 of file pio.c.
References ata_reset(), ata_drive::flush, pio_flush(), pio_init(), pio_read(), pio_write(), ata_drive::read, and ata_drive::write.
Referenced by ata_probe(), and pio_init().