init.h 11 KB

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