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