Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MODULE_PARAMS_H |
| 2 | #define _LINUX_MODULE_PARAMS_H |
| 3 | /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */ |
| 4 | #include <linux/init.h> |
| 5 | #include <linux/stringify.h> |
| 6 | #include <linux/kernel.h> |
| 7 | |
| 8 | /* You can override this manually, but generally this should match the |
| 9 | module name. */ |
| 10 | #ifdef MODULE |
| 11 | #define MODULE_PARAM_PREFIX /* empty */ |
| 12 | #else |
Sam Ravnborg | 367cb70 | 2006-01-06 21:17:50 +0100 | [diff] [blame] | 13 | #define MODULE_PARAM_PREFIX KBUILD_MODNAME "." |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #endif |
| 15 | |
Rusty Russell | 730b69d | 2008-10-22 10:00:22 -0500 | [diff] [blame] | 16 | /* Chosen so that structs with an unsigned long line up. */ |
| 17 | #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define ___module_cat(a,b) __mod_ ## a ## b |
| 20 | #define __module_cat(a,b) ___module_cat(a,b) |
Linus Walleij | b75be42 | 2011-01-05 13:27:04 +0100 | [diff] [blame] | 21 | #ifdef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define __MODULE_INFO(tag, name, info) \ |
| 23 | static const char __module_cat(name,__LINE__)[] \ |
Jan Beulich | b647277 | 2010-10-26 14:22:26 -0700 | [diff] [blame] | 24 | __used __attribute__((section(".modinfo"), unused, aligned(1))) \ |
| 25 | = __stringify(tag) "=" info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #else /* !MODULE */ |
Linus Walleij | b75be42 | 2011-01-05 13:27:04 +0100 | [diff] [blame] | 27 | /* This struct is here for syntactic coherency, it is not used */ |
| 28 | #define __MODULE_INFO(tag, name, info) \ |
| 29 | struct __module_cat(name,__LINE__) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #endif |
| 31 | #define __MODULE_PARM_TYPE(name, _type) \ |
| 32 | __MODULE_INFO(parmtype, name##type, #name ":" _type) |
| 33 | |
Paul Gortmaker | 639938e | 2011-08-30 11:24:44 -0400 | [diff] [blame] | 34 | /* One for each parameter, describing how to use it. Some files do |
| 35 | multiple of these per line, so can't just use MODULE_INFO. */ |
| 36 | #define MODULE_PARM_DESC(_parm, desc) \ |
| 37 | __MODULE_INFO(parm, _parm, #_parm ":" desc) |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | struct kernel_param; |
| 40 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 41 | struct kernel_param_ops { |
| 42 | /* Returns 0, or -errno. arg is in kp->arg. */ |
| 43 | int (*set)(const char *val, const struct kernel_param *kp); |
| 44 | /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ |
| 45 | int (*get)(char *buffer, const struct kernel_param *kp); |
Rusty Russell | e6df34a | 2010-08-11 23:04:17 -0600 | [diff] [blame] | 46 | /* Optional function to free kp->arg when module unloaded. */ |
| 47 | void (*free)(void *arg); |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 48 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | struct kernel_param { |
| 51 | const char *name; |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 52 | const struct kernel_param_ops *ops; |
Rusty Russell | 45fcc70 | 2009-06-12 21:46:56 -0600 | [diff] [blame] | 53 | u16 perm; |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 54 | s16 level; |
Jan Beulich | 22e48ea | 2007-10-16 23:29:34 -0700 | [diff] [blame] | 55 | union { |
| 56 | void *arg; |
| 57 | const struct kparam_string *str; |
| 58 | const struct kparam_array *arr; |
| 59 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* Special one for strings we want to copy into */ |
| 63 | struct kparam_string { |
| 64 | unsigned int maxlen; |
| 65 | char *string; |
| 66 | }; |
| 67 | |
| 68 | /* Special one for arrays */ |
| 69 | struct kparam_array |
| 70 | { |
| 71 | unsigned int max; |
Richard Kennedy | c5be0b2 | 2011-05-19 16:55:25 -0600 | [diff] [blame] | 72 | unsigned int elemsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | unsigned int *num; |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 74 | const struct kernel_param_ops *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | void *elem; |
| 76 | }; |
| 77 | |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 78 | /** |
| 79 | * module_param - typesafe helper for a module/cmdline parameter |
| 80 | * @value: the variable to alter, and exposed parameter name. |
| 81 | * @type: the type of the parameter |
| 82 | * @perm: visibility in sysfs. |
| 83 | * |
| 84 | * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a |
| 85 | * ".") the kernel commandline parameter. Note that - is changed to _, so |
| 86 | * the user can use "foo-bar=1" even for variable "foo_bar". |
| 87 | * |
| 88 | * @perm is 0 if the the variable is not to appear in sysfs, or 0444 |
| 89 | * for world-readable, 0644 for root-writable, etc. Note that if it |
| 90 | * is writable, you may need to use kparam_block_sysfs_write() around |
| 91 | * accesses (esp. charp, which can be kfreed when it changes). |
| 92 | * |
| 93 | * The @type is simply pasted to refer to a param_ops_##type and a |
| 94 | * param_check_##type: for convenience many standard types are provided but |
| 95 | * you can create your own by defining those variables. |
| 96 | * |
| 97 | * Standard types are: |
| 98 | * byte, short, ushort, int, uint, long, ulong |
| 99 | * charp: a character pointer |
| 100 | * bool: a bool, values 0/1, y/n, Y/N. |
| 101 | * invbool: the above, only sense-reversed (N = true). |
| 102 | */ |
| 103 | #define module_param(name, type, perm) \ |
| 104 | module_param_named(name, name, type, perm) |
| 105 | |
| 106 | /** |
| 107 | * module_param_named - typesafe helper for a renamed module/cmdline parameter |
| 108 | * @name: a valid C identifier which is the parameter name. |
| 109 | * @value: the actual lvalue to alter. |
| 110 | * @type: the type of the parameter |
| 111 | * @perm: visibility in sysfs. |
| 112 | * |
| 113 | * Usually it's a good idea to have variable names and user-exposed names the |
| 114 | * same, but that's harder if the variable must be non-static or is inside a |
| 115 | * structure. This allows exposure under a different name. |
| 116 | */ |
| 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) |
| 121 | |
| 122 | /** |
| 123 | * module_param_cb - general callback for a module/cmdline parameter |
| 124 | * @name: a valid C identifier which is the parameter name. |
| 125 | * @ops: the set & get operations for this parameter. |
| 126 | * @perm: visibility in sysfs. |
| 127 | * |
| 128 | * The ops can have NULL set or get functions. |
| 129 | */ |
| 130 | #define module_param_cb(name, ops, arg, perm) \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 131 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, 0) |
| 132 | |
| 133 | /** |
| 134 | * <level>_param_cb - general callback for a module/cmdline parameter |
| 135 | * to be evaluated before certain initcall level |
| 136 | * @name: a valid C identifier which is the parameter name. |
| 137 | * @ops: the set & get operations for this parameter. |
| 138 | * @perm: visibility in sysfs. |
| 139 | * |
| 140 | * The ops can have NULL set or get functions. |
| 141 | */ |
| 142 | #define __level_param_cb(name, ops, arg, perm, level) \ |
| 143 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level) |
| 144 | |
| 145 | #define core_param_cb(name, ops, arg, perm) \ |
| 146 | __level_param_cb(name, ops, arg, perm, 1) |
| 147 | |
| 148 | #define postcore_param_cb(name, ops, arg, perm) \ |
| 149 | __level_param_cb(name, ops, arg, perm, 2) |
| 150 | |
| 151 | #define arch_param_cb(name, ops, arg, perm) \ |
| 152 | __level_param_cb(name, ops, arg, perm, 3) |
| 153 | |
| 154 | #define subsys_param_cb(name, ops, arg, perm) \ |
| 155 | __level_param_cb(name, ops, arg, perm, 4) |
| 156 | |
| 157 | #define fs_param_cb(name, ops, arg, perm) \ |
| 158 | __level_param_cb(name, ops, arg, perm, 5) |
| 159 | |
| 160 | #define device_param_cb(name, ops, arg, perm) \ |
| 161 | __level_param_cb(name, ops, arg, perm, 6) |
| 162 | |
| 163 | #define late_param_cb(name, ops, arg, perm) \ |
| 164 | __level_param_cb(name, ops, arg, perm, 7) |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 165 | |
Ivan Kokshaysky | 91d35dd | 2008-02-13 15:03:26 -0800 | [diff] [blame] | 166 | /* On alpha, ia64 and ppc64 relocations to global data cannot go into |
| 167 | read-only sections (which is part of respective UNIX ABI on these |
| 168 | platforms). So 'const' makes no sense and even causes compile failures |
| 169 | with some compilers. */ |
| 170 | #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64) |
| 171 | #define __moduleparam_const |
| 172 | #else |
| 173 | #define __moduleparam_const const |
| 174 | #endif |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* This is the fundamental function for registering boot/module |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 177 | parameters. */ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 178 | #define __module_param_call(prefix, name, ops, arg, perm, level) \ |
Alexey Dobriyan | 9774a1f | 2006-12-06 20:36:56 -0800 | [diff] [blame] | 179 | /* Default value instead of permissions? */ \ |
| 180 | static int __param_perm_check_##name __attribute__((unused)) = \ |
Rusty Russell | 730b69d | 2008-10-22 10:00:22 -0500 | [diff] [blame] | 181 | BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ |
| 182 | + BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN); \ |
Jan Beulich | 22e48ea | 2007-10-16 23:29:34 -0700 | [diff] [blame] | 183 | static const char __param_str_##name[] = prefix #name; \ |
Ivan Kokshaysky | 91d35dd | 2008-02-13 15:03:26 -0800 | [diff] [blame] | 184 | static struct kernel_param __moduleparam_const __param_##name \ |
Adrian Bunk | 3ff6eec | 2008-01-24 22:16:20 +0100 | [diff] [blame] | 185 | __used \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 187 | = { __param_str_##name, ops, perm, level, { arg } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 189 | /* Obsolete - use module_param_cb() */ |
| 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, \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 195 | (perm) + sizeof(__check_old_set_param(set))*0, 0) |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 196 | |
| 197 | /* We don't get oldget: it's often a new-style param_get_uint, etc. */ |
| 198 | static inline int |
| 199 | __check_old_set_param(int (*oldset)(const char *, struct kernel_param *)) |
| 200 | { |
| 201 | return 0; |
| 202 | } |
| 203 | |
Rusty Russell | 907b29e | 2010-08-11 23:04:19 -0600 | [diff] [blame] | 204 | /** |
| 205 | * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs. |
| 206 | * @name: the name of the parameter |
| 207 | * |
| 208 | * There's no point blocking write on a paramter that isn't writable via sysfs! |
| 209 | */ |
| 210 | #define kparam_block_sysfs_write(name) \ |
| 211 | do { \ |
| 212 | BUG_ON(!(__param_##name.perm & 0222)); \ |
| 213 | __kernel_param_lock(); \ |
| 214 | } while (0) |
| 215 | |
| 216 | /** |
| 217 | * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again. |
| 218 | * @name: the name of the parameter |
| 219 | */ |
| 220 | #define kparam_unblock_sysfs_write(name) \ |
| 221 | do { \ |
| 222 | BUG_ON(!(__param_##name.perm & 0222)); \ |
| 223 | __kernel_param_unlock(); \ |
| 224 | } while (0) |
| 225 | |
| 226 | /** |
| 227 | * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs. |
| 228 | * @name: the name of the parameter |
| 229 | * |
| 230 | * This also blocks sysfs writes. |
| 231 | */ |
| 232 | #define kparam_block_sysfs_read(name) \ |
| 233 | do { \ |
| 234 | BUG_ON(!(__param_##name.perm & 0444)); \ |
| 235 | __kernel_param_lock(); \ |
| 236 | } while (0) |
| 237 | |
| 238 | /** |
| 239 | * kparam_unblock_sysfs_read - allows sysfs to read a parameter again. |
| 240 | * @name: the name of the parameter |
| 241 | */ |
| 242 | #define kparam_unblock_sysfs_read(name) \ |
| 243 | do { \ |
| 244 | BUG_ON(!(__param_##name.perm & 0444)); \ |
| 245 | __kernel_param_unlock(); \ |
| 246 | } while (0) |
| 247 | |
| 248 | #ifdef CONFIG_SYSFS |
| 249 | extern void __kernel_param_lock(void); |
| 250 | extern void __kernel_param_unlock(void); |
| 251 | #else |
| 252 | static inline void __kernel_param_lock(void) |
| 253 | { |
| 254 | } |
| 255 | static inline void __kernel_param_unlock(void) |
| 256 | { |
| 257 | } |
| 258 | #endif |
| 259 | |
Rusty Russell | 67e67ce | 2008-10-22 10:00:23 -0500 | [diff] [blame] | 260 | #ifndef MODULE |
| 261 | /** |
| 262 | * core_param - define a historical core kernel parameter. |
| 263 | * @name: the name of the cmdline and sysfs parameter (often the same as var) |
| 264 | * @var: the variable |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 265 | * @type: the type of the parameter |
Rusty Russell | 67e67ce | 2008-10-22 10:00:23 -0500 | [diff] [blame] | 266 | * @perm: visibility in sysfs |
| 267 | * |
| 268 | * core_param is just like module_param(), but cannot be modular and |
| 269 | * doesn't add a prefix (such as "printk."). This is for compatibility |
| 270 | * with __setup(), and it makes sense as truly core parameters aren't |
| 271 | * tied to the particular file they're in. |
| 272 | */ |
| 273 | #define core_param(name, var, type, perm) \ |
| 274 | param_check_##type(name, &(var)); \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 275 | __module_param_call("", name, ¶m_ops_##type, &var, perm, 0) |
Rusty Russell | 67e67ce | 2008-10-22 10:00:23 -0500 | [diff] [blame] | 276 | #endif /* !MODULE */ |
| 277 | |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 278 | /** |
| 279 | * module_param_string - a char array parameter |
| 280 | * @name: the name of the parameter |
| 281 | * @string: the string variable |
| 282 | * @len: the maximum length of the string, incl. terminator |
| 283 | * @perm: visibility in sysfs. |
| 284 | * |
| 285 | * This actually copies the string when it's set (unlike type charp). |
| 286 | * @len is usually just sizeof(string). |
| 287 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | #define module_param_string(name, string, len, perm) \ |
Jan Beulich | 22e48ea | 2007-10-16 23:29:34 -0700 | [diff] [blame] | 289 | static const struct kparam_string __param_string_##name \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | = { len, string }; \ |
Rusty Russell | fddd520 | 2009-06-12 21:46:57 -0600 | [diff] [blame] | 291 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 292 | ¶m_ops_string, \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 293 | .str = &__param_string_##name, perm, 0); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | __MODULE_PARM_TYPE(name, "string") |
| 295 | |
Michal Schmidt | b1e4d20 | 2011-10-10 00:03:37 +0200 | [diff] [blame] | 296 | /** |
| 297 | * parameq - checks if two parameter names match |
| 298 | * @name1: parameter name 1 |
| 299 | * @name2: parameter name 2 |
| 300 | * |
| 301 | * Returns true if the two parameter names are equal. |
| 302 | * Dashes (-) are considered equal to underscores (_). |
| 303 | */ |
| 304 | extern bool parameq(const char *name1, const char *name2); |
| 305 | |
| 306 | /** |
| 307 | * parameqn - checks if two parameter names match |
| 308 | * @name1: parameter name 1 |
| 309 | * @name2: parameter name 2 |
| 310 | * @n: the length to compare |
| 311 | * |
| 312 | * Similar to parameq(), except it compares @n characters. |
| 313 | */ |
| 314 | extern bool parameqn(const char *name1, const char *name2, size_t n); |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* Called on module insert or kernel boot */ |
| 317 | extern int parse_args(const char *name, |
| 318 | char *args, |
Rusty Russell | 914dcaa | 2010-08-11 23:04:18 -0600 | [diff] [blame] | 319 | const struct kernel_param *params, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | unsigned num, |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 321 | s16 level_min, |
| 322 | s16 level_max, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | int (*unknown)(char *param, char *val)); |
| 324 | |
Rusty Russell | e180a6b | 2009-03-31 13:05:29 -0600 | [diff] [blame] | 325 | /* Called by module remove. */ |
| 326 | #ifdef CONFIG_SYSFS |
| 327 | extern void destroy_params(const struct kernel_param *params, unsigned num); |
| 328 | #else |
| 329 | static inline void destroy_params(const struct kernel_param *params, |
| 330 | unsigned num) |
| 331 | { |
| 332 | } |
| 333 | #endif /* !CONFIG_SYSFS */ |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* All the helper functions */ |
| 336 | /* The macros to do compile-time type checking stolen from Jakub |
| 337 | Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ |
| 338 | #define __param_check(name, p, type) \ |
| 339 | static inline type *__check_##name(void) { return(p); } |
| 340 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 341 | extern struct kernel_param_ops param_ops_byte; |
| 342 | extern int param_set_byte(const char *val, const struct kernel_param *kp); |
| 343 | extern int param_get_byte(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #define param_check_byte(name, p) __param_check(name, p, unsigned char) |
| 345 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 346 | extern struct kernel_param_ops param_ops_short; |
| 347 | extern int param_set_short(const char *val, const struct kernel_param *kp); |
| 348 | extern int param_get_short(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | #define param_check_short(name, p) __param_check(name, p, short) |
| 350 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 351 | extern struct kernel_param_ops param_ops_ushort; |
| 352 | extern int param_set_ushort(const char *val, const struct kernel_param *kp); |
| 353 | extern int param_get_ushort(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | #define param_check_ushort(name, p) __param_check(name, p, unsigned short) |
| 355 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 356 | extern struct kernel_param_ops param_ops_int; |
| 357 | extern int param_set_int(const char *val, const struct kernel_param *kp); |
| 358 | extern int param_get_int(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #define param_check_int(name, p) __param_check(name, p, int) |
| 360 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 361 | extern struct kernel_param_ops param_ops_uint; |
| 362 | extern int param_set_uint(const char *val, const struct kernel_param *kp); |
| 363 | extern int param_get_uint(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | #define param_check_uint(name, p) __param_check(name, p, unsigned int) |
| 365 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 366 | extern struct kernel_param_ops param_ops_long; |
| 367 | extern int param_set_long(const char *val, const struct kernel_param *kp); |
| 368 | extern int param_get_long(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | #define param_check_long(name, p) __param_check(name, p, long) |
| 370 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 371 | extern struct kernel_param_ops param_ops_ulong; |
| 372 | extern int param_set_ulong(const char *val, const struct kernel_param *kp); |
| 373 | extern int param_get_ulong(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | #define param_check_ulong(name, p) __param_check(name, p, unsigned long) |
| 375 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 376 | extern struct kernel_param_ops param_ops_charp; |
| 377 | extern int param_set_charp(const char *val, const struct kernel_param *kp); |
| 378 | extern int param_get_charp(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | #define param_check_charp(name, p) __param_check(name, p, char *) |
| 380 | |
Rusty Russell | 72db395 | 2012-01-13 09:32:28 +1030 | [diff] [blame] | 381 | /* We used to allow int as well as bool. We're taking that away! */ |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 382 | extern struct kernel_param_ops param_ops_bool; |
| 383 | extern int param_set_bool(const char *val, const struct kernel_param *kp); |
| 384 | extern int param_get_bool(char *buffer, const struct kernel_param *kp); |
Rusty Russell | 72db395 | 2012-01-13 09:32:28 +1030 | [diff] [blame] | 385 | #define param_check_bool(name, p) __param_check(name, p, bool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 387 | extern struct kernel_param_ops param_ops_invbool; |
| 388 | extern int param_set_invbool(const char *val, const struct kernel_param *kp); |
| 389 | extern int param_get_invbool(char *buffer, const struct kernel_param *kp); |
Rusty Russell | 9a71af2 | 2009-06-12 21:46:53 -0600 | [diff] [blame] | 390 | #define param_check_invbool(name, p) __param_check(name, p, bool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Rusty Russell | 69116f2 | 2012-01-13 09:32:17 +1030 | [diff] [blame] | 392 | /* An int, which can only be set like a bool (though it shows as an int). */ |
| 393 | extern struct kernel_param_ops param_ops_bint; |
| 394 | extern int param_set_bint(const char *val, const struct kernel_param *kp); |
| 395 | #define param_get_bint param_get_int |
| 396 | #define param_check_bint param_check_int |
| 397 | |
Rusty Russell | 546970b | 2010-08-11 23:04:20 -0600 | [diff] [blame] | 398 | /** |
| 399 | * module_param_array - a parameter which is an array of some type |
| 400 | * @name: the name of the array variable |
| 401 | * @type: the type, as per module_param() |
| 402 | * @nump: optional pointer filled in with the number written |
| 403 | * @perm: visibility in sysfs |
| 404 | * |
| 405 | * Input and output are as comma-separated values. Commas inside values |
| 406 | * don't work properly (eg. an array of charp). |
| 407 | * |
| 408 | * ARRAY_SIZE(@name) is used to determine the number of elements in the |
| 409 | * array, so the definition must be visible. |
| 410 | */ |
| 411 | #define module_param_array(name, type, nump, perm) \ |
| 412 | module_param_array_named(name, name, type, nump, perm) |
| 413 | |
| 414 | /** |
| 415 | * module_param_array_named - renamed parameter which is an array of some type |
| 416 | * @name: a valid C identifier which is the parameter name |
| 417 | * @array: the name of the array variable |
| 418 | * @type: the type, as per module_param() |
| 419 | * @nump: optional pointer filled in with the number written |
| 420 | * @perm: visibility in sysfs |
| 421 | * |
| 422 | * This exposes a different name than the actual variable name. See |
| 423 | * module_param_named() for why this might be necessary. |
| 424 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | #define module_param_array_named(name, array, type, nump, perm) \ |
Rusty Russell | bafeafe | 2012-01-13 09:32:16 +1030 | [diff] [blame] | 426 | param_check_##type(name, &(array)[0]); \ |
Jan Beulich | 22e48ea | 2007-10-16 23:29:34 -0700 | [diff] [blame] | 427 | static const struct kparam_array __param_arr_##name \ |
Richard Kennedy | c5be0b2 | 2011-05-19 16:55:25 -0600 | [diff] [blame] | 428 | = { .max = ARRAY_SIZE(array), .num = nump, \ |
| 429 | .ops = ¶m_ops_##type, \ |
| 430 | .elemsize = sizeof(array[0]), .elem = array }; \ |
Rusty Russell | fddd520 | 2009-06-12 21:46:57 -0600 | [diff] [blame] | 431 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 432 | ¶m_array_ops, \ |
Rusty Russell | fddd520 | 2009-06-12 21:46:57 -0600 | [diff] [blame] | 433 | .arr = &__param_arr_##name, \ |
Pawel Moll | 026cee0 | 2012-03-26 12:50:51 +1030 | [diff] [blame^] | 434 | perm, 0); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | __MODULE_PARM_TYPE(name, "array of " #type) |
| 436 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 437 | extern struct kernel_param_ops param_array_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 439 | extern struct kernel_param_ops param_ops_string; |
| 440 | extern int param_set_copystring(const char *val, const struct kernel_param *); |
| 441 | extern int param_get_string(char *buffer, const struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* for exporting parameters in /sys/parameters */ |
| 444 | |
| 445 | struct module; |
| 446 | |
Randy Dunlap | ef665c1 | 2007-02-13 15:19:06 -0800 | [diff] [blame] | 447 | #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | extern int module_param_sysfs_setup(struct module *mod, |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 449 | const struct kernel_param *kparam, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | unsigned int num_params); |
| 451 | |
| 452 | extern void module_param_sysfs_remove(struct module *mod); |
Randy Dunlap | ef665c1 | 2007-02-13 15:19:06 -0800 | [diff] [blame] | 453 | #else |
| 454 | static inline int module_param_sysfs_setup(struct module *mod, |
Rusty Russell | 9bbb9e5 | 2010-08-11 23:04:12 -0600 | [diff] [blame] | 455 | const struct kernel_param *kparam, |
Randy Dunlap | ef665c1 | 2007-02-13 15:19:06 -0800 | [diff] [blame] | 456 | unsigned int num_params) |
| 457 | { |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static inline void module_param_sysfs_remove(struct module *mod) |
| 462 | { } |
| 463 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | #endif /* _LINUX_MODULE_PARAMS_H */ |