xref: /linux/include/linux/moduleparam.h (revision 51e158c12aca3c9ac63988611a97c05109b14dc9)
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 
19b75be420SLinus Walleij #ifdef MODULE
201da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info)					  \
2134182eeaSRusty Russell static const char __UNIQUE_ID(name)[]					  \
22b6472776SJan Beulich   __used __attribute__((section(".modinfo"), unused, aligned(1)))	  \
23b6472776SJan Beulich   = __stringify(tag) "=" info
241da177e4SLinus Torvalds #else  /* !MODULE */
25b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */
26b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info)					  \
2734182eeaSRusty Russell   struct __UNIQUE_ID(name) {}
281da177e4SLinus Torvalds #endif
291da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type)					  \
301da177e4SLinus Torvalds   __MODULE_INFO(parmtype, name##type, #name ":" _type)
311da177e4SLinus Torvalds 
32639938ebSPaul Gortmaker /* One for each parameter, describing how to use it.  Some files do
33639938ebSPaul Gortmaker    multiple of these per line, so can't just use MODULE_INFO. */
34639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \
35639938ebSPaul Gortmaker 	__MODULE_INFO(parm, _parm, #_parm ":" desc)
36639938ebSPaul Gortmaker 
371da177e4SLinus Torvalds struct kernel_param;
381da177e4SLinus Torvalds 
39ab013c5fSSteven Rostedt /*
40ab013c5fSSteven Rostedt  * Flags available for kernel_param_ops
41ab013c5fSSteven Rostedt  *
42ab013c5fSSteven Rostedt  * NOARG - the parameter allows for no argument (foo instead of foo=1)
43ab013c5fSSteven Rostedt  */
44ab013c5fSSteven Rostedt enum {
45ab013c5fSSteven Rostedt 	KERNEL_PARAM_FL_NOARG = (1 << 0)
46ab013c5fSSteven Rostedt };
47ab013c5fSSteven Rostedt 
489bbb9e5aSRusty Russell struct kernel_param_ops {
49ab013c5fSSteven Rostedt 	/* How the ops should behave */
50ab013c5fSSteven Rostedt 	unsigned int flags;
511da177e4SLinus Torvalds 	/* Returns 0, or -errno.  arg is in kp->arg. */
529bbb9e5aSRusty Russell 	int (*set)(const char *val, const struct kernel_param *kp);
531da177e4SLinus Torvalds 	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
549bbb9e5aSRusty Russell 	int (*get)(char *buffer, const struct kernel_param *kp);
55e6df34a4SRusty Russell 	/* Optional function to free kp->arg when module unloaded. */
56e6df34a4SRusty Russell 	void (*free)(void *arg);
579bbb9e5aSRusty Russell };
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds struct kernel_param {
601da177e4SLinus Torvalds 	const char *name;
619bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
6245fcc70cSRusty Russell 	u16 perm;
63026cee00SPawel Moll 	s16 level;
6422e48eafSJan Beulich 	union {
651da177e4SLinus Torvalds 		void *arg;
6622e48eafSJan Beulich 		const struct kparam_string *str;
6722e48eafSJan Beulich 		const struct kparam_array *arr;
6822e48eafSJan Beulich 	};
691da177e4SLinus Torvalds };
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /* Special one for strings we want to copy into */
721da177e4SLinus Torvalds struct kparam_string {
731da177e4SLinus Torvalds 	unsigned int maxlen;
741da177e4SLinus Torvalds 	char *string;
751da177e4SLinus Torvalds };
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* Special one for arrays */
781da177e4SLinus Torvalds struct kparam_array
791da177e4SLinus Torvalds {
801da177e4SLinus Torvalds 	unsigned int max;
81c5be0b2eSRichard Kennedy 	unsigned int elemsize;
821da177e4SLinus Torvalds 	unsigned int *num;
839bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
841da177e4SLinus Torvalds 	void *elem;
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds 
87546970bcSRusty Russell /**
88546970bcSRusty Russell  * module_param - typesafe helper for a module/cmdline parameter
89546970bcSRusty Russell  * @value: the variable to alter, and exposed parameter name.
90546970bcSRusty Russell  * @type: the type of the parameter
91546970bcSRusty Russell  * @perm: visibility in sysfs.
92546970bcSRusty Russell  *
93546970bcSRusty Russell  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
94546970bcSRusty Russell  * ".") the kernel commandline parameter.  Note that - is changed to _, so
95546970bcSRusty Russell  * the user can use "foo-bar=1" even for variable "foo_bar".
96546970bcSRusty Russell  *
97546970bcSRusty Russell  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
98546970bcSRusty Russell  * for world-readable, 0644 for root-writable, etc.  Note that if it
99546970bcSRusty Russell  * is writable, you may need to use kparam_block_sysfs_write() around
100546970bcSRusty Russell  * accesses (esp. charp, which can be kfreed when it changes).
101546970bcSRusty Russell  *
102546970bcSRusty Russell  * The @type is simply pasted to refer to a param_ops_##type and a
103546970bcSRusty Russell  * param_check_##type: for convenience many standard types are provided but
104546970bcSRusty Russell  * you can create your own by defining those variables.
105546970bcSRusty Russell  *
106546970bcSRusty Russell  * Standard types are:
107546970bcSRusty Russell  *	byte, short, ushort, int, uint, long, ulong
108546970bcSRusty Russell  *	charp: a character pointer
109546970bcSRusty Russell  *	bool: a bool, values 0/1, y/n, Y/N.
110546970bcSRusty Russell  *	invbool: the above, only sense-reversed (N = true).
111546970bcSRusty Russell  */
112546970bcSRusty Russell #define module_param(name, type, perm)				\
113546970bcSRusty Russell 	module_param_named(name, name, type, perm)
114546970bcSRusty Russell 
115546970bcSRusty Russell /**
116546970bcSRusty Russell  * module_param_named - typesafe helper for a renamed module/cmdline parameter
117546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
118546970bcSRusty Russell  * @value: the actual lvalue to alter.
119546970bcSRusty Russell  * @type: the type of the parameter
120546970bcSRusty Russell  * @perm: visibility in sysfs.
121546970bcSRusty Russell  *
122546970bcSRusty Russell  * Usually it's a good idea to have variable names and user-exposed names the
123546970bcSRusty Russell  * same, but that's harder if the variable must be non-static or is inside a
124546970bcSRusty Russell  * structure.  This allows exposure under a different name.
125546970bcSRusty Russell  */
126546970bcSRusty Russell #define module_param_named(name, value, type, perm)			   \
127546970bcSRusty Russell 	param_check_##type(name, &(value));				   \
128546970bcSRusty Russell 	module_param_cb(name, &param_ops_##type, &value, perm);		   \
129546970bcSRusty Russell 	__MODULE_PARM_TYPE(name, #type)
130546970bcSRusty Russell 
131546970bcSRusty Russell /**
132546970bcSRusty Russell  * module_param_cb - general callback for a module/cmdline parameter
133546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
134546970bcSRusty Russell  * @ops: the set & get operations for this parameter.
135546970bcSRusty Russell  * @perm: visibility in sysfs.
136546970bcSRusty Russell  *
137546970bcSRusty Russell  * The ops can have NULL set or get functions.
138546970bcSRusty Russell  */
139546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm)				      \
140ae82fdb1SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1)
141026cee00SPawel Moll 
142026cee00SPawel Moll /**
143026cee00SPawel Moll  * <level>_param_cb - general callback for a module/cmdline parameter
144026cee00SPawel Moll  *                    to be evaluated before certain initcall level
145026cee00SPawel Moll  * @name: a valid C identifier which is the parameter name.
146026cee00SPawel Moll  * @ops: the set & get operations for this parameter.
147026cee00SPawel Moll  * @perm: visibility in sysfs.
148026cee00SPawel Moll  *
149026cee00SPawel Moll  * The ops can have NULL set or get functions.
150026cee00SPawel Moll  */
151026cee00SPawel Moll #define __level_param_cb(name, ops, arg, perm, level)			\
152026cee00SPawel Moll 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)
153026cee00SPawel Moll 
154026cee00SPawel Moll #define core_param_cb(name, ops, arg, perm)		\
155026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 1)
156026cee00SPawel Moll 
157026cee00SPawel Moll #define postcore_param_cb(name, ops, arg, perm)		\
158026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 2)
159026cee00SPawel Moll 
160026cee00SPawel Moll #define arch_param_cb(name, ops, arg, perm)		\
161026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 3)
162026cee00SPawel Moll 
163026cee00SPawel Moll #define subsys_param_cb(name, ops, arg, perm)		\
164026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 4)
165026cee00SPawel Moll 
166026cee00SPawel Moll #define fs_param_cb(name, ops, arg, perm)		\
167026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 5)
168026cee00SPawel Moll 
169026cee00SPawel Moll #define device_param_cb(name, ops, arg, perm)		\
170026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 6)
171026cee00SPawel Moll 
172026cee00SPawel Moll #define late_param_cb(name, ops, arg, perm)		\
173026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 7)
174546970bcSRusty Russell 
17591d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into
17691d35dd9SIvan Kokshaysky    read-only sections (which is part of respective UNIX ABI on these
17791d35dd9SIvan Kokshaysky    platforms). So 'const' makes no sense and even causes compile failures
17891d35dd9SIvan Kokshaysky    with some compilers. */
17991d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
18091d35dd9SIvan Kokshaysky #define __moduleparam_const
18191d35dd9SIvan Kokshaysky #else
18291d35dd9SIvan Kokshaysky #define __moduleparam_const const
18391d35dd9SIvan Kokshaysky #endif
18491d35dd9SIvan Kokshaysky 
1851da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module
186546970bcSRusty Russell    parameters. */
187026cee00SPawel Moll #define __module_param_call(prefix, name, ops, arg, perm, level)	\
1889774a1f5SAlexey Dobriyan 	/* Default value instead of permissions? */			\
18922e48eafSJan Beulich 	static const char __param_str_##name[] = prefix #name; \
19091d35dd9SIvan Kokshaysky 	static struct kernel_param __moduleparam_const __param_##name	\
1913ff6eeccSAdrian Bunk 	__used								\
1921da177e4SLinus Torvalds     __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
19358f86cc8SRusty Russell 	= { __param_str_##name, ops, VERIFY_OCTAL_PERMISSIONS(perm),	\
19458f86cc8SRusty Russell 	    level, { arg } }
1951da177e4SLinus Torvalds 
1969bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */
1971da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm)			\
1989bbb9e5aSRusty Russell 	static struct kernel_param_ops __param_ops_##name =		\
199ab013c5fSSteven Rostedt 		{ 0, (void *)set, (void *)get };			\
200fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			\
2019bbb9e5aSRusty Russell 			    name, &__param_ops_##name, arg,		\
202ae82fdb1SRusty Russell 			    (perm) + sizeof(__check_old_set_param(set))*0, -1)
2031da177e4SLinus Torvalds 
2049bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */
2059bbb9e5aSRusty Russell static inline int
2069bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
2079bbb9e5aSRusty Russell {
2089bbb9e5aSRusty Russell 	return 0;
2099bbb9e5aSRusty Russell }
2109bbb9e5aSRusty Russell 
211907b29ebSRusty Russell /**
212907b29ebSRusty Russell  * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
213907b29ebSRusty Russell  * @name: the name of the parameter
214907b29ebSRusty Russell  *
215907b29ebSRusty Russell  * There's no point blocking write on a paramter that isn't writable via sysfs!
216907b29ebSRusty Russell  */
217907b29ebSRusty Russell #define kparam_block_sysfs_write(name)			\
218907b29ebSRusty Russell 	do {						\
219907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
220907b29ebSRusty Russell 		__kernel_param_lock();			\
221907b29ebSRusty Russell 	} while (0)
222907b29ebSRusty Russell 
223907b29ebSRusty Russell /**
224907b29ebSRusty Russell  * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
225907b29ebSRusty Russell  * @name: the name of the parameter
226907b29ebSRusty Russell  */
227907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name)		\
228907b29ebSRusty Russell 	do {						\
229907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
230907b29ebSRusty Russell 		__kernel_param_unlock();		\
231907b29ebSRusty Russell 	} while (0)
232907b29ebSRusty Russell 
233907b29ebSRusty Russell /**
234907b29ebSRusty Russell  * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
235907b29ebSRusty Russell  * @name: the name of the parameter
236907b29ebSRusty Russell  *
237907b29ebSRusty Russell  * This also blocks sysfs writes.
238907b29ebSRusty Russell  */
239907b29ebSRusty Russell #define kparam_block_sysfs_read(name)			\
240907b29ebSRusty Russell 	do {						\
241907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
242907b29ebSRusty Russell 		__kernel_param_lock();			\
243907b29ebSRusty Russell 	} while (0)
244907b29ebSRusty Russell 
245907b29ebSRusty Russell /**
246907b29ebSRusty Russell  * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
247907b29ebSRusty Russell  * @name: the name of the parameter
248907b29ebSRusty Russell  */
249907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name)			\
250907b29ebSRusty Russell 	do {						\
251907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
252907b29ebSRusty Russell 		__kernel_param_unlock();		\
253907b29ebSRusty Russell 	} while (0)
254907b29ebSRusty Russell 
255907b29ebSRusty Russell #ifdef CONFIG_SYSFS
256907b29ebSRusty Russell extern void __kernel_param_lock(void);
257907b29ebSRusty Russell extern void __kernel_param_unlock(void);
258907b29ebSRusty Russell #else
259907b29ebSRusty Russell static inline void __kernel_param_lock(void)
260907b29ebSRusty Russell {
261907b29ebSRusty Russell }
262907b29ebSRusty Russell static inline void __kernel_param_unlock(void)
263907b29ebSRusty Russell {
264907b29ebSRusty Russell }
265907b29ebSRusty Russell #endif
266907b29ebSRusty Russell 
26767e67ceaSRusty Russell #ifndef MODULE
26867e67ceaSRusty Russell /**
26967e67ceaSRusty Russell  * core_param - define a historical core kernel parameter.
27067e67ceaSRusty Russell  * @name: the name of the cmdline and sysfs parameter (often the same as var)
27167e67ceaSRusty Russell  * @var: the variable
272546970bcSRusty Russell  * @type: the type of the parameter
27367e67ceaSRusty Russell  * @perm: visibility in sysfs
27467e67ceaSRusty Russell  *
27567e67ceaSRusty Russell  * core_param is just like module_param(), but cannot be modular and
27667e67ceaSRusty Russell  * doesn't add a prefix (such as "printk.").  This is for compatibility
27767e67ceaSRusty Russell  * with __setup(), and it makes sense as truly core parameters aren't
27867e67ceaSRusty Russell  * tied to the particular file they're in.
27967e67ceaSRusty Russell  */
28067e67ceaSRusty Russell #define core_param(name, var, type, perm)				\
28167e67ceaSRusty Russell 	param_check_##type(name, &(var));				\
282ae82fdb1SRusty Russell 	__module_param_call("", name, &param_ops_##type, &var, perm, -1)
28367e67ceaSRusty Russell #endif /* !MODULE */
28467e67ceaSRusty Russell 
285546970bcSRusty Russell /**
286546970bcSRusty Russell  * module_param_string - a char array parameter
287546970bcSRusty Russell  * @name: the name of the parameter
288546970bcSRusty Russell  * @string: the string variable
289546970bcSRusty Russell  * @len: the maximum length of the string, incl. terminator
290546970bcSRusty Russell  * @perm: visibility in sysfs.
291546970bcSRusty Russell  *
292546970bcSRusty Russell  * This actually copies the string when it's set (unlike type charp).
293546970bcSRusty Russell  * @len is usually just sizeof(string).
294546970bcSRusty Russell  */
2951da177e4SLinus Torvalds #define module_param_string(name, string, len, perm)			\
29622e48eafSJan Beulich 	static const struct kparam_string __param_string_##name		\
2971da177e4SLinus Torvalds 		= { len, string };					\
298fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
2999bbb9e5aSRusty Russell 			    &param_ops_string,				\
300ae82fdb1SRusty Russell 			    .str = &__param_string_##name, perm, -1);	\
3011da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "string")
3021da177e4SLinus Torvalds 
303b1e4d20cSMichal Schmidt /**
304b1e4d20cSMichal Schmidt  * parameq - checks if two parameter names match
305b1e4d20cSMichal Schmidt  * @name1: parameter name 1
306b1e4d20cSMichal Schmidt  * @name2: parameter name 2
307b1e4d20cSMichal Schmidt  *
308b1e4d20cSMichal Schmidt  * Returns true if the two parameter names are equal.
309b1e4d20cSMichal Schmidt  * Dashes (-) are considered equal to underscores (_).
310b1e4d20cSMichal Schmidt  */
311b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2);
312b1e4d20cSMichal Schmidt 
313b1e4d20cSMichal Schmidt /**
314b1e4d20cSMichal Schmidt  * parameqn - checks if two parameter names match
315b1e4d20cSMichal Schmidt  * @name1: parameter name 1
316b1e4d20cSMichal Schmidt  * @name2: parameter name 2
317b1e4d20cSMichal Schmidt  * @n: the length to compare
318b1e4d20cSMichal Schmidt  *
319b1e4d20cSMichal Schmidt  * Similar to parameq(), except it compares @n characters.
320b1e4d20cSMichal Schmidt  */
321b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n);
322b1e4d20cSMichal Schmidt 
3231da177e4SLinus Torvalds /* Called on module insert or kernel boot */
324*51e158c1SRusty Russell extern char *parse_args(const char *name,
3251da177e4SLinus Torvalds 		      char *args,
326914dcaa8SRusty Russell 		      const struct kernel_param *params,
3271da177e4SLinus Torvalds 		      unsigned num,
328026cee00SPawel Moll 		      s16 level_min,
329026cee00SPawel Moll 		      s16 level_max,
3309fb48c74SJim Cromie 		      int (*unknown)(char *param, char *val,
3319fb48c74SJim Cromie 			      const char *doing));
3321da177e4SLinus Torvalds 
333e180a6b7SRusty Russell /* Called by module remove. */
334e180a6b7SRusty Russell #ifdef CONFIG_SYSFS
335e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num);
336e180a6b7SRusty Russell #else
337e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params,
338e180a6b7SRusty Russell 				  unsigned num)
339e180a6b7SRusty Russell {
340e180a6b7SRusty Russell }
341e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */
342e180a6b7SRusty Russell 
3431da177e4SLinus Torvalds /* All the helper functions */
3441da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub
3451da177e4SLinus Torvalds    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
3461da177e4SLinus Torvalds #define __param_check(name, p, type) \
3470283f9a5SMark Charlebois 	static inline type __always_unused *__check_##name(void) { return(p); }
3481da177e4SLinus Torvalds 
3499bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte;
3509bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp);
3519bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp);
3521da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char)
3531da177e4SLinus Torvalds 
3549bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short;
3559bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp);
3569bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp);
3571da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short)
3581da177e4SLinus Torvalds 
3599bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort;
3609bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp);
3619bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
3621da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
3631da177e4SLinus Torvalds 
3649bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int;
3659bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp);
3669bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp);
3671da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int)
3681da177e4SLinus Torvalds 
3699bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint;
3709bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp);
3719bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp);
3721da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int)
3731da177e4SLinus Torvalds 
3749bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long;
3759bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp);
3769bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp);
3771da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long)
3781da177e4SLinus Torvalds 
3799bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong;
3809bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp);
3819bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
3821da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
3831da177e4SLinus Torvalds 
3849bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp;
3859bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp);
3869bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp);
3871da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *)
3881da177e4SLinus Torvalds 
38972db395fSRusty Russell /* We used to allow int as well as bool.  We're taking that away! */
3909bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool;
3919bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp);
3929bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp);
39372db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool)
3941da177e4SLinus Torvalds 
3959bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool;
3969bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp);
3979bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
3989a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool)
3991da177e4SLinus Torvalds 
40069116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */
40169116f27SRusty Russell extern struct kernel_param_ops param_ops_bint;
40269116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp);
40369116f27SRusty Russell #define param_get_bint param_get_int
40469116f27SRusty Russell #define param_check_bint param_check_int
40569116f27SRusty Russell 
406546970bcSRusty Russell /**
407546970bcSRusty Russell  * module_param_array - a parameter which is an array of some type
408546970bcSRusty Russell  * @name: the name of the array variable
409546970bcSRusty Russell  * @type: the type, as per module_param()
410546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
411546970bcSRusty Russell  * @perm: visibility in sysfs
412546970bcSRusty Russell  *
413546970bcSRusty Russell  * Input and output are as comma-separated values.  Commas inside values
414546970bcSRusty Russell  * don't work properly (eg. an array of charp).
415546970bcSRusty Russell  *
416546970bcSRusty Russell  * ARRAY_SIZE(@name) is used to determine the number of elements in the
417546970bcSRusty Russell  * array, so the definition must be visible.
418546970bcSRusty Russell  */
419546970bcSRusty Russell #define module_param_array(name, type, nump, perm)		\
420546970bcSRusty Russell 	module_param_array_named(name, name, type, nump, perm)
421546970bcSRusty Russell 
422546970bcSRusty Russell /**
423546970bcSRusty Russell  * module_param_array_named - renamed parameter which is an array of some type
424546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name
425546970bcSRusty Russell  * @array: the name of the array variable
426546970bcSRusty Russell  * @type: the type, as per module_param()
427546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
428546970bcSRusty Russell  * @perm: visibility in sysfs
429546970bcSRusty Russell  *
430546970bcSRusty Russell  * This exposes a different name than the actual variable name.  See
431546970bcSRusty Russell  * module_param_named() for why this might be necessary.
432546970bcSRusty Russell  */
4331da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm)		\
434bafeafeaSRusty Russell 	param_check_##type(name, &(array)[0]);				\
43522e48eafSJan Beulich 	static const struct kparam_array __param_arr_##name		\
436c5be0b2eSRichard Kennedy 	= { .max = ARRAY_SIZE(array), .num = nump,                      \
437c5be0b2eSRichard Kennedy 	    .ops = &param_ops_##type,					\
438c5be0b2eSRichard Kennedy 	    .elemsize = sizeof(array[0]), .elem = array };		\
439fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
4409bbb9e5aSRusty Russell 			    &param_array_ops,				\
441fddd5201SRusty Russell 			    .arr = &__param_arr_##name,			\
442ae82fdb1SRusty Russell 			    perm, -1);					\
4431da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "array of " #type)
4441da177e4SLinus Torvalds 
4459bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops;
4461da177e4SLinus Torvalds 
4479bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string;
4489bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *);
4499bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp);
4501da177e4SLinus Torvalds 
451b634d130SJean Delvare /* for exporting parameters in /sys/module/.../parameters */
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds struct module;
4541da177e4SLinus Torvalds 
455ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
4561da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod,
4579bbb9e5aSRusty Russell 				    const struct kernel_param *kparam,
4581da177e4SLinus Torvalds 				    unsigned int num_params);
4591da177e4SLinus Torvalds 
4601da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod);
461ef665c1aSRandy Dunlap #else
462ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod,
4639bbb9e5aSRusty Russell 			     const struct kernel_param *kparam,
464ef665c1aSRandy Dunlap 			     unsigned int num_params)
465ef665c1aSRandy Dunlap {
466ef665c1aSRandy Dunlap 	return 0;
467ef665c1aSRandy Dunlap }
468ef665c1aSRandy Dunlap 
469ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod)
470ef665c1aSRandy Dunlap { }
471ef665c1aSRandy Dunlap #endif
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */
474