1 /*
2 * Copyright (c) 2013-2015 Travis Geiselbrecht
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8 #pragma once
9
10 #include <lk/compiler.h>
11 #include <sys/types.h>
12
13 __BEGIN_CDECLS
14
15 /*
16 * LK's init system
17 */
18
19 typedef void (*lk_init_hook)(uint level);
20
21 enum lk_init_level {
22 LK_INIT_LEVEL_EARLIEST = 1,
23
24 LK_INIT_LEVEL_ARCH_EARLY = 0x10000,
25 LK_INIT_LEVEL_PLATFORM_EARLY = 0x20000,
26 LK_INIT_LEVEL_TARGET_EARLY = 0x30000,
27 LK_INIT_LEVEL_HEAP = 0x40000,
28 LK_INIT_LEVEL_VM = 0x50000,
29 LK_INIT_LEVEL_KERNEL = 0x60000,
30 LK_INIT_LEVEL_THREADING = 0x70000,
31 LK_INIT_LEVEL_ARCH = 0x80000,
32 LK_INIT_LEVEL_PLATFORM = 0x90000,
33 LK_INIT_LEVEL_TARGET = 0xa0000,
34 LK_INIT_LEVEL_APPS = 0xb0000,
35
36 LK_INIT_LEVEL_LAST = UINT_MAX,
37 };
38
39 enum lk_init_flags {
40 LK_INIT_FLAG_PRIMARY_CPU = 0x1,
41 LK_INIT_FLAG_SECONDARY_CPUS = 0x2,
42 LK_INIT_FLAG_ALL_CPUS = LK_INIT_FLAG_PRIMARY_CPU | LK_INIT_FLAG_SECONDARY_CPUS,
43 LK_INIT_FLAG_CPU_SUSPEND = 0x4,
44 LK_INIT_FLAG_CPU_RESUME = 0x8,
45 };
46
47 void lk_init_level(enum lk_init_flags flags, uint start_level, uint stop_level);
48
lk_primary_cpu_init_level(uint start_level,uint stop_level)49 static inline void lk_primary_cpu_init_level(uint start_level, uint stop_level) {
50 lk_init_level(LK_INIT_FLAG_PRIMARY_CPU, start_level, stop_level);
51 }
52
lk_init_level_all(enum lk_init_flags flags)53 static inline void lk_init_level_all(enum lk_init_flags flags) {
54 lk_init_level(flags, LK_INIT_LEVEL_EARLIEST, LK_INIT_LEVEL_LAST);
55 }
56
57 struct lk_init_struct {
58 uint level;
59 uint flags;
60 lk_init_hook hook;
61 const char *name;
62 };
63
64 #define LK_INIT_HOOK_FLAGS(_name, _hook, _level, _flags) \
65 const struct lk_init_struct _init_struct_##_name __ALIGNED(sizeof(void *)) __SECTION("lk_init") = { \
66 .level = _level, \
67 .flags = _flags, \
68 .hook = _hook, \
69 .name = #_name, \
70 };
71
72 #define LK_INIT_HOOK(_name, _hook, _level) \
73 LK_INIT_HOOK_FLAGS(_name, _hook, _level, LK_INIT_FLAG_PRIMARY_CPU)
74
75 __END_CDECLS
76