There is a bug in the CKRM CPU scheduler. This has been reported to the
[linux-2.6.git] / include / linux / module.h
1 #ifndef _LINUX_MODULE_H
2 #define _LINUX_MODULE_H
3 /*
4  * Dynamic loading of modules into the kernel.
5  *
6  * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
7  * Rewritten again by Rusty Russell, 2002
8  */
9 #include <linux/config.h>
10 #include <linux/sched.h>
11 #include <linux/spinlock.h>
12 #include <linux/list.h>
13 #include <linux/stat.h>
14 #include <linux/compiler.h>
15 #include <linux/cache.h>
16 #include <linux/kmod.h>
17 #include <linux/elf.h>
18 #include <linux/stringify.h>
19 #include <linux/kobject.h>
20 #include <linux/moduleparam.h>
21 #include <asm/local.h>
22
23 #include <asm/module.h>
24
25 /* Not Yet Implemented */
26 #define MODULE_SUPPORTED_DEVICE(name)
27
28 /* v850 toolchain uses a `_' prefix for all user symbols */
29 #ifndef MODULE_SYMBOL_PREFIX
30 #define MODULE_SYMBOL_PREFIX ""
31 #endif
32
33 #define MODULE_NAME_LEN (64 - sizeof(unsigned long))
34
35 struct kernel_symbol
36 {
37         unsigned long value;
38         const char *name;
39 };
40
41 struct modversion_info
42 {
43         unsigned long crc;
44         char name[MODULE_NAME_LEN];
45 };
46
47 /* These are either module local, or the kernel's dummy ones. */
48 extern int init_module(void);
49 extern void cleanup_module(void);
50
51 /* Archs provide a method of finding the correct exception table. */
52 struct exception_table_entry;
53
54 const struct exception_table_entry *
55 search_extable(const struct exception_table_entry *first,
56                const struct exception_table_entry *last,
57                unsigned long value);
58 void sort_extable(struct exception_table_entry *start,
59                   struct exception_table_entry *finish);
60 void sort_main_extable(void);
61
62 #ifdef MODULE
63 #define ___module_cat(a,b) __mod_ ## a ## b
64 #define __module_cat(a,b) ___module_cat(a,b)
65 #define __MODULE_INFO(tag, name, info)                                    \
66 static const char __module_cat(name,__LINE__)[]                           \
67   __attribute_used__                                                      \
68   __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
69
70 #define MODULE_GENERIC_TABLE(gtype,name)                        \
71 extern const struct gtype##_id __mod_##gtype##_table            \
72   __attribute__ ((unused, alias(__stringify(name))))
73
74 extern struct module __this_module;
75 #define THIS_MODULE (&__this_module)
76
77 #else  /* !MODULE */
78
79 #define MODULE_GENERIC_TABLE(gtype,name)
80 #define __MODULE_INFO(tag, name, info)
81 #define THIS_MODULE ((struct module *)0)
82 #endif
83
84 /* Generic info of form tag = "info" */
85 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
86
87 /* For userspace: you can also call me... */
88 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
89
90 /*
91  * The following license idents are currently accepted as indicating free
92  * software modules
93  *
94  *      "GPL"                           [GNU Public License v2 or later]
95  *      "GPL v2"                        [GNU Public License v2]
96  *      "GPL and additional rights"     [GNU Public License v2 rights and more]
97  *      "Dual BSD/GPL"                  [GNU Public License v2
98  *                                       or BSD license choice]
99  *      "Dual MPL/GPL"                  [GNU Public License v2
100  *                                       or Mozilla license choice]
101  *
102  * The following other idents are available
103  *
104  *      "Proprietary"                   [Non free products]
105  *
106  * There are dual licensed components, but when running with Linux it is the
107  * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
108  * is a GPL combined work.
109  *
110  * This exists for several reasons
111  * 1.   So modinfo can show license info for users wanting to vet their setup 
112  *      is free
113  * 2.   So the community can ignore bug reports including proprietary modules
114  * 3.   So vendors can do likewise based on their own policies
115  */
116 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
117
118 /* Author, ideally of form NAME <EMAIL>[, NAME <EMAIL>]*[ and NAME <EMAIL>] */
119 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
120   
121 /* What your module does. */
122 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
123
124 /* One for each parameter, describing how to use it.  Some files do
125    multiple of these per line, so can't just use MODULE_INFO. */
126 #define MODULE_PARM_DESC(_parm, desc) \
127         __MODULE_INFO(parm, _parm, #_parm ":" desc)
128
129 #define MODULE_DEVICE_TABLE(type,name)          \
130   MODULE_GENERIC_TABLE(type##_device,name)
131
132 /* Version of form [<epoch>:]<version>[-<extra-version>].
133    Or for CVS/RCS ID version, everything but the number is stripped.
134   <epoch>: A (small) unsigned integer which allows you to start versions
135            anew. If not mentioned, it's zero.  eg. "2:1.0" is after
136            "1:2.0".
137   <version>: The <version> may contain only alphanumerics and the
138            character `.'.  Ordered by numeric sort for numeric parts,
139            ascii sort for ascii parts (as per RPM or DEB algorithm).
140   <extraversion>: Like <version>, but inserted for local
141            customizations, eg "rh3" or "rusty1".
142
143   Using this automatically adds a checksum of the .c files and the
144   local headers to the end.  Use MODULE_VERSION("") if you want just
145   this.  Macro includes room for this.
146 */
147 #define MODULE_VERSION(_version) \
148   MODULE_INFO(version, _version "\0xxxxxxxxxxxxxxxxxxxxxxxx")
149
150 /* Given an address, look for it in the exception tables */
151 const struct exception_table_entry *search_exception_tables(unsigned long add);
152
153 struct notifier_block;
154
155 #ifdef CONFIG_MODULES
156
157 /* Get/put a kernel symbol (calls must be symmetric) */
158 void *__symbol_get(const char *symbol);
159 void *__symbol_get_gpl(const char *symbol);
160 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x)))
161
162 #ifndef __GENKSYMS__
163 #ifdef CONFIG_MODVERSIONS
164 /* Mark the CRC weak since genksyms apparently decides not to
165  * generate a checksums for some symbols */
166 #define __CRC_SYMBOL(sym, sec)                                  \
167         extern void *__crc_##sym __attribute__((weak));         \
168         static const unsigned long __kcrctab_##sym              \
169         __attribute_used__                                      \
170         __attribute__((section("__kcrctab" sec), unused))       \
171         = (unsigned long) &__crc_##sym;
172 #else
173 #define __CRC_SYMBOL(sym, sec)
174 #endif
175
176 /* For every exported symbol, place a struct in the __ksymtab section */
177 #define __EXPORT_SYMBOL(sym, sec)                               \
178         __CRC_SYMBOL(sym, sec)                                  \
179         static const char __kstrtab_##sym[]                     \
180         __attribute__((section("__ksymtab_strings")))           \
181         = MODULE_SYMBOL_PREFIX #sym;                            \
182         static const struct kernel_symbol __ksymtab_##sym       \
183         __attribute_used__                                      \
184         __attribute__((section("__ksymtab" sec), unused))       \
185         = { (unsigned long)&sym, __kstrtab_##sym }
186
187 #define EXPORT_SYMBOL(sym)                                      \
188         __EXPORT_SYMBOL(sym, "")
189
190 #define EXPORT_SYMBOL_GPL(sym)                                  \
191         __EXPORT_SYMBOL(sym, "_gpl")
192
193 #endif
194
195 /* We don't mangle the actual symbol anymore, so no need for
196  * special casing EXPORT_SYMBOL_NOVERS.  FIXME: Deprecated */
197 #define EXPORT_SYMBOL_NOVERS(sym) EXPORT_SYMBOL(sym)
198
199 struct module_ref
200 {
201         local_t count;
202 } ____cacheline_aligned;
203
204 enum module_state
205 {
206         MODULE_STATE_LIVE,
207         MODULE_STATE_COMING,
208         MODULE_STATE_GOING,
209 };
210
211 /* sysfs stuff */
212 struct module_attribute
213 {
214         struct attribute attr;
215         struct kernel_param *param;
216 };
217
218 struct module_kobject
219 {
220         /* Everyone should have one of these. */
221         struct kobject kobj;
222
223         /* We always have refcnt, we may have others from module_param(). */
224         unsigned int num_attributes;
225         struct module_attribute attr[0];
226 };
227
228 /* Similar stuff for section attributes. */
229 #define MODULE_SECT_NAME_LEN 32
230 struct module_sect_attr
231 {
232         struct attribute attr;
233         char name[MODULE_SECT_NAME_LEN];
234         unsigned long address;
235 };
236
237 struct module_sections
238 {
239         struct kobject kobj;
240         struct module_sect_attr attrs[0];
241 };
242
243
244 struct module
245 {
246         enum module_state state;
247
248         /* Member of list of modules */
249         struct list_head list;
250
251         /* Unique handle for this module */
252         char name[MODULE_NAME_LEN];
253
254         /* Sysfs stuff. */
255         struct module_kobject *mkobj;
256
257         /* Exported symbols */
258         const struct kernel_symbol *syms;
259         unsigned int num_syms;
260         const unsigned long *crcs;
261
262         /* GPL-only exported symbols. */
263         const struct kernel_symbol *gpl_syms;
264         unsigned int num_gpl_syms;
265         const unsigned long *gpl_crcs;
266
267         /* Exception table */
268         unsigned int num_exentries;
269         const struct exception_table_entry *extable;
270
271         /* Startup function. */
272         int (*init)(void);
273
274         /* If this is non-NULL, vfree after init() returns */
275         void *module_init;
276
277         /* Here is the actual code + data, vfree'd on unload. */
278         void *module_core;
279
280         /* Here are the sizes of the init and core sections */
281         unsigned long init_size, core_size;
282
283         /* The size of the executable code in each section.  */
284         unsigned long init_text_size, core_text_size;
285
286         /* Arch-specific module values */
287         struct mod_arch_specific arch;
288
289         /* Am I unsafe to unload? */
290         int unsafe;
291
292         /* Am I GPL-compatible */
293         int license_gplok;
294         
295         /* Am I gpg signed */
296         int gpgsig_ok;
297
298 #ifdef CONFIG_MODULE_UNLOAD
299         /* Reference counts */
300         struct module_ref ref[NR_CPUS];
301
302         /* What modules depend on me? */
303         struct list_head modules_which_use_me;
304
305         /* Who is waiting for us to be unloaded */
306         struct task_struct *waiter;
307
308         /* Destruction function. */
309         void (*exit)(void);
310
311         /* Fake kernel param for refcnt. */
312         struct kernel_param refcnt_param;
313 #endif
314
315 #ifdef CONFIG_KALLSYMS
316         /* We keep the symbol and string tables for kallsyms. */
317         Elf_Sym *symtab;
318         unsigned long num_symtab;
319         char *strtab;
320
321         /* Section attributes */
322         struct module_sections *sect_attrs;
323 #endif
324
325         /* Per-cpu data. */
326         void *percpu;
327
328         /* The command line arguments (may be mangled).  People like
329            keeping pointers to this stuff */
330         char *args;
331 };
332
333 /* FIXME: It'd be nice to isolate modules during init, too, so they
334    aren't used before they (may) fail.  But presently too much code
335    (IDE & SCSI) require entry into the module during init.*/
336 static inline int module_is_live(struct module *mod)
337 {
338         return mod->state != MODULE_STATE_GOING;
339 }
340
341 /* Is this address in a module? (second is with no locks, for oops) */
342 struct module *module_text_address(unsigned long addr);
343 struct module *__module_text_address(unsigned long addr);
344
345 /* Returns module and fills in value, defined and namebuf, or NULL if
346    symnum out of range. */
347 struct module *module_get_kallsym(unsigned int symnum,
348                                   unsigned long *value,
349                                   char *type,
350                                   char namebuf[128]);
351
352 /* Look for this name: can be of form module:name. */
353 unsigned long module_kallsyms_lookup_name(const char *name);
354
355 int is_exported(const char *name, const struct module *mod);
356
357 extern void __module_put_and_exit(struct module *mod, long code)
358         __attribute__((noreturn));
359 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
360
361 #ifdef CONFIG_MODULE_UNLOAD
362 unsigned int module_refcount(struct module *mod);
363 void __symbol_put(const char *symbol);
364 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
365 void symbol_put_addr(void *addr);
366
367 /* Sometimes we know we already have a refcount, and it's easier not
368    to handle the error case (which only happens with rmmod --wait). */
369 static inline void __module_get(struct module *module)
370 {
371         if (module) {
372                 BUG_ON(module_refcount(module) == 0);
373                 local_inc(&module->ref[get_cpu()].count);
374                 put_cpu();
375         }
376 }
377
378 static inline int try_module_get(struct module *module)
379 {
380         int ret = 1;
381
382         if (module) {
383                 unsigned int cpu = get_cpu();
384                 if (likely(module_is_live(module)))
385                         local_inc(&module->ref[cpu].count);
386                 else
387                         ret = 0;
388                 put_cpu();
389         }
390         return ret;
391 }
392
393 static inline void module_put(struct module *module)
394 {
395         if (module) {
396                 unsigned int cpu = get_cpu();
397                 local_dec(&module->ref[cpu].count);
398                 /* Maybe they're waiting for us to drop reference? */
399                 if (unlikely(!module_is_live(module)))
400                         wake_up_process(module->waiter);
401                 put_cpu();
402         }
403 }
404
405 #else /*!CONFIG_MODULE_UNLOAD*/
406 static inline int try_module_get(struct module *module)
407 {
408         return !module || module_is_live(module);
409 }
410 static inline void module_put(struct module *module)
411 {
412 }
413 static inline void __module_get(struct module *module)
414 {
415 }
416 #define symbol_put(x) do { } while(0)
417 #define symbol_put_addr(p) do { } while(0)
418
419 #endif /* CONFIG_MODULE_UNLOAD */
420
421 /* This is a #define so the string doesn't get put in every .o file */
422 #define module_name(mod)                        \
423 ({                                              \
424         struct module *__mod = (mod);           \
425         __mod ? __mod->name : "kernel";         \
426 })
427
428 #define __unsafe(mod)                                                        \
429 do {                                                                         \
430         if (mod && !(mod)->unsafe) {                                         \
431                 printk(KERN_WARNING                                          \
432                        "Module %s cannot be unloaded due to unsafe usage in" \
433                        " %s:%u\n", (mod)->name, __FILE__, __LINE__);         \
434                 (mod)->unsafe = 1;                                           \
435         }                                                                    \
436 } while(0)
437
438 /* For kallsyms to ask for address resolution.  NULL means not found. */
439 const char *module_address_lookup(unsigned long addr,
440                                   unsigned long *symbolsize,
441                                   unsigned long *offset,
442                                   char **modname);
443
444 /* For extable.c to search modules' exception tables. */
445 const struct exception_table_entry *search_module_extables(unsigned long addr);
446
447 int register_module_notifier(struct notifier_block * nb);
448 int unregister_module_notifier(struct notifier_block * nb);
449
450 extern void print_modules(void);
451 #else /* !CONFIG_MODULES... */
452 #define EXPORT_SYMBOL(sym)
453 #define EXPORT_SYMBOL_GPL(sym)
454 #define EXPORT_SYMBOL_NOVERS(sym)
455
456 /* Given an address, look for it in the exception tables. */
457 static inline const struct exception_table_entry *
458 search_module_extables(unsigned long addr)
459 {
460         return NULL;
461 }
462
463 /* Is this address in a module? */
464 static inline struct module *module_text_address(unsigned long addr)
465 {
466         return NULL;
467 }
468
469 /* Is this address in a module? (don't take a lock, we're oopsing) */
470 static inline struct module *__module_text_address(unsigned long addr)
471 {
472         return NULL;
473 }
474
475 /* Get/put a kernel symbol (calls should be symmetric) */
476 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
477 #define symbol_put(x) do { } while(0)
478 #define symbol_put_addr(x) do { } while(0)
479
480 static inline void __module_get(struct module *module)
481 {
482 }
483
484 static inline int try_module_get(struct module *module)
485 {
486         return 1;
487 }
488
489 static inline void module_put(struct module *module)
490 {
491 }
492
493 #define module_name(mod) "kernel"
494
495 #define __unsafe(mod)
496
497 /* For kallsyms to ask for address resolution.  NULL means not found. */
498 static inline const char *module_address_lookup(unsigned long addr,
499                                                 unsigned long *symbolsize,
500                                                 unsigned long *offset,
501                                                 char **modname)
502 {
503         return NULL;
504 }
505
506 static inline struct module *module_get_kallsym(unsigned int symnum,
507                                                 unsigned long *value,
508                                                 char *type,
509                                                 char namebuf[128])
510 {
511         return NULL;
512 }
513
514 static inline unsigned long module_kallsyms_lookup_name(const char *name)
515 {
516         return 0;
517 }
518
519 static inline int is_exported(const char *name, const struct module *mod)
520 {
521         return 0;
522 }
523
524 static inline int register_module_notifier(struct notifier_block * nb)
525 {
526         /* no events will happen anyway, so this can always succeed */
527         return 0;
528 }
529
530 static inline int unregister_module_notifier(struct notifier_block * nb)
531 {
532         return 0;
533 }
534
535 #define module_put_and_exit(code) do_exit(code)
536
537 static inline void print_modules(void)
538 {
539 }
540 #endif /* CONFIG_MODULES */
541
542 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
543
544 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
545
546 struct obsolete_modparm {
547         char name[64];
548         char type[64-sizeof(void *)];
549         void *addr;
550 };
551 #ifdef MODULE
552 /* DEPRECATED: Do not use. */
553 #define MODULE_PARM(var,type)                                               \
554 struct obsolete_modparm __parm_##var __attribute__((section("__obsparm"))) = \
555 { __stringify(var), type };
556
557 #else
558 #define MODULE_PARM(var,type)
559 #endif
560
561 #define __MODULE_STRING(x) __stringify(x)
562
563 /* Use symbol_get and symbol_put instead.  You'll thank me. */
564 #define HAVE_INTER_MODULE
565 extern void inter_module_register(const char *, struct module *, const void *);
566 extern void inter_module_unregister(const char *);
567 extern const void *inter_module_get(const char *);
568 extern const void *inter_module_get_request(const char *, const char *);
569 extern void inter_module_put(const char *);
570
571 #endif /* _LINUX_MODULE_H */