xref: /linux/include/linux/moduleparam.h (revision b75be4204e7871869b2c268c00783703197aaa7d)
11da177e4SLinus Torvalds #ifndef _LINUX_MODULE_PARAMS_H
21da177e4SLinus Torvalds #define _LINUX_MODULE_PARAMS_H
31da177e4SLinus Torvalds /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
41da177e4SLinus Torvalds #include <linux/init.h>
51da177e4SLinus Torvalds #include <linux/stringify.h>
61da177e4SLinus Torvalds #include <linux/kernel.h>
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds /* You can override this manually, but generally this should match the
91da177e4SLinus Torvalds    module name. */
101da177e4SLinus Torvalds #ifdef MODULE
111da177e4SLinus Torvalds #define MODULE_PARAM_PREFIX /* empty */
121da177e4SLinus Torvalds #else
13367cb704SSam Ravnborg #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
141da177e4SLinus Torvalds #endif
151da177e4SLinus Torvalds 
16730b69d2SRusty Russell /* Chosen so that structs with an unsigned long line up. */
17730b69d2SRusty Russell #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
18730b69d2SRusty Russell 
191da177e4SLinus Torvalds #define ___module_cat(a,b) __mod_ ## a ## b
201da177e4SLinus Torvalds #define __module_cat(a,b) ___module_cat(a,b)
21*b75be420SLinus Walleij #ifdef MODULE
221da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info)					  \
231da177e4SLinus Torvalds static const char __module_cat(name,__LINE__)[]				  \
24b6472776SJan Beulich   __used __attribute__((section(".modinfo"), unused, aligned(1)))	  \
25b6472776SJan Beulich   = __stringify(tag) "=" info
261da177e4SLinus Torvalds #else  /* !MODULE */
27*b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */
28*b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info)					  \
29*b75be420SLinus Walleij   struct __module_cat(name,__LINE__) {}
301da177e4SLinus Torvalds #endif
311da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type)					  \
321da177e4SLinus Torvalds   __MODULE_INFO(parmtype, name##type, #name ":" _type)
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds struct kernel_param;
351da177e4SLinus Torvalds 
369bbb9e5aSRusty Russell struct kernel_param_ops {
371da177e4SLinus Torvalds 	/* Returns 0, or -errno.  arg is in kp->arg. */
389bbb9e5aSRusty Russell 	int (*set)(const char *val, const struct kernel_param *kp);
391da177e4SLinus Torvalds 	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
409bbb9e5aSRusty Russell 	int (*get)(char *buffer, const struct kernel_param *kp);
41e6df34a4SRusty Russell 	/* Optional function to free kp->arg when module unloaded. */
42e6df34a4SRusty Russell 	void (*free)(void *arg);
439bbb9e5aSRusty Russell };
441da177e4SLinus Torvalds 
4545fcc70cSRusty Russell /* Flag bits for kernel_param.flags */
46fddd5201SRusty Russell #define KPARAM_ISBOOL		2
4745fcc70cSRusty Russell 
481da177e4SLinus Torvalds struct kernel_param {
491da177e4SLinus Torvalds 	const char *name;
509bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
5145fcc70cSRusty Russell 	u16 perm;
5245fcc70cSRusty Russell 	u16 flags;
5322e48eafSJan Beulich 	union {
541da177e4SLinus Torvalds 		void *arg;
5522e48eafSJan Beulich 		const struct kparam_string *str;
5622e48eafSJan Beulich 		const struct kparam_array *arr;
5722e48eafSJan Beulich 	};
581da177e4SLinus Torvalds };
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds /* Special one for strings we want to copy into */
611da177e4SLinus Torvalds struct kparam_string {
621da177e4SLinus Torvalds 	unsigned int maxlen;
631da177e4SLinus Torvalds 	char *string;
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* Special one for arrays */
671da177e4SLinus Torvalds struct kparam_array
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds 	unsigned int max;
701da177e4SLinus Torvalds 	unsigned int *num;
719bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
721da177e4SLinus Torvalds 	unsigned int elemsize;
731da177e4SLinus Torvalds 	void *elem;
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds 
76546970bcSRusty Russell /**
77546970bcSRusty Russell  * module_param - typesafe helper for a module/cmdline parameter
78546970bcSRusty Russell  * @value: the variable to alter, and exposed parameter name.
79546970bcSRusty Russell  * @type: the type of the parameter
80546970bcSRusty Russell  * @perm: visibility in sysfs.
81546970bcSRusty Russell  *
82546970bcSRusty Russell  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
83546970bcSRusty Russell  * ".") the kernel commandline parameter.  Note that - is changed to _, so
84546970bcSRusty Russell  * the user can use "foo-bar=1" even for variable "foo_bar".
85546970bcSRusty Russell  *
86546970bcSRusty Russell  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
87546970bcSRusty Russell  * for world-readable, 0644 for root-writable, etc.  Note that if it
88546970bcSRusty Russell  * is writable, you may need to use kparam_block_sysfs_write() around
89546970bcSRusty Russell  * accesses (esp. charp, which can be kfreed when it changes).
90546970bcSRusty Russell  *
91546970bcSRusty Russell  * The @type is simply pasted to refer to a param_ops_##type and a
92546970bcSRusty Russell  * param_check_##type: for convenience many standard types are provided but
93546970bcSRusty Russell  * you can create your own by defining those variables.
94546970bcSRusty Russell  *
95546970bcSRusty Russell  * Standard types are:
96546970bcSRusty Russell  *	byte, short, ushort, int, uint, long, ulong
97546970bcSRusty Russell  *	charp: a character pointer
98546970bcSRusty Russell  *	bool: a bool, values 0/1, y/n, Y/N.
99546970bcSRusty Russell  *	invbool: the above, only sense-reversed (N = true).
100546970bcSRusty Russell  */
101546970bcSRusty Russell #define module_param(name, type, perm)				\
102546970bcSRusty Russell 	module_param_named(name, name, type, perm)
103546970bcSRusty Russell 
104546970bcSRusty Russell /**
105546970bcSRusty Russell  * module_param_named - typesafe helper for a renamed module/cmdline parameter
106546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
107546970bcSRusty Russell  * @value: the actual lvalue to alter.
108546970bcSRusty Russell  * @type: the type of the parameter
109546970bcSRusty Russell  * @perm: visibility in sysfs.
110546970bcSRusty Russell  *
111546970bcSRusty Russell  * Usually it's a good idea to have variable names and user-exposed names the
112546970bcSRusty Russell  * same, but that's harder if the variable must be non-static or is inside a
113546970bcSRusty Russell  * structure.  This allows exposure under a different name.
114546970bcSRusty Russell  */
115546970bcSRusty Russell #define module_param_named(name, value, type, perm)			   \
116546970bcSRusty Russell 	param_check_##type(name, &(value));				   \
117546970bcSRusty Russell 	module_param_cb(name, &param_ops_##type, &value, perm);		   \
118546970bcSRusty Russell 	__MODULE_PARM_TYPE(name, #type)
119546970bcSRusty Russell 
120546970bcSRusty Russell /**
121546970bcSRusty Russell  * module_param_cb - general callback for a module/cmdline parameter
122546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
123546970bcSRusty Russell  * @ops: the set & get operations for this parameter.
124546970bcSRusty Russell  * @perm: visibility in sysfs.
125546970bcSRusty Russell  *
126546970bcSRusty Russell  * The ops can have NULL set or get functions.
127546970bcSRusty Russell  */
128546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm)				      \
129546970bcSRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			      \
130a6de51b2SRusty Russell 			    name, ops, arg, __same_type((arg), bool *), perm)
131546970bcSRusty Russell 
13291d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into
13391d35dd9SIvan Kokshaysky    read-only sections (which is part of respective UNIX ABI on these
13491d35dd9SIvan Kokshaysky    platforms). So 'const' makes no sense and even causes compile failures
13591d35dd9SIvan Kokshaysky    with some compilers. */
13691d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
13791d35dd9SIvan Kokshaysky #define __moduleparam_const
13891d35dd9SIvan Kokshaysky #else
13991d35dd9SIvan Kokshaysky #define __moduleparam_const const
14091d35dd9SIvan Kokshaysky #endif
14191d35dd9SIvan Kokshaysky 
1421da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module
143546970bcSRusty Russell    parameters. */
1449bbb9e5aSRusty Russell #define __module_param_call(prefix, name, ops, arg, isbool, perm)	\
1459774a1f5SAlexey Dobriyan 	/* Default value instead of permissions? */			\
1469774a1f5SAlexey Dobriyan 	static int __param_perm_check_##name __attribute__((unused)) =	\
147730b69d2SRusty Russell 	BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2))	\
148730b69d2SRusty Russell 	+ BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN);	\
14922e48eafSJan Beulich 	static const char __param_str_##name[] = prefix #name;		\
15091d35dd9SIvan Kokshaysky 	static struct kernel_param __moduleparam_const __param_##name	\
1513ff6eeccSAdrian Bunk 	__used								\
1521da177e4SLinus Torvalds     __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
1539bbb9e5aSRusty Russell 	= { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0,	\
1549bbb9e5aSRusty Russell 	    { arg } }
1551da177e4SLinus Torvalds 
1569bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */
1571da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm)			\
1589bbb9e5aSRusty Russell 	static struct kernel_param_ops __param_ops_##name =		\
1599bbb9e5aSRusty Russell 		 { (void *)set, (void *)get };				\
160fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			\
1619bbb9e5aSRusty Russell 			    name, &__param_ops_##name, arg,		\
162a6de51b2SRusty Russell 			    __same_type(arg, bool *),			\
1639bbb9e5aSRusty Russell 			    (perm) + sizeof(__check_old_set_param(set))*0)
1641da177e4SLinus Torvalds 
1659bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */
1669bbb9e5aSRusty Russell static inline int
1679bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
1689bbb9e5aSRusty Russell {
1699bbb9e5aSRusty Russell 	return 0;
1709bbb9e5aSRusty Russell }
1719bbb9e5aSRusty Russell 
172907b29ebSRusty Russell /**
173907b29ebSRusty Russell  * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
174907b29ebSRusty Russell  * @name: the name of the parameter
175907b29ebSRusty Russell  *
176907b29ebSRusty Russell  * There's no point blocking write on a paramter that isn't writable via sysfs!
177907b29ebSRusty Russell  */
178907b29ebSRusty Russell #define kparam_block_sysfs_write(name)			\
179907b29ebSRusty Russell 	do {						\
180907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
181907b29ebSRusty Russell 		__kernel_param_lock();			\
182907b29ebSRusty Russell 	} while (0)
183907b29ebSRusty Russell 
184907b29ebSRusty Russell /**
185907b29ebSRusty Russell  * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
186907b29ebSRusty Russell  * @name: the name of the parameter
187907b29ebSRusty Russell  */
188907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name)		\
189907b29ebSRusty Russell 	do {						\
190907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
191907b29ebSRusty Russell 		__kernel_param_unlock();		\
192907b29ebSRusty Russell 	} while (0)
193907b29ebSRusty Russell 
194907b29ebSRusty Russell /**
195907b29ebSRusty Russell  * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
196907b29ebSRusty Russell  * @name: the name of the parameter
197907b29ebSRusty Russell  *
198907b29ebSRusty Russell  * This also blocks sysfs writes.
199907b29ebSRusty Russell  */
200907b29ebSRusty Russell #define kparam_block_sysfs_read(name)			\
201907b29ebSRusty Russell 	do {						\
202907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
203907b29ebSRusty Russell 		__kernel_param_lock();			\
204907b29ebSRusty Russell 	} while (0)
205907b29ebSRusty Russell 
206907b29ebSRusty Russell /**
207907b29ebSRusty Russell  * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
208907b29ebSRusty Russell  * @name: the name of the parameter
209907b29ebSRusty Russell  */
210907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name)			\
211907b29ebSRusty Russell 	do {						\
212907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
213907b29ebSRusty Russell 		__kernel_param_unlock();		\
214907b29ebSRusty Russell 	} while (0)
215907b29ebSRusty Russell 
216907b29ebSRusty Russell #ifdef CONFIG_SYSFS
217907b29ebSRusty Russell extern void __kernel_param_lock(void);
218907b29ebSRusty Russell extern void __kernel_param_unlock(void);
219907b29ebSRusty Russell #else
220907b29ebSRusty Russell static inline void __kernel_param_lock(void)
221907b29ebSRusty Russell {
222907b29ebSRusty Russell }
223907b29ebSRusty Russell static inline void __kernel_param_unlock(void)
224907b29ebSRusty Russell {
225907b29ebSRusty Russell }
226907b29ebSRusty Russell #endif
227907b29ebSRusty Russell 
22867e67ceaSRusty Russell #ifndef MODULE
22967e67ceaSRusty Russell /**
23067e67ceaSRusty Russell  * core_param - define a historical core kernel parameter.
23167e67ceaSRusty Russell  * @name: the name of the cmdline and sysfs parameter (often the same as var)
23267e67ceaSRusty Russell  * @var: the variable
233546970bcSRusty Russell  * @type: the type of the parameter
23467e67ceaSRusty Russell  * @perm: visibility in sysfs
23567e67ceaSRusty Russell  *
23667e67ceaSRusty Russell  * core_param is just like module_param(), but cannot be modular and
23767e67ceaSRusty Russell  * doesn't add a prefix (such as "printk.").  This is for compatibility
23867e67ceaSRusty Russell  * with __setup(), and it makes sense as truly core parameters aren't
23967e67ceaSRusty Russell  * tied to the particular file they're in.
24067e67ceaSRusty Russell  */
24167e67ceaSRusty Russell #define core_param(name, var, type, perm)				\
24267e67ceaSRusty Russell 	param_check_##type(name, &(var));				\
2439bbb9e5aSRusty Russell 	__module_param_call("", name, &param_ops_##type,		\
244fddd5201SRusty Russell 			    &var, __same_type(var, bool), perm)
24567e67ceaSRusty Russell #endif /* !MODULE */
24667e67ceaSRusty Russell 
247546970bcSRusty Russell /**
248546970bcSRusty Russell  * module_param_string - a char array parameter
249546970bcSRusty Russell  * @name: the name of the parameter
250546970bcSRusty Russell  * @string: the string variable
251546970bcSRusty Russell  * @len: the maximum length of the string, incl. terminator
252546970bcSRusty Russell  * @perm: visibility in sysfs.
253546970bcSRusty Russell  *
254546970bcSRusty Russell  * This actually copies the string when it's set (unlike type charp).
255546970bcSRusty Russell  * @len is usually just sizeof(string).
256546970bcSRusty Russell  */
2571da177e4SLinus Torvalds #define module_param_string(name, string, len, perm)			\
25822e48eafSJan Beulich 	static const struct kparam_string __param_string_##name		\
2591da177e4SLinus Torvalds 		= { len, string };					\
260fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
2619bbb9e5aSRusty Russell 			    &param_ops_string,				\
262fddd5201SRusty Russell 			    .str = &__param_string_##name, 0, perm);	\
2631da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "string")
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds /* Called on module insert or kernel boot */
2661da177e4SLinus Torvalds extern int parse_args(const char *name,
2671da177e4SLinus Torvalds 		      char *args,
268914dcaa8SRusty Russell 		      const struct kernel_param *params,
2691da177e4SLinus Torvalds 		      unsigned num,
2701da177e4SLinus Torvalds 		      int (*unknown)(char *param, char *val));
2711da177e4SLinus Torvalds 
272e180a6b7SRusty Russell /* Called by module remove. */
273e180a6b7SRusty Russell #ifdef CONFIG_SYSFS
274e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num);
275e180a6b7SRusty Russell #else
276e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params,
277e180a6b7SRusty Russell 				  unsigned num)
278e180a6b7SRusty Russell {
279e180a6b7SRusty Russell }
280e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */
281e180a6b7SRusty Russell 
2821da177e4SLinus Torvalds /* All the helper functions */
2831da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub
2841da177e4SLinus Torvalds    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
2851da177e4SLinus Torvalds #define __param_check(name, p, type) \
2861da177e4SLinus Torvalds 	static inline type *__check_##name(void) { return(p); }
2871da177e4SLinus Torvalds 
2889bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte;
2899bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp);
2909bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp);
2911da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char)
2921da177e4SLinus Torvalds 
2939bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short;
2949bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp);
2959bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp);
2961da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short)
2971da177e4SLinus Torvalds 
2989bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort;
2999bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp);
3009bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
3011da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
3021da177e4SLinus Torvalds 
3039bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int;
3049bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp);
3059bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp);
3061da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int)
3071da177e4SLinus Torvalds 
3089bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint;
3099bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp);
3109bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp);
3111da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int)
3121da177e4SLinus Torvalds 
3139bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long;
3149bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp);
3159bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp);
3161da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long)
3171da177e4SLinus Torvalds 
3189bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong;
3199bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp);
3209bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
3211da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
3221da177e4SLinus Torvalds 
3239bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp;
3249bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp);
3259bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp);
3261da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *)
3271da177e4SLinus Torvalds 
328fddd5201SRusty Russell /* For historical reasons "bool" parameters can be (unsigned) "int". */
3299bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool;
3309bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp);
3319bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp);
332fddd5201SRusty Russell #define param_check_bool(name, p)					\
333fddd5201SRusty Russell 	static inline void __check_##name(void)				\
334fddd5201SRusty Russell 	{								\
335a6de51b2SRusty Russell 		BUILD_BUG_ON(!__same_type((p), bool *) &&		\
336a6de51b2SRusty Russell 			     !__same_type((p), unsigned int *) &&	\
337a6de51b2SRusty Russell 			     !__same_type((p), int *));			\
338fddd5201SRusty Russell 	}
3391da177e4SLinus Torvalds 
3409bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool;
3419bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp);
3429bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
3439a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool)
3441da177e4SLinus Torvalds 
345546970bcSRusty Russell /**
346546970bcSRusty Russell  * module_param_array - a parameter which is an array of some type
347546970bcSRusty Russell  * @name: the name of the array variable
348546970bcSRusty Russell  * @type: the type, as per module_param()
349546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
350546970bcSRusty Russell  * @perm: visibility in sysfs
351546970bcSRusty Russell  *
352546970bcSRusty Russell  * Input and output are as comma-separated values.  Commas inside values
353546970bcSRusty Russell  * don't work properly (eg. an array of charp).
354546970bcSRusty Russell  *
355546970bcSRusty Russell  * ARRAY_SIZE(@name) is used to determine the number of elements in the
356546970bcSRusty Russell  * array, so the definition must be visible.
357546970bcSRusty Russell  */
358546970bcSRusty Russell #define module_param_array(name, type, nump, perm)		\
359546970bcSRusty Russell 	module_param_array_named(name, name, type, nump, perm)
360546970bcSRusty Russell 
361546970bcSRusty Russell /**
362546970bcSRusty Russell  * module_param_array_named - renamed parameter which is an array of some type
363546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name
364546970bcSRusty Russell  * @array: the name of the array variable
365546970bcSRusty Russell  * @type: the type, as per module_param()
366546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
367546970bcSRusty Russell  * @perm: visibility in sysfs
368546970bcSRusty Russell  *
369546970bcSRusty Russell  * This exposes a different name than the actual variable name.  See
370546970bcSRusty Russell  * module_param_named() for why this might be necessary.
371546970bcSRusty Russell  */
3721da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm)		\
37322e48eafSJan Beulich 	static const struct kparam_array __param_arr_##name		\
3749bbb9e5aSRusty Russell 	= { ARRAY_SIZE(array), nump, &param_ops_##type,			\
3751da177e4SLinus Torvalds 	    sizeof(array[0]), array };					\
376fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
3779bbb9e5aSRusty Russell 			    &param_array_ops,				\
378fddd5201SRusty Russell 			    .arr = &__param_arr_##name,			\
379fddd5201SRusty Russell 			    __same_type(array[0], bool), perm);		\
3801da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "array of " #type)
3811da177e4SLinus Torvalds 
3829bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops;
3831da177e4SLinus Torvalds 
3849bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string;
3859bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *);
3869bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp);
3871da177e4SLinus Torvalds 
3881da177e4SLinus Torvalds /* for exporting parameters in /sys/parameters */
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds struct module;
3911da177e4SLinus Torvalds 
392ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
3931da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod,
3949bbb9e5aSRusty Russell 				    const struct kernel_param *kparam,
3951da177e4SLinus Torvalds 				    unsigned int num_params);
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod);
398ef665c1aSRandy Dunlap #else
399ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod,
4009bbb9e5aSRusty Russell 			     const struct kernel_param *kparam,
401ef665c1aSRandy Dunlap 			     unsigned int num_params)
402ef665c1aSRandy Dunlap {
403ef665c1aSRandy Dunlap 	return 0;
404ef665c1aSRandy Dunlap }
405ef665c1aSRandy Dunlap 
406ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod)
407ef665c1aSRandy Dunlap { }
408ef665c1aSRandy Dunlap #endif
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */
411