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