- Stephen Rothwell: APM updates
[davej-history.git] / include / linux / init.h
blob6ef5b4c780f9b38099e5c2c3f59b4d0e459e10c4
1 #ifndef _LINUX_INIT_H
2 #define _LINUX_INIT_H
4 #include <linux/config.h>
6 /* These macros are used to mark some functions or
7 * initialized data (doesn't apply to uninitialized data)
8 * as `initialization' functions. The kernel can take this
9 * as hint that the function is used only during the initialization
10 * phase and free up used memory resources after
12 * Usage:
13 * For functions:
15 * You should add __init immediately before the function name, like:
17 * static void __init initme(int x, int y)
18 * {
19 * extern int z; z = x * y;
20 * }
22 * If the function has a prototype somewhere, you can also add
23 * __init between closing brace of the prototype and semicolon:
25 * extern int initialize_foobar_device(int, int, int) __init;
27 * For initialized data:
28 * You should insert __initdata between the variable name and equal
29 * sign followed by value, e.g.:
31 * static int init_variable __initdata = 0;
32 * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
34 * Don't forget to initialize data not at file scope, i.e. within a function,
35 * as gcc otherwise puts the data into the bss section and not into the init
36 * section.
39 #ifndef MODULE
41 #ifndef __ASSEMBLY__
44 * Used for initialization calls..
46 typedef int (*initcall_t)(void);
47 typedef void (*exitcall_t)(void);
49 extern initcall_t __initcall_start, __initcall_end;
51 #define __initcall(fn) \
52 static initcall_t __initcall_##fn __init_call = fn
53 #define __exitcall(fn) \
54 static exitcall_t __exitcall_##fn __exit_call = fn
57 * Used for kernel command line parameter setup
59 struct kernel_param {
60 const char *str;
61 int (*setup_func)(char *);
64 extern struct kernel_param __setup_start, __setup_end;
66 #define __setup(str, fn) \
67 static char __setup_str_##fn[] __initdata = str; \
68 static struct kernel_param __setup_##fn __initsetup = { __setup_str_##fn, fn }
70 #endif /* __ASSEMBLY__ */
73 * Mark functions and data as being only used at initialization
74 * or exit time.
76 #define __init __attribute__ ((__section__ (".text.init")))
77 #define __exit __attribute__ ((unused, __section__(".text.exit")))
78 #define __initdata __attribute__ ((__section__ (".data.init")))
79 #define __exitdata __attribute__ ((unused, __section__ (".data.exit")))
80 #define __initsetup __attribute__ ((unused,__section__ (".setup.init")))
81 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
82 #define __exit_call __attribute__ ((unused,__section__ (".exitcall.exit")))
84 /* For assembly routines */
85 #define __INIT .section ".text.init","ax"
86 #define __FINIT .previous
87 #define __INITDATA .section ".data.init","aw"
89 #define module_init(x) __initcall(x);
90 #define module_exit(x) __exitcall(x);
92 #else
94 #define __init
95 #define __exit
96 #define __initdata
97 #define __exitdata
98 #define __initcall(fn)
99 /* For assembly routines */
100 #define __INIT
101 #define __FINIT
102 #define __INITDATA
104 /* These macros create a dummy inline: gcc 2.9x does not count alias
105 as usage, hence the `unused function' warning when __init functions
106 are declared static. We use the dummy __*_module_inline functions
107 both to kill the warning and check the type of the init/cleanup
108 function. */
109 typedef int (*__init_module_func_t)(void);
110 typedef void (*__cleanup_module_func_t)(void);
111 #define module_init(x) \
112 int init_module(void) __attribute__((alias(#x))); \
113 extern inline __init_module_func_t __init_module_inline(void) \
114 { return x; }
115 #define module_exit(x) \
116 void cleanup_module(void) __attribute__((alias(#x))); \
117 extern inline __cleanup_module_func_t __cleanup_module_inline(void) \
118 { return x; }
120 #define __setup(str,func) /* nothing */
122 #endif
124 #ifdef CONFIG_HOTPLUG
125 #define __devinit
126 #define __devinitdata
127 #define __devexit
128 #define __devexitdata
129 #else
130 #define __devinit __init
131 #define __devinitdata __initdata
132 #define __devexit __exit
133 #define __devexitdata __exitdata
134 #endif
136 #endif /* _LINUX_INIT_H */