1 #ifndef _LINUX_INIT_H 2 #define _LINUX_INIT_H 3 4 #include <asm/init.h> 5 6 /* 7 * Mark functions and data as being only used at initialization 8 * or exit time. 9 */ 10 #define __init __text_section(".init.text") 11 #define __exit __text_section(".exit.text") 12 #define __initdata __section(".init.data") 13 #define __initconst __section(".init.rodata") 14 #define __initconstrel __section(".init.rodata.rel") 15 #define __exitdata __used_section(".exit.data") 16 #define __initsetup __used_section(".init.setup") 17 #define __init_call(lvl) __used_section(".initcall" lvl ".init") 18 #define __exit_call __used_section(".exitcall.exit") 19 20 /* These macros are used to mark some functions or 21 * initialized data (doesn't apply to uninitialized data) 22 * as `initialization' functions. The kernel can take this 23 * as hint that the function is used only during the initialization 24 * phase and free up used memory resources after 25 * 26 * Usage: 27 * For functions: 28 * 29 * You should add __init immediately before the function name, like: 30 * 31 * static void __init initme(int x, int y) 32 * { 33 * extern int z; z = x * y; 34 * } 35 * 36 * If the function has a prototype somewhere, you can also add 37 * __init between closing brace of the prototype and semicolon: 38 * 39 * extern int initialize_foobar_device(int, int, int) __init; 40 * 41 * For initialized data: 42 * You should insert __initdata between the variable name and equal 43 * sign followed by value, e.g.: 44 * 45 * static int init_variable __initdata = 0; 46 * static char linux_logo[] __initdata = { 0x32, 0x36, ... }; 47 * 48 * Don't forget to initialize data not at file scope, i.e. within a function, 49 * as gcc otherwise puts the data into the bss section and not into the init 50 * section. 51 * 52 * Also note, that this data cannot be "const". 53 */ 54 55 #ifndef __ASSEMBLY__ 56 57 /* 58 * Used for initialization calls.. 59 */ 60 typedef int (*initcall_t)(void); 61 typedef void (*exitcall_t)(void); 62 63 #define presmp_initcall(fn) \ 64 const static initcall_t __initcall_##fn __init_call("presmp") = fn 65 #define __initcall(fn) \ 66 const static initcall_t __initcall_##fn __init_call("1") = fn 67 #define __exitcall(fn) \ 68 static exitcall_t __exitcall_##fn __exit_call = fn 69 70 void do_presmp_initcalls(void); 71 void do_initcalls(void); 72 73 /* 74 * Used for kernel command line parameter setup 75 */ 76 struct kernel_param { 77 const char *name; 78 enum { 79 OPT_STR, 80 OPT_UINT, 81 OPT_BOOL, 82 OPT_SIZE, 83 OPT_CUSTOM 84 } type; 85 unsigned int len; 86 union { 87 void *var; 88 int (*func)(const char *); 89 } par; 90 }; 91 92 extern const struct kernel_param __setup_start[], __setup_end[]; 93 extern const struct kernel_param __param_start[], __param_end[]; 94 95 #define __dataparam __used_section(".data.param") 96 97 #define __param(att) static const att \ 98 __attribute__((__aligned__(sizeof(void *)))) struct kernel_param 99 100 #define __setup_str static const __initconst \ 101 __attribute__((__aligned__(1))) char 102 #define __kparam __param(__initsetup) 103 104 #define custom_param(_name, _var) \ 105 __setup_str __setup_str_##_var[] = _name; \ 106 __kparam __setup_##_var = \ 107 { .name = __setup_str_##_var, \ 108 .type = OPT_CUSTOM, \ 109 .par.func = _var } 110 #define boolean_param(_name, _var) \ 111 __setup_str __setup_str_##_var[] = _name; \ 112 __kparam __setup_##_var = \ 113 { .name = __setup_str_##_var, \ 114 .type = OPT_BOOL, \ 115 .len = sizeof(_var), \ 116 .par.var = &_var } 117 #define integer_param(_name, _var) \ 118 __setup_str __setup_str_##_var[] = _name; \ 119 __kparam __setup_##_var = \ 120 { .name = __setup_str_##_var, \ 121 .type = OPT_UINT, \ 122 .len = sizeof(_var), \ 123 .par.var = &_var } 124 #define size_param(_name, _var) \ 125 __setup_str __setup_str_##_var[] = _name; \ 126 __kparam __setup_##_var = \ 127 { .name = __setup_str_##_var, \ 128 .type = OPT_SIZE, \ 129 .len = sizeof(_var), \ 130 .par.var = &_var } 131 #define string_param(_name, _var) \ 132 __setup_str __setup_str_##_var[] = _name; \ 133 __kparam __setup_##_var = \ 134 { .name = __setup_str_##_var, \ 135 .type = OPT_STR, \ 136 .len = sizeof(_var), \ 137 .par.var = &_var } 138 139 #define __rtparam __param(__dataparam) 140 141 #define custom_runtime_only_param(_name, _var) \ 142 __rtparam __rtpar_##_var = \ 143 { .name = _name, \ 144 .type = OPT_CUSTOM, \ 145 .par.func = _var } 146 #define boolean_runtime_only_param(_name, _var) \ 147 __rtparam __rtpar_##_var = \ 148 { .name = _name, \ 149 .type = OPT_BOOL, \ 150 .len = sizeof(_var), \ 151 .par.var = &_var } 152 #define integer_runtime_only_param(_name, _var) \ 153 __rtparam __rtpar_##_var = \ 154 { .name = _name, \ 155 .type = OPT_UINT, \ 156 .len = sizeof(_var), \ 157 .par.var = &_var } 158 #define size_runtime_only_param(_name, _var) \ 159 __rtparam __rtpar_##_var = \ 160 { .name = _name, \ 161 .type = OPT_SIZE, \ 162 .len = sizeof(_var), \ 163 .par.var = &_var } 164 #define string_runtime_only_param(_name, _var) \ 165 __rtparam __rtpar_##_var = \ 166 { .name = _name, \ 167 .type = OPT_STR, \ 168 .len = sizeof(_var), \ 169 .par.var = &_var } 170 171 #define custom_runtime_param(_name, _var) \ 172 custom_param(_name, _var); \ 173 custom_runtime_only_param(_name, _var) 174 #define boolean_runtime_param(_name, _var) \ 175 boolean_param(_name, _var); \ 176 boolean_runtime_only_param(_name, _var) 177 #define integer_runtime_param(_name, _var) \ 178 integer_param(_name, _var); \ 179 integer_runtime_only_param(_name, _var) 180 #define size_runtime_param(_name, _var) \ 181 size_param(_name, _var); \ 182 size_runtime_only_param(_name, _var) 183 #define string_runtime_param(_name, _var) \ 184 string_param(_name, _var); \ 185 string_runtime_only_param(_name, _var) 186 187 #endif /* __ASSEMBLY__ */ 188 189 #ifdef CONFIG_LATE_HWDOM 190 #define __hwdom_init 191 #define __hwdom_initdata __read_mostly 192 #else 193 #define __hwdom_init __init 194 #define __hwdom_initdata __initdata 195 #endif 196 197 #endif /* _LINUX_INIT_H */ 198