diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2010-08-12 01:04:20 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-08-11 09:34:21 -0400 |
commit | 546970bc6afc7fb37447fbac09b82c7884662c21 (patch) | |
tree | 34b6e87121061554d0ae8d4f14d7388a7fdf271c /include | |
parent | 907b29eb41aa604477a655bff7345731da94514d (diff) |
param: add kerneldoc to moduleparam.h
Also reorders the macros with the most common ones at the top.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Tested-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/moduleparam.h | 121 |
1 files changed, 95 insertions, 26 deletions
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index ca74a3402d63..893549c04265 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h | |||
@@ -71,6 +71,62 @@ struct kparam_array | |||
71 | void *elem; | 71 | void *elem; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | /** | ||
75 | * module_param - typesafe helper for a module/cmdline parameter | ||
76 | * @value: the variable to alter, and exposed parameter name. | ||
77 | * @type: the type of the parameter | ||
78 | * @perm: visibility in sysfs. | ||
79 | * | ||
80 | * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a | ||
81 | * ".") the kernel commandline parameter. Note that - is changed to _, so | ||
82 | * the user can use "foo-bar=1" even for variable "foo_bar". | ||
83 | * | ||
84 | * @perm is 0 if the the variable is not to appear in sysfs, or 0444 | ||
85 | * for world-readable, 0644 for root-writable, etc. Note that if it | ||
86 | * is writable, you may need to use kparam_block_sysfs_write() around | ||
87 | * accesses (esp. charp, which can be kfreed when it changes). | ||
88 | * | ||
89 | * The @type is simply pasted to refer to a param_ops_##type and a | ||
90 | * param_check_##type: for convenience many standard types are provided but | ||
91 | * you can create your own by defining those variables. | ||
92 | * | ||
93 | * Standard types are: | ||
94 | * byte, short, ushort, int, uint, long, ulong | ||
95 | * charp: a character pointer | ||
96 | * bool: a bool, values 0/1, y/n, Y/N. | ||
97 | * invbool: the above, only sense-reversed (N = true). | ||
98 | */ | ||
99 | #define module_param(name, type, perm) \ | ||
100 | module_param_named(name, name, type, perm) | ||
101 | |||
102 | /** | ||
103 | * module_param_named - typesafe helper for a renamed module/cmdline parameter | ||
104 | * @name: a valid C identifier which is the parameter name. | ||
105 | * @value: the actual lvalue to alter. | ||
106 | * @type: the type of the parameter | ||
107 | * @perm: visibility in sysfs. | ||
108 | * | ||
109 | * Usually it's a good idea to have variable names and user-exposed names the | ||
110 | * same, but that's harder if the variable must be non-static or is inside a | ||
111 | * structure. This allows exposure under a different name. | ||
112 | */ | ||
113 | #define module_param_named(name, value, type, perm) \ | ||
114 | param_check_##type(name, &(value)); \ | ||
115 | module_param_cb(name, ¶m_ops_##type, &value, perm); \ | ||
116 | __MODULE_PARM_TYPE(name, #type) | ||
117 | |||
118 | /** | ||
119 | * module_param_cb - general callback for a module/cmdline parameter | ||
120 | * @name: a valid C identifier which is the parameter name. | ||
121 | * @ops: the set & get operations for this parameter. | ||
122 | * @perm: visibility in sysfs. | ||
123 | * | ||
124 | * The ops can have NULL set or get functions. | ||
125 | */ | ||
126 | #define module_param_cb(name, ops, arg, perm) \ | ||
127 | __module_param_call(MODULE_PARAM_PREFIX, \ | ||
128 | name, ops, arg, __same_type(*(arg), bool), perm) | ||
129 | |||
74 | /* On alpha, ia64 and ppc64 relocations to global data cannot go into | 130 | /* On alpha, ia64 and ppc64 relocations to global data cannot go into |
75 | read-only sections (which is part of respective UNIX ABI on these | 131 | read-only sections (which is part of respective UNIX ABI on these |
76 | platforms). So 'const' makes no sense and even causes compile failures | 132 | platforms). So 'const' makes no sense and even causes compile failures |
@@ -82,9 +138,7 @@ struct kparam_array | |||
82 | #endif | 138 | #endif |
83 | 139 | ||
84 | /* This is the fundamental function for registering boot/module | 140 | /* This is the fundamental function for registering boot/module |
85 | parameters. perm sets the visibility in sysfs: 000 means it's | 141 | parameters. */ |
86 | not there, read bits mean it's readable, write bits mean it's | ||
87 | writable. */ | ||
88 | #define __module_param_call(prefix, name, ops, arg, isbool, perm) \ | 142 | #define __module_param_call(prefix, name, ops, arg, isbool, perm) \ |
89 | /* Default value instead of permissions? */ \ | 143 | /* Default value instead of permissions? */ \ |
90 | static int __param_perm_check_##name __attribute__((unused)) = \ | 144 | static int __param_perm_check_##name __attribute__((unused)) = \ |
@@ -113,23 +167,6 @@ __check_old_set_param(int (*oldset)(const char *, struct kernel_param *)) | |||
113 | return 0; | 167 | return 0; |
114 | } | 168 | } |
115 | 169 | ||
116 | #define module_param_cb(name, ops, arg, perm) \ | ||
117 | __module_param_call(MODULE_PARAM_PREFIX, \ | ||
118 | name, ops, arg, __same_type(*(arg), bool), perm) | ||
119 | |||
120 | /* | ||
121 | * Helper functions: type is byte, short, ushort, int, uint, long, | ||
122 | * ulong, charp, bool or invbool, or XXX if you define param_ops_XXX | ||
123 | * and param_check_XXX. | ||
124 | */ | ||
125 | #define module_param_named(name, value, type, perm) \ | ||
126 | param_check_##type(name, &(value)); \ | ||
127 | module_param_cb(name, ¶m_ops_##type, &value, perm); \ | ||
128 | __MODULE_PARM_TYPE(name, #type) | ||
129 | |||
130 | #define module_param(name, type, perm) \ | ||
131 | module_param_named(name, name, type, perm) | ||
132 | |||
133 | /** | 170 | /** |
134 | * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs. | 171 | * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs. |
135 | * @name: the name of the parameter | 172 | * @name: the name of the parameter |
@@ -191,7 +228,7 @@ static inline void __kernel_param_unlock(void) | |||
191 | * core_param - define a historical core kernel parameter. | 228 | * core_param - define a historical core kernel parameter. |
192 | * @name: the name of the cmdline and sysfs parameter (often the same as var) | 229 | * @name: the name of the cmdline and sysfs parameter (often the same as var) |
193 | * @var: the variable | 230 | * @var: the variable |
194 | * @type: the type (for param_set_##type and param_get_##type) | 231 | * @type: the type of the parameter |
195 | * @perm: visibility in sysfs | 232 | * @perm: visibility in sysfs |
196 | * | 233 | * |
197 | * core_param is just like module_param(), but cannot be modular and | 234 | * core_param is just like module_param(), but cannot be modular and |
@@ -205,7 +242,16 @@ static inline void __kernel_param_unlock(void) | |||
205 | &var, __same_type(var, bool), perm) | 242 | &var, __same_type(var, bool), perm) |
206 | #endif /* !MODULE */ | 243 | #endif /* !MODULE */ |
207 | 244 | ||
208 | /* Actually copy string: maxlen param is usually sizeof(string). */ | 245 | /** |
246 | * module_param_string - a char array parameter | ||
247 | * @name: the name of the parameter | ||
248 | * @string: the string variable | ||
249 | * @len: the maximum length of the string, incl. terminator | ||
250 | * @perm: visibility in sysfs. | ||
251 | * | ||
252 | * This actually copies the string when it's set (unlike type charp). | ||
253 | * @len is usually just sizeof(string). | ||
254 | */ | ||
209 | #define module_param_string(name, string, len, perm) \ | 255 | #define module_param_string(name, string, len, perm) \ |
210 | static const struct kparam_string __param_string_##name \ | 256 | static const struct kparam_string __param_string_##name \ |
211 | = { len, string }; \ | 257 | = { len, string }; \ |
@@ -294,7 +340,33 @@ extern int param_set_invbool(const char *val, const struct kernel_param *kp); | |||
294 | extern int param_get_invbool(char *buffer, const struct kernel_param *kp); | 340 | extern int param_get_invbool(char *buffer, const struct kernel_param *kp); |
295 | #define param_check_invbool(name, p) __param_check(name, p, bool) | 341 | #define param_check_invbool(name, p) __param_check(name, p, bool) |
296 | 342 | ||
297 | /* Comma-separated array: *nump is set to number they actually specified. */ | 343 | /** |
344 | * module_param_array - a parameter which is an array of some type | ||
345 | * @name: the name of the array variable | ||
346 | * @type: the type, as per module_param() | ||
347 | * @nump: optional pointer filled in with the number written | ||
348 | * @perm: visibility in sysfs | ||
349 | * | ||
350 | * Input and output are as comma-separated values. Commas inside values | ||
351 | * don't work properly (eg. an array of charp). | ||
352 | * | ||
353 | * ARRAY_SIZE(@name) is used to determine the number of elements in the | ||
354 | * array, so the definition must be visible. | ||
355 | */ | ||
356 | #define module_param_array(name, type, nump, perm) \ | ||
357 | module_param_array_named(name, name, type, nump, perm) | ||
358 | |||
359 | /** | ||
360 | * module_param_array_named - renamed parameter which is an array of some type | ||
361 | * @name: a valid C identifier which is the parameter name | ||
362 | * @array: the name of the array variable | ||
363 | * @type: the type, as per module_param() | ||
364 | * @nump: optional pointer filled in with the number written | ||
365 | * @perm: visibility in sysfs | ||
366 | * | ||
367 | * This exposes a different name than the actual variable name. See | ||
368 | * module_param_named() for why this might be necessary. | ||
369 | */ | ||
298 | #define module_param_array_named(name, array, type, nump, perm) \ | 370 | #define module_param_array_named(name, array, type, nump, perm) \ |
299 | static const struct kparam_array __param_arr_##name \ | 371 | static const struct kparam_array __param_arr_##name \ |
300 | = { ARRAY_SIZE(array), nump, ¶m_ops_##type, \ | 372 | = { ARRAY_SIZE(array), nump, ¶m_ops_##type, \ |
@@ -305,9 +377,6 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp); | |||
305 | __same_type(array[0], bool), perm); \ | 377 | __same_type(array[0], bool), perm); \ |
306 | __MODULE_PARM_TYPE(name, "array of " #type) | 378 | __MODULE_PARM_TYPE(name, "array of " #type) |
307 | 379 | ||
308 | #define module_param_array(name, type, nump, perm) \ | ||
309 | module_param_array_named(name, name, type, nump, perm) | ||
310 | |||
311 | extern struct kernel_param_ops param_array_ops; | 380 | extern struct kernel_param_ops param_array_ops; |
312 | 381 | ||
313 | extern struct kernel_param_ops param_ops_string; | 382 | extern struct kernel_param_ops param_ops_string; |