ahci: add ahci driver
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
bd02ddc640
commit
105bdb4464
11 changed files with 522 additions and 260 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#define _AHCI_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/sg.h>
|
||||
|
||||
/* Frame information structure (FIS) */
|
||||
#define FIS_REG_H2D 0x27
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
#define ATA_CMD_READ_DMA_EX 0x25
|
||||
#define ATA_CMD_WRITE_DMA_EX 0x35
|
||||
#define ATA_CMD_IDENT 0xEC
|
||||
#define ATA_CMD_IDENTIFY_PACKET 0xA1
|
||||
|
||||
#define SATA_SIG_ATA 0x00000101
|
||||
#define SATA_SIG_ATAPI 0xEB140101
|
||||
|
|
@ -46,203 +48,203 @@
|
|||
|
||||
struct fis_reg_h2d {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 3;
|
||||
uint8_t cmd_mode : 1; /* high: command, low: control */
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 3;
|
||||
u8 cmd_mode : 1; /* high: command, low: control */
|
||||
|
||||
uint8_t command;
|
||||
uint8_t feature_low;
|
||||
u8 command;
|
||||
u8 feature_low;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
u8 lba0;
|
||||
u8 lba1;
|
||||
u8 lba2;
|
||||
u8 device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t feature_high;
|
||||
u8 lba3;
|
||||
u8 lba4;
|
||||
u8 lba5;
|
||||
u8 feature_high;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t icc;
|
||||
uint8_t control;
|
||||
u8 count_low;
|
||||
u8 count_high;
|
||||
u8 icc;
|
||||
u8 control;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t reserved2;
|
||||
u32 reserved2;
|
||||
} PACKED;
|
||||
|
||||
struct fis_reg_d2h {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 2;
|
||||
uint8_t intr : 1;
|
||||
uint8_t reserved2 : 1;
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 2;
|
||||
u8 intr : 1;
|
||||
u8 reserved2 : 1;
|
||||
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
u8 status;
|
||||
u8 error;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
u8 lba0;
|
||||
u8 lba1;
|
||||
u8 lba2;
|
||||
u8 device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t feature_high;
|
||||
u8 lba3;
|
||||
u8 lba4;
|
||||
u8 lba5;
|
||||
u8 feature_high;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t icc;
|
||||
uint8_t control;
|
||||
u8 count_low;
|
||||
u8 count_high;
|
||||
u8 icc;
|
||||
u8 control;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t reserved3;
|
||||
u32 reserved3;
|
||||
} PACKED;
|
||||
|
||||
struct fis_data {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 4;
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 4;
|
||||
|
||||
uint8_t reserved2[2];
|
||||
u8 reserved2[2];
|
||||
|
||||
/* 0x04 */
|
||||
uint32_t data[1]; /* Variable length */
|
||||
u32 data[1]; /* Variable length */
|
||||
} PACKED;
|
||||
|
||||
struct fis_dma_setup {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t data_dir : 1;
|
||||
uint8_t intr : 1;
|
||||
uint8_t auto_act : 1;
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 1;
|
||||
u8 data_dir : 1;
|
||||
u8 intr : 1;
|
||||
u8 auto_act : 1;
|
||||
|
||||
uint16_t reserved2;
|
||||
u16 reserved2;
|
||||
|
||||
/* 0x04 */
|
||||
uint64_t dma_buffer_id;
|
||||
u64 dma_buffer_id;
|
||||
|
||||
/* 0x0C */
|
||||
uint32_t reserved3;
|
||||
u32 reserved3;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t dma_buffer_offset;
|
||||
u32 dma_buffer_offset;
|
||||
|
||||
/* 0x14 */
|
||||
uint32_t transfer_count;
|
||||
u32 transfer_count;
|
||||
|
||||
/* 0x18 */
|
||||
uint32_t reserved4;
|
||||
u32 reserved4;
|
||||
} PACKED;
|
||||
|
||||
struct fis_pio_setup {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t data_dir : 1;
|
||||
uint8_t intr : 1;
|
||||
uint8_t reserved2 : 1;
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 1;
|
||||
u8 data_dir : 1;
|
||||
u8 intr : 1;
|
||||
u8 reserved2 : 1;
|
||||
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
u8 status;
|
||||
u8 error;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t lba0;
|
||||
uint8_t lba1;
|
||||
uint8_t lba2;
|
||||
uint8_t device;
|
||||
u8 lba0;
|
||||
u8 lba1;
|
||||
u8 lba2;
|
||||
u8 device;
|
||||
|
||||
/* 0x08 */
|
||||
uint8_t lba3;
|
||||
uint8_t lba4;
|
||||
uint8_t lba5;
|
||||
uint8_t reserved3;
|
||||
u8 lba3;
|
||||
u8 lba4;
|
||||
u8 lba5;
|
||||
u8 reserved3;
|
||||
|
||||
/* 0x0C */
|
||||
uint8_t count_low;
|
||||
uint8_t count_high;
|
||||
uint8_t reserved4;
|
||||
uint8_t e_status;
|
||||
u8 count_low;
|
||||
u8 count_high;
|
||||
u8 reserved4;
|
||||
u8 e_status;
|
||||
|
||||
/* 0x10 */
|
||||
uint16_t transfer_count;
|
||||
uint16_t reserved5;
|
||||
u16 transfer_count;
|
||||
u16 reserved5;
|
||||
} PACKED;
|
||||
|
||||
struct fis_set_device_bits {
|
||||
/* 0x00 */
|
||||
uint8_t fis_type;
|
||||
u8 fis_type;
|
||||
|
||||
uint8_t pmult : 4;
|
||||
uint8_t reserved : 2;
|
||||
uint8_t interrupt : 1;
|
||||
uint8_t n : 1;
|
||||
u8 pmult : 4;
|
||||
u8 reserved : 2;
|
||||
u8 interrupt : 1;
|
||||
u8 n : 1;
|
||||
|
||||
uint8_t statusl : 3;
|
||||
uint8_t reserved2 : 1;
|
||||
uint8_t statush : 3;
|
||||
uint8_t reserved3 : 1;
|
||||
u8 statusl : 3;
|
||||
u8 reserved2 : 1;
|
||||
u8 statush : 3;
|
||||
u8 reserved3 : 1;
|
||||
|
||||
/* 0x04 */
|
||||
uint8_t errorl : 3;
|
||||
u8 errorl : 3;
|
||||
} PACKED;
|
||||
|
||||
struct hba_cmd_header {
|
||||
uint8_t cmd_fis_len : 5;
|
||||
uint8_t atapi : 1;
|
||||
uint8_t write : 1;
|
||||
uint8_t prefetch : 1;
|
||||
u8 cmd_fis_len : 5;
|
||||
u8 atapi : 1;
|
||||
u8 write : 1;
|
||||
u8 prefetch : 1;
|
||||
|
||||
uint8_t reset : 1;
|
||||
uint8_t bist : 1;
|
||||
uint8_t clear_busy : 1;
|
||||
uint8_t reserved : 1;
|
||||
uint8_t pmp : 4;
|
||||
u8 reset : 1;
|
||||
u8 bist : 1;
|
||||
u8 clear_busy : 1;
|
||||
u8 reserved : 1;
|
||||
u8 pmp : 4;
|
||||
|
||||
uint16_t prdt_len;
|
||||
u16 prdt_len;
|
||||
|
||||
volatile uint32_t prdb_count;
|
||||
volatile u32 prdb_count;
|
||||
|
||||
paddr_t cmd_table_base;
|
||||
|
||||
uint32_t reserved2[4];
|
||||
u32 reserved2[4];
|
||||
} PACKED;
|
||||
|
||||
struct hba_prdt_entry {
|
||||
paddr_t data_base;
|
||||
|
||||
uint32_t reserved;
|
||||
u32 reserved;
|
||||
|
||||
uint32_t byte_count : 22;
|
||||
uint32_t reserved2 : 9;
|
||||
uint32_t interrupt : 1;
|
||||
u32 byte_count : 22;
|
||||
u32 reserved2 : 9;
|
||||
u32 interrupt : 1;
|
||||
} PACKED;
|
||||
|
||||
struct hba_cmd_tbl {
|
||||
uint8_t cfis[64];
|
||||
u8 cfis[64];
|
||||
|
||||
uint8_t acmd[16];
|
||||
u8 acmd[16];
|
||||
|
||||
uint8_t reserved[48];
|
||||
u8 reserved[48];
|
||||
|
||||
struct hba_prdt_entry prdt_entry[1];
|
||||
} PACKED;
|
||||
|
|
@ -254,53 +256,53 @@ typedef volatile struct {
|
|||
paddr_t fb;
|
||||
|
||||
/* 0x10 */
|
||||
uint32_t is;
|
||||
uint32_t ie;
|
||||
uint32_t cmd;
|
||||
uint32_t reserved;
|
||||
u32 is;
|
||||
u32 ie;
|
||||
u32 cmd;
|
||||
u32 reserved;
|
||||
|
||||
/* 0x20 */
|
||||
uint32_t tfd;
|
||||
uint32_t sig;
|
||||
uint32_t ssts;
|
||||
uint32_t sctl;
|
||||
u32 tfd;
|
||||
u32 sig;
|
||||
u32 ssts;
|
||||
u32 sctl;
|
||||
|
||||
/* 0x30 */
|
||||
uint32_t serr;
|
||||
uint32_t sact;
|
||||
uint32_t ci;
|
||||
uint32_t sntf;
|
||||
u32 serr;
|
||||
u32 sact;
|
||||
u32 ci;
|
||||
u32 sntf;
|
||||
|
||||
/* 0x40 */
|
||||
uint32_t fbs;
|
||||
u32 fbs;
|
||||
|
||||
uint32_t reserved1[11];
|
||||
uint32_t vendor[4];
|
||||
u32 reserved1[11];
|
||||
u32 vendor[4];
|
||||
} PACKED hbaport_t;
|
||||
|
||||
typedef volatile struct {
|
||||
/* 0x00 */
|
||||
uint32_t cap;
|
||||
uint32_t ghc;
|
||||
uint32_t is;
|
||||
uint32_t pi;
|
||||
uint32_t vs;
|
||||
u32 cap;
|
||||
u32 ghc;
|
||||
u32 is;
|
||||
u32 pi;
|
||||
u32 vs;
|
||||
|
||||
/* 0x14 */
|
||||
uint32_t ccc_ctl;
|
||||
uint32_t ccc_ports;
|
||||
uint32_t em_loc;
|
||||
uint32_t em_ctl;
|
||||
uint32_t cap2;
|
||||
u32 ccc_ctl;
|
||||
u32 ccc_ports;
|
||||
u32 em_loc;
|
||||
u32 em_ctl;
|
||||
u32 cap2;
|
||||
|
||||
/* 0x28 */
|
||||
uint32_t bohc;
|
||||
u32 bohc;
|
||||
|
||||
/* 0x2C */
|
||||
uint8_t reserved[0x74];
|
||||
u8 reserved[0x74];
|
||||
|
||||
/* 0xA0 */
|
||||
uint8_t vendor[0x60];
|
||||
u8 vendor[0x60];
|
||||
|
||||
/* 0x100 */
|
||||
hbaport_t ports[32];
|
||||
|
|
@ -309,38 +311,98 @@ typedef volatile struct {
|
|||
typedef volatile struct {
|
||||
/* 0x00 */
|
||||
struct fis_dma_setup dfis;
|
||||
uint32_t reserved;
|
||||
u32 reserved;
|
||||
|
||||
/* 0x20 */
|
||||
struct fis_pio_setup pfis;
|
||||
uint32_t reserved1[3];
|
||||
u32 reserved1[3];
|
||||
|
||||
/* 0x40 */
|
||||
struct fis_reg_d2h rfis;
|
||||
uint32_t reserved2;
|
||||
u32 reserved2;
|
||||
|
||||
struct fis_set_device_bits sdbfis;
|
||||
|
||||
/* 0x60 */
|
||||
uint8_t ufis[64];
|
||||
u8 ufis[64];
|
||||
|
||||
/* 0xA0 */
|
||||
uint8_t reserved3[0x60];
|
||||
u8 reserved3[0x60];
|
||||
|
||||
} PACKED hbafis_t;
|
||||
|
||||
struct ahci_host {
|
||||
struct pci_device *device;
|
||||
struct pci_device *device;
|
||||
hbamem_t *abar;
|
||||
};
|
||||
|
||||
struct ahci_identify {
|
||||
u16 config_flags;
|
||||
u16 cylinders_obsolete;
|
||||
u16 specific_config;
|
||||
u16 heads_obsolete;
|
||||
u16 reserved1[2];
|
||||
u16 sectors_obsolete;
|
||||
u16 reserved_for_compact[3];
|
||||
u8 serial_number[20];
|
||||
u16 buffer_type_obsolete;
|
||||
u16 buffer_size_obsolete;
|
||||
u16 ecc_bytes_obsolete;
|
||||
u8 firmware_revision[8];
|
||||
u8 model_number[40];
|
||||
u16 max_multiple_sectors;
|
||||
u16 trusted_computing;
|
||||
u32 capabilities;
|
||||
u16 obsolescent_word51;
|
||||
u16 obsolescent_word52;
|
||||
u16 field_validity;
|
||||
u16 current_cylinders;
|
||||
u16 current_heads;
|
||||
u16 current_sectors;
|
||||
u32 current_capacity_sectors;
|
||||
u16 multiple_sector_setting;
|
||||
u32 total_lba28_sectors;
|
||||
u16 double_word_dma_obsolete;
|
||||
u16 multiword_dma_settings;
|
||||
u16 advanced_pio_modes;
|
||||
u16 min_mwdma_cycle_time;
|
||||
u16 rec_mwdma_cycle_time;
|
||||
u16 min_pio_cycle_no_flow;
|
||||
u16 min_pio_cycle_flow;
|
||||
u16 reserved2[2];
|
||||
u16 reserved_packet_dev[4];
|
||||
u16 queue_depth;
|
||||
u16 serial_ata_capabilities;
|
||||
u16 reserved_sata;
|
||||
u16 serial_ata_features;
|
||||
u16 serial_ata_features_en;
|
||||
u16 major_version;
|
||||
u16 minor_version;
|
||||
u16 cmd_set_supported1;
|
||||
u16 cmd_set_supported2;
|
||||
u16 cmd_set_supported3;
|
||||
u16 cmd_set_enabled1;
|
||||
u16 cmd_set_enabled2;
|
||||
u16 cmd_set_enabled3;
|
||||
u16 ultra_dma_modes;
|
||||
u16 reserved3[11];
|
||||
u64 total_lba48_sectors;
|
||||
u16 streaming_transfer_time;
|
||||
u16 reserved4;
|
||||
u64 physical_logical_sectors;
|
||||
u16 reserved5[15];
|
||||
u16 data_structure_checksum;
|
||||
u16 reserved6[130];
|
||||
} PACKED;
|
||||
|
||||
struct sata_device {
|
||||
struct ahci_host *host;
|
||||
char name[16];
|
||||
struct ahci_host *host;
|
||||
uint8_t port;
|
||||
size_t sector_size;
|
||||
size_t sector_count;
|
||||
char model[41];
|
||||
int media_type;
|
||||
};
|
||||
|
||||
int ahci_access_sectors(struct sata_device *dev, paddr_t lba, uint16_t count, paddr_t buf, bool write);
|
||||
|
||||
#endif /* _AHCI_H_ */
|
||||
|
|
|
|||
Loading…
Reference in a new issue