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