fix: incorrect settings of msi registers.
[lunaix-os.git] / lunaix-os / includes / hal / ahci / scsi.h
1 #ifndef __LUNAIX_SCSI_H
2 #define __LUNAIX_SCSI_H
3
4 #include <stdint.h>
5
6 #define SCSI_FLIP(val)                                                         \
7     ((((val)&0x000000ff) << 24) | (((val)&0x0000ff00) << 8) |                  \
8      (((val)&0x00ff0000) >> 8) | (((val)&0xff000000) >> 24))
9
10 #define SCSI_READ_CAPACITY_16 0x9e
11 #define SCSI_READ_CAPACITY_10 0x25
12 #define SCSI_READ_BLOCKS_16 0x88
13 #define SCSI_READ_BLOCKS_12 0xa8
14 #define SCSI_WRITE_BLOCKS_16 0x8a
15 #define SCSI_WRITE_BLOCKS_12 0xaa
16
17 struct scsi_cdb12
18 {
19     uint8_t opcode;
20     uint8_t misc1;
21     uint32_t lba_be;
22     uint32_t length;
23     uint8_t misc2;
24     uint8_t ctrl;
25 } __attribute__((packed));
26
27 struct scsi_cdb16
28 {
29     uint8_t opcode;
30     uint8_t misc1;
31     uint32_t lba_be_hi;
32     uint32_t lba_be_lo;
33     uint32_t length;
34     uint8_t misc2;
35     uint8_t ctrl;
36 } __attribute__((packed));
37
38 void
39 scsi_create_packet12(struct scsi_cdb12* cdb,
40                      uint8_t opcode,
41                      uint32_t lba,
42                      uint32_t alloc_size);
43
44 void
45 scsi_create_packet16(struct scsi_cdb16* cdb,
46                      uint8_t opcode,
47                      uint64_t lba,
48                      uint32_t alloc_size);
49
50 void
51 scsi_read_buffer(struct hba_port* port,
52                  uint64_t lba,
53                  void* buffer,
54                  uint32_t size);
55
56 void
57 scsi_write_buffer(struct hba_port* port,
58                   uint64_t lba,
59                   void* buffer,
60                   uint32_t size);
61
62 #endif /* __LUNAIX_ATAPI_H */