- David Miller: sparc and net updates. Fix merge_segments.
[davej-history.git] / include / linux / module.h
blob7f416d7fb9b73eb47ed463decb01e54643d0623c
1 /*
2 * Dynamic loading of modules into the kernel.
4 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
5 */
7 #ifndef _LINUX_MODULE_H
8 #define _LINUX_MODULE_H
10 #include <linux/config.h>
11 #include <linux/spinlock.h>
12 #include <linux/list.h>
14 #ifdef __GENKSYMS__
15 # define _set_ver(sym) sym
16 # undef MODVERSIONS
17 # define MODVERSIONS
18 #else /* ! __GENKSYMS__ */
19 # if !defined(MODVERSIONS) && defined(EXPORT_SYMTAB)
20 # define _set_ver(sym) sym
21 # include <linux/modversions.h>
22 # endif
23 #endif /* __GENKSYMS__ */
25 #include <asm/atomic.h>
27 /* Don't need to bring in all of uaccess.h just for this decl. */
28 struct exception_table_entry;
30 /* Used by get_kernel_syms, which is obsolete. */
31 struct kernel_sym
33 unsigned long value;
34 char name[60]; /* should have been 64-sizeof(long); oh well */
37 struct module_symbol
39 unsigned long value;
40 const char *name;
43 struct module_ref
45 struct module *dep; /* "parent" pointer */
46 struct module *ref; /* "child" pointer */
47 struct module_ref *next_ref;
50 /* TBD */
51 struct module_persist;
53 struct module
55 unsigned long size_of_struct; /* == sizeof(module) */
56 struct module *next;
57 const char *name;
58 unsigned long size;
60 union
62 atomic_t usecount;
63 long pad;
64 } uc; /* Needs to keep its size - so says rth */
66 unsigned long flags; /* AUTOCLEAN et al */
68 unsigned nsyms;
69 unsigned ndeps;
71 struct module_symbol *syms;
72 struct module_ref *deps;
73 struct module_ref *refs;
74 int (*init)(void);
75 void (*cleanup)(void);
76 const struct exception_table_entry *ex_table_start;
77 const struct exception_table_entry *ex_table_end;
78 #ifdef __alpha__
79 unsigned long gp;
80 #endif
81 /* Members past this point are extensions to the basic
82 module support and are optional. Use mod_member_present()
83 to examine them. */
84 const struct module_persist *persist_start;
85 const struct module_persist *persist_end;
86 int (*can_unload)(void);
87 int runsize; /* In modutils, not currently used */
88 const char *kallsyms_start; /* All symbols for kernel debugging */
89 const char *kallsyms_end;
90 const char *archdata_start; /* arch specific data for module */
91 const char *archdata_end;
92 const char *kernel_data; /* Reserved for kernel internal use */
95 struct module_info
97 unsigned long addr;
98 unsigned long size;
99 unsigned long flags;
100 long usecount;
103 /* Bits of module.flags. */
105 #define MOD_UNINITIALIZED 0
106 #define MOD_RUNNING 1
107 #define MOD_DELETED 2
108 #define MOD_AUTOCLEAN 4
109 #define MOD_VISITED 8
110 #define MOD_USED_ONCE 16
111 #define MOD_JUST_FREED 32
112 #define MOD_INITIALIZING 64
114 /* Values for query_module's which. */
116 #define QM_MODULES 1
117 #define QM_DEPS 2
118 #define QM_REFS 3
119 #define QM_SYMBOLS 4
120 #define QM_INFO 5
122 /* Can the module be queried? */
123 #define MOD_CAN_QUERY(mod) (((mod)->flags & (MOD_RUNNING | MOD_INITIALIZING)) && !((mod)->flags & MOD_DELETED))
125 /* When struct module is extended, we must test whether the new member
126 is present in the header received from insmod before we can use it.
127 This function returns true if the member is present. */
129 #define mod_member_present(mod,member) \
130 ((unsigned long)(&((struct module *)0L)->member + 1) \
131 <= (mod)->size_of_struct)
133 /* Check if an address p with number of entries n is within the body of module m */
134 #define mod_bound(p, n, m) ((unsigned long)(p) >= ((unsigned long)(m) + ((m)->size_of_struct)) && \
135 (unsigned long)((p)+(n)) <= (unsigned long)(m) + (m)->size)
137 /* Backwards compatibility definition. */
139 #define GET_USE_COUNT(module) (atomic_read(&(module)->uc.usecount))
141 /* Poke the use count of a module. */
143 #define __MOD_INC_USE_COUNT(mod) \
144 (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
145 #define __MOD_DEC_USE_COUNT(mod) \
146 (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
147 #define __MOD_IN_USE(mod) \
148 (mod_member_present((mod), can_unload) && (mod)->can_unload \
149 ? (mod)->can_unload() : atomic_read(&(mod)->uc.usecount))
151 /* Indirect stringification. */
153 #define __MODULE_STRING_1(x) #x
154 #define __MODULE_STRING(x) __MODULE_STRING_1(x)
156 /* Generic inter module communication.
158 * NOTE: This interface is intended for small amounts of data that are
159 * passed between two objects and either or both of the objects
160 * might be compiled as modules. Do not over use this interface.
162 * If more than two objects need to communicate then you probably
163 * need a specific interface instead of abusing this generic
164 * interface. If both objects are *always* built into the kernel
165 * then a global extern variable is good enough, you do not need
166 * this interface.
168 * Keith Owens <kaos@ocs.com.au> 28 Oct 2000.
171 #ifdef __KERNEL__
172 #define HAVE_INTER_MODULE
173 extern void inter_module_register(const char *, struct module *, const void *);
174 extern void inter_module_unregister(const char *);
175 extern const void *inter_module_get(const char *);
176 extern const void *inter_module_get_request(const char *, const char *);
177 extern void inter_module_put(const char *);
179 struct inter_module_entry {
180 struct list_head list;
181 const char *im_name;
182 struct module *owner;
183 const void *userdata;
186 extern int try_inc_mod_count(struct module *mod);
187 #endif /* __KERNEL__ */
189 #if defined(MODULE) && !defined(__GENKSYMS__)
191 /* Embedded module documentation macros. */
193 /* For documentation purposes only. */
195 #define MODULE_AUTHOR(name) \
196 const char __module_author[] __attribute__((section(".modinfo"))) = \
197 "author=" name
199 #define MODULE_DESCRIPTION(desc) \
200 const char __module_description[] __attribute__((section(".modinfo"))) = \
201 "description=" desc
203 /* Could potentially be used by kmod... */
205 #define MODULE_SUPPORTED_DEVICE(dev) \
206 const char __module_device[] __attribute__((section(".modinfo"))) = \
207 "device=" dev
209 /* Used to verify parameters given to the module. The TYPE arg should
210 be a string in the following format:
211 [min[-max]]{b,h,i,l,s}
212 The MIN and MAX specifiers delimit the length of the array. If MAX
213 is omitted, it defaults to MIN; if both are omitted, the default is 1.
214 The final character is a type specifier:
215 b byte
216 h short
217 i int
218 l long
219 s string
222 #define MODULE_PARM(var,type) \
223 const char __module_parm_##var[] \
224 __attribute__((section(".modinfo"))) = \
225 "parm_" __MODULE_STRING(var) "=" type
227 #define MODULE_PARM_DESC(var,desc) \
228 const char __module_parm_desc_##var[] \
229 __attribute__((section(".modinfo"))) = \
230 "parm_desc_" __MODULE_STRING(var) "=" desc
233 * MODULE_DEVICE_TABLE exports information about devices
234 * currently supported by this module. A device type, such as PCI,
235 * is a C-like identifier passed as the first arg to this macro.
236 * The second macro arg is the variable containing the device
237 * information being made public.
239 * The following is a list of known device types (arg 1),
240 * and the C types which are to be passed as arg 2.
241 * pci - struct pci_device_id - List of PCI ids supported by this module
242 * isapnp - struct isapnp_device_id - List of ISA PnP ids supported by this module
243 * usb - struct usb_device_id - List of USB ids supported by this module
245 #define MODULE_GENERIC_TABLE(gtype,name) \
246 static const unsigned long __module_##gtype##_size \
247 __attribute__ ((unused)) = sizeof(struct gtype##_id); \
248 static const struct gtype##_id * __module_##gtype##_table \
249 __attribute__ ((unused)) = name
250 #define MODULE_DEVICE_TABLE(type,name) \
251 MODULE_GENERIC_TABLE(type##_device,name)
252 /* not put to .modinfo section to avoid section type conflicts */
254 /* The attributes of a section are set the first time the section is
255 seen; we want .modinfo to not be allocated. */
257 __asm__(".section .modinfo\n\t.previous");
259 /* Define the module variable, and usage macros. */
260 extern struct module __this_module;
262 #define THIS_MODULE (&__this_module)
263 #define MOD_INC_USE_COUNT __MOD_INC_USE_COUNT(THIS_MODULE)
264 #define MOD_DEC_USE_COUNT __MOD_DEC_USE_COUNT(THIS_MODULE)
265 #define MOD_IN_USE __MOD_IN_USE(THIS_MODULE)
267 #include <linux/version.h>
268 static const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
269 "kernel_version=" UTS_RELEASE;
270 #ifdef MODVERSIONS
271 static const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
272 "using_checksums=1";
273 #endif
275 #else /* MODULE */
277 #define MODULE_AUTHOR(name)
278 #define MODULE_DESCRIPTION(desc)
279 #define MODULE_SUPPORTED_DEVICE(name)
280 #define MODULE_PARM(var,type)
281 #define MODULE_PARM_DESC(var,desc)
282 #define MODULE_GENERIC_TABLE(gtype,name)
283 #define MODULE_DEVICE_TABLE(type,name)
285 #ifndef __GENKSYMS__
287 #define THIS_MODULE NULL
288 #define MOD_INC_USE_COUNT do { } while (0)
289 #define MOD_DEC_USE_COUNT do { } while (0)
290 #define MOD_IN_USE 1
292 extern struct module *module_list;
294 #endif /* !__GENKSYMS__ */
296 #endif /* MODULE */
298 /* Export a symbol either from the kernel or a module.
300 In the kernel, the symbol is added to the kernel's global symbol table.
302 In a module, it controls which variables are exported. If no
303 variables are explicitly exported, the action is controled by the
304 insmod -[xX] flags. Otherwise, only the variables listed are exported.
305 This obviates the need for the old register_symtab() function. */
307 #if defined(__GENKSYMS__)
309 /* We want the EXPORT_SYMBOL tag left intact for recognition. */
311 #elif !defined(AUTOCONF_INCLUDED)
313 #define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module
314 #define EXPORT_SYMBOL(var) error config_must_be_included_before_module
315 #define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module
317 #elif !defined(CONFIG_MODULES)
319 #define __EXPORT_SYMBOL(sym,str)
320 #define EXPORT_SYMBOL(var)
321 #define EXPORT_SYMBOL_NOVERS(var)
323 #else
325 #define __EXPORT_SYMBOL(sym, str) \
326 const char __kstrtab_##sym[] \
327 __attribute__((section(".kstrtab"))) = str; \
328 const struct module_symbol __ksymtab_##sym \
329 __attribute__((section("__ksymtab"))) = \
330 { (unsigned long)&sym, __kstrtab_##sym }
332 #if defined(MODVERSIONS) || !defined(CONFIG_MODVERSIONS)
333 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
334 #else
335 #define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var)))
336 #endif
338 #define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var))
340 #endif /* __GENKSYMS__ */
342 #ifdef MODULE
343 /* Force a module to export no symbols. */
344 #define EXPORT_NO_SYMBOLS __asm__(".section __ksymtab\n.previous")
345 #else
346 #define EXPORT_NO_SYMBOLS
347 #endif /* MODULE */
349 #ifdef CONFIG_MODULES
350 #define SET_MODULE_OWNER(some_struct) do { (some_struct)->owner = THIS_MODULE; } while (0)
351 #else
352 #define SET_MODULE_OWNER(some_struct) do { } while (0)
353 #endif
355 #endif /* _LINUX_MODULE_H */