init.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 between the variable name and equal
  28. * 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. * Also note, that this data cannot be "const".
  38. */
  39. /* These are for everybody (although not all archs will actually
  40. discard it in modules) */
  41. #define __init __section(.init.text) __cold notrace
  42. #define __initdata __section(.init.data)
  43. #define __initconst __constsection(.init.rodata)
  44. #define __exitdata __section(.exit.data)
  45. #define __exit_call __used __section(.exitcall.exit)
  46. /*
  47. * Some architecture have tool chains which do not handle rodata attributes
  48. * correctly. For those disable special sections for const, so that other
  49. * architectures can annotate correctly.
  50. */
  51. #ifdef CONFIG_BROKEN_RODATA
  52. #define __constsection(x)
  53. #else
  54. #define __constsection(x) __section(x)
  55. #endif
  56. /*
  57. * modpost check for section mismatches during the kernel build.
  58. * A section mismatch happens when there are references from a
  59. * code or data section to an init section (both code or data).
  60. * The init sections are (for most archs) discarded by the kernel
  61. * when early init has completed so all such references are potential bugs.
  62. * For exit sections the same issue exists.
  63. *
  64. * The following markers are used for the cases where the reference to
  65. * the *init / *exit section (code or data) is valid and will teach
  66. * modpost not to issue a warning. Intended semantics is that a code or
  67. * data tagged __ref* can reference code or data from init section without
  68. * producing a warning (of course, no warning does not mean code is
  69. * correct, so optimally document why the __ref is needed and why it's OK).
  70. *
  71. * The markers follow same syntax rules as __init / __initdata.
  72. */
  73. #define __ref __section(.ref.text) noinline
  74. #define __refdata __section(.ref.data)
  75. #define __refconst __constsection(.ref.rodata)
  76. /* compatibility defines */
  77. #define __init_refok __ref
  78. #define __initdata_refok __refdata
  79. #define __exit_refok __ref
  80. #ifdef MODULE
  81. #define __exitused
  82. #else
  83. #define __exitused __used
  84. #endif
  85. #define __exit __section(.exit.text) __exitused __cold notrace
  86. /* Used for HOTPLUG_CPU */
  87. #define __cpuinit __section(.cpuinit.text) __cold notrace
  88. #define __cpuinitdata __section(.cpuinit.data)
  89. #define __cpuinitconst __constsection(.cpuinit.rodata)
  90. #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
  91. #define __cpuexitdata __section(.cpuexit.data)
  92. #define __cpuexitconst __constsection(.cpuexit.rodata)
  93. /* Used for MEMORY_HOTPLUG */
  94. #define __meminit __section(.meminit.text) __cold notrace
  95. #define __meminitdata __section(.meminit.data)
  96. #define __meminitconst __constsection(.meminit.rodata)
  97. #define __memexit __section(.memexit.text) __exitused __cold notrace
  98. #define __memexitdata __section(.memexit.data)
  99. #define __memexitconst __constsection(.memexit.rodata)
  100. /* For assembly routines */
  101. #define __HEAD .section ".head.text","ax"
  102. #define __INIT .section ".init.text","ax"
  103. #define __FINIT .previous
  104. #define __INITDATA .section ".init.data","aw",%progbits
  105. #define __INITRODATA .section ".init.rodata","a",%progbits
  106. #define __FINITDATA .previous
  107. #define __CPUINIT .section ".cpuinit.text", "ax"
  108. #define __CPUINITDATA .section ".cpuinit.data", "aw"
  109. #define __CPUINITRODATA .section ".cpuinit.rodata", "a"
  110. #define __MEMINIT .section ".meminit.text", "ax"
  111. #define __MEMINITDATA .section ".meminit.data", "aw"
  112. #define __MEMINITRODATA .section ".meminit.rodata", "a"
  113. /* silence warnings when references are OK */
  114. #define __REF .section ".ref.text", "ax"
  115. #define __REFDATA .section ".ref.data", "aw"
  116. #define __REFCONST .section ".ref.rodata", "a"
  117. #ifndef __ASSEMBLY__
  118. /*
  119. * Used for initialization calls..
  120. */
  121. typedef int (*initcall_t)(void);
  122. typedef void (*exitcall_t)(void);
  123. extern initcall_t __con_initcall_start[], __con_initcall_end[];
  124. extern initcall_t __security_initcall_start[], __security_initcall_end[];
  125. /* Used for contructor calls. */
  126. typedef void (*ctor_fn_t)(void);
  127. /* Defined in init/main.c */
  128. extern int do_one_initcall(initcall_t fn);
  129. extern char __initdata boot_command_line[];
  130. extern char *saved_command_line;
  131. extern unsigned int reset_devices;
  132. /* used by init/main.c */
  133. void setup_arch(char **);
  134. void prepare_namespace(void);
  135. void __init load_default_modules(void);
  136. extern void (*late_time_init)(void);
  137. extern bool initcall_debug;
  138. #endif
  139. #ifndef MODULE
  140. #ifndef __ASSEMBLY__
  141. /* initcalls are now grouped by functionality into separate
  142. * subsections. Ordering inside the subsections is determined
  143. * by link order.
  144. * For backwards compatibility, initcall() puts the call in
  145. * the device init subsection.
  146. *
  147. * The `id' arg to __define_initcall() is needed so that multiple initcalls
  148. * can point at the same handler without causing duplicate-symbol build errors.
  149. */
  150. #define __define_initcall(fn, id) \
  151. static initcall_t __initcall_##fn##id __used \
  152. __attribute__((__section__(".initcall" #id ".init"))) = fn
  153. /*
  154. * Early initcalls run before initializing SMP.
  155. *
  156. * Only for built-in code, not modules.
  157. */
  158. #define early_initcall(fn) __define_initcall(fn, early)
  159. /*
  160. * A "pure" initcall has no dependencies on anything else, and purely
  161. * initializes variables that couldn't be statically initialized.
  162. *
  163. * This only exists for built-in code, not for modules.
  164. * Keep main.c:initcall_level_names[] in sync.
  165. */
  166. #define pure_initcall(fn) __define_initcall(fn, 0)
  167. #define core_initcall(fn) __define_initcall(fn, 1)
  168. #define core_initcall_sync(fn) __define_initcall(fn, 1s)
  169. #define postcore_initcall(fn) __define_initcall(fn, 2)
  170. #define postcore_initcall_sync(fn) __define_initcall(fn, 2s)
  171. #define arch_initcall(fn) __define_initcall(fn, 3)
  172. #define arch_initcall_sync(fn) __define_initcall(fn, 3s)
  173. #define subsys_initcall(fn) __define_initcall(fn, 4)
  174. #define subsys_initcall_sync(fn) __define_initcall(fn, 4s)
  175. #define fs_initcall(fn) __define_initcall(fn, 5)
  176. #define fs_initcall_sync(fn) __define_initcall(fn, 5s)
  177. #define rootfs_initcall(fn) __define_initcall(fn, rootfs)
  178. #define device_initcall(fn) __define_initcall(fn, 6)
  179. #define device_initcall_sync(fn) __define_initcall(fn, 6s)
  180. #define late_initcall(fn) __define_initcall(fn, 7)
  181. #define late_initcall_sync(fn) __define_initcall(fn, 7s)
  182. #define __initcall(fn) device_initcall(fn)
  183. #define __exitcall(fn) \
  184. static exitcall_t __exitcall_##fn __exit_call = fn
  185. #define console_initcall(fn) \
  186. static initcall_t __initcall_##fn \
  187. __used __section(.con_initcall.init) = fn
  188. #define security_initcall(fn) \
  189. static initcall_t __initcall_##fn \
  190. __used __section(.security_initcall.init) = fn
  191. struct obs_kernel_param {
  192. const char *str;
  193. int (*setup_func)(char *);
  194. int early;
  195. };
  196. /*
  197. * Only for really core code. See moduleparam.h for the normal way.
  198. *
  199. * Force the alignment so the compiler doesn't space elements of the
  200. * obs_kernel_param "array" too far apart in .init.setup.
  201. */
  202. #define __setup_param(str, unique_id, fn, early) \
  203. static const char __setup_str_##unique_id[] __initconst \
  204. __aligned(1) = str; \
  205. static struct obs_kernel_param __setup_##unique_id \
  206. __used __section(.init.setup) \
  207. __attribute__((aligned((sizeof(long))))) \
  208. = { __setup_str_##unique_id, fn, early }
  209. #define __setup(str, fn) \
  210. __setup_param(str, fn, fn, 0)
  211. /* NOTE: fn is as per module_param, not __setup! Emits warning if fn
  212. * returns non-zero. */
  213. #define early_param(str, fn) \
  214. __setup_param(str, fn, fn, 1)
  215. /* Relies on boot_command_line being set */
  216. void __init parse_early_param(void);
  217. void __init parse_early_options(char *cmdline);
  218. #endif /* __ASSEMBLY__ */
  219. /**
  220. * module_init() - driver initialization entry point
  221. * @x: function to be run at kernel boot time or module insertion
  222. *
  223. * module_init() will either be called during do_initcalls() (if
  224. * builtin) or at module insertion time (if a module). There can only
  225. * be one per module.
  226. */
  227. #define module_init(x) __initcall(x);
  228. /**
  229. * module_exit() - driver exit entry point
  230. * @x: function to be run when driver is removed
  231. *
  232. * module_exit() will wrap the driver clean-up code
  233. * with cleanup_module() when used with rmmod when
  234. * the driver is a module. If the driver is statically
  235. * compiled into the kernel, module_exit() has no effect.
  236. * There can only be one per module.
  237. */
  238. #define module_exit(x) __exitcall(x);
  239. #else /* MODULE */
  240. /* Don't use these in loadable modules, but some people do... */
  241. #define early_initcall(fn) module_init(fn)
  242. #define core_initcall(fn) module_init(fn)
  243. #define postcore_initcall(fn) module_init(fn)
  244. #define arch_initcall(fn) module_init(fn)
  245. #define subsys_initcall(fn) module_init(fn)
  246. #define fs_initcall(fn) module_init(fn)
  247. #define device_initcall(fn) module_init(fn)
  248. #define late_initcall(fn) module_init(fn)
  249. #define security_initcall(fn) module_init(fn)
  250. /* Each module must use one module_init(). */
  251. #define module_init(initfn) \
  252. static inline initcall_t __inittest(void) \
  253. { return initfn; } \
  254. int init_module(void) __attribute__((alias(#initfn)));
  255. /* This is only required if you want to be unloadable. */
  256. #define module_exit(exitfn) \
  257. static inline exitcall_t __exittest(void) \
  258. { return exitfn; } \
  259. void cleanup_module(void) __attribute__((alias(#exitfn)));
  260. #define __setup_param(str, unique_id, fn) /* nothing */
  261. #define __setup(str, func) /* nothing */
  262. #endif
  263. /* Data marked not to be saved by software suspend */
  264. #define __nosavedata __section(.data..nosave)
  265. /* This means "can be init if no module support, otherwise module load
  266. may call it." */
  267. #ifdef CONFIG_MODULES
  268. #define __init_or_module
  269. #define __initdata_or_module
  270. #define __initconst_or_module
  271. #define __INIT_OR_MODULE .text
  272. #define __INITDATA_OR_MODULE .data
  273. #define __INITRODATA_OR_MODULE .section ".rodata","a",%progbits
  274. #else
  275. #define __init_or_module __init
  276. #define __initdata_or_module __initdata
  277. #define __initconst_or_module __initconst
  278. #define __INIT_OR_MODULE __INIT
  279. #define __INITDATA_OR_MODULE __INITDATA
  280. #define __INITRODATA_OR_MODULE __INITRODATA
  281. #endif /*CONFIG_MODULES*/
  282. #ifdef MODULE
  283. #define __exit_p(x) x
  284. #else
  285. #define __exit_p(x) NULL
  286. #endif
  287. #endif /* _LINUX_INIT_H */