0001
0002 #ifndef _LINUX_MODULE_PARAMS_H
0003 #define _LINUX_MODULE_PARAMS_H
0004
0005 #include <linux/init.h>
0006 #include <linux/stringify.h>
0007 #include <linux/kernel.h>
0008
0009
0010
0011 #ifdef MODULE
0012 #define MODULE_PARAM_PREFIX
0013 #define __MODULE_INFO_PREFIX
0014 #else
0015 #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
0016
0017 #define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
0018 #endif
0019
0020
0021 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
0022
0023 #define __MODULE_INFO(tag, name, info) \
0024 static const char __UNIQUE_ID(name)[] \
0025 __used __section(".modinfo") __aligned(1) \
0026 = __MODULE_INFO_PREFIX __stringify(tag) "=" info
0027
0028 #define __MODULE_PARM_TYPE(name, _type) \
0029 __MODULE_INFO(parmtype, name##type, #name ":" _type)
0030
0031
0032
0033 #define MODULE_PARM_DESC(_parm, desc) \
0034 __MODULE_INFO(parm, _parm, #_parm ":" desc)
0035
0036 struct kernel_param;
0037
0038
0039
0040
0041
0042
0043 enum {
0044 KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
0045 };
0046
0047 struct kernel_param_ops {
0048
0049 unsigned int flags;
0050
0051 int (*set)(const char *val, const struct kernel_param *kp);
0052
0053 int (*get)(char *buffer, const struct kernel_param *kp);
0054
0055 void (*free)(void *arg);
0056 };
0057
0058
0059
0060
0061
0062
0063
0064 enum {
0065 KERNEL_PARAM_FL_UNSAFE = (1 << 0),
0066 KERNEL_PARAM_FL_HWPARAM = (1 << 1),
0067 };
0068
0069 struct kernel_param {
0070 const char *name;
0071 struct module *mod;
0072 const struct kernel_param_ops *ops;
0073 const u16 perm;
0074 s8 level;
0075 u8 flags;
0076 union {
0077 void *arg;
0078 const struct kparam_string *str;
0079 const struct kparam_array *arr;
0080 };
0081 };
0082
0083 extern const struct kernel_param __start___param[], __stop___param[];
0084
0085
0086 struct kparam_string {
0087 unsigned int maxlen;
0088 char *string;
0089 };
0090
0091
0092 struct kparam_array
0093 {
0094 unsigned int max;
0095 unsigned int elemsize;
0096 unsigned int *num;
0097 const struct kernel_param_ops *ops;
0098 void *elem;
0099 };
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 #define module_param(name, type, perm) \
0127 module_param_named(name, name, type, perm)
0128
0129
0130
0131
0132
0133
0134
0135 #define module_param_unsafe(name, type, perm) \
0136 module_param_named_unsafe(name, name, type, perm)
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 #define module_param_named(name, value, type, perm) \
0150 param_check_##type(name, &(value)); \
0151 module_param_cb(name, ¶m_ops_##type, &value, perm); \
0152 __MODULE_PARM_TYPE(name, #type)
0153
0154
0155
0156
0157
0158
0159
0160
0161 #define module_param_named_unsafe(name, value, type, perm) \
0162 param_check_##type(name, &(value)); \
0163 module_param_cb_unsafe(name, ¶m_ops_##type, &value, perm); \
0164 __MODULE_PARM_TYPE(name, #type)
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 #define module_param_cb(name, ops, arg, perm) \
0176 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
0177
0178 #define module_param_cb_unsafe(name, ops, arg, perm) \
0179 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
0180 KERNEL_PARAM_FL_UNSAFE)
0181
0182 #define __level_param_cb(name, ops, arg, perm, level) \
0183 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 #define core_param_cb(name, ops, arg, perm) \
0195 __level_param_cb(name, ops, arg, perm, 1)
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 #define postcore_param_cb(name, ops, arg, perm) \
0208 __level_param_cb(name, ops, arg, perm, 2)
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 #define arch_param_cb(name, ops, arg, perm) \
0221 __level_param_cb(name, ops, arg, perm, 3)
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 #define subsys_param_cb(name, ops, arg, perm) \
0234 __level_param_cb(name, ops, arg, perm, 4)
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246 #define fs_param_cb(name, ops, arg, perm) \
0247 __level_param_cb(name, ops, arg, perm, 5)
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259 #define device_param_cb(name, ops, arg, perm) \
0260 __level_param_cb(name, ops, arg, perm, 6)
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272 #define late_param_cb(name, ops, arg, perm) \
0273 __level_param_cb(name, ops, arg, perm, 7)
0274
0275
0276
0277
0278
0279 #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
0280 #define __moduleparam_const
0281 #else
0282 #define __moduleparam_const const
0283 #endif
0284
0285
0286
0287 #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
0288 \
0289 static const char __param_str_##name[] = prefix #name; \
0290 static struct kernel_param __moduleparam_const __param_##name \
0291 __used __section("__param") \
0292 __aligned(__alignof__(struct kernel_param)) \
0293 = { __param_str_##name, THIS_MODULE, ops, \
0294 VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
0295
0296
0297 #define module_param_call(name, _set, _get, arg, perm) \
0298 static const struct kernel_param_ops __param_ops_##name = \
0299 { .flags = 0, .set = _set, .get = _get }; \
0300 __module_param_call(MODULE_PARAM_PREFIX, \
0301 name, &__param_ops_##name, arg, perm, -1, 0)
0302
0303 #ifdef CONFIG_SYSFS
0304 extern void kernel_param_lock(struct module *mod);
0305 extern void kernel_param_unlock(struct module *mod);
0306 #else
0307 static inline void kernel_param_lock(struct module *mod)
0308 {
0309 }
0310 static inline void kernel_param_unlock(struct module *mod)
0311 {
0312 }
0313 #endif
0314
0315 #ifndef MODULE
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 #define core_param(name, var, type, perm) \
0329 param_check_##type(name, &(var)); \
0330 __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0)
0331
0332
0333
0334
0335
0336
0337
0338
0339 #define core_param_unsafe(name, var, type, perm) \
0340 param_check_##type(name, &(var)); \
0341 __module_param_call("", name, ¶m_ops_##type, &var, perm, \
0342 -1, KERNEL_PARAM_FL_UNSAFE)
0343
0344 #endif
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 #define module_param_string(name, string, len, perm) \
0357 static const struct kparam_string __param_string_##name \
0358 = { len, string }; \
0359 __module_param_call(MODULE_PARAM_PREFIX, name, \
0360 ¶m_ops_string, \
0361 .str = &__param_string_##name, perm, -1, 0);\
0362 __MODULE_PARM_TYPE(name, "string")
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 extern bool parameq(const char *name1, const char *name2);
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382 extern bool parameqn(const char *name1, const char *name2, size_t n);
0383
0384
0385 extern char *parse_args(const char *name,
0386 char *args,
0387 const struct kernel_param *params,
0388 unsigned num,
0389 s16 level_min,
0390 s16 level_max,
0391 void *arg,
0392 int (*unknown)(char *param, char *val,
0393 const char *doing, void *arg));
0394
0395
0396 #ifdef CONFIG_SYSFS
0397 extern void destroy_params(const struct kernel_param *params, unsigned num);
0398 #else
0399 static inline void destroy_params(const struct kernel_param *params,
0400 unsigned num)
0401 {
0402 }
0403 #endif
0404
0405
0406
0407
0408 #define __param_check(name, p, type) \
0409 static inline type __always_unused *__check_##name(void) { return(p); }
0410
0411 extern const struct kernel_param_ops param_ops_byte;
0412 extern int param_set_byte(const char *val, const struct kernel_param *kp);
0413 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
0414 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
0415
0416 extern const struct kernel_param_ops param_ops_short;
0417 extern int param_set_short(const char *val, const struct kernel_param *kp);
0418 extern int param_get_short(char *buffer, const struct kernel_param *kp);
0419 #define param_check_short(name, p) __param_check(name, p, short)
0420
0421 extern const struct kernel_param_ops param_ops_ushort;
0422 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
0423 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
0424 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
0425
0426 extern const struct kernel_param_ops param_ops_int;
0427 extern int param_set_int(const char *val, const struct kernel_param *kp);
0428 extern int param_get_int(char *buffer, const struct kernel_param *kp);
0429 #define param_check_int(name, p) __param_check(name, p, int)
0430
0431 extern const struct kernel_param_ops param_ops_uint;
0432 extern int param_set_uint(const char *val, const struct kernel_param *kp);
0433 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
0434 int param_set_uint_minmax(const char *val, const struct kernel_param *kp,
0435 unsigned int min, unsigned int max);
0436 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
0437
0438 extern const struct kernel_param_ops param_ops_long;
0439 extern int param_set_long(const char *val, const struct kernel_param *kp);
0440 extern int param_get_long(char *buffer, const struct kernel_param *kp);
0441 #define param_check_long(name, p) __param_check(name, p, long)
0442
0443 extern const struct kernel_param_ops param_ops_ulong;
0444 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
0445 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
0446 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
0447
0448 extern const struct kernel_param_ops param_ops_ullong;
0449 extern int param_set_ullong(const char *val, const struct kernel_param *kp);
0450 extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
0451 #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
0452
0453 extern const struct kernel_param_ops param_ops_hexint;
0454 extern int param_set_hexint(const char *val, const struct kernel_param *kp);
0455 extern int param_get_hexint(char *buffer, const struct kernel_param *kp);
0456 #define param_check_hexint(name, p) param_check_uint(name, p)
0457
0458 extern const struct kernel_param_ops param_ops_charp;
0459 extern int param_set_charp(const char *val, const struct kernel_param *kp);
0460 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
0461 extern void param_free_charp(void *arg);
0462 #define param_check_charp(name, p) __param_check(name, p, char *)
0463
0464
0465 extern const struct kernel_param_ops param_ops_bool;
0466 extern int param_set_bool(const char *val, const struct kernel_param *kp);
0467 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
0468 #define param_check_bool(name, p) __param_check(name, p, bool)
0469
0470 extern const struct kernel_param_ops param_ops_bool_enable_only;
0471 extern int param_set_bool_enable_only(const char *val,
0472 const struct kernel_param *kp);
0473
0474 #define param_check_bool_enable_only param_check_bool
0475
0476 extern const struct kernel_param_ops param_ops_invbool;
0477 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
0478 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
0479 #define param_check_invbool(name, p) __param_check(name, p, bool)
0480
0481
0482 extern const struct kernel_param_ops param_ops_bint;
0483 extern int param_set_bint(const char *val, const struct kernel_param *kp);
0484 #define param_get_bint param_get_int
0485 #define param_check_bint param_check_int
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500 #define module_param_array(name, type, nump, perm) \
0501 module_param_array_named(name, name, type, nump, perm)
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514 #define module_param_array_named(name, array, type, nump, perm) \
0515 param_check_##type(name, &(array)[0]); \
0516 static const struct kparam_array __param_arr_##name \
0517 = { .max = ARRAY_SIZE(array), .num = nump, \
0518 .ops = ¶m_ops_##type, \
0519 .elemsize = sizeof(array[0]), .elem = array }; \
0520 __module_param_call(MODULE_PARAM_PREFIX, name, \
0521 ¶m_array_ops, \
0522 .arr = &__param_arr_##name, \
0523 perm, -1, 0); \
0524 __MODULE_PARM_TYPE(name, "array of " #type)
0525
0526 enum hwparam_type {
0527 hwparam_ioport,
0528 hwparam_iomem,
0529 hwparam_ioport_or_iomem,
0530 hwparam_irq,
0531 hwparam_dma,
0532 hwparam_dma_addr,
0533 hwparam_other,
0534 };
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548 #define module_param_hw_named(name, value, type, hwtype, perm) \
0549 param_check_##type(name, &(value)); \
0550 __module_param_call(MODULE_PARAM_PREFIX, name, \
0551 ¶m_ops_##type, &value, \
0552 perm, -1, \
0553 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
0554 __MODULE_PARM_TYPE(name, #type)
0555
0556 #define module_param_hw(name, type, hwtype, perm) \
0557 module_param_hw_named(name, name, type, hwtype, perm)
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573 #define module_param_hw_array(name, type, hwtype, nump, perm) \
0574 param_check_##type(name, &(name)[0]); \
0575 static const struct kparam_array __param_arr_##name \
0576 = { .max = ARRAY_SIZE(name), .num = nump, \
0577 .ops = ¶m_ops_##type, \
0578 .elemsize = sizeof(name[0]), .elem = name }; \
0579 __module_param_call(MODULE_PARAM_PREFIX, name, \
0580 ¶m_array_ops, \
0581 .arr = &__param_arr_##name, \
0582 perm, -1, \
0583 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
0584 __MODULE_PARM_TYPE(name, "array of " #type)
0585
0586
0587 extern const struct kernel_param_ops param_array_ops;
0588
0589 extern const struct kernel_param_ops param_ops_string;
0590 extern int param_set_copystring(const char *val, const struct kernel_param *);
0591 extern int param_get_string(char *buffer, const struct kernel_param *kp);
0592
0593
0594
0595 struct module;
0596
0597 #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
0598 extern int module_param_sysfs_setup(struct module *mod,
0599 const struct kernel_param *kparam,
0600 unsigned int num_params);
0601
0602 extern void module_param_sysfs_remove(struct module *mod);
0603 #else
0604 static inline int module_param_sysfs_setup(struct module *mod,
0605 const struct kernel_param *kparam,
0606 unsigned int num_params)
0607 {
0608 return 0;
0609 }
0610
0611 static inline void module_param_sysfs_remove(struct module *mod)
0612 { }
0613 #endif
0614
0615 #endif