1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 28569c914SAl Viro #ifndef _LINUX_UML_INIT_H 38569c914SAl Viro #define _LINUX_UML_INIT_H 48569c914SAl Viro 58569c914SAl Viro /* These macros are used to mark some functions or 68569c914SAl Viro * initialized data (doesn't apply to uninitialized data) 78569c914SAl Viro * as `initialization' functions. The kernel can take this 88569c914SAl Viro * as hint that the function is used only during the initialization 98569c914SAl Viro * phase and free up used memory resources after 108569c914SAl Viro * 118569c914SAl Viro * Usage: 128569c914SAl Viro * For functions: 138569c914SAl Viro * 148569c914SAl Viro * You should add __init immediately before the function name, like: 158569c914SAl Viro * 168569c914SAl Viro * static void __init initme(int x, int y) 178569c914SAl Viro * { 188569c914SAl Viro * extern int z; z = x * y; 198569c914SAl Viro * } 208569c914SAl Viro * 218569c914SAl Viro * If the function has a prototype somewhere, you can also add 228569c914SAl Viro * __init between closing brace of the prototype and semicolon: 238569c914SAl Viro * 248569c914SAl Viro * extern int initialize_foobar_device(int, int, int) __init; 258569c914SAl Viro * 268569c914SAl Viro * For initialized data: 278569c914SAl Viro * You should insert __initdata between the variable name and equal 288569c914SAl Viro * sign followed by value, e.g.: 298569c914SAl Viro * 308569c914SAl Viro * static int init_variable __initdata = 0; 31ae52bb23SGeert Uytterhoeven * static const char linux_logo[] __initconst = { 0x32, 0x36, ... }; 328569c914SAl Viro * 338569c914SAl Viro * Don't forget to initialize data not at file scope, i.e. within a function, 348569c914SAl Viro * as gcc otherwise puts the data into the bss section and not into the init 358569c914SAl Viro * section. 368569c914SAl Viro * 378569c914SAl Viro * Also note, that this data cannot be "const". 388569c914SAl Viro */ 398569c914SAl Viro 408569c914SAl Viro #ifndef _LINUX_INIT_H 418569c914SAl Viro typedef int (*initcall_t)(void); 428569c914SAl Viro typedef void (*exitcall_t)(void); 438569c914SAl Viro 448569c914SAl Viro #include <linux/compiler.h> 4530b11ee9SRichard Weinberger 468569c914SAl Viro /* These are for everybody (although not all archs will actually 478569c914SAl Viro discard it in modules) */ 488569c914SAl Viro #define __init __section(.init.text) 498569c914SAl Viro #define __initdata __section(.init.data) 508569c914SAl Viro #define __exitdata __section(.exit.data) 518569c914SAl Viro #define __exit_call __used __section(.exitcall.exit) 528569c914SAl Viro 538569c914SAl Viro #ifdef MODULE 548569c914SAl Viro #define __exit __section(.exit.text) 558569c914SAl Viro #else 568569c914SAl Viro #define __exit __used __section(.exit.text) 578569c914SAl Viro #endif 588569c914SAl Viro 598569c914SAl Viro #endif 608569c914SAl Viro 618569c914SAl Viro #ifndef MODULE 628569c914SAl Viro struct uml_param { 638569c914SAl Viro const char *str; 648569c914SAl Viro int (*setup_func)(char *, int *); 658569c914SAl Viro }; 668569c914SAl Viro 678569c914SAl Viro extern initcall_t __uml_initcall_start, __uml_initcall_end; 688569c914SAl Viro extern initcall_t __uml_postsetup_start, __uml_postsetup_end; 698569c914SAl Viro extern const char *__uml_help_start, *__uml_help_end; 708569c914SAl Viro #endif 718569c914SAl Viro 728569c914SAl Viro #define __uml_initcall(fn) \ 738569c914SAl Viro static initcall_t __uml_initcall_##fn __uml_init_call = fn 748569c914SAl Viro 758569c914SAl Viro #define __uml_exitcall(fn) \ 768569c914SAl Viro static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn 778569c914SAl Viro 788569c914SAl Viro extern struct uml_param __uml_setup_start, __uml_setup_end; 798569c914SAl Viro 808569c914SAl Viro #define __uml_postsetup(fn) \ 818569c914SAl Viro static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn 828569c914SAl Viro 838569c914SAl Viro #define __non_empty_string(dummyname,string) \ 848569c914SAl Viro struct __uml_non_empty_string_struct_##dummyname \ 858569c914SAl Viro { \ 868569c914SAl Viro char _string[sizeof(string)-2]; \ 878569c914SAl Viro } 888569c914SAl Viro 898569c914SAl Viro #ifndef MODULE 908569c914SAl Viro #define __uml_setup(str, fn, help...) \ 918569c914SAl Viro __non_empty_string(fn ##_setup, str); \ 928569c914SAl Viro __uml_help(fn, help); \ 938569c914SAl Viro static char __uml_setup_str_##fn[] __initdata = str; \ 948569c914SAl Viro static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn } 958569c914SAl Viro #else 968569c914SAl Viro #define __uml_setup(str, fn, help...) \ 978569c914SAl Viro 988569c914SAl Viro #endif 998569c914SAl Viro 1008569c914SAl Viro #define __uml_help(fn, help...) \ 1018569c914SAl Viro __non_empty_string(fn ##__help, help); \ 1028569c914SAl Viro static char __uml_help_str_##fn[] __initdata = help; \ 1038569c914SAl Viro static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn 1048569c914SAl Viro 1058569c914SAl Viro /* 1068569c914SAl Viro * Mark functions and data as being only used at initialization 1078569c914SAl Viro * or exit time. 1088569c914SAl Viro */ 1098569c914SAl Viro #define __uml_init_setup __used __section(.uml.setup.init) 1108569c914SAl Viro #define __uml_setup_help __used __section(.uml.help.init) 1118569c914SAl Viro #define __uml_init_call __used __section(.uml.initcall.init) 1128569c914SAl Viro #define __uml_postsetup_call __used __section(.uml.postsetup.init) 1138569c914SAl Viro #define __uml_exit_call __used __section(.uml.exitcall.exit) 1148569c914SAl Viro 115298e20baSRichard Weinberger #ifdef __UM_HOST__ 1168569c914SAl Viro 1178569c914SAl Viro #define __define_initcall(level,fn) \ 1188569c914SAl Viro static initcall_t __initcall_##fn __used \ 1198569c914SAl Viro __attribute__((__section__(".initcall" level ".init"))) = fn 1208569c914SAl Viro 1218569c914SAl Viro /* Userspace initcalls shouldn't depend on anything in the kernel, so we'll 1228569c914SAl Viro * make them run first. 1238569c914SAl Viro */ 1248569c914SAl Viro #define __initcall(fn) __define_initcall("1", fn) 1258569c914SAl Viro 1268569c914SAl Viro #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn 1278569c914SAl Viro 1288569c914SAl Viro #define __init_call __used __section(.initcall.init) 1298569c914SAl Viro 1308569c914SAl Viro #endif 1318569c914SAl Viro 1328569c914SAl Viro #endif /* _LINUX_UML_INIT_H */ 133