init.h 8.8 KB

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