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