feat: (ahci) support multiple AHCI controller
[lunaix-os.git] / lunaix-os / includes / lunaix / block.h
1 #ifndef __LUNAIX_BLOCK_H
2 #define __LUNAIX_BLOCK_H
3
4 #include <hal/ahci/hba.h>
5 #include <lunaix/blkio.h>
6 #include <lunaix/device.h>
7
8 #define LPT_SIG 0x414e554c
9 #define PARTITION_NAME_SIZE 48
10 #define DEV_ID_SIZE 32
11
12 struct block_dev
13 {
14     struct llist_header parts;
15     struct blkio_context* blkio;
16     struct device* dev;
17     char bdev_id[DEV_ID_SIZE];
18     char name[PARTITION_NAME_SIZE];
19     void* driver;
20     u64_t start_lba;
21     u64_t end_lba;
22     u32_t blk_size;
23 };
24
25 // Lunaix Partition Table
26 struct lpt_header
27 {
28     u32_t signature;
29     u32_t crc;
30     u32_t pt_start_lba;
31     u32_t pt_end_lba;
32     u32_t table_len;
33 } __attribute__((packed));
34
35 typedef u64_t partition_t;
36 typedef uint32_t bdev_t;
37 typedef void (*devfs_exporter)(struct block_dev* bdev, void* fsnode);
38
39 void
40 block_init();
41
42 struct block_dev*
43 block_alloc_dev(const char* blk_id, void* driver, req_handler ioreq_handler);
44
45 int
46 block_mount(struct block_dev* bdev, devfs_exporter export);
47
48 void
49 blk_mapping_init();
50
51 void
52 blk_set_blkmapping(struct block_dev* bdev, void* fsnode);
53
54 struct block_dev*
55 blk_mount_part(struct block_dev* bdev,
56                const char* name,
57                size_t index,
58                u64_t start_lba,
59                u64_t end_lba);
60
61 #endif /* __LUNAIX_BLOCK_H */