xref: /linux-6.15/include/linux/moduleparam.h (revision 026cee00)
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)
21b75be420SLinus 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 */
27b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */
28b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info)					  \
29b75be420SLinus 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 
34639938ebSPaul Gortmaker /* One for each parameter, describing how to use it.  Some files do
35639938ebSPaul Gortmaker    multiple of these per line, so can't just use MODULE_INFO. */
36639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \
37639938ebSPaul Gortmaker 	__MODULE_INFO(parm, _parm, #_parm ":" desc)
38639938ebSPaul Gortmaker 
391da177e4SLinus Torvalds struct kernel_param;
401da177e4SLinus Torvalds 
419bbb9e5aSRusty Russell struct kernel_param_ops {
421da177e4SLinus Torvalds 	/* Returns 0, or -errno.  arg is in kp->arg. */
439bbb9e5aSRusty Russell 	int (*set)(const char *val, const struct kernel_param *kp);
441da177e4SLinus Torvalds 	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
459bbb9e5aSRusty Russell 	int (*get)(char *buffer, const struct kernel_param *kp);
46e6df34a4SRusty Russell 	/* Optional function to free kp->arg when module unloaded. */
47e6df34a4SRusty Russell 	void (*free)(void *arg);
489bbb9e5aSRusty Russell };
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds struct kernel_param {
511da177e4SLinus Torvalds 	const char *name;
529bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
5345fcc70cSRusty Russell 	u16 perm;
54*026cee00SPawel Moll 	s16 level;
5522e48eafSJan Beulich 	union {
561da177e4SLinus Torvalds 		void *arg;
5722e48eafSJan Beulich 		const struct kparam_string *str;
5822e48eafSJan Beulich 		const struct kparam_array *arr;
5922e48eafSJan Beulich 	};
601da177e4SLinus Torvalds };
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /* Special one for strings we want to copy into */
631da177e4SLinus Torvalds struct kparam_string {
641da177e4SLinus Torvalds 	unsigned int maxlen;
651da177e4SLinus Torvalds 	char *string;
661da177e4SLinus Torvalds };
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /* Special one for arrays */
691da177e4SLinus Torvalds struct kparam_array
701da177e4SLinus Torvalds {
711da177e4SLinus Torvalds 	unsigned int max;
72c5be0b2eSRichard Kennedy 	unsigned int elemsize;
731da177e4SLinus Torvalds 	unsigned int *num;
749bbb9e5aSRusty Russell 	const struct kernel_param_ops *ops;
751da177e4SLinus Torvalds 	void *elem;
761da177e4SLinus Torvalds };
771da177e4SLinus Torvalds 
78546970bcSRusty Russell /**
79546970bcSRusty Russell  * module_param - typesafe helper for a module/cmdline parameter
80546970bcSRusty Russell  * @value: the variable to alter, and exposed parameter name.
81546970bcSRusty Russell  * @type: the type of the parameter
82546970bcSRusty Russell  * @perm: visibility in sysfs.
83546970bcSRusty Russell  *
84546970bcSRusty Russell  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
85546970bcSRusty Russell  * ".") the kernel commandline parameter.  Note that - is changed to _, so
86546970bcSRusty Russell  * the user can use "foo-bar=1" even for variable "foo_bar".
87546970bcSRusty Russell  *
88546970bcSRusty Russell  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
89546970bcSRusty Russell  * for world-readable, 0644 for root-writable, etc.  Note that if it
90546970bcSRusty Russell  * is writable, you may need to use kparam_block_sysfs_write() around
91546970bcSRusty Russell  * accesses (esp. charp, which can be kfreed when it changes).
92546970bcSRusty Russell  *
93546970bcSRusty Russell  * The @type is simply pasted to refer to a param_ops_##type and a
94546970bcSRusty Russell  * param_check_##type: for convenience many standard types are provided but
95546970bcSRusty Russell  * you can create your own by defining those variables.
96546970bcSRusty Russell  *
97546970bcSRusty Russell  * Standard types are:
98546970bcSRusty Russell  *	byte, short, ushort, int, uint, long, ulong
99546970bcSRusty Russell  *	charp: a character pointer
100546970bcSRusty Russell  *	bool: a bool, values 0/1, y/n, Y/N.
101546970bcSRusty Russell  *	invbool: the above, only sense-reversed (N = true).
102546970bcSRusty Russell  */
103546970bcSRusty Russell #define module_param(name, type, perm)				\
104546970bcSRusty Russell 	module_param_named(name, name, type, perm)
105546970bcSRusty Russell 
106546970bcSRusty Russell /**
107546970bcSRusty Russell  * module_param_named - typesafe helper for a renamed module/cmdline parameter
108546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
109546970bcSRusty Russell  * @value: the actual lvalue to alter.
110546970bcSRusty Russell  * @type: the type of the parameter
111546970bcSRusty Russell  * @perm: visibility in sysfs.
112546970bcSRusty Russell  *
113546970bcSRusty Russell  * Usually it's a good idea to have variable names and user-exposed names the
114546970bcSRusty Russell  * same, but that's harder if the variable must be non-static or is inside a
115546970bcSRusty Russell  * structure.  This allows exposure under a different name.
116546970bcSRusty Russell  */
117546970bcSRusty Russell #define module_param_named(name, value, type, perm)			   \
118546970bcSRusty Russell 	param_check_##type(name, &(value));				   \
119546970bcSRusty Russell 	module_param_cb(name, &param_ops_##type, &value, perm);		   \
120546970bcSRusty Russell 	__MODULE_PARM_TYPE(name, #type)
121546970bcSRusty Russell 
122546970bcSRusty Russell /**
123546970bcSRusty Russell  * module_param_cb - general callback for a module/cmdline parameter
124546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name.
125546970bcSRusty Russell  * @ops: the set & get operations for this parameter.
126546970bcSRusty Russell  * @perm: visibility in sysfs.
127546970bcSRusty Russell  *
128546970bcSRusty Russell  * The ops can have NULL set or get functions.
129546970bcSRusty Russell  */
130546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm)				      \
131*026cee00SPawel Moll 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, 0)
132*026cee00SPawel Moll 
133*026cee00SPawel Moll /**
134*026cee00SPawel Moll  * <level>_param_cb - general callback for a module/cmdline parameter
135*026cee00SPawel Moll  *                    to be evaluated before certain initcall level
136*026cee00SPawel Moll  * @name: a valid C identifier which is the parameter name.
137*026cee00SPawel Moll  * @ops: the set & get operations for this parameter.
138*026cee00SPawel Moll  * @perm: visibility in sysfs.
139*026cee00SPawel Moll  *
140*026cee00SPawel Moll  * The ops can have NULL set or get functions.
141*026cee00SPawel Moll  */
142*026cee00SPawel Moll #define __level_param_cb(name, ops, arg, perm, level)			\
143*026cee00SPawel Moll 	__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)
144*026cee00SPawel Moll 
145*026cee00SPawel Moll #define core_param_cb(name, ops, arg, perm)		\
146*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 1)
147*026cee00SPawel Moll 
148*026cee00SPawel Moll #define postcore_param_cb(name, ops, arg, perm)		\
149*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 2)
150*026cee00SPawel Moll 
151*026cee00SPawel Moll #define arch_param_cb(name, ops, arg, perm)		\
152*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 3)
153*026cee00SPawel Moll 
154*026cee00SPawel Moll #define subsys_param_cb(name, ops, arg, perm)		\
155*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 4)
156*026cee00SPawel Moll 
157*026cee00SPawel Moll #define fs_param_cb(name, ops, arg, perm)		\
158*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 5)
159*026cee00SPawel Moll 
160*026cee00SPawel Moll #define device_param_cb(name, ops, arg, perm)		\
161*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 6)
162*026cee00SPawel Moll 
163*026cee00SPawel Moll #define late_param_cb(name, ops, arg, perm)		\
164*026cee00SPawel Moll 	__level_param_cb(name, ops, arg, perm, 7)
165546970bcSRusty Russell 
16691d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into
16791d35dd9SIvan Kokshaysky    read-only sections (which is part of respective UNIX ABI on these
16891d35dd9SIvan Kokshaysky    platforms). So 'const' makes no sense and even causes compile failures
16991d35dd9SIvan Kokshaysky    with some compilers. */
17091d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
17191d35dd9SIvan Kokshaysky #define __moduleparam_const
17291d35dd9SIvan Kokshaysky #else
17391d35dd9SIvan Kokshaysky #define __moduleparam_const const
17491d35dd9SIvan Kokshaysky #endif
17591d35dd9SIvan Kokshaysky 
1761da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module
177546970bcSRusty Russell    parameters. */
178*026cee00SPawel Moll #define __module_param_call(prefix, name, ops, arg, perm, level)	\
1799774a1f5SAlexey Dobriyan 	/* Default value instead of permissions? */			\
1809774a1f5SAlexey Dobriyan 	static int __param_perm_check_##name __attribute__((unused)) =	\
181730b69d2SRusty Russell 	BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2))	\
182730b69d2SRusty Russell 	+ BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN);	\
18322e48eafSJan Beulich 	static const char __param_str_##name[] = prefix #name;		\
18491d35dd9SIvan Kokshaysky 	static struct kernel_param __moduleparam_const __param_##name	\
1853ff6eeccSAdrian Bunk 	__used								\
1861da177e4SLinus Torvalds     __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
187*026cee00SPawel Moll 	= { __param_str_##name, ops, perm, level, { arg } }
1881da177e4SLinus Torvalds 
1899bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */
1901da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm)			\
1919bbb9e5aSRusty Russell 	static struct kernel_param_ops __param_ops_##name =		\
1929bbb9e5aSRusty Russell 		 { (void *)set, (void *)get };				\
193fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX,			\
1949bbb9e5aSRusty Russell 			    name, &__param_ops_##name, arg,		\
195*026cee00SPawel Moll 			    (perm) + sizeof(__check_old_set_param(set))*0, 0)
1961da177e4SLinus Torvalds 
1979bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */
1989bbb9e5aSRusty Russell static inline int
1999bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
2009bbb9e5aSRusty Russell {
2019bbb9e5aSRusty Russell 	return 0;
2029bbb9e5aSRusty Russell }
2039bbb9e5aSRusty Russell 
204907b29ebSRusty Russell /**
205907b29ebSRusty Russell  * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
206907b29ebSRusty Russell  * @name: the name of the parameter
207907b29ebSRusty Russell  *
208907b29ebSRusty Russell  * There's no point blocking write on a paramter that isn't writable via sysfs!
209907b29ebSRusty Russell  */
210907b29ebSRusty Russell #define kparam_block_sysfs_write(name)			\
211907b29ebSRusty Russell 	do {						\
212907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
213907b29ebSRusty Russell 		__kernel_param_lock();			\
214907b29ebSRusty Russell 	} while (0)
215907b29ebSRusty Russell 
216907b29ebSRusty Russell /**
217907b29ebSRusty Russell  * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
218907b29ebSRusty Russell  * @name: the name of the parameter
219907b29ebSRusty Russell  */
220907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name)		\
221907b29ebSRusty Russell 	do {						\
222907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0222));	\
223907b29ebSRusty Russell 		__kernel_param_unlock();		\
224907b29ebSRusty Russell 	} while (0)
225907b29ebSRusty Russell 
226907b29ebSRusty Russell /**
227907b29ebSRusty Russell  * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
228907b29ebSRusty Russell  * @name: the name of the parameter
229907b29ebSRusty Russell  *
230907b29ebSRusty Russell  * This also blocks sysfs writes.
231907b29ebSRusty Russell  */
232907b29ebSRusty Russell #define kparam_block_sysfs_read(name)			\
233907b29ebSRusty Russell 	do {						\
234907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
235907b29ebSRusty Russell 		__kernel_param_lock();			\
236907b29ebSRusty Russell 	} while (0)
237907b29ebSRusty Russell 
238907b29ebSRusty Russell /**
239907b29ebSRusty Russell  * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
240907b29ebSRusty Russell  * @name: the name of the parameter
241907b29ebSRusty Russell  */
242907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name)			\
243907b29ebSRusty Russell 	do {						\
244907b29ebSRusty Russell 		BUG_ON(!(__param_##name.perm & 0444));	\
245907b29ebSRusty Russell 		__kernel_param_unlock();		\
246907b29ebSRusty Russell 	} while (0)
247907b29ebSRusty Russell 
248907b29ebSRusty Russell #ifdef CONFIG_SYSFS
249907b29ebSRusty Russell extern void __kernel_param_lock(void);
250907b29ebSRusty Russell extern void __kernel_param_unlock(void);
251907b29ebSRusty Russell #else
252907b29ebSRusty Russell static inline void __kernel_param_lock(void)
253907b29ebSRusty Russell {
254907b29ebSRusty Russell }
255907b29ebSRusty Russell static inline void __kernel_param_unlock(void)
256907b29ebSRusty Russell {
257907b29ebSRusty Russell }
258907b29ebSRusty Russell #endif
259907b29ebSRusty Russell 
26067e67ceaSRusty Russell #ifndef MODULE
26167e67ceaSRusty Russell /**
26267e67ceaSRusty Russell  * core_param - define a historical core kernel parameter.
26367e67ceaSRusty Russell  * @name: the name of the cmdline and sysfs parameter (often the same as var)
26467e67ceaSRusty Russell  * @var: the variable
265546970bcSRusty Russell  * @type: the type of the parameter
26667e67ceaSRusty Russell  * @perm: visibility in sysfs
26767e67ceaSRusty Russell  *
26867e67ceaSRusty Russell  * core_param is just like module_param(), but cannot be modular and
26967e67ceaSRusty Russell  * doesn't add a prefix (such as "printk.").  This is for compatibility
27067e67ceaSRusty Russell  * with __setup(), and it makes sense as truly core parameters aren't
27167e67ceaSRusty Russell  * tied to the particular file they're in.
27267e67ceaSRusty Russell  */
27367e67ceaSRusty Russell #define core_param(name, var, type, perm)				\
27467e67ceaSRusty Russell 	param_check_##type(name, &(var));				\
275*026cee00SPawel Moll 	__module_param_call("", name, &param_ops_##type, &var, perm, 0)
27667e67ceaSRusty Russell #endif /* !MODULE */
27767e67ceaSRusty Russell 
278546970bcSRusty Russell /**
279546970bcSRusty Russell  * module_param_string - a char array parameter
280546970bcSRusty Russell  * @name: the name of the parameter
281546970bcSRusty Russell  * @string: the string variable
282546970bcSRusty Russell  * @len: the maximum length of the string, incl. terminator
283546970bcSRusty Russell  * @perm: visibility in sysfs.
284546970bcSRusty Russell  *
285546970bcSRusty Russell  * This actually copies the string when it's set (unlike type charp).
286546970bcSRusty Russell  * @len is usually just sizeof(string).
287546970bcSRusty Russell  */
2881da177e4SLinus Torvalds #define module_param_string(name, string, len, perm)			\
28922e48eafSJan Beulich 	static const struct kparam_string __param_string_##name		\
2901da177e4SLinus Torvalds 		= { len, string };					\
291fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
2929bbb9e5aSRusty Russell 			    &param_ops_string,				\
293*026cee00SPawel Moll 			    .str = &__param_string_##name, perm, 0);	\
2941da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "string")
2951da177e4SLinus Torvalds 
296b1e4d20cSMichal Schmidt /**
297b1e4d20cSMichal Schmidt  * parameq - checks if two parameter names match
298b1e4d20cSMichal Schmidt  * @name1: parameter name 1
299b1e4d20cSMichal Schmidt  * @name2: parameter name 2
300b1e4d20cSMichal Schmidt  *
301b1e4d20cSMichal Schmidt  * Returns true if the two parameter names are equal.
302b1e4d20cSMichal Schmidt  * Dashes (-) are considered equal to underscores (_).
303b1e4d20cSMichal Schmidt  */
304b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2);
305b1e4d20cSMichal Schmidt 
306b1e4d20cSMichal Schmidt /**
307b1e4d20cSMichal Schmidt  * parameqn - checks if two parameter names match
308b1e4d20cSMichal Schmidt  * @name1: parameter name 1
309b1e4d20cSMichal Schmidt  * @name2: parameter name 2
310b1e4d20cSMichal Schmidt  * @n: the length to compare
311b1e4d20cSMichal Schmidt  *
312b1e4d20cSMichal Schmidt  * Similar to parameq(), except it compares @n characters.
313b1e4d20cSMichal Schmidt  */
314b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n);
315b1e4d20cSMichal Schmidt 
3161da177e4SLinus Torvalds /* Called on module insert or kernel boot */
3171da177e4SLinus Torvalds extern int parse_args(const char *name,
3181da177e4SLinus Torvalds 		      char *args,
319914dcaa8SRusty Russell 		      const struct kernel_param *params,
3201da177e4SLinus Torvalds 		      unsigned num,
321*026cee00SPawel Moll 		      s16 level_min,
322*026cee00SPawel Moll 		      s16 level_max,
3231da177e4SLinus Torvalds 		      int (*unknown)(char *param, char *val));
3241da177e4SLinus Torvalds 
325e180a6b7SRusty Russell /* Called by module remove. */
326e180a6b7SRusty Russell #ifdef CONFIG_SYSFS
327e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num);
328e180a6b7SRusty Russell #else
329e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params,
330e180a6b7SRusty Russell 				  unsigned num)
331e180a6b7SRusty Russell {
332e180a6b7SRusty Russell }
333e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */
334e180a6b7SRusty Russell 
3351da177e4SLinus Torvalds /* All the helper functions */
3361da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub
3371da177e4SLinus Torvalds    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
3381da177e4SLinus Torvalds #define __param_check(name, p, type) \
3391da177e4SLinus Torvalds 	static inline type *__check_##name(void) { return(p); }
3401da177e4SLinus Torvalds 
3419bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte;
3429bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp);
3439bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp);
3441da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char)
3451da177e4SLinus Torvalds 
3469bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short;
3479bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp);
3489bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp);
3491da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short)
3501da177e4SLinus Torvalds 
3519bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort;
3529bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp);
3539bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
3541da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
3551da177e4SLinus Torvalds 
3569bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int;
3579bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp);
3589bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp);
3591da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int)
3601da177e4SLinus Torvalds 
3619bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint;
3629bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp);
3639bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp);
3641da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int)
3651da177e4SLinus Torvalds 
3669bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long;
3679bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp);
3689bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp);
3691da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long)
3701da177e4SLinus Torvalds 
3719bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong;
3729bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp);
3739bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
3741da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
3751da177e4SLinus Torvalds 
3769bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp;
3779bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp);
3789bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp);
3791da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *)
3801da177e4SLinus Torvalds 
38172db395fSRusty Russell /* We used to allow int as well as bool.  We're taking that away! */
3829bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool;
3839bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp);
3849bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp);
38572db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool)
3861da177e4SLinus Torvalds 
3879bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool;
3889bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp);
3899bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
3909a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool)
3911da177e4SLinus Torvalds 
39269116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */
39369116f27SRusty Russell extern struct kernel_param_ops param_ops_bint;
39469116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp);
39569116f27SRusty Russell #define param_get_bint param_get_int
39669116f27SRusty Russell #define param_check_bint param_check_int
39769116f27SRusty Russell 
398546970bcSRusty Russell /**
399546970bcSRusty Russell  * module_param_array - a parameter which is an array of some type
400546970bcSRusty Russell  * @name: the name of the array variable
401546970bcSRusty Russell  * @type: the type, as per module_param()
402546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
403546970bcSRusty Russell  * @perm: visibility in sysfs
404546970bcSRusty Russell  *
405546970bcSRusty Russell  * Input and output are as comma-separated values.  Commas inside values
406546970bcSRusty Russell  * don't work properly (eg. an array of charp).
407546970bcSRusty Russell  *
408546970bcSRusty Russell  * ARRAY_SIZE(@name) is used to determine the number of elements in the
409546970bcSRusty Russell  * array, so the definition must be visible.
410546970bcSRusty Russell  */
411546970bcSRusty Russell #define module_param_array(name, type, nump, perm)		\
412546970bcSRusty Russell 	module_param_array_named(name, name, type, nump, perm)
413546970bcSRusty Russell 
414546970bcSRusty Russell /**
415546970bcSRusty Russell  * module_param_array_named - renamed parameter which is an array of some type
416546970bcSRusty Russell  * @name: a valid C identifier which is the parameter name
417546970bcSRusty Russell  * @array: the name of the array variable
418546970bcSRusty Russell  * @type: the type, as per module_param()
419546970bcSRusty Russell  * @nump: optional pointer filled in with the number written
420546970bcSRusty Russell  * @perm: visibility in sysfs
421546970bcSRusty Russell  *
422546970bcSRusty Russell  * This exposes a different name than the actual variable name.  See
423546970bcSRusty Russell  * module_param_named() for why this might be necessary.
424546970bcSRusty Russell  */
4251da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm)		\
426bafeafeaSRusty Russell 	param_check_##type(name, &(array)[0]);				\
42722e48eafSJan Beulich 	static const struct kparam_array __param_arr_##name		\
428c5be0b2eSRichard Kennedy 	= { .max = ARRAY_SIZE(array), .num = nump,                      \
429c5be0b2eSRichard Kennedy 	    .ops = &param_ops_##type,					\
430c5be0b2eSRichard Kennedy 	    .elemsize = sizeof(array[0]), .elem = array };		\
431fddd5201SRusty Russell 	__module_param_call(MODULE_PARAM_PREFIX, name,			\
4329bbb9e5aSRusty Russell 			    &param_array_ops,				\
433fddd5201SRusty Russell 			    .arr = &__param_arr_##name,			\
434*026cee00SPawel Moll 			    perm, 0);					\
4351da177e4SLinus Torvalds 	__MODULE_PARM_TYPE(name, "array of " #type)
4361da177e4SLinus Torvalds 
4379bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops;
4381da177e4SLinus Torvalds 
4399bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string;
4409bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *);
4419bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp);
4421da177e4SLinus Torvalds 
4431da177e4SLinus Torvalds /* for exporting parameters in /sys/parameters */
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds struct module;
4461da177e4SLinus Torvalds 
447ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
4481da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod,
4499bbb9e5aSRusty Russell 				    const struct kernel_param *kparam,
4501da177e4SLinus Torvalds 				    unsigned int num_params);
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod);
453ef665c1aSRandy Dunlap #else
454ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod,
4559bbb9e5aSRusty Russell 			     const struct kernel_param *kparam,
456ef665c1aSRandy Dunlap 			     unsigned int num_params)
457ef665c1aSRandy Dunlap {
458ef665c1aSRandy Dunlap 	return 0;
459ef665c1aSRandy Dunlap }
460ef665c1aSRandy Dunlap 
461ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod)
462ef665c1aSRandy Dunlap { }
463ef665c1aSRandy Dunlap #endif
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */
466