1*8569c914SAl Viro #ifndef _LINUX_UML_INIT_H 2*8569c914SAl Viro #define _LINUX_UML_INIT_H 3*8569c914SAl Viro 4*8569c914SAl Viro /* These macros are used to mark some functions or 5*8569c914SAl Viro * initialized data (doesn't apply to uninitialized data) 6*8569c914SAl Viro * as `initialization' functions. The kernel can take this 7*8569c914SAl Viro * as hint that the function is used only during the initialization 8*8569c914SAl Viro * phase and free up used memory resources after 9*8569c914SAl Viro * 10*8569c914SAl Viro * Usage: 11*8569c914SAl Viro * For functions: 12*8569c914SAl Viro * 13*8569c914SAl Viro * You should add __init immediately before the function name, like: 14*8569c914SAl Viro * 15*8569c914SAl Viro * static void __init initme(int x, int y) 16*8569c914SAl Viro * { 17*8569c914SAl Viro * extern int z; z = x * y; 18*8569c914SAl Viro * } 19*8569c914SAl Viro * 20*8569c914SAl Viro * If the function has a prototype somewhere, you can also add 21*8569c914SAl Viro * __init between closing brace of the prototype and semicolon: 22*8569c914SAl Viro * 23*8569c914SAl Viro * extern int initialize_foobar_device(int, int, int) __init; 24*8569c914SAl Viro * 25*8569c914SAl Viro * For initialized data: 26*8569c914SAl Viro * You should insert __initdata between the variable name and equal 27*8569c914SAl Viro * sign followed by value, e.g.: 28*8569c914SAl Viro * 29*8569c914SAl Viro * static int init_variable __initdata = 0; 30*8569c914SAl Viro * static char linux_logo[] __initdata = { 0x32, 0x36, ... }; 31*8569c914SAl Viro * 32*8569c914SAl Viro * Don't forget to initialize data not at file scope, i.e. within a function, 33*8569c914SAl Viro * as gcc otherwise puts the data into the bss section and not into the init 34*8569c914SAl Viro * section. 35*8569c914SAl Viro * 36*8569c914SAl Viro * Also note, that this data cannot be "const". 37*8569c914SAl Viro */ 38*8569c914SAl Viro 39*8569c914SAl Viro #ifndef _LINUX_INIT_H 40*8569c914SAl Viro typedef int (*initcall_t)(void); 41*8569c914SAl Viro typedef void (*exitcall_t)(void); 42*8569c914SAl Viro 43*8569c914SAl Viro #ifndef __KERNEL__ 44*8569c914SAl Viro #ifndef __section 45*8569c914SAl Viro # define __section(S) __attribute__ ((__section__(#S))) 46*8569c914SAl Viro #endif 47*8569c914SAl Viro 48*8569c914SAl Viro #if __GNUC__ == 3 49*8569c914SAl Viro 50*8569c914SAl Viro #if __GNUC_MINOR__ >= 3 51*8569c914SAl Viro # define __used __attribute__((__used__)) 52*8569c914SAl Viro #else 53*8569c914SAl Viro # define __used __attribute__((__unused__)) 54*8569c914SAl Viro #endif 55*8569c914SAl Viro 56*8569c914SAl Viro #else 57*8569c914SAl Viro #if __GNUC__ == 4 58*8569c914SAl Viro # define __used __attribute__((__used__)) 59*8569c914SAl Viro #endif 60*8569c914SAl Viro #endif 61*8569c914SAl Viro 62*8569c914SAl Viro #else 63*8569c914SAl Viro #include <linux/compiler.h> 64*8569c914SAl Viro #endif 65*8569c914SAl Viro /* These are for everybody (although not all archs will actually 66*8569c914SAl Viro discard it in modules) */ 67*8569c914SAl Viro #define __init __section(.init.text) 68*8569c914SAl Viro #define __initdata __section(.init.data) 69*8569c914SAl Viro #define __exitdata __section(.exit.data) 70*8569c914SAl Viro #define __exit_call __used __section(.exitcall.exit) 71*8569c914SAl Viro 72*8569c914SAl Viro #ifdef MODULE 73*8569c914SAl Viro #define __exit __section(.exit.text) 74*8569c914SAl Viro #else 75*8569c914SAl Viro #define __exit __used __section(.exit.text) 76*8569c914SAl Viro #endif 77*8569c914SAl Viro 78*8569c914SAl Viro #endif 79*8569c914SAl Viro 80*8569c914SAl Viro #ifndef MODULE 81*8569c914SAl Viro struct uml_param { 82*8569c914SAl Viro const char *str; 83*8569c914SAl Viro int (*setup_func)(char *, int *); 84*8569c914SAl Viro }; 85*8569c914SAl Viro 86*8569c914SAl Viro extern initcall_t __uml_initcall_start, __uml_initcall_end; 87*8569c914SAl Viro extern initcall_t __uml_postsetup_start, __uml_postsetup_end; 88*8569c914SAl Viro extern const char *__uml_help_start, *__uml_help_end; 89*8569c914SAl Viro #endif 90*8569c914SAl Viro 91*8569c914SAl Viro #define __uml_initcall(fn) \ 92*8569c914SAl Viro static initcall_t __uml_initcall_##fn __uml_init_call = fn 93*8569c914SAl Viro 94*8569c914SAl Viro #define __uml_exitcall(fn) \ 95*8569c914SAl Viro static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn 96*8569c914SAl Viro 97*8569c914SAl Viro extern struct uml_param __uml_setup_start, __uml_setup_end; 98*8569c914SAl Viro 99*8569c914SAl Viro #define __uml_postsetup(fn) \ 100*8569c914SAl Viro static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn 101*8569c914SAl Viro 102*8569c914SAl Viro #define __non_empty_string(dummyname,string) \ 103*8569c914SAl Viro struct __uml_non_empty_string_struct_##dummyname \ 104*8569c914SAl Viro { \ 105*8569c914SAl Viro char _string[sizeof(string)-2]; \ 106*8569c914SAl Viro } 107*8569c914SAl Viro 108*8569c914SAl Viro #ifndef MODULE 109*8569c914SAl Viro #define __uml_setup(str, fn, help...) \ 110*8569c914SAl Viro __non_empty_string(fn ##_setup, str); \ 111*8569c914SAl Viro __uml_help(fn, help); \ 112*8569c914SAl Viro static char __uml_setup_str_##fn[] __initdata = str; \ 113*8569c914SAl Viro static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn } 114*8569c914SAl Viro #else 115*8569c914SAl Viro #define __uml_setup(str, fn, help...) \ 116*8569c914SAl Viro 117*8569c914SAl Viro #endif 118*8569c914SAl Viro 119*8569c914SAl Viro #define __uml_help(fn, help...) \ 120*8569c914SAl Viro __non_empty_string(fn ##__help, help); \ 121*8569c914SAl Viro static char __uml_help_str_##fn[] __initdata = help; \ 122*8569c914SAl Viro static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn 123*8569c914SAl Viro 124*8569c914SAl Viro /* 125*8569c914SAl Viro * Mark functions and data as being only used at initialization 126*8569c914SAl Viro * or exit time. 127*8569c914SAl Viro */ 128*8569c914SAl Viro #define __uml_init_setup __used __section(.uml.setup.init) 129*8569c914SAl Viro #define __uml_setup_help __used __section(.uml.help.init) 130*8569c914SAl Viro #define __uml_init_call __used __section(.uml.initcall.init) 131*8569c914SAl Viro #define __uml_postsetup_call __used __section(.uml.postsetup.init) 132*8569c914SAl Viro #define __uml_exit_call __used __section(.uml.exitcall.exit) 133*8569c914SAl Viro 134*8569c914SAl Viro #ifndef __KERNEL__ 135*8569c914SAl Viro 136*8569c914SAl Viro #define __define_initcall(level,fn) \ 137*8569c914SAl Viro static initcall_t __initcall_##fn __used \ 138*8569c914SAl Viro __attribute__((__section__(".initcall" level ".init"))) = fn 139*8569c914SAl Viro 140*8569c914SAl Viro /* Userspace initcalls shouldn't depend on anything in the kernel, so we'll 141*8569c914SAl Viro * make them run first. 142*8569c914SAl Viro */ 143*8569c914SAl Viro #define __initcall(fn) __define_initcall("1", fn) 144*8569c914SAl Viro 145*8569c914SAl Viro #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn 146*8569c914SAl Viro 147*8569c914SAl Viro #define __init_call __used __section(.initcall.init) 148*8569c914SAl Viro 149*8569c914SAl Viro #endif 150*8569c914SAl Viro 151*8569c914SAl Viro #endif /* _LINUX_UML_INIT_H */ 152