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
15 * You should add __init immediately before the function name, like:
17 * static void __init initme(int x, int y)
19 * extern int z; z = x * y;
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
38 * Also note, that this data cannot be "const".
46 * Used for initialization calls..
48 typedef int (*initcall_t)(void);
49 typedef void (*exitcall_t)(void);
51 extern initcall_t __initcall_start, __initcall_end;
53 #define __initcall(fn) \
54 static initcall_t __initcall_##fn __init_call = fn
55 #define __exitcall(fn) \
56 static exitcall_t __exitcall_##fn __exit_call = fn
59 * Used for kernel command line parameter setup
63 int (*setup_func)(char *);
66 extern struct kernel_param __setup_start, __setup_end;
68 #define __setup(str, fn) \
69 static char __setup_str_##fn[] __initdata = str; \
70 static struct kernel_param __setup_##fn __attribute__((unused)) __initsetup = { __setup_str_##fn, fn }
72 #endif /* __ASSEMBLY__ */
75 * Mark functions and data as being only used at initialization
78 #define __init __attribute__ ((__section__ (".text.init")))
79 #define __exit __attribute__ ((unused, __section__(".text.exit")))
80 #define __initdata __attribute__ ((__section__ (".data.init")))
81 #define __exitdata __attribute__ ((unused, __section__ (".data.exit")))
82 #define __initsetup __attribute__ ((unused,__section__ (".setup.init")))
83 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
84 #define __exit_call __attribute__ ((unused,__section__ (".exitcall.exit")))
86 /* For assembly routines */
87 #define __INIT .section ".text.init","ax"
88 #define __FINIT .previous
89 #define __INITDATA .section ".data.init","aw"
92 * module_init() - driver initialization entry point
93 * @x: function to be run at kernel boot time or module insertion
95 * module_init() will add the driver initialization routine in
96 * the "__initcall.int" code segment if the driver is checked as
97 * "y" or static, or else it will wrap the driver initialization
98 * routine with init_module() which is used by insmod and
99 * modprobe when the driver is used as a module.
101 #define module_init(x) __initcall(x);
104 * module_exit() - driver exit entry point
105 * @x: function to be run when driver is removed
107 * module_exit() will wrap the driver clean-up code
108 * with cleanup_module() when used with rmmod when
109 * the driver is a module. If the driver is statically
110 * compiled into the kernel, module_exit() has no effect.
112 #define module_exit(x) __exitcall(x);
120 #define __initcall(fn)
121 /* For assembly routines */
126 /* These macros create a dummy inline: gcc 2.9x does not count alias
127 as usage, hence the `unused function' warning when __init functions
128 are declared static. We use the dummy __*_module_inline functions
129 both to kill the warning and check the type of the init/cleanup
131 typedef int (*__init_module_func_t)(void);
132 typedef void (*__cleanup_module_func_t)(void);
133 #define module_init(x) \
134 int init_module(void) __attribute__((alias(#x))); \
135 static inline __init_module_func_t __init_module_inline(void) \
137 #define module_exit(x) \
138 void cleanup_module(void) __attribute__((alias(#x))); \
139 static inline __cleanup_module_func_t __cleanup_module_inline(void) \
142 #define __setup(str,func) /* nothing */
146 #ifdef CONFIG_HOTPLUG
148 #define __devinitdata
150 #define __devexitdata
152 #define __devinit __init
153 #define __devinitdata __initdata
154 #define __devexit __exit
155 #define __devexitdata __exitdata
158 /* Functions marked as __devexit may be discarded at kernel link time, depending
159 on config options. Newer versions of binutils detect references from
160 retained sections to discarded sections and flag an error. Pointers to
161 __devexit functions must use __devexit_p(function_name), the wrapper will
162 insert either the function_name or NULL, depending on the config options.
164 #if defined(MODULE) || defined(CONFIG_HOTPLUG)
165 #define __devexit_p(x) x
167 #define __devexit_p(x) NULL
170 #endif /* _LINUX_INIT_H */