| 1 | #ifndef _LINUX_INIT_H |
|---|
| 2 | #define _LINUX_INIT_H |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | /* These macros are used to mark some functions or |
|---|
| 6 | * initialized data (doesn't apply to uninitialized data) |
|---|
| 7 | * as `initialization' functions. The kernel can take this |
|---|
| 8 | * as hint that the function is used only during the initialization |
|---|
| 9 | * phase and free up used memory resources after |
|---|
| 10 | * |
|---|
| 11 | * Usage: |
|---|
| 12 | * For functions: |
|---|
| 13 | * |
|---|
| 14 | * You should add __init immediately before the function name, like: |
|---|
| 15 | * |
|---|
| 16 | * static void __init initme(int x, int y) |
|---|
| 17 | * { |
|---|
| 18 | * extern int z; z = x * y; |
|---|
| 19 | * } |
|---|
| 20 | * |
|---|
| 21 | * If the function has a prototype somewhere, you can also add |
|---|
| 22 | * __init between closing brace of the prototype and semicolon: |
|---|
| 23 | * |
|---|
| 24 | * extern int initialize_foobar_device(int, int, int) __init; |
|---|
| 25 | * |
|---|
| 26 | * For initialized data: |
|---|
| 27 | * You should insert __initdata between the variable name and equal |
|---|
| 28 | * sign followed by value, e.g.: |
|---|
| 29 | * |
|---|
| 30 | * static int init_variable __initdata = 0; |
|---|
| 31 | * static char linux_logo[] __initdata = { 0x32, 0x36, ... }; |
|---|
| 32 | * |
|---|
| 33 | * Don't forget to initialize data not at file scope, i.e. within a function, |
|---|
| 34 | * as gcc otherwise puts the data into the bss section and not into the init |
|---|
| 35 | * section. |
|---|
| 36 | * |
|---|
| 37 | * Also note, that this data cannot be "const". |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | /* These are for everybody (although not all archs will actually |
|---|
| 41 | discard it in modules) */ |
|---|
| 42 | #define __init __attribute__ ((__section__ (".init.text"))) |
|---|
| 43 | #define __initdata __attribute__ ((__section__ (".init.data"))) |
|---|
| 44 | #define __exitdata __attribute__ ((__section__(".exit.data"))) |
|---|
| 45 | #define __exit_call __attribute__ ((__section__ (".exitcall.exit"))) |
|---|
| 46 | |
|---|
| 47 | #ifdef MODULE |
|---|
| 48 | #define __exit __attribute__ ((__section__(".exit.text"))) |
|---|
| 49 | #else |
|---|
| 50 | #define __exit __attribute__ ((__section__(".exit.text"))) |
|---|
| 51 | #endif |
|---|
| 52 | |
|---|
| 53 | /* For assembly routines */ |
|---|
| 54 | #define __INIT .section ".init.text","ax" |
|---|
| 55 | #define __FINIT .previous |
|---|
| 56 | #define __INITDATA .section ".init.data","aw" |
|---|
| 57 | |
|---|
| 58 | #ifndef __ASSEMBLY__ |
|---|
| 59 | /* |
|---|
| 60 | * Used for initialization calls.. |
|---|
| 61 | */ |
|---|
| 62 | typedef int (*initcall_t)(void); |
|---|
| 63 | typedef void (*exitcall_t)(void); |
|---|
| 64 | |
|---|
| 65 | extern initcall_t __con_initcall_start[], __con_initcall_end[]; |
|---|
| 66 | extern initcall_t __security_initcall_start[], __security_initcall_end[]; |
|---|
| 67 | |
|---|
| 68 | /* Defined in init/main.c */ |
|---|
| 69 | extern char saved_command_line[]; |
|---|
| 70 | #endif |
|---|
| 71 | |
|---|
| 72 | #ifndef MODULE |
|---|
| 73 | |
|---|
| 74 | #ifndef __ASSEMBLY__ |
|---|
| 75 | |
|---|
| 76 | /* initcalls are now grouped by functionality into separate |
|---|
| 77 | * subsections. Ordering inside the subsections is determined |
|---|
| 78 | * by link order. |
|---|
| 79 | * For backwards compatibility, initcall() puts the call in |
|---|
| 80 | * the device init subsection. |
|---|
| 81 | */ |
|---|
| 82 | |
|---|
| 83 | #define __define_initcall(level,fn) \ |
|---|
| 84 | static initcall_t __initcall_##fn \ |
|---|
| 85 | __attribute__((__section__(".initcall" level ".init"))) = fn |
|---|
| 86 | |
|---|
| 87 | #define core_initcall(fn) __define_initcall("1",fn) |
|---|
| 88 | #define postcore_initcall(fn) __define_initcall("2",fn) |
|---|
| 89 | #define arch_initcall(fn) __define_initcall("3",fn) |
|---|
| 90 | #define subsys_initcall(fn) __define_initcall("4",fn) |
|---|
| 91 | #define fs_initcall(fn) __define_initcall("5",fn) |
|---|
| 92 | #define device_initcall(fn) __define_initcall("6",fn) |
|---|
| 93 | #define late_initcall(fn) __define_initcall("7",fn) |
|---|
| 94 | |
|---|
| 95 | #define __initcall(fn) device_initcall(fn) |
|---|
| 96 | |
|---|
| 97 | #define __exitcall(fn) \ |
|---|
| 98 | static exitcall_t __exitcall_##fn __exit_call = fn |
|---|
| 99 | |
|---|
| 100 | #define console_initcall(fn) \ |
|---|
| 101 | static initcall_t __initcall_##fn \ |
|---|
| 102 | __attribute__((__section__(".con_initcall.init")))=fn |
|---|
| 103 | |
|---|
| 104 | #define security_initcall(fn) \ |
|---|
| 105 | static initcall_t __initcall_##fn \ |
|---|
| 106 | __attribute__((__section__(".security_initcall.init"))) = fn |
|---|
| 107 | |
|---|
| 108 | struct obs_kernel_param { |
|---|
| 109 | const char *str; |
|---|
| 110 | int (*setup_func)(char *); |
|---|
| 111 | int early; |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | /* |
|---|
| 115 | * Only for really core code. See moduleparam.h for the normal way. |
|---|
| 116 | * |
|---|
| 117 | * Force the alignment so the compiler doesn't space elements of the |
|---|
| 118 | * obs_kernel_param "array" too far apart in .init.setup. |
|---|
| 119 | */ |
|---|
| 120 | #define __setup_param(str, unique_id, fn, early) \ |
|---|
| 121 | static char __setup_str_##unique_id[] __initdata = str; \ |
|---|
| 122 | static struct obs_kernel_param __setup_##unique_id \ |
|---|
| 123 | __attribute__((__section__(".init.setup"))) \ |
|---|
| 124 | __attribute__((aligned((sizeof(long))))) \ |
|---|
| 125 | = { __setup_str_##unique_id, fn, early } |
|---|
| 126 | |
|---|
| 127 | #define __setup_null_param(str, unique_id) \ |
|---|
| 128 | __setup_param(str, unique_id, NULL, 0) |
|---|
| 129 | |
|---|
| 130 | #define __setup(str, fn) \ |
|---|
| 131 | __setup_param(str, fn, fn, 0) |
|---|
| 132 | |
|---|
| 133 | #define __obsolete_setup(str) \ |
|---|
| 134 | __setup_null_param(str, __LINE__) |
|---|
| 135 | |
|---|
| 136 | /* NOTE: fn is as per module_param, not __setup! Emits warning if fn |
|---|
| 137 | * returns non-zero. */ |
|---|
| 138 | #define early_param(str, fn) \ |
|---|
| 139 | __setup_param(str, fn, fn, 1) |
|---|
| 140 | |
|---|
| 141 | /* Relies on saved_command_line being set */ |
|---|
| 142 | void __init parse_early_param(void); |
|---|
| 143 | #endif /* __ASSEMBLY__ */ |
|---|
| 144 | |
|---|
| 145 | /** |
|---|
| 146 | * module_init() - driver initialization entry point |
|---|
| 147 | * @x: function to be run at kernel boot time or module insertion |
|---|
| 148 | * |
|---|
| 149 | * module_init() will either be called during do_initcalls (if |
|---|
| 150 | * builtin) or at module insertion time (if a module). There can only |
|---|
| 151 | * be one per module. |
|---|
| 152 | */ |
|---|
| 153 | #define module_init(x) __initcall(x); |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * module_exit() - driver exit entry point |
|---|
| 157 | * @x: function to be run when driver is removed |
|---|
| 158 | * |
|---|
| 159 | * module_exit() will wrap the driver clean-up code |
|---|
| 160 | * with cleanup_module() when used with rmmod when |
|---|
| 161 | * the driver is a module. If the driver is statically |
|---|
| 162 | * compiled into the kernel, module_exit() has no effect. |
|---|
| 163 | * There can only be one per module. |
|---|
| 164 | */ |
|---|
| 165 | #define module_exit(x) __exitcall(x); |
|---|
| 166 | |
|---|
| 167 | #else /* MODULE */ |
|---|
| 168 | |
|---|
| 169 | /* Don't use these in modules, but some people do... */ |
|---|
| 170 | #define core_initcall(fn) module_init(fn) |
|---|
| 171 | #define postcore_initcall(fn) module_init(fn) |
|---|
| 172 | #define arch_initcall(fn) module_init(fn) |
|---|
| 173 | #define subsys_initcall(fn) module_init(fn) |
|---|
| 174 | #define fs_initcall(fn) module_init(fn) |
|---|
| 175 | #define device_initcall(fn) module_init(fn) |
|---|
| 176 | #define late_initcall(fn) module_init(fn) |
|---|
| 177 | |
|---|
| 178 | #define security_initcall(fn) module_init(fn) |
|---|
| 179 | |
|---|
| 180 | /* These macros create a dummy inline: gcc 2.9x does not count alias |
|---|
| 181 | as usage, hence the `unused function' warning when __init functions |
|---|
| 182 | are declared static. We use the dummy __*_module_inline functions |
|---|
| 183 | both to kill the warning and check the type of the init/cleanup |
|---|
| 184 | function. */ |
|---|
| 185 | |
|---|
| 186 | /* Each module must use one module_init(), or one no_module_init */ |
|---|
| 187 | #define module_init(initfn) \ |
|---|
| 188 | static inline initcall_t __inittest(void) \ |
|---|
| 189 | { return initfn; } \ |
|---|
| 190 | int init_module(void) __attribute__((alias(#initfn))); |
|---|
| 191 | |
|---|
| 192 | /* This is only required if you want to be unloadable. */ |
|---|
| 193 | #define module_exit(exitfn) \ |
|---|
| 194 | static inline exitcall_t __exittest(void) \ |
|---|
| 195 | { return exitfn; } \ |
|---|
| 196 | void cleanup_module(void) __attribute__((alias(#exitfn))); |
|---|
| 197 | |
|---|
| 198 | #define __setup_param(str, unique_id, fn) /* nothing */ |
|---|
| 199 | #define __setup_null_param(str, unique_id) /* nothing */ |
|---|
| 200 | #define __setup(str, func) /* nothing */ |
|---|
| 201 | #define __obsolete_setup(str) /* nothing */ |
|---|
| 202 | #endif |
|---|
| 203 | |
|---|
| 204 | /* Data marked not to be saved by software_suspend() */ |
|---|
| 205 | #define __nosavedata __attribute__ ((__section__ (".data.nosave"))) |
|---|
| 206 | |
|---|
| 207 | /* This means "can be init if no module support, otherwise module load |
|---|
| 208 | may call it." */ |
|---|
| 209 | #ifdef CONFIG_MODULES |
|---|
| 210 | #define __init_or_module |
|---|
| 211 | #define __initdata_or_module |
|---|
| 212 | #else |
|---|
| 213 | #define __init_or_module __init |
|---|
| 214 | #define __initdata_or_module __initdata |
|---|
| 215 | #endif /*CONFIG_MODULES*/ |
|---|
| 216 | |
|---|
| 217 | #ifdef CONFIG_HOTPLUG |
|---|
| 218 | #define __devinit |
|---|
| 219 | #define __devinitdata |
|---|
| 220 | #define __devexit |
|---|
| 221 | #define __devexitdata |
|---|
| 222 | #else |
|---|
| 223 | #define __devinit __init |
|---|
| 224 | #define __devinitdata __initdata |
|---|
| 225 | #define __devexit __exit |
|---|
| 226 | #define __devexitdata __exitdata |
|---|
| 227 | #endif |
|---|
| 228 | |
|---|
| 229 | /* Functions marked as __devexit may be discarded at kernel link time, depending |
|---|
| 230 | on config options. Newer versions of binutils detect references from |
|---|
| 231 | retained sections to discarded sections and flag an error. Pointers to |
|---|
| 232 | __devexit functions must use __devexit_p(function_name), the wrapper will |
|---|
| 233 | insert either the function_name or NULL, depending on the config options. |
|---|
| 234 | */ |
|---|
| 235 | #if defined(MODULE) || defined(CONFIG_HOTPLUG) |
|---|
| 236 | #define __devexit_p(x) x |
|---|
| 237 | #else |
|---|
| 238 | #define __devexit_p(x) NULL |
|---|
| 239 | #endif |
|---|
| 240 | |
|---|
| 241 | #ifdef MODULE |
|---|
| 242 | #define __exit_p(x) x |
|---|
| 243 | #else |
|---|
| 244 | #define __exit_p(x) NULL |
|---|
| 245 | #endif |
|---|
| 246 | |
|---|
| 247 | #endif /* _LINUX_INIT_H */ |
|---|