Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_MODULE_PARAMS_H |
3 | #define _LINUX_MODULE_PARAMS_H | |
4 | /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */ | |
5 | #include <linux/init.h> | |
6 | #include <linux/stringify.h> | |
7 | #include <linux/kernel.h> | |
8 | ||
9 | /* You can override this manually, but generally this should match the | |
10 | module name. */ | |
11 | #ifdef MODULE | |
12 | #define MODULE_PARAM_PREFIX /* empty */ | |
898490c0 | 13 | #define __MODULE_INFO_PREFIX /* empty */ |
1da177e4 | 14 | #else |
367cb704 | 15 | #define MODULE_PARAM_PREFIX KBUILD_MODNAME "." |
898490c0 AG |
16 | /* We cannot use MODULE_PARAM_PREFIX because some modules override it. */ |
17 | #define __MODULE_INFO_PREFIX KBUILD_MODNAME "." | |
1da177e4 LT |
18 | #endif |
19 | ||
730b69d2 RR |
20 | /* Chosen so that structs with an unsigned long line up. */ |
21 | #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) | |
22 | ||
1da177e4 | 23 | #define __MODULE_INFO(tag, name, info) \ |
34182eea | 24 | static const char __UNIQUE_ID(name)[] \ |
b6472776 | 25 | __used __attribute__((section(".modinfo"), unused, aligned(1))) \ |
898490c0 AG |
26 | = __MODULE_INFO_PREFIX __stringify(tag) "=" info |
27 | ||
1da177e4 LT |
28 | #define __MODULE_PARM_TYPE(name, _type) \ |
29 | __MODULE_INFO(parmtype, name##type, #name ":" _type) | |
30 | ||
639938eb PG |
31 | /* One for each parameter, describing how to use it. Some files do |
32 | multiple of these per line, so can't just use MODULE_INFO. */ | |
33 | #define MODULE_PARM_DESC(_parm, desc) \ | |
34 | __MODULE_INFO(parm, _parm, #_parm ":" desc) | |
35 | ||
1da177e4 LT |
36 | struct kernel_param; |
37 | ||
ab013c5f SR |
38 | /* |
39 | * Flags available for kernel_param_ops | |
40 | * | |
41 | * NOARG - the parameter allows for no argument (foo instead of foo=1) | |
42 | */ | |
43 | enum { | |
6a4c2643 | 44 | KERNEL_PARAM_OPS_FL_NOARG = (1 << 0) |
ab013c5f SR |
45 | }; |
46 | ||
9bbb9e5a | 47 | struct kernel_param_ops { |
ab013c5f SR |
48 | /* How the ops should behave */ |
49 | unsigned int flags; | |
9bbb9e5a RR |
50 | /* Returns 0, or -errno. arg is in kp->arg. */ |
51 | int (*set)(const char *val, const struct kernel_param *kp); | |
52 | /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
53 | int (*get)(char *buffer, const struct kernel_param *kp); | |
e6df34a4 RR |
54 | /* Optional function to free kp->arg when module unloaded. */ |
55 | void (*free)(void *arg); | |
9bbb9e5a | 56 | }; |
1da177e4 | 57 | |
91f9d330 JN |
58 | /* |
59 | * Flags available for kernel_param | |
60 | * | |
61 | * UNSAFE - the parameter is dangerous and setting it will taint the kernel | |
bf616d21 | 62 | * HWPARAM - Hardware param not permitted in lockdown mode |
91f9d330 JN |
63 | */ |
64 | enum { | |
bf616d21 DH |
65 | KERNEL_PARAM_FL_UNSAFE = (1 << 0), |
66 | KERNEL_PARAM_FL_HWPARAM = (1 << 1), | |
91f9d330 JN |
67 | }; |
68 | ||
1da177e4 LT |
69 | struct kernel_param { |
70 | const char *name; | |
b51d23e4 | 71 | struct module *mod; |
9bbb9e5a | 72 | const struct kernel_param_ops *ops; |
5104b7d7 | 73 | const u16 perm; |
91f9d330 JN |
74 | s8 level; |
75 | u8 flags; | |
22e48eaf JB |
76 | union { |
77 | void *arg; | |
78 | const struct kparam_string *str; | |
79 | const struct kparam_array *arr; | |
80 | }; | |
1da177e4 LT |
81 | }; |
82 | ||
63a12d9d GU |
83 | extern const struct kernel_param __start___param[], __stop___param[]; |
84 | ||
1da177e4 LT |
85 | /* Special one for strings we want to copy into */ |
86 | struct kparam_string { | |
87 | unsigned int maxlen; | |
88 | char *string; | |
89 | }; | |
90 | ||
91 | /* Special one for arrays */ | |
92 | struct kparam_array | |
93 | { | |
94 | unsigned int max; | |
c5be0b2e | 95 | unsigned int elemsize; |
1da177e4 | 96 | unsigned int *num; |
9bbb9e5a | 97 | const struct kernel_param_ops *ops; |
1da177e4 LT |
98 | void *elem; |
99 | }; | |
100 | ||
546970bc RR |
101 | /** |
102 | * module_param - typesafe helper for a module/cmdline parameter | |
e2854a10 | 103 | * @name: the variable to alter, and exposed parameter name. |
546970bc RR |
104 | * @type: the type of the parameter |
105 | * @perm: visibility in sysfs. | |
106 | * | |
e2854a10 | 107 | * @name becomes the module parameter, or (prefixed by KBUILD_MODNAME and a |
546970bc RR |
108 | * ".") the kernel commandline parameter. Note that - is changed to _, so |
109 | * the user can use "foo-bar=1" even for variable "foo_bar". | |
110 | * | |
c6a8b84d | 111 | * @perm is 0 if the variable is not to appear in sysfs, or 0444 |
546970bc | 112 | * for world-readable, 0644 for root-writable, etc. Note that if it |
b51d23e4 | 113 | * is writable, you may need to use kernel_param_lock() around |
546970bc RR |
114 | * accesses (esp. charp, which can be kfreed when it changes). |
115 | * | |
116 | * The @type is simply pasted to refer to a param_ops_##type and a | |
117 | * param_check_##type: for convenience many standard types are provided but | |
118 | * you can create your own by defining those variables. | |
119 | * | |
120 | * Standard types are: | |
121 | * byte, short, ushort, int, uint, long, ulong | |
122 | * charp: a character pointer | |
123 | * bool: a bool, values 0/1, y/n, Y/N. | |
124 | * invbool: the above, only sense-reversed (N = true). | |
125 | */ | |
126 | #define module_param(name, type, perm) \ | |
127 | module_param_named(name, name, type, perm) | |
128 | ||
3baee201 JN |
129 | /** |
130 | * module_param_unsafe - same as module_param but taints kernel | |
b6d0531e FD |
131 | * @name: the variable to alter, and exposed parameter name. |
132 | * @type: the type of the parameter | |
133 | * @perm: visibility in sysfs. | |
3baee201 JN |
134 | */ |
135 | #define module_param_unsafe(name, type, perm) \ | |
136 | module_param_named_unsafe(name, name, type, perm) | |
137 | ||
546970bc RR |
138 | /** |
139 | * module_param_named - typesafe helper for a renamed module/cmdline parameter | |
140 | * @name: a valid C identifier which is the parameter name. | |
141 | * @value: the actual lvalue to alter. | |
142 | * @type: the type of the parameter | |
143 | * @perm: visibility in sysfs. | |
144 | * | |
145 | * Usually it's a good idea to have variable names and user-exposed names the | |
146 | * same, but that's harder if the variable must be non-static or is inside a | |
147 | * structure. This allows exposure under a different name. | |
148 | */ | |
149 | #define module_param_named(name, value, type, perm) \ | |
150 | param_check_##type(name, &(value)); \ | |
151 | module_param_cb(name, ¶m_ops_##type, &value, perm); \ | |
152 | __MODULE_PARM_TYPE(name, #type) | |
153 | ||
3baee201 JN |
154 | /** |
155 | * module_param_named_unsafe - same as module_param_named but taints kernel | |
b6d0531e FD |
156 | * @name: a valid C identifier which is the parameter name. |
157 | * @value: the actual lvalue to alter. | |
158 | * @type: the type of the parameter | |
159 | * @perm: visibility in sysfs. | |
3baee201 JN |
160 | */ |
161 | #define module_param_named_unsafe(name, value, type, perm) \ | |
162 | param_check_##type(name, &(value)); \ | |
163 | module_param_cb_unsafe(name, ¶m_ops_##type, &value, perm); \ | |
164 | __MODULE_PARM_TYPE(name, #type) | |
165 | ||
546970bc RR |
166 | /** |
167 | * module_param_cb - general callback for a module/cmdline parameter | |
168 | * @name: a valid C identifier which is the parameter name. | |
169 | * @ops: the set & get operations for this parameter. | |
b6d0531e | 170 | * @arg: args for @ops |
546970bc RR |
171 | * @perm: visibility in sysfs. |
172 | * | |
173 | * The ops can have NULL set or get functions. | |
174 | */ | |
175 | #define module_param_cb(name, ops, arg, perm) \ | |
91f9d330 | 176 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0) |
026cee00 | 177 | |
3baee201 JN |
178 | #define module_param_cb_unsafe(name, ops, arg, perm) \ |
179 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \ | |
180 | KERNEL_PARAM_FL_UNSAFE) | |
181 | ||
b6d0531e FD |
182 | #define __level_param_cb(name, ops, arg, perm, level) \ |
183 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) | |
026cee00 | 184 | /** |
b6d0531e FD |
185 | * core_param_cb - general callback for a module/cmdline parameter |
186 | * to be evaluated before core initcall level | |
026cee00 PM |
187 | * @name: a valid C identifier which is the parameter name. |
188 | * @ops: the set & get operations for this parameter. | |
b6d0531e | 189 | * @arg: args for @ops |
026cee00 PM |
190 | * @perm: visibility in sysfs. |
191 | * | |
192 | * The ops can have NULL set or get functions. | |
193 | */ | |
026cee00 PM |
194 | #define core_param_cb(name, ops, arg, perm) \ |
195 | __level_param_cb(name, ops, arg, perm, 1) | |
196 | ||
b6d0531e FD |
197 | /** |
198 | * postcore_param_cb - general callback for a module/cmdline parameter | |
199 | * to be evaluated before postcore initcall level | |
200 | * @name: a valid C identifier which is the parameter name. | |
201 | * @ops: the set & get operations for this parameter. | |
202 | * @arg: args for @ops | |
203 | * @perm: visibility in sysfs. | |
204 | * | |
205 | * The ops can have NULL set or get functions. | |
206 | */ | |
026cee00 PM |
207 | #define postcore_param_cb(name, ops, arg, perm) \ |
208 | __level_param_cb(name, ops, arg, perm, 2) | |
209 | ||
b6d0531e FD |
210 | /** |
211 | * arch_param_cb - general callback for a module/cmdline parameter | |
212 | * to be evaluated before arch initcall level | |
213 | * @name: a valid C identifier which is the parameter name. | |
214 | * @ops: the set & get operations for this parameter. | |
215 | * @arg: args for @ops | |
216 | * @perm: visibility in sysfs. | |
217 | * | |
218 | * The ops can have NULL set or get functions. | |
219 | */ | |
026cee00 PM |
220 | #define arch_param_cb(name, ops, arg, perm) \ |
221 | __level_param_cb(name, ops, arg, perm, 3) | |
222 | ||
b6d0531e FD |
223 | /** |
224 | * subsys_param_cb - general callback for a module/cmdline parameter | |
225 | * to be evaluated before subsys initcall level | |
226 | * @name: a valid C identifier which is the parameter name. | |
227 | * @ops: the set & get operations for this parameter. | |
228 | * @arg: args for @ops | |
229 | * @perm: visibility in sysfs. | |
230 | * | |
231 | * The ops can have NULL set or get functions. | |
232 | */ | |
026cee00 PM |
233 | #define subsys_param_cb(name, ops, arg, perm) \ |
234 | __level_param_cb(name, ops, arg, perm, 4) | |
235 | ||
b6d0531e FD |
236 | /** |
237 | * fs_param_cb - general callback for a module/cmdline parameter | |
238 | * to be evaluated before fs initcall level | |
239 | * @name: a valid C identifier which is the parameter name. | |
240 | * @ops: the set & get operations for this parameter. | |
241 | * @arg: args for @ops | |
242 | * @perm: visibility in sysfs. | |
243 | * | |
244 | * The ops can have NULL set or get functions. | |
245 | */ | |
026cee00 PM |
246 | #define fs_param_cb(name, ops, arg, perm) \ |
247 | __level_param_cb(name, ops, arg, perm, 5) | |
248 | ||
b6d0531e FD |
249 | /** |
250 | * device_param_cb - general callback for a module/cmdline parameter | |
251 | * to be evaluated before device initcall level | |
252 | * @name: a valid C identifier which is the parameter name. | |
253 | * @ops: the set & get operations for this parameter. | |
254 | * @arg: args for @ops | |
255 | * @perm: visibility in sysfs. | |
256 | * | |
257 | * The ops can have NULL set or get functions. | |
258 | */ | |
026cee00 PM |
259 | #define device_param_cb(name, ops, arg, perm) \ |
260 | __level_param_cb(name, ops, arg, perm, 6) | |
261 | ||
b6d0531e FD |
262 | /** |
263 | * late_param_cb - general callback for a module/cmdline parameter | |
264 | * to be evaluated before late initcall level | |
265 | * @name: a valid C identifier which is the parameter name. | |
266 | * @ops: the set & get operations for this parameter. | |
267 | * @arg: args for @ops | |
268 | * @perm: visibility in sysfs. | |
269 | * | |
270 | * The ops can have NULL set or get functions. | |
271 | */ | |
026cee00 PM |
272 | #define late_param_cb(name, ops, arg, perm) \ |
273 | __level_param_cb(name, ops, arg, perm, 7) | |
546970bc | 274 | |
91d35dd9 IK |
275 | /* On alpha, ia64 and ppc64 relocations to global data cannot go into |
276 | read-only sections (which is part of respective UNIX ABI on these | |
277 | platforms). So 'const' makes no sense and even causes compile failures | |
278 | with some compilers. */ | |
279 | #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64) | |
280 | #define __moduleparam_const | |
281 | #else | |
282 | #define __moduleparam_const const | |
283 | #endif | |
284 | ||
1da177e4 | 285 | /* This is the fundamental function for registering boot/module |
546970bc | 286 | parameters. */ |
91f9d330 | 287 | #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \ |
9774a1f5 | 288 | /* Default value instead of permissions? */ \ |
b51d23e4 | 289 | static const char __param_str_##name[] = prefix #name; \ |
91d35dd9 | 290 | static struct kernel_param __moduleparam_const __param_##name \ |
3ff6eecc | 291 | __used \ |
1da177e4 | 292 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ |
b51d23e4 DS |
293 | = { __param_str_##name, THIS_MODULE, ops, \ |
294 | VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } } | |
9bbb9e5a RR |
295 | |
296 | /* Obsolete - use module_param_cb() */ | |
ece1996a | 297 | #define module_param_call(name, _set, _get, arg, perm) \ |
b2f270e8 | 298 | static const struct kernel_param_ops __param_ops_##name = \ |
ece1996a | 299 | { .flags = 0, .set = _set, .get = _get }; \ |
9bbb9e5a | 300 | __module_param_call(MODULE_PARAM_PREFIX, \ |
b2f270e8 | 301 | name, &__param_ops_##name, arg, perm, -1, 0) |
1da177e4 | 302 | |
907b29eb | 303 | #ifdef CONFIG_SYSFS |
b51d23e4 DS |
304 | extern void kernel_param_lock(struct module *mod); |
305 | extern void kernel_param_unlock(struct module *mod); | |
907b29eb | 306 | #else |
b51d23e4 | 307 | static inline void kernel_param_lock(struct module *mod) |
907b29eb RR |
308 | { |
309 | } | |
b51d23e4 | 310 | static inline void kernel_param_unlock(struct module *mod) |
907b29eb RR |
311 | { |
312 | } | |
313 | #endif | |
314 | ||
67e67cea RR |
315 | #ifndef MODULE |
316 | /** | |
317 | * core_param - define a historical core kernel parameter. | |
318 | * @name: the name of the cmdline and sysfs parameter (often the same as var) | |
319 | * @var: the variable | |
546970bc | 320 | * @type: the type of the parameter |
67e67cea RR |
321 | * @perm: visibility in sysfs |
322 | * | |
323 | * core_param is just like module_param(), but cannot be modular and | |
324 | * doesn't add a prefix (such as "printk."). This is for compatibility | |
325 | * with __setup(), and it makes sense as truly core parameters aren't | |
326 | * tied to the particular file they're in. | |
327 | */ | |
328 | #define core_param(name, var, type, perm) \ | |
329 | param_check_##type(name, &(var)); \ | |
91f9d330 | 330 | __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0) |
ec0ccc16 DT |
331 | |
332 | /** | |
333 | * core_param_unsafe - same as core_param but taints kernel | |
b6d0531e FD |
334 | * @name: the name of the cmdline and sysfs parameter (often the same as var) |
335 | * @var: the variable | |
336 | * @type: the type of the parameter | |
337 | * @perm: visibility in sysfs | |
ec0ccc16 DT |
338 | */ |
339 | #define core_param_unsafe(name, var, type, perm) \ | |
340 | param_check_##type(name, &(var)); \ | |
341 | __module_param_call("", name, ¶m_ops_##type, &var, perm, \ | |
342 | -1, KERNEL_PARAM_FL_UNSAFE) | |
343 | ||
67e67cea RR |
344 | #endif /* !MODULE */ |
345 | ||
546970bc RR |
346 | /** |
347 | * module_param_string - a char array parameter | |
348 | * @name: the name of the parameter | |
349 | * @string: the string variable | |
350 | * @len: the maximum length of the string, incl. terminator | |
351 | * @perm: visibility in sysfs. | |
352 | * | |
353 | * This actually copies the string when it's set (unlike type charp). | |
354 | * @len is usually just sizeof(string). | |
355 | */ | |
1da177e4 | 356 | #define module_param_string(name, string, len, perm) \ |
22e48eaf | 357 | static const struct kparam_string __param_string_##name \ |
1da177e4 | 358 | = { len, string }; \ |
fddd5201 | 359 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
9bbb9e5a | 360 | ¶m_ops_string, \ |
91f9d330 | 361 | .str = &__param_string_##name, perm, -1, 0);\ |
1da177e4 LT |
362 | __MODULE_PARM_TYPE(name, "string") |
363 | ||
b1e4d20c MS |
364 | /** |
365 | * parameq - checks if two parameter names match | |
366 | * @name1: parameter name 1 | |
367 | * @name2: parameter name 2 | |
368 | * | |
369 | * Returns true if the two parameter names are equal. | |
370 | * Dashes (-) are considered equal to underscores (_). | |
371 | */ | |
372 | extern bool parameq(const char *name1, const char *name2); | |
373 | ||
374 | /** | |
375 | * parameqn - checks if two parameter names match | |
376 | * @name1: parameter name 1 | |
377 | * @name2: parameter name 2 | |
378 | * @n: the length to compare | |
379 | * | |
380 | * Similar to parameq(), except it compares @n characters. | |
381 | */ | |
382 | extern bool parameqn(const char *name1, const char *name2, size_t n); | |
383 | ||
1da177e4 | 384 | /* Called on module insert or kernel boot */ |
51e158c1 | 385 | extern char *parse_args(const char *name, |
1da177e4 | 386 | char *args, |
914dcaa8 | 387 | const struct kernel_param *params, |
1da177e4 | 388 | unsigned num, |
026cee00 PM |
389 | s16 level_min, |
390 | s16 level_max, | |
ecc86170 | 391 | void *arg, |
9fb48c74 | 392 | int (*unknown)(char *param, char *val, |
ecc86170 | 393 | const char *doing, void *arg)); |
1da177e4 | 394 | |
e180a6b7 RR |
395 | /* Called by module remove. */ |
396 | #ifdef CONFIG_SYSFS | |
397 | extern void destroy_params(const struct kernel_param *params, unsigned num); | |
398 | #else | |
399 | static inline void destroy_params(const struct kernel_param *params, | |
400 | unsigned num) | |
401 | { | |
402 | } | |
403 | #endif /* !CONFIG_SYSFS */ | |
404 | ||
1da177e4 LT |
405 | /* All the helper functions */ |
406 | /* The macros to do compile-time type checking stolen from Jakub | |
407 | Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ | |
408 | #define __param_check(name, p, type) \ | |
0283f9a5 | 409 | static inline type __always_unused *__check_##name(void) { return(p); } |
1da177e4 | 410 | |
9c27847d | 411 | extern const struct kernel_param_ops param_ops_byte; |
9bbb9e5a RR |
412 | extern int param_set_byte(const char *val, const struct kernel_param *kp); |
413 | extern int param_get_byte(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
414 | #define param_check_byte(name, p) __param_check(name, p, unsigned char) |
415 | ||
9c27847d | 416 | extern const struct kernel_param_ops param_ops_short; |
9bbb9e5a RR |
417 | extern int param_set_short(const char *val, const struct kernel_param *kp); |
418 | extern int param_get_short(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
419 | #define param_check_short(name, p) __param_check(name, p, short) |
420 | ||
9c27847d | 421 | extern const struct kernel_param_ops param_ops_ushort; |
9bbb9e5a RR |
422 | extern int param_set_ushort(const char *val, const struct kernel_param *kp); |
423 | extern int param_get_ushort(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
424 | #define param_check_ushort(name, p) __param_check(name, p, unsigned short) |
425 | ||
9c27847d | 426 | extern const struct kernel_param_ops param_ops_int; |
9bbb9e5a RR |
427 | extern int param_set_int(const char *val, const struct kernel_param *kp); |
428 | extern int param_get_int(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
429 | #define param_check_int(name, p) __param_check(name, p, int) |
430 | ||
9c27847d | 431 | extern const struct kernel_param_ops param_ops_uint; |
9bbb9e5a RR |
432 | extern int param_set_uint(const char *val, const struct kernel_param *kp); |
433 | extern int param_get_uint(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
434 | #define param_check_uint(name, p) __param_check(name, p, unsigned int) |
435 | ||
9c27847d | 436 | extern const struct kernel_param_ops param_ops_long; |
9bbb9e5a RR |
437 | extern int param_set_long(const char *val, const struct kernel_param *kp); |
438 | extern int param_get_long(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
439 | #define param_check_long(name, p) __param_check(name, p, long) |
440 | ||
9c27847d | 441 | extern const struct kernel_param_ops param_ops_ulong; |
9bbb9e5a RR |
442 | extern int param_set_ulong(const char *val, const struct kernel_param *kp); |
443 | extern int param_get_ulong(char *buffer, const struct kernel_param *kp); | |
1da177e4 LT |
444 | #define param_check_ulong(name, p) __param_check(name, p, unsigned long) |
445 | ||
9c27847d | 446 | extern const struct kernel_param_ops param_ops_ullong; |
b4210b81 HR |
447 | extern int param_set_ullong(const char *val, const struct kernel_param *kp); |
448 | extern int param_get_ullong(char *buffer, const struct kernel_param *kp); | |
449 | #define param_check_ullong(name, p) __param_check(name, p, unsigned long long) | |
450 | ||
9c27847d | 451 | extern const struct kernel_param_ops param_ops_charp; |
9bbb9e5a RR |
452 | extern int param_set_charp(const char *val, const struct kernel_param *kp); |
453 | extern int param_get_charp(char *buffer, const struct kernel_param *kp); | |
3d9c637f | 454 | extern void param_free_charp(void *arg); |
1da177e4 LT |
455 | #define param_check_charp(name, p) __param_check(name, p, char *) |
456 | ||
72db395f | 457 | /* We used to allow int as well as bool. We're taking that away! */ |
9c27847d | 458 | extern const struct kernel_param_ops param_ops_bool; |
9bbb9e5a RR |
459 | extern int param_set_bool(const char *val, const struct kernel_param *kp); |
460 | extern int param_get_bool(char *buffer, const struct kernel_param *kp); | |
72db395f | 461 | #define param_check_bool(name, p) __param_check(name, p, bool) |
1da177e4 | 462 | |
d19f05d8 LR |
463 | extern const struct kernel_param_ops param_ops_bool_enable_only; |
464 | extern int param_set_bool_enable_only(const char *val, | |
465 | const struct kernel_param *kp); | |
466 | /* getter is the same as for the regular bool */ | |
467 | #define param_check_bool_enable_only param_check_bool | |
468 | ||
9c27847d | 469 | extern const struct kernel_param_ops param_ops_invbool; |
9bbb9e5a RR |
470 | extern int param_set_invbool(const char *val, const struct kernel_param *kp); |
471 | extern int param_get_invbool(char *buffer, const struct kernel_param *kp); | |
9a71af2c | 472 | #define param_check_invbool(name, p) __param_check(name, p, bool) |
1da177e4 | 473 | |
69116f27 | 474 | /* An int, which can only be set like a bool (though it shows as an int). */ |
9c27847d | 475 | extern const struct kernel_param_ops param_ops_bint; |
69116f27 RR |
476 | extern int param_set_bint(const char *val, const struct kernel_param *kp); |
477 | #define param_get_bint param_get_int | |
478 | #define param_check_bint param_check_int | |
479 | ||
546970bc RR |
480 | /** |
481 | * module_param_array - a parameter which is an array of some type | |
482 | * @name: the name of the array variable | |
483 | * @type: the type, as per module_param() | |
484 | * @nump: optional pointer filled in with the number written | |
485 | * @perm: visibility in sysfs | |
486 | * | |
487 | * Input and output are as comma-separated values. Commas inside values | |
488 | * don't work properly (eg. an array of charp). | |
489 | * | |
490 | * ARRAY_SIZE(@name) is used to determine the number of elements in the | |
491 | * array, so the definition must be visible. | |
492 | */ | |
493 | #define module_param_array(name, type, nump, perm) \ | |
494 | module_param_array_named(name, name, type, nump, perm) | |
495 | ||
496 | /** | |
497 | * module_param_array_named - renamed parameter which is an array of some type | |
498 | * @name: a valid C identifier which is the parameter name | |
499 | * @array: the name of the array variable | |
500 | * @type: the type, as per module_param() | |
501 | * @nump: optional pointer filled in with the number written | |
502 | * @perm: visibility in sysfs | |
503 | * | |
504 | * This exposes a different name than the actual variable name. See | |
505 | * module_param_named() for why this might be necessary. | |
506 | */ | |
1da177e4 | 507 | #define module_param_array_named(name, array, type, nump, perm) \ |
bafeafea | 508 | param_check_##type(name, &(array)[0]); \ |
22e48eaf | 509 | static const struct kparam_array __param_arr_##name \ |
c5be0b2e RK |
510 | = { .max = ARRAY_SIZE(array), .num = nump, \ |
511 | .ops = ¶m_ops_##type, \ | |
512 | .elemsize = sizeof(array[0]), .elem = array }; \ | |
fddd5201 | 513 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
9bbb9e5a | 514 | ¶m_array_ops, \ |
fddd5201 | 515 | .arr = &__param_arr_##name, \ |
91f9d330 | 516 | perm, -1, 0); \ |
1da177e4 LT |
517 | __MODULE_PARM_TYPE(name, "array of " #type) |
518 | ||
bf616d21 DH |
519 | enum hwparam_type { |
520 | hwparam_ioport, /* Module parameter configures an I/O port */ | |
521 | hwparam_iomem, /* Module parameter configures an I/O mem address */ | |
522 | hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */ | |
401e000a | 523 | hwparam_irq, /* Module parameter configures an IRQ */ |
bf616d21 DH |
524 | hwparam_dma, /* Module parameter configures a DMA channel */ |
525 | hwparam_dma_addr, /* Module parameter configures a DMA buffer address */ | |
526 | hwparam_other, /* Module parameter configures some other value */ | |
527 | }; | |
528 | ||
529 | /** | |
530 | * module_param_hw_named - A parameter representing a hw parameters | |
531 | * @name: a valid C identifier which is the parameter name. | |
532 | * @value: the actual lvalue to alter. | |
533 | * @type: the type of the parameter | |
534 | * @hwtype: what the value represents (enum hwparam_type) | |
535 | * @perm: visibility in sysfs. | |
536 | * | |
537 | * Usually it's a good idea to have variable names and user-exposed names the | |
538 | * same, but that's harder if the variable must be non-static or is inside a | |
539 | * structure. This allows exposure under a different name. | |
540 | */ | |
541 | #define module_param_hw_named(name, value, type, hwtype, perm) \ | |
542 | param_check_##type(name, &(value)); \ | |
543 | __module_param_call(MODULE_PARAM_PREFIX, name, \ | |
544 | ¶m_ops_##type, &value, \ | |
545 | perm, -1, \ | |
546 | KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ | |
547 | __MODULE_PARM_TYPE(name, #type) | |
548 | ||
549 | #define module_param_hw(name, type, hwtype, perm) \ | |
550 | module_param_hw_named(name, name, type, hwtype, perm) | |
551 | ||
552 | /** | |
553 | * module_param_hw_array - A parameter representing an array of hw parameters | |
554 | * @name: the name of the array variable | |
555 | * @type: the type, as per module_param() | |
556 | * @hwtype: what the value represents (enum hwparam_type) | |
557 | * @nump: optional pointer filled in with the number written | |
558 | * @perm: visibility in sysfs | |
559 | * | |
560 | * Input and output are as comma-separated values. Commas inside values | |
561 | * don't work properly (eg. an array of charp). | |
562 | * | |
563 | * ARRAY_SIZE(@name) is used to determine the number of elements in the | |
564 | * array, so the definition must be visible. | |
565 | */ | |
566 | #define module_param_hw_array(name, type, hwtype, nump, perm) \ | |
567 | param_check_##type(name, &(name)[0]); \ | |
568 | static const struct kparam_array __param_arr_##name \ | |
569 | = { .max = ARRAY_SIZE(name), .num = nump, \ | |
570 | .ops = ¶m_ops_##type, \ | |
571 | .elemsize = sizeof(name[0]), .elem = name }; \ | |
572 | __module_param_call(MODULE_PARAM_PREFIX, name, \ | |
573 | ¶m_array_ops, \ | |
574 | .arr = &__param_arr_##name, \ | |
575 | perm, -1, \ | |
576 | KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ | |
577 | __MODULE_PARM_TYPE(name, "array of " #type) | |
578 | ||
579 | ||
9c27847d | 580 | extern const struct kernel_param_ops param_array_ops; |
1da177e4 | 581 | |
9c27847d | 582 | extern const struct kernel_param_ops param_ops_string; |
9bbb9e5a RR |
583 | extern int param_set_copystring(const char *val, const struct kernel_param *); |
584 | extern int param_get_string(char *buffer, const struct kernel_param *kp); | |
1da177e4 | 585 | |
b634d130 | 586 | /* for exporting parameters in /sys/module/.../parameters */ |
1da177e4 LT |
587 | |
588 | struct module; | |
589 | ||
ef665c1a | 590 | #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) |
1da177e4 | 591 | extern int module_param_sysfs_setup(struct module *mod, |
9bbb9e5a | 592 | const struct kernel_param *kparam, |
1da177e4 LT |
593 | unsigned int num_params); |
594 | ||
595 | extern void module_param_sysfs_remove(struct module *mod); | |
ef665c1a RD |
596 | #else |
597 | static inline int module_param_sysfs_setup(struct module *mod, | |
9bbb9e5a | 598 | const struct kernel_param *kparam, |
ef665c1a RD |
599 | unsigned int num_params) |
600 | { | |
601 | return 0; | |
602 | } | |
603 | ||
604 | static inline void module_param_sysfs_remove(struct module *mod) | |
605 | { } | |
606 | #endif | |
1da177e4 LT |
607 | |
608 | #endif /* _LINUX_MODULE_PARAMS_H */ |