xref: /openbmc/linux/arch/um/include/shared/init.h (revision d15155824c5014803d91b829736d249c500bdda6)
18569c914SAl Viro #ifndef _LINUX_UML_INIT_H
28569c914SAl Viro #define _LINUX_UML_INIT_H
38569c914SAl Viro 
48569c914SAl Viro /* These macros are used to mark some functions or
58569c914SAl Viro  * initialized data (doesn't apply to uninitialized data)
68569c914SAl Viro  * as `initialization' functions. The kernel can take this
78569c914SAl Viro  * as hint that the function is used only during the initialization
88569c914SAl Viro  * phase and free up used memory resources after
98569c914SAl Viro  *
108569c914SAl Viro  * Usage:
118569c914SAl Viro  * For functions:
128569c914SAl Viro  *
138569c914SAl Viro  * You should add __init immediately before the function name, like:
148569c914SAl Viro  *
158569c914SAl Viro  * static void __init initme(int x, int y)
168569c914SAl Viro  * {
178569c914SAl Viro  *    extern int z; z = x * y;
188569c914SAl Viro  * }
198569c914SAl Viro  *
208569c914SAl Viro  * If the function has a prototype somewhere, you can also add
218569c914SAl Viro  * __init between closing brace of the prototype and semicolon:
228569c914SAl Viro  *
238569c914SAl Viro  * extern int initialize_foobar_device(int, int, int) __init;
248569c914SAl Viro  *
258569c914SAl Viro  * For initialized data:
268569c914SAl Viro  * You should insert __initdata between the variable name and equal
278569c914SAl Viro  * sign followed by value, e.g.:
288569c914SAl Viro  *
298569c914SAl Viro  * static int init_variable __initdata = 0;
30ae52bb23SGeert Uytterhoeven  * static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
318569c914SAl Viro  *
328569c914SAl Viro  * Don't forget to initialize data not at file scope, i.e. within a function,
338569c914SAl Viro  * as gcc otherwise puts the data into the bss section and not into the init
348569c914SAl Viro  * section.
358569c914SAl Viro  *
368569c914SAl Viro  * Also note, that this data cannot be "const".
378569c914SAl Viro  */
388569c914SAl Viro 
398569c914SAl Viro #ifndef _LINUX_INIT_H
408569c914SAl Viro typedef int (*initcall_t)(void);
418569c914SAl Viro typedef void (*exitcall_t)(void);
428569c914SAl Viro 
43*d1515582SWill Deacon #include <linux/compiler_types.h>
4430b11ee9SRichard Weinberger 
458569c914SAl Viro /* These are for everybody (although not all archs will actually
468569c914SAl Viro    discard it in modules) */
478569c914SAl Viro #define __init		__section(.init.text)
488569c914SAl Viro #define __initdata	__section(.init.data)
498569c914SAl Viro #define __exitdata	__section(.exit.data)
508569c914SAl Viro #define __exit_call	__used __section(.exitcall.exit)
518569c914SAl Viro 
528569c914SAl Viro #ifdef MODULE
538569c914SAl Viro #define __exit		__section(.exit.text)
548569c914SAl Viro #else
558569c914SAl Viro #define __exit		__used __section(.exit.text)
568569c914SAl Viro #endif
578569c914SAl Viro 
588569c914SAl Viro #endif
598569c914SAl Viro 
608569c914SAl Viro #ifndef MODULE
618569c914SAl Viro struct uml_param {
628569c914SAl Viro         const char *str;
638569c914SAl Viro         int (*setup_func)(char *, int *);
648569c914SAl Viro };
658569c914SAl Viro 
668569c914SAl Viro extern initcall_t __uml_initcall_start, __uml_initcall_end;
678569c914SAl Viro extern initcall_t __uml_postsetup_start, __uml_postsetup_end;
688569c914SAl Viro extern const char *__uml_help_start, *__uml_help_end;
698569c914SAl Viro #endif
708569c914SAl Viro 
718569c914SAl Viro #define __uml_initcall(fn)					  	\
728569c914SAl Viro 	static initcall_t __uml_initcall_##fn __uml_init_call = fn
738569c914SAl Viro 
748569c914SAl Viro #define __uml_exitcall(fn)						\
758569c914SAl Viro 	static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn
768569c914SAl Viro 
778569c914SAl Viro extern struct uml_param __uml_setup_start, __uml_setup_end;
788569c914SAl Viro 
798569c914SAl Viro #define __uml_postsetup(fn)						\
808569c914SAl Viro 	static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn
818569c914SAl Viro 
828569c914SAl Viro #define __non_empty_string(dummyname,string)				\
838569c914SAl Viro 	struct __uml_non_empty_string_struct_##dummyname		\
848569c914SAl Viro 	{								\
858569c914SAl Viro 		char _string[sizeof(string)-2];				\
868569c914SAl Viro 	}
878569c914SAl Viro 
888569c914SAl Viro #ifndef MODULE
898569c914SAl Viro #define __uml_setup(str, fn, help...)					\
908569c914SAl Viro 	__non_empty_string(fn ##_setup, str);				\
918569c914SAl Viro 	__uml_help(fn, help);						\
928569c914SAl Viro 	static char __uml_setup_str_##fn[] __initdata = str;		\
938569c914SAl Viro 	static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn }
948569c914SAl Viro #else
958569c914SAl Viro #define __uml_setup(str, fn, help...)					\
968569c914SAl Viro 
978569c914SAl Viro #endif
988569c914SAl Viro 
998569c914SAl Viro #define __uml_help(fn, help...)						\
1008569c914SAl Viro 	__non_empty_string(fn ##__help, help);				\
1018569c914SAl Viro 	static char __uml_help_str_##fn[] __initdata = help;		\
1028569c914SAl Viro 	static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn
1038569c914SAl Viro 
1048569c914SAl Viro /*
1058569c914SAl Viro  * Mark functions and data as being only used at initialization
1068569c914SAl Viro  * or exit time.
1078569c914SAl Viro  */
1088569c914SAl Viro #define __uml_init_setup	__used __section(.uml.setup.init)
1098569c914SAl Viro #define __uml_setup_help	__used __section(.uml.help.init)
1108569c914SAl Viro #define __uml_init_call		__used __section(.uml.initcall.init)
1118569c914SAl Viro #define __uml_postsetup_call	__used __section(.uml.postsetup.init)
1128569c914SAl Viro #define __uml_exit_call		__used __section(.uml.exitcall.exit)
1138569c914SAl Viro 
114298e20baSRichard Weinberger #ifdef __UM_HOST__
1158569c914SAl Viro 
1168569c914SAl Viro #define __define_initcall(level,fn) \
1178569c914SAl Viro 	static initcall_t __initcall_##fn __used \
1188569c914SAl Viro 	__attribute__((__section__(".initcall" level ".init"))) = fn
1198569c914SAl Viro 
1208569c914SAl Viro /* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
1218569c914SAl Viro  * make them run first.
1228569c914SAl Viro  */
1238569c914SAl Viro #define __initcall(fn) __define_initcall("1", fn)
1248569c914SAl Viro 
1258569c914SAl Viro #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
1268569c914SAl Viro 
1278569c914SAl Viro #define __init_call	__used __section(.initcall.init)
1288569c914SAl Viro 
1298569c914SAl Viro #endif
1308569c914SAl Viro 
1318569c914SAl Viro #endif /* _LINUX_UML_INIT_H */
132