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