1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/types.h>
6
7typedef enum
8{
9 INIT_TARGET_POST_MM, // Post memory management
10 INIT_TARGET_SLAB_AUTOINIT, // Slab allocator
11 INIT_TARGET_POWER, // Power management subsystem
12 INIT_TARGET_PRE_VFS, // Pre-virtual file system
13 INIT_TARGET_VFS, // Virtual file system
14 INIT_TARGET_SYSFS, // sysfs filesystem
15 INIT_TARGET_KTHREAD, // Kernel threads
16} init_target_t;
17
18typedef struct
19{
20 const char *param;
21 bool (*hook)(const char *arg);
22} mos_cmdline_hook_t;
23
24typedef struct
25{
26 init_target_t target;
27 void (*init_fn)(void);
28} mos_init_t;
29
30#define MOS_EARLY_SETUP(_param, _fn) \
31 static bool _fn(const char *arg); \
32 MOS_PUT_IN_SECTION(".mos.early_setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn }); \
33 static bool _fn(const char *arg)
34
35#define MOS_SETUP(_param, _fn) \
36 static bool _fn(const char *arg); \
37 MOS_PUT_IN_SECTION(".mos.setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn }); \
38 static bool _fn(const char *arg)
39
40#define MOS_INIT(_comp, _fn) \
41 static void _fn(void); \
42 MOS_PUT_IN_SECTION(".mos.init", mos_init_t, __init_##_fn, { .target = INIT_TARGET_##_comp, .init_fn = _fn }); \
43 static void _fn(void)
44
45__BEGIN_DECLS
46
47void startup_invoke_cmdline_hooks(void);
48void startup_invoke_early_cmdline_hooks(void);
49void startup_invoke_autoinit(init_target_t target);
50
51__END_DECLS
52