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