Merge branch 'master' into isa/arm64
[lunaix-os.git] / lunaix-os / includes / hal / ahci / sata.h
1 #ifndef __LUNAIX_SATA_H
2 #define __LUNAIX_SATA_H
3
4 #include <hal/ahci/hba.h>
5
6 #define SATA_REG_FIS_D2H 0x34
7 #define SATA_REG_FIS_H2D 0x27
8 #define SATA_REG_FIS_COMMAND 0x80
9 #define SATA_LBA_COMPONENT(lba, offset) ((((lba) >> (offset)) & 0xff))
10
11 #define ATA_IDENTIFY_DEVICE 0xec
12 #define ATA_IDENTIFY_PAKCET_DEVICE 0xa1
13 #define ATA_PACKET 0xa0
14 #define ATA_READ_DMA_EXT 0x25
15 #define ATA_READ_DMA 0xc8
16 #define ATA_WRITE_DMA_EXT 0x35
17 #define ATA_WRITE_DMA 0xca
18
19 #define MAX_RETRY 2
20
21 struct sata_fis_head
22 {
23     u8_t type;
24     u8_t options;
25     u8_t status_cmd;
26     u8_t feat_err;
27 } __HBA_PACKED__;
28
29 struct sata_reg_fis
30 {
31     struct sata_fis_head head;
32
33     u8_t lba0, lba8, lba16;
34     u8_t dev;
35     u8_t lba24, lba32, lba40;
36     u8_t feature;
37
38     u16_t count;
39
40     u8_t reserved[6];
41 } __HBA_PACKED__;
42
43 struct sata_data_fis
44 {
45     struct sata_fis_head head;
46
47     u8_t data[0];
48 } __HBA_PACKED__;
49
50 void
51 sata_create_fis(struct sata_reg_fis* cmd_fis,
52                 u8_t command,
53                 lba_t lba,
54                 u16_t sector_count);
55
56 void
57 sata_submit(struct hba_device* dev, struct blkio_req* io_req);
58
59 void
60 sata_read_error(struct hba_port* port);
61 #endif /* __LUNAIX_SATA_H */