xref: /linux/include/linux/moduleparam.h (revision b6472776816af1ed52848c93d26e3edb3b17adab)
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 #ifdef MODULE
201da177e4SLinus Torvalds #define ___module_cat(a,b) __mod_ ## a ## b
211da177e4SLinus Torvalds #define __module_cat(a,b) ___module_cat(a,b)
221da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info)					  \
231da177e4SLinus Torvalds static const char __module_cat(name,__LINE__)[]				  \
24*b6472776SJan Beulich   __used __attribute__((section(".modinfo"), unused, aligned(1)))	  \
25*b6472776SJan Beulich   = __stringify(tag) "=" info
261da177e4SLinus Torvalds #else  /* !MODULE */
271da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info)
281da177e4SLinus Torvalds #endif
291da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type)					  \
301da177e4SLinus Torvalds   __MODULE_INFO(parmtype, name##type, #name ":" _type)
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds struct kernel_param;
331da177e4SLinus Torvalds 
349bbb9e5aSRusty Russell struct kernel_param_ops {
351da177e4SLinus Torvalds 	/* Returns 0, or -errno.  arg is in kp->arg. */
369bbb9e5aSRusty Russell 	int (*set)(const char *val, const struct kernel_param *kp);
371da177e4SLinus Torvalds 	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
389bbb9e5aSRusty Russell 	int (*get)(char *buffer, const struct kernel_param *kp);
39e6df34a4SRusty Russell 	/* Optional function to free kp->arg when module unloaded. */
40e6df34a4SRusty Russell 	void (*free)(void *arg);
419bbb9e5aSRusty Russell };
421da177e4SLinus Torvalds 
4345fcc70cSRusty Russell /* Flag bits for kernel_param.flags */
44fddd5201SRusty Russell #define KPARAM_ISBOOL		2
4545fcc70cSRusty Russell 
461da177e4SLinus Torvalds struct kernel_param {
471da177e4SLinus Torvalds 	const char *name;
489bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
4945fcc70cSRusty Russell 	u16 perm;
5045fcc70cSRusty Russell 	u16 flags;
5122e48eafSJan Beulich 	union {
521da177e4SLinus Torvalds 		void *arg;
5322e48eafSJan Beulich 		const struct kparam_string *str;
5422e48eafSJan Beulich 		const struct kparam_array *arr;
5522e48eafSJan Beulich 	};
561da177e4SLinus Torvalds };
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds /* Special one for strings we want to copy into */
591da177e4SLinus Torvalds struct kparam_string {
601da177e4SLinus Torvalds 	unsigned int maxlen;
611da177e4SLinus Torvalds 	char *string;
621da177e4SLinus Torvalds };
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /* Special one for arrays */
651da177e4SLinus Torvalds struct kparam_array
661da177e4SLinus Torvalds {
671da177e4SLinus Torvalds 	unsigned int max;
681da177e4SLinus Torvalds 	unsigned int *num;
699bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
701da177e4SLinus Torvalds 	unsigned int elemsize;
711da177e4SLinus Torvalds 	void *elem;
721da177e4SLinus Torvalds };
731da177e4SLinus Torvalds 
74546970bcSRusty Russell /**
75546970bcSRusty Russell  * module_param - typesafe helper for a module/cmdline parameter
76546970bcSRusty Russell  * @value: the variable to alter, and exposed parameter name.
77546970bcSRusty Russell  * @type: the type of the parameter
78546970bcSRusty Russell  * @perm: visibility in sysfs.
79546970bcSRusty Russell  *
80546970bcSRusty Russell  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
81546970bcSRusty Russell  * ".") the kernel commandline parameter.  Note that - is changed to _, so
82546970bcSRusty Russell  * the user can use "foo-bar=1" even for variable "foo_bar".
83546970bcSRusty Russell  *
84546970bcSRusty Russell  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
85546970bcSRusty Russell  * for world-readable, 0644 for root-writable, etc.  Note that if it
86546970bcSRusty Russell  * is writable, you may need to use kparam_block_sysfs_write() around
87546970bcSRusty Russell  * accesses (esp. charp, which can be kfreed when it changes).
88546970bcSRusty Russell  *
89546970bcSRusty Russell  * The @type is simply pasted to refer to a param_ops_##type and a
90546970bcSRusty Russell  * param_check_##type: for convenience many standard types are provided but
91546970bcSRusty Russell  * you can create your own by defining those variables.
92546970bcSRusty Russell  *
93546970bcSRusty Russell  * Standard types are:
94546970bcSRusty Russell  *	byte, short, ushort, int, uint, long, ulong
95546970bcSRusty Russell  *	charp: a character pointer
96546970bcSRusty Russell  *	bool: a bool, values 0/1, y/n, Y/N.
97546970bcSRusty Russell  *	invbool: the above, only sense-reversed (N = true).
98546970bcSRusty Russell  */
99546970bcSRusty Russell #define module_param(name, type, perm)				\
100546970bcSRusty Russell 	module_param_named(name, name, type, perm)
101546970bcSRusty Russell 
102546970bcSRusty Russell /**
103546970bcSRusty Russell  * module_param_named - typesafe helper for a renamed module/cmdline parameter
104546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
105546970bcSRusty Russell  * @value: the actual lvalue to alter.
106546970bcSRusty Russell  * @type: the type of the parameter
107546970bcSRusty Russell  * @perm: visibility in sysfs.
108546970bcSRusty Russell  *
109546970bcSRusty Russell  * Usually it's a good idea to have variable names and user-exposed names the
110546970bcSRusty Russell  * same, but that's harder if the variable must be non-static or is inside a
111546970bcSRusty Russell  * structure.  This allows exposure under a different name.
112546970bcSRusty Russell  */
113546970bcSRusty Russell #define module_param_named(name, value, type, perm)			   \
114546970bcSRusty Russell 	param_check_##type(name, &(value));				   \
115546970bcSRusty Russell 	module_param_cb(name, &param_ops_##type, &value, perm);		   \
116546970bcSRusty Russell 	__MODULE_PARM_TYPE(name, #type)
117546970bcSRusty Russell 
118546970bcSRusty Russell /**
119546970bcSRusty Russell  * module_param_cb - general callback for a module/cmdline parameter
120546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
121546970bcSRusty Russell  * @ops: the set & get operations for this parameter.
122546970bcSRusty Russell  * @perm: visibility in sysfs.
123546970bcSRusty Russell  *
124546970bcSRusty Russell  * The ops can have NULL set or get functions.
125546970bcSRusty Russell  */
126546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm)				      \
127546970bcSRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			      \
128a6de51b2SRusty Russell 			    name, ops, arg, __same_type((arg), bool *), perm)
129546970bcSRusty Russell 
13091d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into
13191d35dd9SIvan Kokshaysky    read-only sections (which is part of respective UNIX ABI on these
13291d35dd9SIvan Kokshaysky    platforms). So 'const' makes no sense and even causes compile failures
13391d35dd9SIvan Kokshaysky    with some compilers. */
13491d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
13591d35dd9SIvan Kokshaysky #define __moduleparam_const
13691d35dd9SIvan Kokshaysky #else
13791d35dd9SIvan Kokshaysky #define __moduleparam_const const
13891d35dd9SIvan Kokshaysky #endif
13991d35dd9SIvan Kokshaysky 
1401da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module
141546970bcSRusty Russell    parameters. */
1429bbb9e5aSRusty Russell #define __module_param_call(prefix, name, ops, arg, isbool, perm)	\
1439774a1f5SAlexey Dobriyan 	/* Default value instead of permissions? */			\
1449774a1f5SAlexey Dobriyan 	static int __param_perm_check_##name __attribute__((unused)) =	\
145730b69d2SRusty Russell 	BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2))	\
146730b69d2SRusty Russell 	+ BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN);	\
14722e48eafSJan Beulich 	static const char __param_str_##name[] = prefix #name;		\
14891d35dd9SIvan Kokshaysky 	static struct kernel_param __moduleparam_const __param_##name	\
1493ff6eeccSAdrian Bunk 	__used								\
1501da177e4SLinus Torvalds     __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
1519bbb9e5aSRusty Russell 	= { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0,	\
1529bbb9e5aSRusty Russell 	    { arg } }
1531da177e4SLinus Torvalds 
1549bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */
1551da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm)			\
1569bbb9e5aSRusty Russell 	static struct kernel_param_ops __param_ops_##name =		\
1579bbb9e5aSRusty Russell 		 { (void *)set, (void *)get };				\
158fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			\
1599bbb9e5aSRusty Russell 			    name, &__param_ops_##name, arg,		\
160a6de51b2SRusty Russell 			    __same_type(arg, bool *),			\
1619bbb9e5aSRusty Russell 			    (perm) + sizeof(__check_old_set_param(set))*0)
1621da177e4SLinus Torvalds 
1639bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */
1649bbb9e5aSRusty Russell static inline int
1659bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
1669bbb9e5aSRusty Russell {
1679bbb9e5aSRusty Russell 	return 0;
1689bbb9e5aSRusty Russell }
1699bbb9e5aSRusty Russell 
170907b29ebSRusty Russell /**
171907b29ebSRusty Russell  * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
172907b29ebSRusty Russell  * @name: the name of the parameter
173907b29ebSRusty Russell  *
174907b29ebSRusty Russell  * There's no point blocking write on a paramter that isn't writable via sysfs!
175907b29ebSRusty Russell  */
176907b29ebSRusty Russell #define kparam_block_sysfs_write(name)			\
177907b29ebSRusty Russell 	do {						\
178907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
179907b29ebSRusty Russell 		__kernel_param_lock();			\
180907b29ebSRusty Russell 	} while (0)
181907b29ebSRusty Russell 
182907b29ebSRusty Russell /**
183907b29ebSRusty Russell  * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
184907b29ebSRusty Russell  * @name: the name of the parameter
185907b29ebSRusty Russell  */
186907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name)		\
187907b29ebSRusty Russell 	do {						\
188907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
189907b29ebSRusty Russell 		__kernel_param_unlock();		\
190907b29ebSRusty Russell 	} while (0)
191907b29ebSRusty Russell 
192907b29ebSRusty Russell /**
193907b29ebSRusty Russell  * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
194907b29ebSRusty Russell  * @name: the name of the parameter
195907b29ebSRusty Russell  *
196907b29ebSRusty Russell  * This also blocks sysfs writes.
197907b29ebSRusty Russell  */
198907b29ebSRusty Russell #define kparam_block_sysfs_read(name)			\
199907b29ebSRusty Russell 	do {						\
200907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
201907b29ebSRusty Russell 		__kernel_param_lock();			\
202907b29ebSRusty Russell 	} while (0)
203907b29ebSRusty Russell 
204907b29ebSRusty Russell /**
205907b29ebSRusty Russell  * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
206907b29ebSRusty Russell  * @name: the name of the parameter
207907b29ebSRusty Russell  */
208907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name)			\
209907b29ebSRusty Russell 	do {						\
210907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
211907b29ebSRusty Russell 		__kernel_param_unlock();		\
212907b29ebSRusty Russell 	} while (0)
213907b29ebSRusty Russell 
214907b29ebSRusty Russell #ifdef CONFIG_SYSFS
215907b29ebSRusty Russell extern void __kernel_param_lock(void);
216907b29ebSRusty Russell extern void __kernel_param_unlock(void);
217907b29ebSRusty Russell #else
218907b29ebSRusty Russell static inline void __kernel_param_lock(void)
219907b29ebSRusty Russell {
220907b29ebSRusty Russell }
221907b29ebSRusty Russell static inline void __kernel_param_unlock(void)
222907b29ebSRusty Russell {
223907b29ebSRusty Russell }
224907b29ebSRusty Russell #endif
225907b29ebSRusty Russell 
22667e67ceaSRusty Russell #ifndef MODULE
22767e67ceaSRusty Russell /**
22867e67ceaSRusty Russell  * core_param - define a historical core kernel parameter.
22967e67ceaSRusty Russell  * @name: the name of the cmdline and sysfs parameter (often the same as var)
23067e67ceaSRusty Russell  * @var: the variable
231546970bcSRusty Russell  * @type: the type of the parameter
23267e67ceaSRusty Russell  * @perm: visibility in sysfs
23367e67ceaSRusty Russell  *
23467e67ceaSRusty Russell  * core_param is just like module_param(), but cannot be modular and
23567e67ceaSRusty Russell  * doesn't add a prefix (such as "printk.").  This is for compatibility
23667e67ceaSRusty Russell  * with __setup(), and it makes sense as truly core parameters aren't
23767e67ceaSRusty Russell  * tied to the particular file they're in.
23867e67ceaSRusty Russell  */
23967e67ceaSRusty Russell #define core_param(name, var, type, perm)				\
24067e67ceaSRusty Russell 	param_check_##type(name, &(var));				\
2419bbb9e5aSRusty Russell 	__module_param_call("", name, &param_ops_##type,		\
242fddd5201SRusty Russell 			    &var, __same_type(var, bool), perm)
24367e67ceaSRusty Russell #endif /* !MODULE */
24467e67ceaSRusty Russell 
245546970bcSRusty Russell /**
246546970bcSRusty Russell  * module_param_string - a char array parameter
247546970bcSRusty Russell  * @name: the name of the parameter
248546970bcSRusty Russell  * @string: the string variable
249546970bcSRusty Russell  * @len: the maximum length of the string, incl. terminator
250546970bcSRusty Russell  * @perm: visibility in sysfs.
251546970bcSRusty Russell  *
252546970bcSRusty Russell  * This actually copies the string when it's set (unlike type charp).
253546970bcSRusty Russell  * @len is usually just sizeof(string).
254546970bcSRusty Russell  */
2551da177e4SLinus Torvalds #define module_param_string(name, string, len, perm)			\
25622e48eafSJan Beulich 	static const struct kparam_string __param_string_##name		\
2571da177e4SLinus Torvalds 		= { len, string };					\
258fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
2599bbb9e5aSRusty Russell 			    &param_ops_string,				\
260fddd5201SRusty Russell 			    .str = &__param_string_##name, 0, perm);	\
2611da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "string")
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds /* Called on module insert or kernel boot */
2641da177e4SLinus Torvalds extern int parse_args(const char *name,
2651da177e4SLinus Torvalds 		      char *args,
266914dcaa8SRusty Russell 		      const struct kernel_param *params,
2671da177e4SLinus Torvalds 		      unsigned num,
2681da177e4SLinus Torvalds 		      int (*unknown)(char *param, char *val));
2691da177e4SLinus Torvalds 
270e180a6b7SRusty Russell /* Called by module remove. */
271e180a6b7SRusty Russell #ifdef CONFIG_SYSFS
272e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num);
273e180a6b7SRusty Russell #else
274e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params,
275e180a6b7SRusty Russell 				  unsigned num)
276e180a6b7SRusty Russell {
277e180a6b7SRusty Russell }
278e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */
279e180a6b7SRusty Russell 
2801da177e4SLinus Torvalds /* All the helper functions */
2811da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub
2821da177e4SLinus Torvalds    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
2831da177e4SLinus Torvalds #define __param_check(name, p, type) \
2841da177e4SLinus Torvalds 	static inline type *__check_##name(void) { return(p); }
2851da177e4SLinus Torvalds 
2869bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte;
2879bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp);
2889bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp);
2891da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char)
2901da177e4SLinus Torvalds 
2919bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short;
2929bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp);
2939bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp);
2941da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short)
2951da177e4SLinus Torvalds 
2969bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort;
2979bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp);
2989bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
2991da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
3001da177e4SLinus Torvalds 
3019bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int;
3029bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp);
3039bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp);
3041da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int)
3051da177e4SLinus Torvalds 
3069bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint;
3079bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp);
3089bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp);
3091da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int)
3101da177e4SLinus Torvalds 
3119bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long;
3129bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp);
3139bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp);
3141da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long)
3151da177e4SLinus Torvalds 
3169bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong;
3179bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp);
3189bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
3191da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
3201da177e4SLinus Torvalds 
3219bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp;
3229bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp);
3239bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp);
3241da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *)
3251da177e4SLinus Torvalds 
326fddd5201SRusty Russell /* For historical reasons "bool" parameters can be (unsigned) "int". */
3279bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool;
3289bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp);
3299bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp);
330fddd5201SRusty Russell #define param_check_bool(name, p)					\
331fddd5201SRusty Russell 	static inline void __check_##name(void)				\
332fddd5201SRusty Russell 	{								\
333a6de51b2SRusty Russell 		BUILD_BUG_ON(!__same_type((p), bool *) &&		\
334a6de51b2SRusty Russell 			     !__same_type((p), unsigned int *) &&	\
335a6de51b2SRusty Russell 			     !__same_type((p), int *));			\
336fddd5201SRusty Russell 	}
3371da177e4SLinus Torvalds 
3389bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool;
3399bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp);
3409bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
3419a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool)
3421da177e4SLinus Torvalds 
343546970bcSRusty Russell /**
344546970bcSRusty Russell  * module_param_array - a parameter which is an array of some type
345546970bcSRusty Russell  * @name: the name of the array variable
346546970bcSRusty Russell  * @type: the type, as per module_param()
347546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
348546970bcSRusty Russell  * @perm: visibility in sysfs
349546970bcSRusty Russell  *
350546970bcSRusty Russell  * Input and output are as comma-separated values.  Commas inside values
351546970bcSRusty Russell  * don't work properly (eg. an array of charp).
352546970bcSRusty Russell  *
353546970bcSRusty Russell  * ARRAY_SIZE(@name) is used to determine the number of elements in the
354546970bcSRusty Russell  * array, so the definition must be visible.
355546970bcSRusty Russell  */
356546970bcSRusty Russell #define module_param_array(name, type, nump, perm)		\
357546970bcSRusty Russell 	module_param_array_named(name, name, type, nump, perm)
358546970bcSRusty Russell 
359546970bcSRusty Russell /**
360546970bcSRusty Russell  * module_param_array_named - renamed parameter which is an array of some type
361546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name
362546970bcSRusty Russell  * @array: the name of the array variable
363546970bcSRusty Russell  * @type: the type, as per module_param()
364546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
365546970bcSRusty Russell  * @perm: visibility in sysfs
366546970bcSRusty Russell  *
367546970bcSRusty Russell  * This exposes a different name than the actual variable name.  See
368546970bcSRusty Russell  * module_param_named() for why this might be necessary.
369546970bcSRusty Russell  */
3701da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm)		\
37122e48eafSJan Beulich 	static const struct kparam_array __param_arr_##name		\
3729bbb9e5aSRusty Russell 	= { ARRAY_SIZE(array), nump, &param_ops_##type,			\
3731da177e4SLinus Torvalds 	    sizeof(array[0]), array };					\
374fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
3759bbb9e5aSRusty Russell 			    &param_array_ops,				\
376fddd5201SRusty Russell 			    .arr = &__param_arr_##name,			\
377fddd5201SRusty Russell 			    __same_type(array[0], bool), perm);		\
3781da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "array of " #type)
3791da177e4SLinus Torvalds 
3809bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops;
3811da177e4SLinus Torvalds 
3829bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string;
3839bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *);
3849bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp);
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds /* for exporting parameters in /sys/parameters */
3871da177e4SLinus Torvalds 
3881da177e4SLinus Torvalds struct module;
3891da177e4SLinus Torvalds 
390ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
3911da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod,
3929bbb9e5aSRusty Russell 				    const struct kernel_param *kparam,
3931da177e4SLinus Torvalds 				    unsigned int num_params);
3941da177e4SLinus Torvalds 
3951da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod);
396ef665c1aSRandy Dunlap #else
397ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod,
3989bbb9e5aSRusty Russell 			     const struct kernel_param *kparam,
399ef665c1aSRandy Dunlap 			     unsigned int num_params)
400ef665c1aSRandy Dunlap {
401ef665c1aSRandy Dunlap 	return 0;
402ef665c1aSRandy Dunlap }
403ef665c1aSRandy Dunlap 
404ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod)
405ef665c1aSRandy Dunlap { }
406ef665c1aSRandy Dunlap #endif
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */
409