diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/moduleparam.h |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'include/linux/moduleparam.h')
-rw-r--r-- | include/linux/moduleparam.h | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h new file mode 100644 index 000000000000..368ec8e45bd0 --- /dev/null +++ b/include/linux/moduleparam.h | |||
@@ -0,0 +1,182 @@ | |||
1 | #ifndef _LINUX_MODULE_PARAMS_H | ||
2 | #define _LINUX_MODULE_PARAMS_H | ||
3 | /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */ | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/stringify.h> | ||
6 | #include <linux/kernel.h> | ||
7 | |||
8 | /* You can override this manually, but generally this should match the | ||
9 | module name. */ | ||
10 | #ifdef MODULE | ||
11 | #define MODULE_PARAM_PREFIX /* empty */ | ||
12 | #else | ||
13 | #define MODULE_PARAM_PREFIX __stringify(KBUILD_MODNAME) "." | ||
14 | #endif | ||
15 | |||
16 | #ifdef MODULE | ||
17 | #define ___module_cat(a,b) __mod_ ## a ## b | ||
18 | #define __module_cat(a,b) ___module_cat(a,b) | ||
19 | #define __MODULE_INFO(tag, name, info) \ | ||
20 | static const char __module_cat(name,__LINE__)[] \ | ||
21 | __attribute_used__ \ | ||
22 | __attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info | ||
23 | #else /* !MODULE */ | ||
24 | #define __MODULE_INFO(tag, name, info) | ||
25 | #endif | ||
26 | #define __MODULE_PARM_TYPE(name, _type) \ | ||
27 | __MODULE_INFO(parmtype, name##type, #name ":" _type) | ||
28 | |||
29 | struct kernel_param; | ||
30 | |||
31 | /* Returns 0, or -errno. arg is in kp->arg. */ | ||
32 | typedef int (*param_set_fn)(const char *val, struct kernel_param *kp); | ||
33 | /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | ||
34 | typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); | ||
35 | |||
36 | struct kernel_param { | ||
37 | const char *name; | ||
38 | unsigned int perm; | ||
39 | param_set_fn set; | ||
40 | param_get_fn get; | ||
41 | void *arg; | ||
42 | }; | ||
43 | |||
44 | /* Special one for strings we want to copy into */ | ||
45 | struct kparam_string { | ||
46 | unsigned int maxlen; | ||
47 | char *string; | ||
48 | }; | ||
49 | |||
50 | /* Special one for arrays */ | ||
51 | struct kparam_array | ||
52 | { | ||
53 | unsigned int max; | ||
54 | unsigned int *num; | ||
55 | param_set_fn set; | ||
56 | param_get_fn get; | ||
57 | unsigned int elemsize; | ||
58 | void *elem; | ||
59 | }; | ||
60 | |||
61 | /* This is the fundamental function for registering boot/module | ||
62 | parameters. perm sets the visibility in driverfs: 000 means it's | ||
63 | not there, read bits mean it's readable, write bits mean it's | ||
64 | writable. */ | ||
65 | #define __module_param_call(prefix, name, set, get, arg, perm) \ | ||
66 | static char __param_str_##name[] = prefix #name; \ | ||
67 | static struct kernel_param const __param_##name \ | ||
68 | __attribute_used__ \ | ||
69 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ | ||
70 | = { __param_str_##name, perm, set, get, arg } | ||
71 | |||
72 | #define module_param_call(name, set, get, arg, perm) \ | ||
73 | __module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm) | ||
74 | |||
75 | /* Helper functions: type is byte, short, ushort, int, uint, long, | ||
76 | ulong, charp, bool or invbool, or XXX if you define param_get_XXX, | ||
77 | param_set_XXX and param_check_XXX. */ | ||
78 | #define module_param_named(name, value, type, perm) \ | ||
79 | param_check_##type(name, &(value)); \ | ||
80 | module_param_call(name, param_set_##type, param_get_##type, &value, perm); \ | ||
81 | __MODULE_PARM_TYPE(name, #type) | ||
82 | |||
83 | #define module_param(name, type, perm) \ | ||
84 | module_param_named(name, name, type, perm) | ||
85 | |||
86 | /* Actually copy string: maxlen param is usually sizeof(string). */ | ||
87 | #define module_param_string(name, string, len, perm) \ | ||
88 | static struct kparam_string __param_string_##name \ | ||
89 | = { len, string }; \ | ||
90 | module_param_call(name, param_set_copystring, param_get_string, \ | ||
91 | &__param_string_##name, perm); \ | ||
92 | __MODULE_PARM_TYPE(name, "string") | ||
93 | |||
94 | /* Called on module insert or kernel boot */ | ||
95 | extern int parse_args(const char *name, | ||
96 | char *args, | ||
97 | struct kernel_param *params, | ||
98 | unsigned num, | ||
99 | int (*unknown)(char *param, char *val)); | ||
100 | |||
101 | /* All the helper functions */ | ||
102 | /* The macros to do compile-time type checking stolen from Jakub | ||
103 | Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ | ||
104 | #define __param_check(name, p, type) \ | ||
105 | static inline type *__check_##name(void) { return(p); } | ||
106 | |||
107 | extern int param_set_byte(const char *val, struct kernel_param *kp); | ||
108 | extern int param_get_byte(char *buffer, struct kernel_param *kp); | ||
109 | #define param_check_byte(name, p) __param_check(name, p, unsigned char) | ||
110 | |||
111 | extern int param_set_short(const char *val, struct kernel_param *kp); | ||
112 | extern int param_get_short(char *buffer, struct kernel_param *kp); | ||
113 | #define param_check_short(name, p) __param_check(name, p, short) | ||
114 | |||
115 | extern int param_set_ushort(const char *val, struct kernel_param *kp); | ||
116 | extern int param_get_ushort(char *buffer, struct kernel_param *kp); | ||
117 | #define param_check_ushort(name, p) __param_check(name, p, unsigned short) | ||
118 | |||
119 | extern int param_set_int(const char *val, struct kernel_param *kp); | ||
120 | extern int param_get_int(char *buffer, struct kernel_param *kp); | ||
121 | #define param_check_int(name, p) __param_check(name, p, int) | ||
122 | |||
123 | extern int param_set_uint(const char *val, struct kernel_param *kp); | ||
124 | extern int param_get_uint(char *buffer, struct kernel_param *kp); | ||
125 | #define param_check_uint(name, p) __param_check(name, p, unsigned int) | ||
126 | |||
127 | extern int param_set_long(const char *val, struct kernel_param *kp); | ||
128 | extern int param_get_long(char *buffer, struct kernel_param *kp); | ||
129 | #define param_check_long(name, p) __param_check(name, p, long) | ||
130 | |||
131 | extern int param_set_ulong(const char *val, struct kernel_param *kp); | ||
132 | extern int param_get_ulong(char *buffer, struct kernel_param *kp); | ||
133 | #define param_check_ulong(name, p) __param_check(name, p, unsigned long) | ||
134 | |||
135 | extern int param_set_charp(const char *val, struct kernel_param *kp); | ||
136 | extern int param_get_charp(char *buffer, struct kernel_param *kp); | ||
137 | #define param_check_charp(name, p) __param_check(name, p, char *) | ||
138 | |||
139 | extern int param_set_bool(const char *val, struct kernel_param *kp); | ||
140 | extern int param_get_bool(char *buffer, struct kernel_param *kp); | ||
141 | #define param_check_bool(name, p) __param_check(name, p, int) | ||
142 | |||
143 | extern int param_set_invbool(const char *val, struct kernel_param *kp); | ||
144 | extern int param_get_invbool(char *buffer, struct kernel_param *kp); | ||
145 | #define param_check_invbool(name, p) __param_check(name, p, int) | ||
146 | |||
147 | /* Comma-separated array: *nump is set to number they actually specified. */ | ||
148 | #define module_param_array_named(name, array, type, nump, perm) \ | ||
149 | static struct kparam_array __param_arr_##name \ | ||
150 | = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ | ||
151 | sizeof(array[0]), array }; \ | ||
152 | module_param_call(name, param_array_set, param_array_get, \ | ||
153 | &__param_arr_##name, perm); \ | ||
154 | __MODULE_PARM_TYPE(name, "array of " #type) | ||
155 | |||
156 | #define module_param_array(name, type, nump, perm) \ | ||
157 | module_param_array_named(name, name, type, nump, perm) | ||
158 | |||
159 | extern int param_array_set(const char *val, struct kernel_param *kp); | ||
160 | extern int param_array_get(char *buffer, struct kernel_param *kp); | ||
161 | |||
162 | extern int param_set_copystring(const char *val, struct kernel_param *kp); | ||
163 | extern int param_get_string(char *buffer, struct kernel_param *kp); | ||
164 | |||
165 | int param_array(const char *name, | ||
166 | const char *val, | ||
167 | unsigned int min, unsigned int max, | ||
168 | void *elem, int elemsize, | ||
169 | int (*set)(const char *, struct kernel_param *kp), | ||
170 | int *num); | ||
171 | |||
172 | /* for exporting parameters in /sys/parameters */ | ||
173 | |||
174 | struct module; | ||
175 | |||
176 | extern int module_param_sysfs_setup(struct module *mod, | ||
177 | struct kernel_param *kparam, | ||
178 | unsigned int num_params); | ||
179 | |||
180 | extern void module_param_sysfs_remove(struct module *mod); | ||
181 | |||
182 | #endif /* _LINUX_MODULE_PARAMS_H */ | ||