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