1 #ifndef _LINUX_MODULE_PARAMS_H
2 #define _LINUX_MODULE_PARAMS_H
6 #include <linux/kernel.h>
11 #define MODULE_PARAM_PREFIX
13 #define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
17 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
19 #define ___module_cat(a,b) __mod_ ## a ## b
20 #define __module_cat(a,b) ___module_cat(a,b)
22 #define __MODULE_INFO(tag, name, info) \
23 static const char __module_cat(name,__LINE__)[] \
24 __used __attribute__((section(".modinfo"), unused, aligned(1))) \
25 = __stringify(tag) "=" info
28 #define __MODULE_INFO(tag, name, info) \
29 struct __module_cat(name,__LINE__) {}
31 #define __MODULE_PARM_TYPE(name, _type) \
32 __MODULE_INFO(parmtype, name##type, #name ":" _type)
36 #define MODULE_PARM_DESC(_parm, desc) \
37 __MODULE_INFO(parm, _parm, #_parm ":" desc)
103 #define module_param(name, type, perm) \
104 module_param_named(name, name, type, perm)
117 #define module_param_named(name, value, type, perm) \
118 param_check_##type(name, &(value)); \
119 module_param_cb(name, ¶m_ops_##type, &value, perm); \
120 __MODULE_PARM_TYPE(name, #type)
130 #define module_param_cb(name, ops, arg, perm) \
131 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1)
142 #define __level_param_cb(name, ops, arg, perm, level) \
143 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)
145 #define core_param_cb(name, ops, arg, perm) \
146 __level_param_cb(name, ops, arg, perm, 1)
148 #define postcore_param_cb(name, ops, arg, perm) \
149 __level_param_cb(name, ops, arg, perm, 2)
151 #define arch_param_cb(name, ops, arg, perm) \
152 __level_param_cb(name, ops, arg, perm, 3)
154 #define subsys_param_cb(name, ops, arg, perm) \
155 __level_param_cb(name, ops, arg, perm, 4)
157 #define fs_param_cb(name, ops, arg, perm) \
158 __level_param_cb(name, ops, arg, perm, 5)
160 #define device_param_cb(name, ops, arg, perm) \
161 __level_param_cb(name, ops, arg, perm, 6)
163 #define late_param_cb(name, ops, arg, perm) \
164 __level_param_cb(name, ops, arg, perm, 7)
170 #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64)
171 #define __moduleparam_const
173 #define __moduleparam_const const
178 #define __module_param_call(prefix, name, ops, arg, perm, level) \
180 static int __param_perm_check_##name __attribute__((unused)) = \
181 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \
182 + BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN); \
183 static const char __param_str_##name[] = prefix #name; \
184 static struct kernel_param __moduleparam_const __param_##name \
186 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
187 = { __param_str_##name, ops, perm, level, { arg } }
190 #define module_param_call(name, set, get, arg, perm) \
191 static struct kernel_param_ops __param_ops_##name = \
192 { (void *)set, (void *)get }; \
193 __module_param_call(MODULE_PARAM_PREFIX, \
194 name, &__param_ops_##name, arg, \
195 (perm) + sizeof(__check_old_set_param(set))*0, -1)
199 __check_old_set_param(
int (*oldset)(
const char *,
struct kernel_param *))
210 #define kparam_block_sysfs_write(name) \
212 BUG_ON(!(__param_##name.perm & 0222)); \
213 __kernel_param_lock(); \
220 #define kparam_unblock_sysfs_write(name) \
222 BUG_ON(!(__param_##name.perm & 0222)); \
223 __kernel_param_unlock(); \
232 #define kparam_block_sysfs_read(name) \
234 BUG_ON(!(__param_##name.perm & 0444)); \
235 __kernel_param_lock(); \
242 #define kparam_unblock_sysfs_read(name) \
244 BUG_ON(!(__param_##name.perm & 0444)); \
245 __kernel_param_unlock(); \
249 extern void __kernel_param_lock(
void);
250 extern void __kernel_param_unlock(
void);
252 static inline void __kernel_param_lock(
void)
255 static inline void __kernel_param_unlock(
void)
273 #define core_param(name, var, type, perm) \
274 param_check_##type(name, &(var)); \
275 __module_param_call("", name, ¶m_ops_##type, &var, perm, -1)
288 #define module_param_string(name, string, len, perm) \
289 static const struct kparam_string __param_string_##name \
291 __module_param_call(MODULE_PARAM_PREFIX, name, \
293 .str = &__param_string_##name, perm, -1); \
294 __MODULE_PARM_TYPE(name, "string")
304 extern bool parameq(
const char *name1,
const char *name2);
314 extern bool parameqn(
const char *name1,
const char *name2,
size_t n);
328 extern void destroy_params(
const struct kernel_param *params,
unsigned num);
330 static inline void destroy_params(
const struct kernel_param *params,
339 #define __param_check(name, p, type) \
340 static inline type *__check_##name(void) { return(p); }
345 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
350 #define param_check_short(name, p) __param_check(name, p, short)
355 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
360 #define param_check_int(name, p) __param_check(name, p, int)
365 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
370 #define param_check_long(name, p) __param_check(name, p, long)
375 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
380 #define param_check_charp(name, p) __param_check(name, p, char *)
386 #define param_check_bool(name, p) __param_check(name, p, bool)
391 #define param_check_invbool(name, p) __param_check(name, p, bool)
396 #define param_get_bint param_get_int
397 #define param_check_bint param_check_int
412 #define module_param_array(name, type, nump, perm) \
413 module_param_array_named(name, name, type, nump, perm)
426 #define module_param_array_named(name, array, type, nump, perm) \
427 param_check_##type(name, &(array)[0]); \
428 static const struct kparam_array __param_arr_##name \
429 = { .max = ARRAY_SIZE(array), .num = nump, \
430 .ops = ¶m_ops_##type, \
431 .elemsize = sizeof(array[0]), .elem = array }; \
432 __module_param_call(MODULE_PARAM_PREFIX, name, \
434 .arr = &__param_arr_##name, \
436 __MODULE_PARM_TYPE(name, "array of " #type)
448 #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
449 extern int module_param_sysfs_setup(
struct module *
mod,
451 unsigned int num_params);
453 extern void module_param_sysfs_remove(
struct module *
mod);
455 static inline int module_param_sysfs_setup(
struct module *
mod,
457 unsigned int num_params)
462 static inline void module_param_sysfs_remove(
struct module *
mod)