linux-bk/include/linux/init.h
<<
>>
Prefs
   1#ifndef _LINUX_INIT_H
   2#define _LINUX_INIT_H
   3
   4#include <linux/config.h>
   5
   6/* These macros are used to mark some functions or 
   7 * initialized data (doesn't apply to uninitialized data)
   8 * as `initialization' functions. The kernel can take this
   9 * as hint that the function is used only during the initialization
  10 * phase and free up used memory resources after
  11 *
  12 * Usage:
  13 * For functions:
  14 * 
  15 * You should add __init immediately before the function name, like:
  16 *
  17 * static void __init initme(int x, int y)
  18 * {
  19 *    extern int z; z = x * y;
  20 * }
  21 *
  22 * If the function has a prototype somewhere, you can also add
  23 * __init between closing brace of the prototype and semicolon:
  24 *
  25 * extern int initialize_foobar_device(int, int, int) __init;
  26 *
  27 * For initialized data:
  28 * You should insert __initdata between the variable name and equal
  29 * sign followed by value, e.g.:
  30 *
  31 * static int init_variable __initdata = 0;
  32 * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
  33 *
  34 * Don't forget to initialize data not at file scope, i.e. within a function,
  35 * as gcc otherwise puts the data into the bss section and not into the init
  36 * section.
  37 * 
  38 * Also note, that this data cannot be "const".
  39 */
  40
  41#ifndef MODULE
  42
  43#ifndef __ASSEMBLY__
  44
  45/*
  46 * Used for initialization calls..
  47 */
  48typedef int (*initcall_t)(void);
  49typedef void (*exitcall_t)(void);
  50
  51extern initcall_t __initcall_start, __initcall_end;
  52
  53/* initcalls are now grouped by functionality into separate 
  54 * subsections. Ordering inside the subsections is determined
  55 * by link order. 
  56 * For backwards compatability, initcall() puts the call in 
  57 * the device init subsection.
  58 */
  59
  60#define __define_initcall(level,fn) \
  61        static initcall_t __initcall_##fn __attribute__ ((unused,__section__ (".initcall" level ".init"))) = fn
  62
  63#define core_initcall(fn)               __define_initcall("1",fn)
  64#define postcore_initcall(fn)           __define_initcall("2",fn)
  65#define arch_initcall(fn)               __define_initcall("3",fn)
  66#define subsys_initcall(fn)             __define_initcall("4",fn)
  67#define fs_initcall(fn)                 __define_initcall("5",fn)
  68#define device_initcall(fn)             __define_initcall("6",fn)
  69#define late_initcall(fn)               __define_initcall("7",fn)
  70
  71#define __initcall(fn) device_initcall(fn)
  72
  73#define __exitcall(fn)                                                          \
  74        static exitcall_t __exitcall_##fn __exit_call = fn
  75
  76/*
  77 * Used for kernel command line parameter setup
  78 */
  79struct kernel_param {
  80        const char *str;
  81        int (*setup_func)(char *);
  82};
  83
  84extern struct kernel_param __setup_start, __setup_end;
  85
  86#define __setup(str, fn)                                                                \
  87        static char __setup_str_##fn[] __initdata = str;                                \
  88        static struct kernel_param __setup_##fn __attribute__((unused)) __initsetup = { __setup_str_##fn, fn }
  89
  90#endif /* __ASSEMBLY__ */
  91
  92/*
  93 * Mark functions and data as being only used at initialization
  94 * or exit time.
  95 */
  96#define __init          __attribute__ ((__section__ (".text.init")))
  97#define __exit          __attribute__ ((unused, __section__(".text.exit")))
  98#define __initdata      __attribute__ ((__section__ (".data.init")))
  99#define __exitdata      __attribute__ ((unused, __section__ (".data.exit")))
 100#define __initsetup     __attribute__ ((unused,__section__ (".setup.init")))
 101#define __init_call(level)  __attribute__ ((unused,__section__ (".initcall" level ".init")))
 102#define __exit_call     __attribute__ ((unused,__section__ (".exitcall.exit")))
 103
 104/* For assembly routines */
 105#define __INIT          .section        ".text.init","ax"
 106#define __FINIT         .previous
 107#define __INITDATA      .section        ".data.init","aw"
 108
 109/**
 110 * module_init() - driver initialization entry point
 111 * @x: function to be run at kernel boot time or module insertion
 112 * 
 113 * module_init() will add the driver initialization routine in
 114 * the "__initcall.int" code segment if the driver is checked as
 115 * "y" or static, or else it will wrap the driver initialization
 116 * routine with init_module() which is used by insmod and
 117 * modprobe when the driver is used as a module.
 118 */
 119#define module_init(x)  __initcall(x);
 120
 121/**
 122 * module_exit() - driver exit entry point
 123 * @x: function to be run when driver is removed
 124 * 
 125 * module_exit() will wrap the driver clean-up code
 126 * with cleanup_module() when used with rmmod when
 127 * the driver is a module.  If the driver is statically
 128 * compiled into the kernel, module_exit() has no effect.
 129 */
 130#define module_exit(x)  __exitcall(x);
 131
 132#else
 133
 134#define __init
 135#define __exit
 136#define __initdata
 137#define __exitdata
 138#define __initcall(fn)
 139/* For assembly routines */
 140#define __INIT
 141#define __FINIT
 142#define __INITDATA
 143
 144/* These macros create a dummy inline: gcc 2.9x does not count alias
 145 as usage, hence the `unused function' warning when __init functions
 146 are declared static. We use the dummy __*_module_inline functions
 147 both to kill the warning and check the type of the init/cleanup
 148 function. */
 149typedef int (*__init_module_func_t)(void);
 150typedef void (*__cleanup_module_func_t)(void);
 151#define module_init(x) \
 152        int init_module(void) __attribute__((alias(#x))); \
 153        static inline __init_module_func_t __init_module_inline(void) \
 154        { return x; }
 155#define module_exit(x) \
 156        void cleanup_module(void) __attribute__((alias(#x))); \
 157        static inline __cleanup_module_func_t __cleanup_module_inline(void) \
 158        { return x; }
 159
 160#define __setup(str,func) /* nothing */
 161
 162#define core_initcall(fn)               module_init(fn)
 163#define postcore_initcall(fn)           module_init(fn)
 164#define arch_initcall(fn)               module_init(fn)
 165#define subsys_initcall(fn)             module_init(fn)
 166#define fs_initcall(fn)                 module_init(fn)
 167#define device_initcall(fn)             module_init(fn)
 168#define late_initcall(fn)               module_init(fn)
 169
 170#endif
 171
 172/* Data marked not to be saved by software_suspend() */
 173#define __nosavedata __attribute__ ((__section__ (".data.nosave")))
 174
 175#ifdef CONFIG_HOTPLUG
 176#define __devinit
 177#define __devinitdata
 178#define __devexit
 179#define __devexitdata
 180#define __devexit_p(x)  &(x)
 181#else
 182#define __devinit __init
 183#define __devinitdata __initdata
 184#define __devexit __exit
 185#define __devexitdata __exitdata
 186#define __devexit_p(x)  0
 187#endif
 188
 189#endif /* _LINUX_INIT_H */
 190
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.