4 #include <linux/config.h>
5 #include <linux/compiler.h>
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
16 * You should add __init immediately before the function name, like:
18 * static void __init initme(int x, int y)
20 * extern int z; z = x * y;
23 * If the function has a prototype somewhere, you can also add
24 * __init between closing brace of the prototype and semicolon:
26 * extern int initialize_foobar_device(int, int, int) __init;
28 * For initialized data:
29 * You should insert __initdata between the variable name and equal
30 * sign followed by value, e.g.:
32 * static int init_variable __initdata = 0;
33 * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
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
39 * Also note, that this data cannot be "const".
47 * Used for initialization calls..
49 typedef int (*initcall_t)(void);
50 typedef void (*exitcall_t)(void);
52 extern initcall_t __initcall_start, __initcall_end;
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
60 * Used for kernel command line parameter setup
64 int (*setup_func)(char *);
67 extern struct kernel_param __setup_start, __setup_end;
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 }
73 #endif /* __ASSEMBLY__ */
76 * Mark functions and data as being only used at initialization
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")))
87 /* For assembly routines */
88 #define __INIT .section ".text.init","ax"
89 #define __FINIT .previous
90 #define __INITDATA .section ".data.init","aw"
93 * module_init() - driver initialization entry point
94 * @x: function to be run at kernel boot time or module insertion
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.
102 #define module_init(x) __initcall(x);
105 * module_exit() - driver exit entry point
106 * @x: function to be run when driver is removed
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.
113 #define module_exit(x) __exitcall(x);
121 #define __initcall(fn)
122 /* For assembly routines */
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
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) \
138 #define module_exit(x) \
139 void cleanup_module(void) __attribute__((alias(#x))); \
140 static inline __cleanup_module_func_t __cleanup_module_inline(void) \
143 #define __setup(str,func) /* nothing */
147 #ifdef CONFIG_HOTPLUG
149 #define __devinitdata
151 #define __devexitdata
153 #define __devinit __init
154 #define __devinitdata __initdata
155 #define __devexit __exit
156 #define __devexitdata __exitdata
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.
165 #if defined(MODULE) || defined(CONFIG_HOTPLUG)
166 #define __devexit_p(x) x
168 #define __devexit_p(x) NULL
171 #endif /* _LINUX_INIT_H */