1#ifndef _LINUX_MODULE_PARAMS_H
2#define _LINUX_MODULE_PARAMS_H
3
4#include <linux/init.h>
5#include <linux/stringify.h>
6#include <linux/kernel.h>
7
8
9
10#ifdef MODULE
11#define MODULE_PARAM_PREFIX
12#else
13#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
14#endif
15
16
17#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
18
19#ifdef MODULE
20#define __MODULE_INFO(tag, name, info) \
21static const char __UNIQUE_ID(name)[] \
22 __used __attribute__((section(".modinfo"), unused, aligned(1))) \
23 = __stringify(tag) "=" info
24#else
25
26#define __MODULE_INFO(tag, name, info) \
27 struct __UNIQUE_ID(name) {}
28#endif
29#define __MODULE_PARM_TYPE(name, _type) \
30 __MODULE_INFO(parmtype, name##type, #name ":" _type)
31
32
33
34#define MODULE_PARM_DESC(_parm, desc) \
35 __MODULE_INFO(parm, _parm, #_parm ":" desc)
36
37struct kernel_param;
38
39
40
41
42
43
44enum {
45 KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
46};
47
48struct kernel_param_ops {
49
50 unsigned int flags;
51
52 int (*set)(const char *val, const struct kernel_param *kp);
53
54 int (*get)(char *buffer, const struct kernel_param *kp);
55
56 void (*free)(void *arg);
57};
58
59
60
61
62
63
64
65enum {
66 KERNEL_PARAM_FL_UNSAFE = (1 << 0),
67 KERNEL_PARAM_FL_HWPARAM = (1 << 1),
68};
69
70struct kernel_param {
71 const char *name;
72 struct module *mod;
73 const struct kernel_param_ops *ops;
74 const u16 perm;
75 s8 level;
76 u8 flags;
77 union {
78 void *arg;
79 const struct kparam_string *str;
80 const struct kparam_array *arr;
81 };
82};
83
84extern const struct kernel_param __start___param[], __stop___param[];
85
86
87struct kparam_string {
88 unsigned int maxlen;
89 char *string;
90};
91
92
93struct kparam_array
94{
95 unsigned int max;
96 unsigned int elemsize;
97 unsigned int *num;
98 const struct kernel_param_ops *ops;
99 void *elem;
100};
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127#define module_param(name, type, perm) \
128 module_param_named(name, name, type, perm)
129
130
131
132
133#define module_param_unsafe(name, type, perm) \
134 module_param_named_unsafe(name, name, type, perm)
135
136
137
138
139
140
141
142
143
144
145
146
147#define module_param_named(name, value, type, perm) \
148 param_check_##type(name, &(value)); \
149 module_param_cb(name, ¶m_ops_##type, &value, perm); \
150 __MODULE_PARM_TYPE(name, #type)
151
152
153
154
155#define module_param_named_unsafe(name, value, type, perm) \
156 param_check_##type(name, &(value)); \
157 module_param_cb_unsafe(name, ¶m_ops_##type, &value, perm); \
158 __MODULE_PARM_TYPE(name, #type)
159
160
161
162
163
164
165
166
167
168#define module_param_cb(name, ops, arg, perm) \
169 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
170
171#define module_param_cb_unsafe(name, ops, arg, perm) \
172 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
173 KERNEL_PARAM_FL_UNSAFE)
174
175
176
177
178
179
180
181
182
183
184#define __level_param_cb(name, ops, arg, perm, level) \
185 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
186
187#define core_param_cb(name, ops, arg, perm) \
188 __level_param_cb(name, ops, arg, perm, 1)
189
190#define postcore_param_cb(name, ops, arg, perm) \
191 __level_param_cb(name, ops, arg, perm, 2)
192
193#define arch_param_cb(name, ops, arg, perm) \
194 __level_param_cb(name, ops, arg, perm, 3)
195
196#define subsys_param_cb(name, ops, arg, perm) \
197 __level_param_cb(name, ops, arg, perm, 4)
198
199#define fs_param_cb(name, ops, arg, perm) \
200 __level_param_cb(name, ops, arg, perm, 5)
201
202#define device_param_cb(name, ops, arg, perm) \
203 __level_param_cb(name, ops, arg, perm, 6)
204
205#define late_param_cb(name, ops, arg, perm) \
206 __level_param_cb(name, ops, arg, perm, 7)
207
208
209
210
211
212#if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
213#define __moduleparam_const
214#else
215#define __moduleparam_const const
216#endif
217
218
219
220#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
221 \
222 static const char __param_str_##name[] = prefix #name; \
223 static struct kernel_param __moduleparam_const __param_##name \
224 __used \
225 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
226 = { __param_str_##name, THIS_MODULE, ops, \
227 VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
228
229
230#define module_param_call(name, set, get, arg, perm) \
231 static const struct kernel_param_ops __param_ops_##name = \
232 { .flags = 0, (void *)set, (void *)get }; \
233 __module_param_call(MODULE_PARAM_PREFIX, \
234 name, &__param_ops_##name, arg, \
235 (perm) + sizeof(__check_old_set_param(set))*0, -1, 0)
236
237
238static inline int
239__check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
240{
241 return 0;
242}
243
244#ifdef CONFIG_SYSFS
245extern void kernel_param_lock(struct module *mod);
246extern void kernel_param_unlock(struct module *mod);
247#else
248static inline void kernel_param_lock(struct module *mod)
249{
250}
251static inline void kernel_param_unlock(struct module *mod)
252{
253}
254#endif
255
256#ifndef MODULE
257
258
259
260
261
262
263
264
265
266
267
268
269#define core_param(name, var, type, perm) \
270 param_check_##type(name, &(var)); \
271 __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0)
272
273
274
275
276#define core_param_unsafe(name, var, type, perm) \
277 param_check_##type(name, &(var)); \
278 __module_param_call("", name, ¶m_ops_##type, &var, perm, \
279 -1, KERNEL_PARAM_FL_UNSAFE)
280
281#endif
282
283
284
285
286
287
288
289
290
291
292
293#define module_param_string(name, string, len, perm) \
294 static const struct kparam_string __param_string_##name \
295 = { len, string }; \
296 __module_param_call(MODULE_PARAM_PREFIX, name, \
297 ¶m_ops_string, \
298 .str = &__param_string_##name, perm, -1, 0);\
299 __MODULE_PARM_TYPE(name, "string")
300
301
302
303
304
305
306
307
308
309extern bool parameq(const char *name1, const char *name2);
310
311
312
313
314
315
316
317
318
319extern bool parameqn(const char *name1, const char *name2, size_t n);
320
321
322extern char *parse_args(const char *name,
323 char *args,
324 const struct kernel_param *params,
325 unsigned num,
326 s16 level_min,
327 s16 level_max,
328 void *arg,
329 int (*unknown)(char *param, char *val,
330 const char *doing, void *arg));
331
332
333#ifdef CONFIG_SYSFS
334extern void destroy_params(const struct kernel_param *params, unsigned num);
335#else
336static inline void destroy_params(const struct kernel_param *params,
337 unsigned num)
338{
339}
340#endif
341
342
343
344
345#define __param_check(name, p, type) \
346 static inline type __always_unused *__check_##name(void) { return(p); }
347
348extern const struct kernel_param_ops param_ops_byte;
349extern int param_set_byte(const char *val, const struct kernel_param *kp);
350extern int param_get_byte(char *buffer, const struct kernel_param *kp);
351#define param_check_byte(name, p) __param_check(name, p, unsigned char)
352
353extern const struct kernel_param_ops param_ops_short;
354extern int param_set_short(const char *val, const struct kernel_param *kp);
355extern int param_get_short(char *buffer, const struct kernel_param *kp);
356#define param_check_short(name, p) __param_check(name, p, short)
357
358extern const struct kernel_param_ops param_ops_ushort;
359extern int param_set_ushort(const char *val, const struct kernel_param *kp);
360extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
361#define param_check_ushort(name, p) __param_check(name, p, unsigned short)
362
363extern const struct kernel_param_ops param_ops_int;
364extern int param_set_int(const char *val, const struct kernel_param *kp);
365extern int param_get_int(char *buffer, const struct kernel_param *kp);
366#define param_check_int(name, p) __param_check(name, p, int)
367
368extern const struct kernel_param_ops param_ops_uint;
369extern int param_set_uint(const char *val, const struct kernel_param *kp);
370extern int param_get_uint(char *buffer, const struct kernel_param *kp);
371#define param_check_uint(name, p) __param_check(name, p, unsigned int)
372
373extern const struct kernel_param_ops param_ops_long;
374extern int param_set_long(const char *val, const struct kernel_param *kp);
375extern int param_get_long(char *buffer, const struct kernel_param *kp);
376#define param_check_long(name, p) __param_check(name, p, long)
377
378extern const struct kernel_param_ops param_ops_ulong;
379extern int param_set_ulong(const char *val, const struct kernel_param *kp);
380extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
381#define param_check_ulong(name, p) __param_check(name, p, unsigned long)
382
383extern const struct kernel_param_ops param_ops_ullong;
384extern int param_set_ullong(const char *val, const struct kernel_param *kp);
385extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
386#define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
387
388extern const struct kernel_param_ops param_ops_charp;
389extern int param_set_charp(const char *val, const struct kernel_param *kp);
390extern int param_get_charp(char *buffer, const struct kernel_param *kp);
391extern void param_free_charp(void *arg);
392#define param_check_charp(name, p) __param_check(name, p, char *)
393
394
395extern const struct kernel_param_ops param_ops_bool;
396extern int param_set_bool(const char *val, const struct kernel_param *kp);
397extern int param_get_bool(char *buffer, const struct kernel_param *kp);
398#define param_check_bool(name, p) __param_check(name, p, bool)
399
400extern const struct kernel_param_ops param_ops_bool_enable_only;
401extern int param_set_bool_enable_only(const char *val,
402 const struct kernel_param *kp);
403
404#define param_check_bool_enable_only param_check_bool
405
406extern const struct kernel_param_ops param_ops_invbool;
407extern int param_set_invbool(const char *val, const struct kernel_param *kp);
408extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
409#define param_check_invbool(name, p) __param_check(name, p, bool)
410
411
412extern const struct kernel_param_ops param_ops_bint;
413extern int param_set_bint(const char *val, const struct kernel_param *kp);
414#define param_get_bint param_get_int
415#define param_check_bint param_check_int
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430#define module_param_array(name, type, nump, perm) \
431 module_param_array_named(name, name, type, nump, perm)
432
433
434
435
436
437
438
439
440
441
442
443
444#define module_param_array_named(name, array, type, nump, perm) \
445 param_check_##type(name, &(array)[0]); \
446 static const struct kparam_array __param_arr_##name \
447 = { .max = ARRAY_SIZE(array), .num = nump, \
448 .ops = ¶m_ops_##type, \
449 .elemsize = sizeof(array[0]), .elem = array }; \
450 __module_param_call(MODULE_PARAM_PREFIX, name, \
451 ¶m_array_ops, \
452 .arr = &__param_arr_##name, \
453 perm, -1, 0); \
454 __MODULE_PARM_TYPE(name, "array of " #type)
455
456enum hwparam_type {
457 hwparam_ioport,
458 hwparam_iomem,
459 hwparam_ioport_or_iomem,
460 hwparam_irq,
461 hwparam_dma,
462 hwparam_dma_addr,
463 hwparam_other,
464};
465
466
467
468
469
470
471
472
473
474
475
476
477
478#define module_param_hw_named(name, value, type, hwtype, perm) \
479 param_check_##type(name, &(value)); \
480 __module_param_call(MODULE_PARAM_PREFIX, name, \
481 ¶m_ops_##type, &value, \
482 perm, -1, \
483 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
484 __MODULE_PARM_TYPE(name, #type)
485
486#define module_param_hw(name, type, hwtype, perm) \
487 module_param_hw_named(name, name, type, hwtype, perm)
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503#define module_param_hw_array(name, type, hwtype, nump, perm) \
504 param_check_##type(name, &(name)[0]); \
505 static const struct kparam_array __param_arr_##name \
506 = { .max = ARRAY_SIZE(name), .num = nump, \
507 .ops = ¶m_ops_##type, \
508 .elemsize = sizeof(name[0]), .elem = name }; \
509 __module_param_call(MODULE_PARAM_PREFIX, name, \
510 ¶m_array_ops, \
511 .arr = &__param_arr_##name, \
512 perm, -1, \
513 KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
514 __MODULE_PARM_TYPE(name, "array of " #type)
515
516
517extern const struct kernel_param_ops param_array_ops;
518
519extern const struct kernel_param_ops param_ops_string;
520extern int param_set_copystring(const char *val, const struct kernel_param *);
521extern int param_get_string(char *buffer, const struct kernel_param *kp);
522
523
524
525struct module;
526
527#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
528extern int module_param_sysfs_setup(struct module *mod,
529 const struct kernel_param *kparam,
530 unsigned int num_params);
531
532extern void module_param_sysfs_remove(struct module *mod);
533#else
534static inline int module_param_sysfs_setup(struct module *mod,
535 const struct kernel_param *kparam,
536 unsigned int num_params)
537{
538 return 0;
539}
540
541static inline void module_param_sysfs_remove(struct module *mod)
542{ }
543#endif
544
545#endif
546