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