diff options
author | Ian McFarlane <i.mcfarlane2002@gmail.com> | 2025-04-20 23:18:35 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-20 23:44:40 -0400 |
commit | 89c356d659016ca3d7d5ebfb2f1a0f605fec3820 (patch) | |
tree | 8f15218f47b911d39a12cb67a6ae3f198b90e087 /kernel/include/comus/drivers/ata.h | |
parent | make stuff public (diff) | |
download | comus-89c356d659016ca3d7d5ebfb2f1a0f605fec3820.tar.gz comus-89c356d659016ca3d7d5ebfb2f1a0f605fec3820.tar.bz2 comus-89c356d659016ca3d7d5ebfb2f1a0f605fec3820.zip |
refactor ATA interface
Diffstat (limited to '')
-rw-r--r-- | kernel/include/comus/drivers/ata.h | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/kernel/include/comus/drivers/ata.h b/kernel/include/comus/drivers/ata.h index 5f97df3..66b3ba5 100644 --- a/kernel/include/comus/drivers/ata.h +++ b/kernel/include/comus/drivers/ata.h @@ -11,49 +11,54 @@ #define ATA_H_ #include <stdint.h> +#include <stdbool.h> -struct ide_channel { - uint16_t io_base; - uint16_t control_base; - uint16_t bus_master_ide_base; - uint8_t no_interrupt; -}; +// type intended to be opaque- may be made into a struct in the future +typedef uint8_t ide_device_t; -struct ide_device { - uint8_t is_reserved; // 0 (Empty) or 1 (This Drive really exists). - uint8_t channel_idx; // 0 (Primary Channel) or 1 (Secondary Channel). - uint8_t drive_idx; // 0 (Master Drive) or 1 (Slave Drive). - uint16_t type; // 0: ATA, 1:ATAPI. - uint16_t drive_signature; - uint16_t features; - uint32_t supported_command_sets; - uint32_t size_in_sectors; - uint8_t model_str[41]; +enum ide_error { + IDE_ERROR_OK = 0, + IDE_ERROR_NULL_DEVICE, // device doesnt exist + IDE_ERROR_INIT_NO_IDE_CONTROLLER, + IDE_ERROR_INIT_BAD_HEADER, + IDE_ERROR_POLL_DRIVE_REQUEST_NOT_READY, + IDE_ERROR_POLL_DEVICE_FAULT, + IDE_ERROR_POLL_STATUS_REGISTER_ERROR, + IDE_ERROR_POLL_WRITE_PROTECTED, }; -extern struct ide_channel ide_channels[2]; -extern struct ide_device ide_devices[4]; +struct ide_devicelist { + ide_device_t devices[4]; + uint8_t num_devices; +}; /** * @returns 0 on success, 1 on failure */ -int ata_init(void); +enum ide_error ata_init(void); /** * reads a number of sectors from the provided IDE/ATA device * - * @returns 0 on success or an error code on failure + * @returns IDE_ERROR_OK (0) on success or an error code on failure */ -int ide_device_read_sectors(struct ide_device *dev, uint8_t numsects, - uint32_t lba, uint16_t buf[numsects * 256]); +enum ide_error ide_device_read_sectors(ide_device_t, uint8_t numsects, + uint32_t lba, + uint16_t buf[numsects * 256]); /** * writes a number of sectors to the provided IDE/ATA device * * @returns 0 on success or an error code on failure */ -int ide_device_write_sectors(struct ide_device *dev, uint8_t numsects, - uint32_t lba, uint16_t buf[numsects * 256]); +enum ide_error ide_device_write_sectors(ide_device_t, uint8_t numsects, + uint32_t lba, + uint16_t buf[numsects * 256]); + +/* + * Returns a variable number (between 0-4, inclusive) of ide_devic_t's. + */ +struct ide_devicelist ide_devices_enumerate(void); /** * report all ata devices to console |