Boot framework rework (#45)
[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     size_t msize;
32     struct
33     {
34         size_t size;
35         struct boot_mmapent* mmap;
36         size_t mmap_len;
37     } mem;
38
39     struct
40     {
41         struct {
42             char* cmdline;
43             size_t len;
44         };
45
46         ptr_t dtb_pa;
47     } kexec;
48
49     struct
50     {
51         size_t mods_num;
52         struct boot_modent* entries;
53     } mods;
54
55     void (*release)(struct boot_handoff*);
56     void (*prepare)(struct boot_handoff*);
57
58     // XXX: should arch specific boot detect platform interface provider?
59 };
60
61 #ifndef __BOOT_CODE__
62 void
63 boot_begin(struct boot_handoff*);
64
65 void
66 boot_parse_cmdline(struct boot_handoff*);
67
68 void
69 boot_end(struct boot_handoff*);
70
71 void
72 boot_begin_arch_reserve(struct boot_handoff*);
73
74 void
75 boot_clean_arch_reserve(struct boot_handoff*);
76
77 static inline bool
78 free_memregion(struct boot_mmapent* mmapent)
79 {
80     return !mmapent->type;
81 }
82
83 static inline bool
84 reserved_memregion(struct boot_mmapent* mmapent)
85 {
86     return !!(mmapent->type & BOOT_MMAP_RSVD);
87 }
88
89 static inline bool
90 reclaimable_memregion(struct boot_mmapent* mmapent)
91 {
92     return !!(mmapent->type & BOOT_MMAP_RCLM);
93 }
94
95 #endif
96
97 #endif /* __LUNAIX_BOOT_GENERIC_H */