blob: 5ba250d9172ac93f470044383708d9c0235264c7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_MODULE_PARAMS_H
3#define _LINUX_MODULE_PARAMS_H
4/* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
5#include <linux/init.h>
6#include <linux/stringify.h>
7#include <linux/kernel.h>
8
9/* You can override this manually, but generally this should match the
10 module name. */
11#ifdef MODULE
12#define MODULE_PARAM_PREFIX /* empty */
Alexey Gladkov898490c2019-04-29 18:11:14 +020013#define __MODULE_INFO_PREFIX /* empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#else
Sam Ravnborg367cb702006-01-06 21:17:50 +010015#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
Alexey Gladkov898490c2019-04-29 18:11:14 +020016/* We cannot use MODULE_PARAM_PREFIX because some modules override it. */
17#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#endif
19
Rusty Russell730b69d2008-10-22 10:00:22 -050020/* Chosen so that structs with an unsigned long line up. */
21#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define __MODULE_INFO(tag, name, info) \
Rusty Russell34182ee2012-11-22 12:30:25 +103024static const char __UNIQUE_ID(name)[] \
Jan Beulichb6472772010-10-26 14:22:26 -070025 __used __attribute__((section(".modinfo"), unused, aligned(1))) \
Alexey Gladkov898490c2019-04-29 18:11:14 +020026 = __MODULE_INFO_PREFIX __stringify(tag) "=" info
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define __MODULE_PARM_TYPE(name, _type) \
29 __MODULE_INFO(parmtype, name##type, #name ":" _type)
30
Paul Gortmaker639938e2011-08-30 11:24:44 -040031/* One for each parameter, describing how to use it. Some files do
32 multiple of these per line, so can't just use MODULE_INFO. */
33#define MODULE_PARM_DESC(_parm, desc) \
34 __MODULE_INFO(parm, _parm, #_parm ":" desc)
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036struct kernel_param;
37
Steven Rostedtab013c52013-08-20 15:33:19 +093038/*
39 * Flags available for kernel_param_ops
40 *
41 * NOARG - the parameter allows for no argument (foo instead of foo=1)
42 */
43enum {
Jani Nikula6a4c2642014-08-27 06:21:23 +093044 KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
Steven Rostedtab013c52013-08-20 15:33:19 +093045};
46
Rusty Russell9bbb9e52010-08-11 23:04:12 -060047struct kernel_param_ops {
Steven Rostedtab013c52013-08-20 15:33:19 +093048 /* How the ops should behave */
49 unsigned int flags;
Rusty Russell9bbb9e52010-08-11 23:04:12 -060050 /* Returns 0, or -errno. arg is in kp->arg. */
51 int (*set)(const char *val, const struct kernel_param *kp);
52 /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
53 int (*get)(char *buffer, const struct kernel_param *kp);
Rusty Russelle6df34a2010-08-11 23:04:17 -060054 /* Optional function to free kp->arg when module unloaded. */
55 void (*free)(void *arg);
Rusty Russell9bbb9e52010-08-11 23:04:12 -060056};
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Jani Nikula91f9d332014-08-27 06:22:23 +093058/*
59 * Flags available for kernel_param
60 *
61 * UNSAFE - the parameter is dangerous and setting it will taint the kernel
David Howellsbf616d22017-04-04 16:54:21 +010062 * HWPARAM - Hardware param not permitted in lockdown mode
Jani Nikula91f9d332014-08-27 06:22:23 +093063 */
64enum {
David Howellsbf616d22017-04-04 16:54:21 +010065 KERNEL_PARAM_FL_UNSAFE = (1 << 0),
66 KERNEL_PARAM_FL_HWPARAM = (1 << 1),
Jani Nikula91f9d332014-08-27 06:22:23 +093067};
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069struct kernel_param {
70 const char *name;
Dan Streetmanb51d23e2015-06-17 06:18:52 +093071 struct module *mod;
Rusty Russell9bbb9e52010-08-11 23:04:12 -060072 const struct kernel_param_ops *ops;
Dan Streetman5104b7d2015-06-17 06:17:52 +093073 const u16 perm;
Jani Nikula91f9d332014-08-27 06:22:23 +093074 s8 level;
75 u8 flags;
Jan Beulich22e48ea2007-10-16 23:29:34 -070076 union {
77 void *arg;
78 const struct kparam_string *str;
79 const struct kparam_array *arr;
80 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
Geert Uytterhoeven63a12d92014-10-13 15:55:44 -070083extern const struct kernel_param __start___param[], __stop___param[];
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* Special one for strings we want to copy into */
86struct kparam_string {
87 unsigned int maxlen;
88 char *string;
89};
90
91/* Special one for arrays */
92struct kparam_array
93{
94 unsigned int max;
Richard Kennedyc5be0b22011-05-19 16:55:25 -060095 unsigned int elemsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned int *num;
Rusty Russell9bbb9e52010-08-11 23:04:12 -060097 const struct kernel_param_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 void *elem;
99};
100
Rusty Russell546970b2010-08-11 23:04:20 -0600101/**
102 * module_param - typesafe helper for a module/cmdline parameter
103 * @value: the variable to alter, and exposed parameter name.
104 * @type: the type of the parameter
105 * @perm: visibility in sysfs.
106 *
107 * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
108 * ".") the kernel commandline parameter. Note that - is changed to _, so
109 * the user can use "foo-bar=1" even for variable "foo_bar".
110 *
111 * @perm is 0 if the the variable is not to appear in sysfs, or 0444
112 * for world-readable, 0644 for root-writable, etc. Note that if it
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930113 * is writable, you may need to use kernel_param_lock() around
Rusty Russell546970b2010-08-11 23:04:20 -0600114 * accesses (esp. charp, which can be kfreed when it changes).
115 *
116 * The @type is simply pasted to refer to a param_ops_##type and a
117 * param_check_##type: for convenience many standard types are provided but
118 * you can create your own by defining those variables.
119 *
120 * Standard types are:
121 * byte, short, ushort, int, uint, long, ulong
122 * charp: a character pointer
123 * bool: a bool, values 0/1, y/n, Y/N.
124 * invbool: the above, only sense-reversed (N = true).
125 */
126#define module_param(name, type, perm) \
127 module_param_named(name, name, type, perm)
128
129/**
Jani Nikula3baee202014-08-27 06:23:23 +0930130 * module_param_unsafe - same as module_param but taints kernel
131 */
132#define module_param_unsafe(name, type, perm) \
133 module_param_named_unsafe(name, name, type, perm)
134
135/**
Rusty Russell546970b2010-08-11 23:04:20 -0600136 * module_param_named - typesafe helper for a renamed module/cmdline parameter
137 * @name: a valid C identifier which is the parameter name.
138 * @value: the actual lvalue to alter.
139 * @type: the type of the parameter
140 * @perm: visibility in sysfs.
141 *
142 * Usually it's a good idea to have variable names and user-exposed names the
143 * same, but that's harder if the variable must be non-static or is inside a
144 * structure. This allows exposure under a different name.
145 */
146#define module_param_named(name, value, type, perm) \
147 param_check_##type(name, &(value)); \
148 module_param_cb(name, &param_ops_##type, &value, perm); \
149 __MODULE_PARM_TYPE(name, #type)
150
151/**
Jani Nikula3baee202014-08-27 06:23:23 +0930152 * module_param_named_unsafe - same as module_param_named but taints kernel
153 */
154#define module_param_named_unsafe(name, value, type, perm) \
155 param_check_##type(name, &(value)); \
156 module_param_cb_unsafe(name, &param_ops_##type, &value, perm); \
157 __MODULE_PARM_TYPE(name, #type)
158
159/**
Rusty Russell546970b2010-08-11 23:04:20 -0600160 * module_param_cb - general callback for a module/cmdline parameter
161 * @name: a valid C identifier which is the parameter name.
162 * @ops: the set & get operations for this parameter.
163 * @perm: visibility in sysfs.
164 *
165 * The ops can have NULL set or get functions.
166 */
167#define module_param_cb(name, ops, arg, perm) \
Jani Nikula91f9d332014-08-27 06:22:23 +0930168 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
Pawel Moll026cee02012-03-26 12:50:51 +1030169
Jani Nikula3baee202014-08-27 06:23:23 +0930170#define module_param_cb_unsafe(name, ops, arg, perm) \
171 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
172 KERNEL_PARAM_FL_UNSAFE)
173
Pawel Moll026cee02012-03-26 12:50:51 +1030174/**
175 * <level>_param_cb - general callback for a module/cmdline parameter
176 * to be evaluated before certain initcall level
177 * @name: a valid C identifier which is the parameter name.
178 * @ops: the set & get operations for this parameter.
179 * @perm: visibility in sysfs.
180 *
181 * The ops can have NULL set or get functions.
182 */
183#define __level_param_cb(name, ops, arg, perm, level) \
Jani Nikula91f9d332014-08-27 06:22:23 +0930184 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
Pawel Moll026cee02012-03-26 12:50:51 +1030185
186#define core_param_cb(name, ops, arg, perm) \
187 __level_param_cb(name, ops, arg, perm, 1)
188
189#define postcore_param_cb(name, ops, arg, perm) \
190 __level_param_cb(name, ops, arg, perm, 2)
191
192#define arch_param_cb(name, ops, arg, perm) \
193 __level_param_cb(name, ops, arg, perm, 3)
194
195#define subsys_param_cb(name, ops, arg, perm) \
196 __level_param_cb(name, ops, arg, perm, 4)
197
198#define fs_param_cb(name, ops, arg, perm) \
199 __level_param_cb(name, ops, arg, perm, 5)
200
201#define device_param_cb(name, ops, arg, perm) \
202 __level_param_cb(name, ops, arg, perm, 6)
203
204#define late_param_cb(name, ops, arg, perm) \
205 __level_param_cb(name, ops, arg, perm, 7)
Rusty Russell546970b2010-08-11 23:04:20 -0600206
Ivan Kokshaysky91d35dd2008-02-13 15:03:26 -0800207/* On alpha, ia64 and ppc64 relocations to global data cannot go into
208 read-only sections (which is part of respective UNIX ABI on these
209 platforms). So 'const' makes no sense and even causes compile failures
210 with some compilers. */
211#if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
212#define __moduleparam_const
213#else
214#define __moduleparam_const const
215#endif
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/* This is the fundamental function for registering boot/module
Rusty Russell546970b2010-08-11 23:04:20 -0600218 parameters. */
Jani Nikula91f9d332014-08-27 06:22:23 +0930219#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
Alexey Dobriyan9774a1f2006-12-06 20:36:56 -0800220 /* Default value instead of permissions? */ \
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930221 static const char __param_str_##name[] = prefix #name; \
Ivan Kokshaysky91d35dd2008-02-13 15:03:26 -0800222 static struct kernel_param __moduleparam_const __param_##name \
Adrian Bunk3ff6eec2008-01-24 22:16:20 +0100223 __used \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930225 = { __param_str_##name, THIS_MODULE, ops, \
226 VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600228/* Obsolete - use module_param_cb() */
Kees Cookece19962017-10-17 19:04:43 -0700229#define module_param_call(name, _set, _get, arg, perm) \
Kees Cookb2f270e2017-10-17 19:04:41 -0700230 static const struct kernel_param_ops __param_ops_##name = \
Kees Cookece19962017-10-17 19:04:43 -0700231 { .flags = 0, .set = _set, .get = _get }; \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600232 __module_param_call(MODULE_PARAM_PREFIX, \
Kees Cookb2f270e2017-10-17 19:04:41 -0700233 name, &__param_ops_##name, arg, perm, -1, 0)
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600234
Rusty Russell907b29e2010-08-11 23:04:19 -0600235#ifdef CONFIG_SYSFS
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930236extern void kernel_param_lock(struct module *mod);
237extern void kernel_param_unlock(struct module *mod);
Rusty Russell907b29e2010-08-11 23:04:19 -0600238#else
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930239static inline void kernel_param_lock(struct module *mod)
Rusty Russell907b29e2010-08-11 23:04:19 -0600240{
241}
Dan Streetmanb51d23e2015-06-17 06:18:52 +0930242static inline void kernel_param_unlock(struct module *mod)
Rusty Russell907b29e2010-08-11 23:04:19 -0600243{
244}
245#endif
246
Rusty Russell67e67ce2008-10-22 10:00:23 -0500247#ifndef MODULE
248/**
249 * core_param - define a historical core kernel parameter.
250 * @name: the name of the cmdline and sysfs parameter (often the same as var)
251 * @var: the variable
Rusty Russell546970b2010-08-11 23:04:20 -0600252 * @type: the type of the parameter
Rusty Russell67e67ce2008-10-22 10:00:23 -0500253 * @perm: visibility in sysfs
254 *
255 * core_param is just like module_param(), but cannot be modular and
256 * doesn't add a prefix (such as "printk."). This is for compatibility
257 * with __setup(), and it makes sense as truly core parameters aren't
258 * tied to the particular file they're in.
259 */
260#define core_param(name, var, type, perm) \
261 param_check_##type(name, &(var)); \
Jani Nikula91f9d332014-08-27 06:22:23 +0930262 __module_param_call("", name, &param_ops_##type, &var, perm, -1, 0)
Dmitry Torokhovec0ccc12015-03-30 16:20:09 -0700263
264/**
265 * core_param_unsafe - same as core_param but taints kernel
266 */
267#define core_param_unsafe(name, var, type, perm) \
268 param_check_##type(name, &(var)); \
269 __module_param_call("", name, &param_ops_##type, &var, perm, \
270 -1, KERNEL_PARAM_FL_UNSAFE)
271
Rusty Russell67e67ce2008-10-22 10:00:23 -0500272#endif /* !MODULE */
273
Rusty Russell546970b2010-08-11 23:04:20 -0600274/**
275 * module_param_string - a char array parameter
276 * @name: the name of the parameter
277 * @string: the string variable
278 * @len: the maximum length of the string, incl. terminator
279 * @perm: visibility in sysfs.
280 *
281 * This actually copies the string when it's set (unlike type charp).
282 * @len is usually just sizeof(string).
283 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#define module_param_string(name, string, len, perm) \
Jan Beulich22e48ea2007-10-16 23:29:34 -0700285 static const struct kparam_string __param_string_##name \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 = { len, string }; \
Rusty Russellfddd5202009-06-12 21:46:57 -0600287 __module_param_call(MODULE_PARAM_PREFIX, name, \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600288 &param_ops_string, \
Jani Nikula91f9d332014-08-27 06:22:23 +0930289 .str = &__param_string_##name, perm, -1, 0);\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 __MODULE_PARM_TYPE(name, "string")
291
Michal Schmidtb1e4d202011-10-10 00:03:37 +0200292/**
293 * parameq - checks if two parameter names match
294 * @name1: parameter name 1
295 * @name2: parameter name 2
296 *
297 * Returns true if the two parameter names are equal.
298 * Dashes (-) are considered equal to underscores (_).
299 */
300extern bool parameq(const char *name1, const char *name2);
301
302/**
303 * parameqn - checks if two parameter names match
304 * @name1: parameter name 1
305 * @name2: parameter name 2
306 * @n: the length to compare
307 *
308 * Similar to parameq(), except it compares @n characters.
309 */
310extern bool parameqn(const char *name1, const char *name2, size_t n);
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312/* Called on module insert or kernel boot */
Rusty Russell51e158c2014-04-28 11:34:33 +0930313extern char *parse_args(const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 char *args,
Rusty Russell914dcaa2010-08-11 23:04:18 -0600315 const struct kernel_param *params,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 unsigned num,
Pawel Moll026cee02012-03-26 12:50:51 +1030317 s16 level_min,
318 s16 level_max,
Luis R. Rodriguezecc86172015-03-30 16:20:03 -0700319 void *arg,
Jim Cromie9fb48c72012-04-27 14:30:34 -0600320 int (*unknown)(char *param, char *val,
Luis R. Rodriguezecc86172015-03-30 16:20:03 -0700321 const char *doing, void *arg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Rusty Russelle180a6b2009-03-31 13:05:29 -0600323/* Called by module remove. */
324#ifdef CONFIG_SYSFS
325extern void destroy_params(const struct kernel_param *params, unsigned num);
326#else
327static inline void destroy_params(const struct kernel_param *params,
328 unsigned num)
329{
330}
331#endif /* !CONFIG_SYSFS */
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/* All the helper functions */
334/* The macros to do compile-time type checking stolen from Jakub
335 Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
336#define __param_check(name, p, type) \
Mark Charlebois0283f9a2014-03-17 13:18:26 +1030337 static inline type __always_unused *__check_##name(void) { return(p); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930339extern const struct kernel_param_ops param_ops_byte;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600340extern int param_set_byte(const char *val, const struct kernel_param *kp);
341extern int param_get_byte(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define param_check_byte(name, p) __param_check(name, p, unsigned char)
343
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930344extern const struct kernel_param_ops param_ops_short;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600345extern int param_set_short(const char *val, const struct kernel_param *kp);
346extern int param_get_short(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347#define param_check_short(name, p) __param_check(name, p, short)
348
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930349extern const struct kernel_param_ops param_ops_ushort;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600350extern int param_set_ushort(const char *val, const struct kernel_param *kp);
351extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#define param_check_ushort(name, p) __param_check(name, p, unsigned short)
353
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930354extern const struct kernel_param_ops param_ops_int;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600355extern int param_set_int(const char *val, const struct kernel_param *kp);
356extern int param_get_int(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#define param_check_int(name, p) __param_check(name, p, int)
358
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930359extern const struct kernel_param_ops param_ops_uint;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600360extern int param_set_uint(const char *val, const struct kernel_param *kp);
361extern int param_get_uint(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define param_check_uint(name, p) __param_check(name, p, unsigned int)
363
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930364extern const struct kernel_param_ops param_ops_long;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600365extern int param_set_long(const char *val, const struct kernel_param *kp);
366extern int param_get_long(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#define param_check_long(name, p) __param_check(name, p, long)
368
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930369extern const struct kernel_param_ops param_ops_ulong;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600370extern int param_set_ulong(const char *val, const struct kernel_param *kp);
371extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372#define param_check_ulong(name, p) __param_check(name, p, unsigned long)
373
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930374extern const struct kernel_param_ops param_ops_ullong;
Hannes Reineckeb4210b82014-06-25 15:27:37 +0200375extern int param_set_ullong(const char *val, const struct kernel_param *kp);
376extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
377#define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
378
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930379extern const struct kernel_param_ops param_ops_charp;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600380extern int param_set_charp(const char *val, const struct kernel_param *kp);
381extern int param_get_charp(char *buffer, const struct kernel_param *kp);
Dan Streetman3d9c6372015-11-06 16:29:12 -0800382extern void param_free_charp(void *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define param_check_charp(name, p) __param_check(name, p, char *)
384
Rusty Russell72db3952012-01-13 09:32:28 +1030385/* We used to allow int as well as bool. We're taking that away! */
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930386extern const struct kernel_param_ops param_ops_bool;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600387extern int param_set_bool(const char *val, const struct kernel_param *kp);
388extern int param_get_bool(char *buffer, const struct kernel_param *kp);
Rusty Russell72db3952012-01-13 09:32:28 +1030389#define param_check_bool(name, p) __param_check(name, p, bool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Luis R. Rodriguezd19f05d2015-05-27 11:09:38 +0930391extern const struct kernel_param_ops param_ops_bool_enable_only;
392extern int param_set_bool_enable_only(const char *val,
393 const struct kernel_param *kp);
394/* getter is the same as for the regular bool */
395#define param_check_bool_enable_only param_check_bool
396
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930397extern const struct kernel_param_ops param_ops_invbool;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600398extern int param_set_invbool(const char *val, const struct kernel_param *kp);
399extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
Rusty Russell9a71af22009-06-12 21:46:53 -0600400#define param_check_invbool(name, p) __param_check(name, p, bool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Rusty Russell69116f22012-01-13 09:32:17 +1030402/* An int, which can only be set like a bool (though it shows as an int). */
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930403extern const struct kernel_param_ops param_ops_bint;
Rusty Russell69116f22012-01-13 09:32:17 +1030404extern int param_set_bint(const char *val, const struct kernel_param *kp);
405#define param_get_bint param_get_int
406#define param_check_bint param_check_int
407
Rusty Russell546970b2010-08-11 23:04:20 -0600408/**
409 * module_param_array - a parameter which is an array of some type
410 * @name: the name of the array variable
411 * @type: the type, as per module_param()
412 * @nump: optional pointer filled in with the number written
413 * @perm: visibility in sysfs
414 *
415 * Input and output are as comma-separated values. Commas inside values
416 * don't work properly (eg. an array of charp).
417 *
418 * ARRAY_SIZE(@name) is used to determine the number of elements in the
419 * array, so the definition must be visible.
420 */
421#define module_param_array(name, type, nump, perm) \
422 module_param_array_named(name, name, type, nump, perm)
423
424/**
425 * module_param_array_named - renamed parameter which is an array of some type
426 * @name: a valid C identifier which is the parameter name
427 * @array: the name of the array variable
428 * @type: the type, as per module_param()
429 * @nump: optional pointer filled in with the number written
430 * @perm: visibility in sysfs
431 *
432 * This exposes a different name than the actual variable name. See
433 * module_param_named() for why this might be necessary.
434 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define module_param_array_named(name, array, type, nump, perm) \
Rusty Russellbafeafe2012-01-13 09:32:16 +1030436 param_check_##type(name, &(array)[0]); \
Jan Beulich22e48ea2007-10-16 23:29:34 -0700437 static const struct kparam_array __param_arr_##name \
Richard Kennedyc5be0b22011-05-19 16:55:25 -0600438 = { .max = ARRAY_SIZE(array), .num = nump, \
439 .ops = &param_ops_##type, \
440 .elemsize = sizeof(array[0]), .elem = array }; \
Rusty Russellfddd5202009-06-12 21:46:57 -0600441 __module_param_call(MODULE_PARAM_PREFIX, name, \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600442 &param_array_ops, \
Rusty Russellfddd5202009-06-12 21:46:57 -0600443 .arr = &__param_arr_##name, \
Jani Nikula91f9d332014-08-27 06:22:23 +0930444 perm, -1, 0); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 __MODULE_PARM_TYPE(name, "array of " #type)
446
David Howellsbf616d22017-04-04 16:54:21 +0100447enum hwparam_type {
448 hwparam_ioport, /* Module parameter configures an I/O port */
449 hwparam_iomem, /* Module parameter configures an I/O mem address */
450 hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */
Sylvain 'ythier' Hitier401e0002017-07-02 15:21:56 +0200451 hwparam_irq, /* Module parameter configures an IRQ */
David Howellsbf616d22017-04-04 16:54:21 +0100452 hwparam_dma, /* Module parameter configures a DMA channel */
453 hwparam_dma_addr, /* Module parameter configures a DMA buffer address */
454 hwparam_other, /* Module parameter configures some other value */
455};
456
457/**
458 * module_param_hw_named - A parameter representing a hw parameters
459 * @name: a valid C identifier which is the parameter name.
460 * @value: the actual lvalue to alter.
461 * @type: the type of the parameter
462 * @hwtype: what the value represents (enum hwparam_type)
463 * @perm: visibility in sysfs.
464 *
465 * Usually it's a good idea to have variable names and user-exposed names the
466 * same, but that's harder if the variable must be non-static or is inside a
467 * structure. This allows exposure under a different name.
468 */
469#define module_param_hw_named(name, value, type, hwtype, perm) \
470 param_check_##type(name, &(value)); \
471 __module_param_call(MODULE_PARAM_PREFIX, name, \
472 &param_ops_##type, &value, \
473 perm, -1, \
474 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
475 __MODULE_PARM_TYPE(name, #type)
476
477#define module_param_hw(name, type, hwtype, perm) \
478 module_param_hw_named(name, name, type, hwtype, perm)
479
480/**
481 * module_param_hw_array - A parameter representing an array of hw parameters
482 * @name: the name of the array variable
483 * @type: the type, as per module_param()
484 * @hwtype: what the value represents (enum hwparam_type)
485 * @nump: optional pointer filled in with the number written
486 * @perm: visibility in sysfs
487 *
488 * Input and output are as comma-separated values. Commas inside values
489 * don't work properly (eg. an array of charp).
490 *
491 * ARRAY_SIZE(@name) is used to determine the number of elements in the
492 * array, so the definition must be visible.
493 */
494#define module_param_hw_array(name, type, hwtype, nump, perm) \
495 param_check_##type(name, &(name)[0]); \
496 static const struct kparam_array __param_arr_##name \
497 = { .max = ARRAY_SIZE(name), .num = nump, \
498 .ops = &param_ops_##type, \
499 .elemsize = sizeof(name[0]), .elem = name }; \
500 __module_param_call(MODULE_PARAM_PREFIX, name, \
501 &param_array_ops, \
502 .arr = &__param_arr_##name, \
503 perm, -1, \
504 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
505 __MODULE_PARM_TYPE(name, "array of " #type)
506
507
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930508extern const struct kernel_param_ops param_array_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930510extern const struct kernel_param_ops param_ops_string;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600511extern int param_set_copystring(const char *val, const struct kernel_param *);
512extern int param_get_string(char *buffer, const struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Jean Delvareb634d132013-07-02 15:35:11 +0930514/* for exporting parameters in /sys/module/.../parameters */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516struct module;
517
Randy Dunlapef665c12007-02-13 15:19:06 -0800518#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519extern int module_param_sysfs_setup(struct module *mod,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600520 const struct kernel_param *kparam,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 unsigned int num_params);
522
523extern void module_param_sysfs_remove(struct module *mod);
Randy Dunlapef665c12007-02-13 15:19:06 -0800524#else
525static inline int module_param_sysfs_setup(struct module *mod,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600526 const struct kernel_param *kparam,
Randy Dunlapef665c12007-02-13 15:19:06 -0800527 unsigned int num_params)
528{
529 return 0;
530}
531
532static inline void module_param_sysfs_remove(struct module *mod)
533{ }
534#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536#endif /* _LINUX_MODULE_PARAMS_H */