Fix: stale dnode caching instance cause locked-up upon accessing (#52)
[lunaix-os.git] / lunaix-os / includes / lunaix / boot_generic.h
1 #ifndef __LUNAIX_BOOT_GENERIC_H
2 #define __LUNAIX_BOOT_GENERIC_H
3
4 #include <lunaix/types.h>
5
6 // Free memory region
7 #define BOOT_MMAP_FREE 0
8
9 // Reserved memory region
10 #define BOOT_MMAP_RSVD 1
11
12 // Reclaimable memory region
13 #define BOOT_MMAP_RCLM 2
14
15 struct boot_mmapent
16 {
17     ptr_t start;
18     size_t size;
19     int type;
20 };
21
22 struct boot_modent
23 {
24     ptr_t start;
25     ptr_t end;
26     char* str;
27 };
28
29 struct boot_handoff
30 {
31     struct
32     {
33         size_t size;
34         struct boot_mmapent* mmap;
35         size_t mmap_len;
36     } mem;
37
38     struct
39     {
40         struct {
41             char* cmdline;
42             size_t len;
43         };
44
45         ptr_t dtb_pa;
46     } kexec;
47
48     struct
49     {
50         size_t mods_num;
51         struct boot_modent* entries;
52     } mods;
53
54     void (*release)(struct boot_handoff*);
55     void (*prepare)(struct boot_handoff*);
56
57     // XXX: should arch specific boot detect platform interface provider?
58 };
59
60 #ifndef __BOOT_CODE__
61 void
62 boot_begin(struct boot_handoff*);
63
64 void
65 boot_parse_cmdline(struct boot_handoff*);
66
67 void
68 boot_end(struct boot_handoff*);
69
70 void
71 boot_begin_arch_reserve(struct boot_handoff*);
72
73 void
74 boot_clean_arch_reserve(struct boot_handoff*);
75
76 static inline bool
77 free_memregion(struct boot_mmapent* mmapent)
78 {
79     return !mmapent->type;
80 }
81
82 static inline bool
83 reserved_memregion(struct boot_mmapent* mmapent)
84 {
85     return !!(mmapent->type & BOOT_MMAP_RSVD);
86 }
87
88 static inline bool
89 reclaimable_memregion(struct boot_mmapent* mmapent)
90 {
91     return !!(mmapent->type & BOOT_MMAP_RCLM);
92 }
93
94 #endif
95
96 #endif /* __LUNAIX_BOOT_GENERIC_H */