init.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #ifndef _LINUX_INIT_H
  2. #define _LINUX_INIT_H
  3. #include <linux/config.h>
  4. #include <linux/compiler.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 char linux_logo[] __initdata = { 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 __attribute__ ((__section__ (".init.text")))
  42. #define __initdata __attribute__ ((__section__ (".init.data")))
  43. #define __exitdata __attribute__ ((__section__(".exit.data")))
  44. #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit")))
  45. #ifdef MODULE
  46. #define __exit __attribute__ ((__section__(".exit.text")))
  47. #else
  48. #define __exit __attribute_used__ __attribute__ ((__section__(".exit.text")))
  49. #endif
  50. /* For assembly routines */
  51. #define __INIT .section ".init.text","ax"
  52. #define __FINIT .previous
  53. #define __INITDATA .section ".init.data","aw"
  54. #ifndef __ASSEMBLY__
  55. /*
  56. * Used for initialization calls..
  57. */
  58. typedef int (*initcall_t)(void);
  59. typedef void (*exitcall_t)(void);
  60. extern initcall_t __con_initcall_start[], __con_initcall_end[];
  61. extern initcall_t __security_initcall_start[], __security_initcall_end[];
  62. /* Defined in init/main.c */
  63. extern char saved_command_line[];
  64. #endif
  65. #ifndef MODULE
  66. #ifndef __ASSEMBLY__
  67. /* initcalls are now grouped by functionality into separate
  68. * subsections. Ordering inside the subsections is determined
  69. * by link order.
  70. * For backwards compatibility, initcall() puts the call in
  71. * the device init subsection.
  72. */
  73. #define __define_initcall(level,fn) \
  74. static initcall_t __initcall_##fn __attribute_used__ \
  75. __attribute__((__section__(".initcall" level ".init"))) = fn
  76. #define core_initcall(fn) __define_initcall("1",fn)
  77. #define postcore_initcall(fn) __define_initcall("2",fn)
  78. #define arch_initcall(fn) __define_initcall("3",fn)
  79. #define subsys_initcall(fn) __define_initcall("4",fn)
  80. #define fs_initcall(fn) __define_initcall("5",fn)
  81. #define device_initcall(fn) __define_initcall("6",fn)
  82. #define late_initcall(fn) __define_initcall("7",fn)
  83. #define __initcall(fn) device_initcall(fn)
  84. #define __exitcall(fn) \
  85. static exitcall_t __exitcall_##fn __exit_call = fn
  86. #define console_initcall(fn) \
  87. static initcall_t __initcall_##fn \
  88. __attribute_used__ __attribute__((__section__(".con_initcall.init")))=fn
  89. #define security_initcall(fn) \
  90. static initcall_t __initcall_##fn \
  91. __attribute_used__ __attribute__((__section__(".security_initcall.init"))) = fn
  92. struct obs_kernel_param {
  93. const char *str;
  94. int (*setup_func)(char *);
  95. int early;
  96. };
  97. /*
  98. * Only for really core code. See moduleparam.h for the normal way.
  99. *
  100. * Force the alignment so the compiler doesn't space elements of the
  101. * obs_kernel_param "array" too far apart in .init.setup.
  102. */
  103. #define __setup_param(str, unique_id, fn, early) \
  104. static char __setup_str_##unique_id[] __initdata = str; \
  105. static struct obs_kernel_param __setup_##unique_id \
  106. __attribute_used__ \
  107. __attribute__((__section__(".init.setup"))) \
  108. __attribute__((aligned((sizeof(long))))) \
  109. = { __setup_str_##unique_id, fn, early }
  110. #define __setup_null_param(str, unique_id) \
  111. __setup_param(str, unique_id, NULL, 0)
  112. #define __setup(str, fn) \
  113. __setup_param(str, fn, fn, 0)
  114. #define __obsolete_setup(str) \
  115. __setup_null_param(str, __LINE__)
  116. /* NOTE: fn is as per module_param, not __setup! Emits warning if fn
  117. * returns non-zero. */
  118. #define early_param(str, fn) \
  119. __setup_param(str, fn, fn, 1)
  120. /* Relies on saved_command_line being set */
  121. void __init parse_early_param(void);
  122. #endif /* __ASSEMBLY__ */
  123. /**
  124. * module_init() - driver initialization entry point
  125. * @x: function to be run at kernel boot time or module insertion
  126. *
  127. * module_init() will either be called during do_initcalls (if
  128. * builtin) or at module insertion time (if a module). There can only
  129. * be one per module.
  130. */
  131. #define module_init(x) __initcall(x);
  132. /**
  133. * module_exit() - driver exit entry point
  134. * @x: function to be run when driver is removed
  135. *
  136. * module_exit() will wrap the driver clean-up code
  137. * with cleanup_module() when used with rmmod when
  138. * the driver is a module. If the driver is statically
  139. * compiled into the kernel, module_exit() has no effect.
  140. * There can only be one per module.
  141. */
  142. #define module_exit(x) __exitcall(x);
  143. #else /* MODULE */
  144. /* Don't use these in modules, but some people do... */
  145. #define core_initcall(fn) module_init(fn)
  146. #define postcore_initcall(fn) module_init(fn)
  147. #define arch_initcall(fn) module_init(fn)
  148. #define subsys_initcall(fn) module_init(fn)
  149. #define fs_initcall(fn) module_init(fn)
  150. #define device_initcall(fn) module_init(fn)
  151. #define late_initcall(fn) module_init(fn)
  152. #define security_initcall(fn) module_init(fn)
  153. /* These macros create a dummy inline: gcc 2.9x does not count alias
  154. as usage, hence the `unused function' warning when __init functions
  155. are declared static. We use the dummy __*_module_inline functions
  156. both to kill the warning and check the type of the init/cleanup
  157. function. */
  158. /* Each module must use one module_init(), or one no_module_init */
  159. #define module_init(initfn) \
  160. static inline initcall_t __inittest(void) \
  161. { return initfn; } \
  162. int init_module(void) __attribute__((alias(#initfn)));
  163. /* This is only required if you want to be unloadable. */
  164. #define module_exit(exitfn) \
  165. static inline exitcall_t __exittest(void) \
  166. { return exitfn; } \
  167. void cleanup_module(void) __attribute__((alias(#exitfn)));
  168. #define __setup_param(str, unique_id, fn) /* nothing */
  169. #define __setup_null_param(str, unique_id) /* nothing */
  170. #define __setup(str, func) /* nothing */
  171. #define __obsolete_setup(str) /* nothing */
  172. #endif
  173. /* Data marked not to be saved by software_suspend() */
  174. #define __nosavedata __attribute__ ((__section__ (".data.nosave")))
  175. /* This means "can be init if no module support, otherwise module load
  176. may call it." */
  177. #ifdef CONFIG_MODULES
  178. #define __init_or_module
  179. #define __initdata_or_module
  180. #else
  181. #define __init_or_module __init
  182. #define __initdata_or_module __initdata
  183. #endif /*CONFIG_MODULES*/
  184. #ifdef CONFIG_HOTPLUG
  185. #define __devinit
  186. #define __devinitdata
  187. #define __devexit
  188. #define __devexitdata
  189. #else
  190. #define __devinit __init
  191. #define __devinitdata __initdata
  192. #define __devexit __exit
  193. #define __devexitdata __exitdata
  194. #endif
  195. #ifdef CONFIG_HOTPLUG_CPU
  196. #define __cpuinit
  197. #define __cpuinitdata
  198. #define __cpuexit
  199. #define __cpuexitdata
  200. #else
  201. #define __cpuinit __init
  202. #define __cpuinitdata __initdata
  203. #define __cpuexit __exit
  204. #define __cpuexitdata __exitdata
  205. #endif
  206. /* Functions marked as __devexit may be discarded at kernel link time, depending
  207. on config options. Newer versions of binutils detect references from
  208. retained sections to discarded sections and flag an error. Pointers to
  209. __devexit functions must use __devexit_p(function_name), the wrapper will
  210. insert either the function_name or NULL, depending on the config options.
  211. */
  212. #if defined(MODULE) || defined(CONFIG_HOTPLUG)
  213. #define __devexit_p(x) x
  214. #else
  215. #define __devexit_p(x) NULL
  216. #endif
  217. #ifdef MODULE
  218. #define __exit_p(x) x
  219. #else
  220. #define __exit_p(x) NULL
  221. #endif
  222. #endif /* _LINUX_INIT_H */