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