init.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #ifndef _LINUX_INIT_H
  2. #define _LINUX_INIT_H
  3. #include <linux/compiler.h>
  4. #include <linux/types.h>
  5. /* Built-in __init functions needn't be compiled with retpoline */
  6. #if defined(__noretpoline) && !defined(MODULE)
  7. #define __noinitretpoline __noretpoline
  8. #else
  9. #define __noinitretpoline
  10. #endif
  11. /* These macros are used to mark some functions or
  12. * initialized data (doesn't apply to uninitialized data)
  13. * as `initialization' functions. The kernel can take this
  14. * as hint that the function is used only during the initialization
  15. * phase and free up used memory resources after
  16. *
  17. * Usage:
  18. * For functions:
  19. *
  20. * You should add __init immediately before the function name, like:
  21. *
  22. * static void __init initme(int x, int y)
  23. * {
  24. * extern int z; z = x * y;
  25. * }
  26. *
  27. * If the function has a prototype somewhere, you can also add
  28. * __init between closing brace of the prototype and semicolon:
  29. *
  30. * extern int initialize_foobar_device(int, int, int) __init;
  31. *
  32. * For initialized data:
  33. * You should insert __initdata or __initconst between the variable name
  34. * and equal sign followed by value, e.g.:
  35. *
  36. * static int init_variable __initdata = 0;
  37. * static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
  38. *
  39. * Don't forget to initialize data not at file scope, i.e. within a function,
  40. * as gcc otherwise puts the data into the bss section and not into the init
  41. * section.
  42. */
  43. /* These are for everybody (although not all archs will actually
  44. discard it in modules) */
  45. #define __init __section(.init.text) __cold notrace __latent_entropy __noinitretpoline
  46. #define __initdata __section(.init.data)
  47. #define __initconst __section(.init.rodata)
  48. #define __exitdata __section(.exit.data)
  49. #define __exit_call __used __section(.exitcall.exit)
  50. /*
  51. * modpost check for section mismatches during the kernel build.
  52. * A section mismatch happens when there are references from a
  53. * code or data section to an init section (both code or data).
  54. * The init sections are (for most archs) discarded by the kernel
  55. * when early init has completed so all such references are potential bugs.
  56. * For exit sections the same issue exists.
  57. *
  58. * The following markers are used for the cases where the reference to
  59. * the *init / *exit section (code or data) is valid and will teach
  60. * modpost not to issue a warning. Intended semantics is that a code or
  61. * data tagged __ref* can reference code or data from init section without
  62. * producing a warning (of course, no warning does not mean code is
  63. * correct, so optimally document why the __ref is needed and why it's OK).
  64. *
  65. * The markers follow same syntax rules as __init / __initdata.
  66. */
  67. #define __ref __section(.ref.text) noinline
  68. #define __refdata __section(.ref.data)
  69. #define __refconst __section(.ref.rodata)
  70. #ifdef MODULE
  71. #define __exitused
  72. #else
  73. #define __exitused __used
  74. #endif
  75. #define __exit __section(.exit.text) __exitused __cold notrace
  76. /* Used for MEMORY_HOTPLUG */
  77. #define __meminit __section(.meminit.text) __cold notrace \
  78. __latent_entropy
  79. #define __meminitdata __section(.meminit.data)
  80. #define __meminitconst __section(.meminit.rodata)
  81. #define __memexit __section(.memexit.text) __exitused __cold notrace
  82. #define __memexitdata __section(.memexit.data)
  83. #define __memexitconst __section(.memexit.rodata)
  84. /* For assembly routines */
  85. #define __HEAD .section ".head.text","ax"
  86. #define __INIT .section ".init.text","ax"
  87. #define __FINIT .previous
  88. #define __INITDATA .section ".init.data","aw",%progbits
  89. #define __INITRODATA .section ".init.rodata","a",%progbits
  90. #define __FINITDATA .previous
  91. #define __MEMINIT .section ".meminit.text", "ax"
  92. #define __MEMINITDATA .section ".meminit.data", "aw"
  93. #define __MEMINITRODATA .section ".meminit.rodata", "a"
  94. /* silence warnings when references are OK */
  95. #define __REF .section ".ref.text", "ax"
  96. #define __REFDATA .section ".ref.data", "aw"
  97. #define __REFCONST .section ".ref.rodata", "a"
  98. #ifndef __ASSEMBLY__
  99. /*
  100. * Used for initialization calls..
  101. */
  102. typedef int (*initcall_t)(void);
  103. typedef void (*exitcall_t)(void);
  104. extern initcall_t __con_initcall_start[], __con_initcall_end[];
  105. extern initcall_t __security_initcall_start[], __security_initcall_end[];
  106. /* Used for contructor calls. */
  107. typedef void (*ctor_fn_t)(void);
  108. /* Defined in init/main.c */
  109. extern int do_one_initcall(initcall_t fn);
  110. extern char __initdata boot_command_line[];
  111. extern char *saved_command_line;
  112. extern unsigned int reset_devices;
  113. /* used by init/main.c */
  114. void setup_arch(char **);
  115. void prepare_namespace(void);
  116. void __init load_default_modules(void);
  117. int __init init_rootfs(void);
  118. #if defined(CONFIG_DEBUG_RODATA) || defined(CONFIG_DEBUG_SET_MODULE_RONX)
  119. extern bool rodata_enabled;
  120. #endif
  121. #ifdef CONFIG_DEBUG_RODATA
  122. void mark_rodata_ro(void);
  123. #endif
  124. extern void (*late_time_init)(void);
  125. extern bool initcall_debug;
  126. #endif
  127. #ifndef MODULE
  128. #ifndef __ASSEMBLY__
  129. /*
  130. * initcalls are now grouped by functionality into separate
  131. * subsections. Ordering inside the subsections is determined
  132. * by link order.
  133. * For backwards compatibility, initcall() puts the call in
  134. * the device init subsection.
  135. *
  136. * The `id' arg to __define_initcall() is needed so that multiple initcalls
  137. * can point at the same handler without causing duplicate-symbol build errors.
  138. *
  139. * Initcalls are run by placing pointers in initcall sections that the
  140. * kernel iterates at runtime. The linker can do dead code / data elimination
  141. * and remove that completely, so the initcall sections have to be marked
  142. * as KEEP() in the linker script.
  143. */
  144. #define __define_initcall(fn, id) \
  145. static initcall_t __initcall_##fn##id __used \
  146. __attribute__((__section__(".initcall" #id ".init"))) = fn;
  147. /*
  148. * Early initcalls run before initializing SMP.
  149. *
  150. * Only for built-in code, not modules.
  151. */
  152. #define early_initcall(fn) __define_initcall(fn, early)
  153. /*
  154. * A "pure" initcall has no dependencies on anything else, and purely
  155. * initializes variables that couldn't be statically initialized.
  156. *
  157. * This only exists for built-in code, not for modules.
  158. * Keep main.c:initcall_level_names[] in sync.
  159. */
  160. #define pure_initcall(fn) __define_initcall(fn, 0)
  161. #define core_initcall(fn) __define_initcall(fn, 1)
  162. #define core_initcall_sync(fn) __define_initcall(fn, 1s)
  163. #define postcore_initcall(fn) __define_initcall(fn, 2)
  164. #define postcore_initcall_sync(fn) __define_initcall(fn, 2s)
  165. #define arch_initcall(fn) __define_initcall(fn, 3)
  166. #define arch_initcall_sync(fn) __define_initcall(fn, 3s)
  167. #define subsys_initcall(fn) __define_initcall(fn, 4)
  168. #define subsys_initcall_sync(fn) __define_initcall(fn, 4s)
  169. #define fs_initcall(fn) __define_initcall(fn, 5)
  170. #define fs_initcall_sync(fn) __define_initcall(fn, 5s)
  171. #define rootfs_initcall(fn) __define_initcall(fn, rootfs)
  172. #define device_initcall(fn) __define_initcall(fn, 6)
  173. #define device_initcall_sync(fn) __define_initcall(fn, 6s)
  174. #define late_initcall(fn) __define_initcall(fn, 7)
  175. #define late_initcall_sync(fn) __define_initcall(fn, 7s)
  176. #define __initcall(fn) device_initcall(fn)
  177. #define __exitcall(fn) \
  178. static exitcall_t __exitcall_##fn __exit_call = fn
  179. #define console_initcall(fn) \
  180. static initcall_t __initcall_##fn \
  181. __used __section(.con_initcall.init) = fn
  182. #define security_initcall(fn) \
  183. static initcall_t __initcall_##fn \
  184. __used __section(.security_initcall.init) = fn
  185. struct obs_kernel_param {
  186. const char *str;
  187. int (*setup_func)(char *);
  188. int early;
  189. };
  190. /*
  191. * Only for really core code. See moduleparam.h for the normal way.
  192. *
  193. * Force the alignment so the compiler doesn't space elements of the
  194. * obs_kernel_param "array" too far apart in .init.setup.
  195. */
  196. #define __setup_param(str, unique_id, fn, early) \
  197. static const char __setup_str_##unique_id[] __initconst \
  198. __aligned(1) = str; \
  199. static struct obs_kernel_param __setup_##unique_id \
  200. __used __section(.init.setup) \
  201. __attribute__((aligned((sizeof(long))))) \
  202. = { __setup_str_##unique_id, fn, early }
  203. #define __setup(str, fn) \
  204. __setup_param(str, fn, fn, 0)
  205. /*
  206. * NOTE: fn is as per module_param, not __setup!
  207. * Emits warning if fn returns non-zero.
  208. */
  209. #define early_param(str, fn) \
  210. __setup_param(str, fn, fn, 1)
  211. #define early_param_on_off(str_on, str_off, var, config) \
  212. \
  213. int var = IS_ENABLED(config); \
  214. \
  215. static int __init parse_##var##_on(char *arg) \
  216. { \
  217. var = 1; \
  218. return 0; \
  219. } \
  220. __setup_param(str_on, parse_##var##_on, parse_##var##_on, 1); \
  221. \
  222. static int __init parse_##var##_off(char *arg) \
  223. { \
  224. var = 0; \
  225. return 0; \
  226. } \
  227. __setup_param(str_off, parse_##var##_off, parse_##var##_off, 1)
  228. /* Relies on boot_command_line being set */
  229. void __init parse_early_param(void);
  230. void __init parse_early_options(char *cmdline);
  231. #endif /* __ASSEMBLY__ */
  232. #else /* MODULE */
  233. #define __setup_param(str, unique_id, fn) /* nothing */
  234. #define __setup(str, func) /* nothing */
  235. #endif
  236. /* Data marked not to be saved by software suspend */
  237. #define __nosavedata __section(.data..nosave)
  238. #ifdef MODULE
  239. #define __exit_p(x) x
  240. #else
  241. #define __exit_p(x) NULL
  242. #endif
  243. #endif /* _LINUX_INIT_H */