add support to MSI based on either SPI or LPI.
[lunaix-os.git] / lunaix-os / hal / ahci / hbadev_export.c
1 #include <hal/ahci/ahci.h>
2 #include <lunaix/block.h>
3 #include <lunaix/fs/twifs.h>
4
5 void
6 __blk_rd_serial(struct twimap* map)
7 {
8     struct hba_device* hbadev = twimap_data(map, struct hba_device*);
9     twimap_printf(map, "%s", hbadev->serial_num);
10 }
11
12 void
13 __blk_rd_last_status(struct twimap* map)
14 {
15     struct hba_device* hbadev = twimap_data(map, struct hba_device*);
16     twimap_printf(map,
17                   "%p\t%p\t%p",
18                   hbadev->last_result.status,
19                   hbadev->last_result.error,
20                   hbadev->last_result.sense_key);
21 }
22
23 void
24 __blk_rd_capabilities(struct twimap* map)
25 {
26     struct hba_device* hbadev = twimap_data(map, struct hba_device*);
27     twimap_printf(map, "%p", hbadev->capabilities);
28 }
29
30 void
31 __blk_rd_aoffset(struct twimap* map)
32 {
33     struct hba_device* hbadev = twimap_data(map, struct hba_device*);
34     twimap_printf(map, "%d", hbadev->alignment_offset);
35 }
36
37 void
38 __blk_rd_wwid(struct twimap* map)
39 {
40     struct hba_device* hbadev = twimap_data(map, struct hba_device*);
41     u32_t h = hbadev->wwn >> 32;
42     u32_t l = (u32_t)hbadev->wwn;
43     if ((h | l)) {
44         twimap_printf(map, "wwn:%x%x", h, l);
45     } else {
46         twimap_printf(map, "0");
47     }
48 }
49
50 void
51 ahci_fsexport(struct block_dev* bdev, void* fs_node)
52 {
53     struct twifs_node* dev_root = (struct twifs_node*)fs_node;
54     struct twimap* map;
55
56     map = twifs_mapping(dev_root, bdev->driver, "serial");
57     map->read = __blk_rd_serial;
58
59     map = twifs_mapping(dev_root, bdev->driver, "last_status");
60     map->read = __blk_rd_last_status;
61
62     map = twifs_mapping(dev_root, bdev->driver, "wwid");
63     map->read = __blk_rd_wwid;
64
65     map = twifs_mapping(dev_root, bdev->driver, "capabilities");
66     map->read = __blk_rd_capabilities;
67
68     map = twifs_mapping(dev_root, bdev->driver, "alignment_offset");
69     map->read = __blk_rd_aoffset;
70 }