feat: ATAPI device capacity probing
[lunaix-os.git] / lunaix-os / hal / ahci / atapi.c
1 #include <hal/ahci/hba.h>
2 #include <hal/ahci/scsi.h>
3 #include <hal/ahci/utils.h>
4
5 #include <klibc/string.h>
6 #include <lunaix/spike.h>
7
8 void
9 scsi_create_packet12(struct scsi_cdb12* cdb,
10                      uint8_t opcode,
11                      uint32_t lba,
12                      uint32_t alloc_size)
13 {
14     memset(cdb, 0, sizeof(*cdb));
15     cdb->opcode = opcode;
16     cdb->lba_be = SCSI_FLIP(lba);
17     cdb->length = alloc_size;
18 }
19
20 void
21 scsi_create_packet16(struct scsi_cdb16* cdb,
22                      uint8_t opcode,
23                      uint32_t lba_hi,
24                      uint32_t lba_lo,
25                      uint32_t alloc_size)
26 {
27     memset(cdb, 0, sizeof(*cdb));
28     cdb->opcode = opcode;
29     cdb->lba_be_hi = SCSI_FLIP(lba_hi);
30     cdb->lba_be_lo = SCSI_FLIP(lba_lo);
31     cdb->length = alloc_size;
32 }
33
34 void
35 scsi_parse_capacity(struct hba_device* device, uint32_t* parameter)
36 {
37     device->max_lba = SCSI_FLIP(*(parameter + 1));
38     device->block_size = SCSI_FLIP(*(parameter + 2));
39 }