kexts: ahci: refactor driver
This commit is contained in:
@@ -2,7 +2,13 @@
|
||||
#define _AHCI_H_
|
||||
|
||||
#include <socks/compiler.h>
|
||||
#include <socks/status.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct driver;
|
||||
struct device;
|
||||
struct iovec;
|
||||
|
||||
#define SATA_SIG_ATA 0x00000101 // SATA drive
|
||||
#define SATA_SIG_ATAPI 0xEB140101 // SATAPI drive
|
||||
@@ -36,6 +42,9 @@
|
||||
#define SCSI_CMD_READ 0xA8u
|
||||
#define SCSI_CMD_READ_CAPACITY 0x25u
|
||||
|
||||
#define ATA_DEV_BUSY 0x80
|
||||
#define ATA_DEV_DRQ 0x08
|
||||
|
||||
enum fis_type {
|
||||
FIS_TYPE_REG_H2D = 0x27u,
|
||||
FIS_TYPE_REG_D2H = 0x34u,
|
||||
@@ -219,13 +228,6 @@ struct scsi_command {
|
||||
} __packed;
|
||||
} __packed;
|
||||
|
||||
/* struct scsi_command /must/ be exactly 16 bytes long, so that it fits properly
|
||||
within struct hba_cmd_table */
|
||||
_Static_assert(sizeof(struct scsi_command) == 16, "ahci: scsi_command must be 16 bytes");
|
||||
_Static_assert(sizeof(struct fis_dma_setup) == 28, "ahci: fis_dma_setup must be 28 bytes");
|
||||
_Static_assert(sizeof(struct fis_pio_setup) == 20, "ahci: fis_pio_set must be 20 bytes");
|
||||
_Static_assert(sizeof(struct fis_reg_d2h) == 20, "ahci: fis_reg_d2h must be 20 bytes");
|
||||
|
||||
struct hba_cmd_table {
|
||||
uint8_t cfis[64];
|
||||
|
||||
@@ -678,4 +680,47 @@ struct scsi_read_capacity_data {
|
||||
uint32_t block_size;
|
||||
} __packed;
|
||||
|
||||
struct rfis_data {
|
||||
struct fis_dma_setup dma_setup;
|
||||
char pad0[4];
|
||||
struct fis_pio_setup pio_setup;
|
||||
char pad1[12];
|
||||
struct fis_reg_d2h reg_d2h;
|
||||
} __packed;
|
||||
|
||||
struct ahci_device {
|
||||
int port_no;
|
||||
int type;
|
||||
volatile struct hba_port *port;
|
||||
|
||||
struct hba_cmd_header cmd_header[32];
|
||||
union {
|
||||
char rfis_data[256];
|
||||
struct rfis_data rfis;
|
||||
};
|
||||
};
|
||||
|
||||
/* struct scsi_command /must/ be exactly 16 bytes long, so that it fits properly
|
||||
within struct hba_cmd_table */
|
||||
_Static_assert(sizeof(struct scsi_command) == 16, "ahci: scsi_command must be 16 bytes");
|
||||
_Static_assert(sizeof(struct fis_dma_setup) == 28, "ahci: fis_dma_setup must be 28 bytes");
|
||||
_Static_assert(sizeof(struct fis_pio_setup) == 20, "ahci: fis_pio_set must be 20 bytes");
|
||||
_Static_assert(sizeof(struct fis_reg_d2h) == 20, "ahci: fis_reg_d2h must be 20 bytes");
|
||||
|
||||
_Static_assert(offsetof(struct rfis_data, dma_setup) == 0, "offsetof dma_setup in rfis_data must be 0x00");
|
||||
_Static_assert(offsetof(struct rfis_data, pio_setup) == 0x20, "offsetof dma_setup in rfis_data must be 0x20");
|
||||
_Static_assert(offsetof(struct rfis_data, reg_d2h) == 0x40, "offsetof dma_setup in rfis_data must be 0x40");
|
||||
|
||||
extern struct driver *ahci_driver(void);
|
||||
|
||||
extern kern_status_t identify_ata_device(struct ahci_device *dev, struct identify_device_data *out);
|
||||
extern kern_status_t identify_atapi_device(struct ahci_device *dev, struct identify_device_data *out);
|
||||
extern kern_status_t send_ata_command(struct ahci_device *dev, unsigned int cmd, struct iovec *vec, size_t nvec);
|
||||
extern kern_status_t send_atapi_command(struct ahci_device *dev, struct scsi_command *cmd, struct iovec *vec, size_t nvec);
|
||||
extern void rebase_ahci_port(struct ahci_device *dev);
|
||||
|
||||
extern void probe_ahci_ports(struct driver *driver, struct device *controller, volatile struct hba_config *abar,
|
||||
void(*callback)(int, struct device *, volatile struct hba_port *, int));
|
||||
extern void create_device_from_ahci_port(int port_no, struct device *controller, volatile struct hba_port *port, int type);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user