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