1 #ifndef _LINUX_INIT_H 2 #define _LINUX_INIT_H 3 4 #include <linux/config.h> 5 #include <linux/compiler.h> 6 7 /* These macros are used to mark some functions or 8 * initialized data (doesn't apply to uninitialized data) 9 * as `initialization' functions. The kernel can take this 10 * as hint that the function is used only during the initialization 11 * phase and free up used memory resources after 12 * 13 * Usage: 14 * For functions: 15 * 16 * You should add __init immediately before the function name, like: 17 * 18 * static void __init initme(int x, int y) 19 * { 20 * extern int z; z = x * y; 21 * } 22 * 23 * If the function has a prototype somewhere, you can also add 24 * __init between closing brace of the prototype and semicolon: 25 * 26 * extern int initialize_foobar_device(int, int, int) __init; 27 * 28 * For initialized data: 29 * You should insert __initdata between the variable name and equal 30 * sign followed by value, e.g.: 31 * 32 * static int init_variable __initdata = 0; 33 * static char linux_logo[] __initdata = { 0x32, 0x36, ... }; 34 * 35 * Don't forget to initialize data not at file scope, i.e. within a function, 36 * as gcc otherwise puts the data into the bss section and not into the init 37 * section. 38 * 39 * Also note, that this data cannot be "const". 40 */ 41 42 #ifndef MODULE 43 44 #ifndef __ASSEMBLY__ 45 46 /* 47 * Used for initialization calls.. 48 */ 49 typedef int (*initcall_t)(void); 50 typedef void (*exitcall_t)(void); 51 52 extern initcall_t __initcall_start, __initcall_end; 53 54 #define __initcall(fn) \ 55 static initcall_t __initcall_##fn __attribute_used__ __init_call = fn 56 #define __exitcall(fn) \ 57 static exitcall_t __exitcall_##fn __exit_call = fn 58 59 /* 60 * Used for kernel command line parameter setup 61 */ 62 struct kernel_param { 63 const char *str; 64 int (*setup_func)(char *); 65 }; 66 67 extern struct kernel_param __setup_start, __setup_end; 68 69 #define __setup(str, fn) \ 70 static char __setup_str_##fn[] __initdata = str; \ 71 static struct kernel_param __setup_##fn __attribute_used__ __initsetup = { __setup_str_##fn, fn } 72 73 #endif /* __ASSEMBLY__ */ 74 75 /* 76 * Mark functions and data as being only used at initialization 77 * or exit time. 78 */ 79 #define __init __attribute__ ((__section__ (".text.init"))) 80 #define __exit __attribute_used__ __attribute__ (( __section__(".text.exit"))) 81 #define __initdata __attribute__ ((__section__ (".data.init"))) 82 #define __exitdata __attribute_used__ __attribute__ ((__section__ (".data.exit"))) 83 #define __initsetup __attribute_used__ __attribute__ ((__section__ (".setup.init"))) 84 #define __init_call __attribute_used__ __attribute__ ((__section__ (".initcall.init"))) 85 #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit"))) 86 87 /* For assembly routines */ 88 #define __INIT .section ".text.init","ax" 89 #define __FINIT .previous 90 #define __INITDATA .section ".data.init","aw" 91 92 /** 93 * module_init() - driver initialization entry point 94 * @x: function to be run at kernel boot time or module insertion 95 * 96 * module_init() will add the driver initialization routine in 97 * the "__initcall.int" code segment if the driver is checked as 98 * "y" or static, or else it will wrap the driver initialization 99 * routine with init_module() which is used by insmod and 100 * modprobe when the driver is used as a module. 101 */ 102 #define module_init(x) __initcall(x); 103 104 /** 105 * module_exit() - driver exit entry point 106 * @x: function to be run when driver is removed 107 * 108 * module_exit() will wrap the driver clean-up code 109 * with cleanup_module() when used with rmmod when 110 * the driver is a module. If the driver is statically 111 * compiled into the kernel, module_exit() has no effect. 112 */ 113 #define module_exit(x) __exitcall(x); 114 115 #else /* MODULE */ 116 117 #define __init 118 #define __exit 119 #define __initdata 120 #define __exitdata 121 #define __initcall(fn) 122 /* For assembly routines */ 123 #define __INIT 124 #define __FINIT 125 #define __INITDATA 126 127 /* These macros create a dummy inline: gcc 2.9x does not count alias 128 as usage, hence the `unused function' warning when __init functions 129 are declared static. We use the dummy __*_module_inline functions 130 both to kill the warning and check the type of the init/cleanup 131 function. */ 132 typedef int (*__init_module_func_t)(void); 133 typedef void (*__cleanup_module_func_t)(void); 134 #define module_init(x) \ 135 int init_module(void) __attribute__((alias(#x))); \ 136 static inline __init_module_func_t __init_module_inline(void) \ 137 { return x; } 138 #define module_exit(x) \ 139 void cleanup_module(void) __attribute__((alias(#x))); \ 140 static inline __cleanup_module_func_t __cleanup_module_inline(void) \ 141 { return x; } 142 143 #define __setup(str,func) /* nothing */ 144 145 #endif /* !MODULE */ 146 147 #ifdef CONFIG_HOTPLUG 148 #define __devinit 149 #define __devinitdata 150 #define __devexit 151 #define __devexitdata 152 #else 153 #define __devinit __init 154 #define __devinitdata __initdata 155 #define __devexit __exit 156 #define __devexitdata __exitdata 157 #endif 158 159 /* Functions marked as __devexit may be discarded at kernel link time, depending 160 on config options. Newer versions of binutils detect references from 161 retained sections to discarded sections and flag an error. Pointers to 162 __devexit functions must use __devexit_p(function_name), the wrapper will 163 insert either the function_name or NULL, depending on the config options. 164 */ 165 #if defined(MODULE) || defined(CONFIG_HOTPLUG) 166 #define __devexit_p(x) x 167 #else 168 #define __devexit_p(x) NULL 169 #endif 170 171 #endif /* _LINUX_INIT_H */ 172