swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <kint.h> |
| 4 | |
| 5 | /** |
| 6 | * ATA PIO Driver for Bluejay. This should be replaced by a proper |
| 7 | * ATAPI driver later on, but for now this will do. It is going to |
| 8 | * be horribly slow by virtue of having to pass all data through |
| 9 | * in() and out(). |
| 10 | */ |
| 11 | |
| 12 | // status codes |
| 13 | enum |
| 14 | { |
| 15 | ATA_BSY = 0x80, // Busy |
| 16 | ATA_RDY = 0x40, // Ready for command |
| 17 | ATA_DRQ = 0x08, // Ready for data |
| 18 | ATA_DF = 0x20, |
| 19 | ATA_ERR = 0x01, // Error code placed in error register |
| 20 | }; |
| 21 | |
| 22 | // IO ports |
| 23 | enum |
| 24 | { |
| 25 | ATA_PORT_CMD = 0x1f7, |
| 26 | ATA_PORT_DATA = 0x1f0, |
| 27 | ATA_PORT_DRIVE_SEL = 0x1f6, |
| 28 | ATA_PORT_SECTOR_COUNT = 0x1f2, |
| 29 | ATA_PORT_LBA_LOW, |
| 30 | ATA_PORT_LBA_MID, |
| 31 | ATA_PORT_LBA_HIGH, |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 32 | ATA_PORT_STATUS = ATA_PORT_CMD, |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | // Commands |
| 36 | enum |
| 37 | { |
swissChili | 45df330 | 2021-06-30 20:47:51 -0700 | [diff] [blame] | 38 | /// Do not retry |
| 39 | ATA_CMD_READ = 0x21, |
| 40 | /// Do not retry |
| 41 | ATA_CMD_WRITE = 0x31, |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 42 | ATA_CMD_IDENTIFY = 0xec, |
swissChili | 45df330 | 2021-06-30 20:47:51 -0700 | [diff] [blame] | 43 | ATA_CMD_FLUSH_CACHE = 0xe7, |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | void ata_pio_wait_bsy(); |
| 47 | void ata_pio_wait_drq(); |
swissChili | 83db6fd | 2021-04-05 21:32:49 -0700 | [diff] [blame] | 48 | void ata_pio_read_sectors(void *buffer, uint lba, uchar num_sectors); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 49 | void ata_pio_write_sectors(uint lba, uchar num_sectors, ushort *buffer); |
swissChili | 83db6fd | 2021-04-05 21:32:49 -0700 | [diff] [blame] | 50 | uint ata_pio_get_error(); |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 51 | |
| 52 | void test_ata_pio(); |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 53 | |
swissChili | 45df330 | 2021-06-30 20:47:51 -0700 | [diff] [blame] | 54 | void init_ata_pio(); |