1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds #ifndef _LINUX_MODULE_PARAMS_H 31da177e4SLinus Torvalds #define _LINUX_MODULE_PARAMS_H 41da177e4SLinus Torvalds /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */ 51da177e4SLinus Torvalds #include <linux/init.h> 61da177e4SLinus Torvalds #include <linux/stringify.h> 71da177e4SLinus Torvalds #include <linux/kernel.h> 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds /* You can override this manually, but generally this should match the 101da177e4SLinus Torvalds module name. */ 111da177e4SLinus Torvalds #ifdef MODULE 121da177e4SLinus Torvalds #define MODULE_PARAM_PREFIX /* empty */ 13898490c0SAlexey Gladkov #define __MODULE_INFO_PREFIX /* empty */ 141da177e4SLinus Torvalds #else 15367cb704SSam Ravnborg #define MODULE_PARAM_PREFIX KBUILD_MODNAME "." 16898490c0SAlexey Gladkov /* We cannot use MODULE_PARAM_PREFIX because some modules override it. */ 17898490c0SAlexey Gladkov #define __MODULE_INFO_PREFIX KBUILD_MODNAME "." 181da177e4SLinus Torvalds #endif 191da177e4SLinus Torvalds 20730b69d2SRusty Russell /* Chosen so that structs with an unsigned long line up. */ 21730b69d2SRusty Russell #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) 22730b69d2SRusty Russell 231da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info) \ 2434182eeaSRusty Russell static const char __UNIQUE_ID(name)[] \ 252aec389eSJohan Hovold __used __section(".modinfo") __aligned(1) \ 26898490c0SAlexey Gladkov = __MODULE_INFO_PREFIX __stringify(tag) "=" info 27898490c0SAlexey Gladkov 281da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type) \ 291da177e4SLinus Torvalds __MODULE_INFO(parmtype, name##type, #name ":" _type) 301da177e4SLinus Torvalds 31639938ebSPaul Gortmaker /* One for each parameter, describing how to use it. Some files do 32639938ebSPaul Gortmaker multiple of these per line, so can't just use MODULE_INFO. */ 33639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \ 34639938ebSPaul Gortmaker __MODULE_INFO(parm, _parm, #_parm ":" desc) 35639938ebSPaul Gortmaker 361da177e4SLinus Torvalds struct kernel_param; 371da177e4SLinus Torvalds 38ab013c5fSSteven Rostedt /* 39ab013c5fSSteven Rostedt * Flags available for kernel_param_ops 40ab013c5fSSteven Rostedt * 41ab013c5fSSteven Rostedt * NOARG - the parameter allows for no argument (foo instead of foo=1) 42ab013c5fSSteven Rostedt */ 43ab013c5fSSteven Rostedt enum { 446a4c2643SJani Nikula KERNEL_PARAM_OPS_FL_NOARG = (1 << 0) 45ab013c5fSSteven Rostedt }; 46ab013c5fSSteven Rostedt 479bbb9e5aSRusty Russell struct kernel_param_ops { 48ab013c5fSSteven Rostedt /* How the ops should behave */ 49ab013c5fSSteven Rostedt unsigned int flags; 501da177e4SLinus Torvalds /* Returns 0, or -errno. arg is in kp->arg. */ 519bbb9e5aSRusty Russell int (*set)(const char *val, const struct kernel_param *kp); 521da177e4SLinus Torvalds /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 539bbb9e5aSRusty Russell int (*get)(char *buffer, const struct kernel_param *kp); 54e6df34a4SRusty Russell /* Optional function to free kp->arg when module unloaded. */ 55e6df34a4SRusty Russell void (*free)(void *arg); 569bbb9e5aSRusty Russell }; 571da177e4SLinus Torvalds 5891f9d330SJani Nikula /* 5991f9d330SJani Nikula * Flags available for kernel_param 6091f9d330SJani Nikula * 6191f9d330SJani Nikula * UNSAFE - the parameter is dangerous and setting it will taint the kernel 62bf616d21SDavid Howells * HWPARAM - Hardware param not permitted in lockdown mode 6391f9d330SJani Nikula */ 6491f9d330SJani Nikula enum { 65bf616d21SDavid Howells KERNEL_PARAM_FL_UNSAFE = (1 << 0), 66bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM = (1 << 1), 6791f9d330SJani Nikula }; 6891f9d330SJani Nikula 691da177e4SLinus Torvalds struct kernel_param { 701da177e4SLinus Torvalds const char *name; 71b51d23e4SDan Streetman struct module *mod; 729bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 735104b7d7SDan Streetman const u16 perm; 7491f9d330SJani Nikula s8 level; 7591f9d330SJani Nikula u8 flags; 7622e48eafSJan Beulich union { 771da177e4SLinus Torvalds void *arg; 7822e48eafSJan Beulich const struct kparam_string *str; 7922e48eafSJan Beulich const struct kparam_array *arr; 8022e48eafSJan Beulich }; 811da177e4SLinus Torvalds }; 821da177e4SLinus Torvalds 8363a12d9dSGeert Uytterhoeven extern const struct kernel_param __start___param[], __stop___param[]; 8463a12d9dSGeert Uytterhoeven 851da177e4SLinus Torvalds /* Special one for strings we want to copy into */ 861da177e4SLinus Torvalds struct kparam_string { 871da177e4SLinus Torvalds unsigned int maxlen; 881da177e4SLinus Torvalds char *string; 891da177e4SLinus Torvalds }; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds /* Special one for arrays */ 921da177e4SLinus Torvalds struct kparam_array 931da177e4SLinus Torvalds { 941da177e4SLinus Torvalds unsigned int max; 95c5be0b2eSRichard Kennedy unsigned int elemsize; 961da177e4SLinus Torvalds unsigned int *num; 979bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 981da177e4SLinus Torvalds void *elem; 991da177e4SLinus Torvalds }; 1001da177e4SLinus Torvalds 101546970bcSRusty Russell /** 102546970bcSRusty Russell * module_param - typesafe helper for a module/cmdline parameter 103e2854a10SZhenzhong Duan * @name: the variable to alter, and exposed parameter name. 104546970bcSRusty Russell * @type: the type of the parameter 105546970bcSRusty Russell * @perm: visibility in sysfs. 106546970bcSRusty Russell * 107e2854a10SZhenzhong Duan * @name becomes the module parameter, or (prefixed by KBUILD_MODNAME and a 108546970bcSRusty Russell * ".") the kernel commandline parameter. Note that - is changed to _, so 109546970bcSRusty Russell * the user can use "foo-bar=1" even for variable "foo_bar". 110546970bcSRusty Russell * 111c6a8b84dSRandy Dunlap * @perm is 0 if the variable is not to appear in sysfs, or 0444 112546970bcSRusty Russell * for world-readable, 0644 for root-writable, etc. Note that if it 113b51d23e4SDan Streetman * is writable, you may need to use kernel_param_lock() around 114546970bcSRusty Russell * accesses (esp. charp, which can be kfreed when it changes). 115546970bcSRusty Russell * 116546970bcSRusty Russell * The @type is simply pasted to refer to a param_ops_##type and a 117546970bcSRusty Russell * param_check_##type: for convenience many standard types are provided but 118546970bcSRusty Russell * you can create your own by defining those variables. 119546970bcSRusty Russell * 120546970bcSRusty Russell * Standard types are: 1217d836577SPaul Menzel * byte, hexint, short, ushort, int, uint, long, ulong 122546970bcSRusty Russell * charp: a character pointer 123546970bcSRusty Russell * bool: a bool, values 0/1, y/n, Y/N. 124546970bcSRusty Russell * invbool: the above, only sense-reversed (N = true). 125546970bcSRusty Russell */ 126546970bcSRusty Russell #define module_param(name, type, perm) \ 127546970bcSRusty Russell module_param_named(name, name, type, perm) 128546970bcSRusty Russell 129546970bcSRusty Russell /** 1303baee201SJani Nikula * module_param_unsafe - same as module_param but taints kernel 131b6d0531eSFabien Dessenne * @name: the variable to alter, and exposed parameter name. 132b6d0531eSFabien Dessenne * @type: the type of the parameter 133b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 1343baee201SJani Nikula */ 1353baee201SJani Nikula #define module_param_unsafe(name, type, perm) \ 1363baee201SJani Nikula module_param_named_unsafe(name, name, type, perm) 1373baee201SJani Nikula 1383baee201SJani Nikula /** 139546970bcSRusty Russell * module_param_named - typesafe helper for a renamed module/cmdline parameter 140546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 141546970bcSRusty Russell * @value: the actual lvalue to alter. 142546970bcSRusty Russell * @type: the type of the parameter 143546970bcSRusty Russell * @perm: visibility in sysfs. 144546970bcSRusty Russell * 145546970bcSRusty Russell * Usually it's a good idea to have variable names and user-exposed names the 146546970bcSRusty Russell * same, but that's harder if the variable must be non-static or is inside a 147546970bcSRusty Russell * structure. This allows exposure under a different name. 148546970bcSRusty Russell */ 149546970bcSRusty Russell #define module_param_named(name, value, type, perm) \ 150546970bcSRusty Russell param_check_##type(name, &(value)); \ 151546970bcSRusty Russell module_param_cb(name, ¶m_ops_##type, &value, perm); \ 152546970bcSRusty Russell __MODULE_PARM_TYPE(name, #type) 153546970bcSRusty Russell 154546970bcSRusty Russell /** 1553baee201SJani Nikula * module_param_named_unsafe - same as module_param_named but taints kernel 156b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 157b6d0531eSFabien Dessenne * @value: the actual lvalue to alter. 158b6d0531eSFabien Dessenne * @type: the type of the parameter 159b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 1603baee201SJani Nikula */ 1613baee201SJani Nikula #define module_param_named_unsafe(name, value, type, perm) \ 1623baee201SJani Nikula param_check_##type(name, &(value)); \ 1633baee201SJani Nikula module_param_cb_unsafe(name, ¶m_ops_##type, &value, perm); \ 1643baee201SJani Nikula __MODULE_PARM_TYPE(name, #type) 1653baee201SJani Nikula 1663baee201SJani Nikula /** 167546970bcSRusty Russell * module_param_cb - general callback for a module/cmdline parameter 168546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 169546970bcSRusty Russell * @ops: the set & get operations for this parameter. 170b6d0531eSFabien Dessenne * @arg: args for @ops 171546970bcSRusty Russell * @perm: visibility in sysfs. 172546970bcSRusty Russell * 173546970bcSRusty Russell * The ops can have NULL set or get functions. 174546970bcSRusty Russell */ 175546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm) \ 17691f9d330SJani Nikula __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0) 177026cee00SPawel Moll 1783baee201SJani Nikula #define module_param_cb_unsafe(name, ops, arg, perm) \ 1793baee201SJani Nikula __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \ 1803baee201SJani Nikula KERNEL_PARAM_FL_UNSAFE) 1813baee201SJani Nikula 182b6d0531eSFabien Dessenne #define __level_param_cb(name, ops, arg, perm, level) \ 183b6d0531eSFabien Dessenne __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) 184026cee00SPawel Moll /** 185b6d0531eSFabien Dessenne * core_param_cb - general callback for a module/cmdline parameter 186b6d0531eSFabien Dessenne * to be evaluated before core initcall level 187026cee00SPawel Moll * @name: a valid C identifier which is the parameter name. 188026cee00SPawel Moll * @ops: the set & get operations for this parameter. 189b6d0531eSFabien Dessenne * @arg: args for @ops 190026cee00SPawel Moll * @perm: visibility in sysfs. 191026cee00SPawel Moll * 192026cee00SPawel Moll * The ops can have NULL set or get functions. 193026cee00SPawel Moll */ 194026cee00SPawel Moll #define core_param_cb(name, ops, arg, perm) \ 195026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 1) 196026cee00SPawel Moll 197b6d0531eSFabien Dessenne /** 198b6d0531eSFabien Dessenne * postcore_param_cb - general callback for a module/cmdline parameter 199b6d0531eSFabien Dessenne * to be evaluated before postcore initcall level 200b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 201b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 202b6d0531eSFabien Dessenne * @arg: args for @ops 203b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 204b6d0531eSFabien Dessenne * 205b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 206b6d0531eSFabien Dessenne */ 207026cee00SPawel Moll #define postcore_param_cb(name, ops, arg, perm) \ 208026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 2) 209026cee00SPawel Moll 210b6d0531eSFabien Dessenne /** 211b6d0531eSFabien Dessenne * arch_param_cb - general callback for a module/cmdline parameter 212b6d0531eSFabien Dessenne * to be evaluated before arch initcall level 213b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 214b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 215b6d0531eSFabien Dessenne * @arg: args for @ops 216b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 217b6d0531eSFabien Dessenne * 218b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 219b6d0531eSFabien Dessenne */ 220026cee00SPawel Moll #define arch_param_cb(name, ops, arg, perm) \ 221026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 3) 222026cee00SPawel Moll 223b6d0531eSFabien Dessenne /** 224b6d0531eSFabien Dessenne * subsys_param_cb - general callback for a module/cmdline parameter 225b6d0531eSFabien Dessenne * to be evaluated before subsys initcall level 226b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 227b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 228b6d0531eSFabien Dessenne * @arg: args for @ops 229b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 230b6d0531eSFabien Dessenne * 231b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 232b6d0531eSFabien Dessenne */ 233026cee00SPawel Moll #define subsys_param_cb(name, ops, arg, perm) \ 234026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 4) 235026cee00SPawel Moll 236b6d0531eSFabien Dessenne /** 237b6d0531eSFabien Dessenne * fs_param_cb - general callback for a module/cmdline parameter 238b6d0531eSFabien Dessenne * to be evaluated before fs initcall level 239b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 240b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 241b6d0531eSFabien Dessenne * @arg: args for @ops 242b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 243b6d0531eSFabien Dessenne * 244b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 245b6d0531eSFabien Dessenne */ 246026cee00SPawel Moll #define fs_param_cb(name, ops, arg, perm) \ 247026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 5) 248026cee00SPawel Moll 249b6d0531eSFabien Dessenne /** 250b6d0531eSFabien Dessenne * device_param_cb - general callback for a module/cmdline parameter 251b6d0531eSFabien Dessenne * to be evaluated before device initcall level 252b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 253b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 254b6d0531eSFabien Dessenne * @arg: args for @ops 255b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 256b6d0531eSFabien Dessenne * 257b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 258b6d0531eSFabien Dessenne */ 259026cee00SPawel Moll #define device_param_cb(name, ops, arg, perm) \ 260026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 6) 261026cee00SPawel Moll 262b6d0531eSFabien Dessenne /** 263b6d0531eSFabien Dessenne * late_param_cb - general callback for a module/cmdline parameter 264b6d0531eSFabien Dessenne * to be evaluated before late initcall level 265b6d0531eSFabien Dessenne * @name: a valid C identifier which is the parameter name. 266b6d0531eSFabien Dessenne * @ops: the set & get operations for this parameter. 267b6d0531eSFabien Dessenne * @arg: args for @ops 268b6d0531eSFabien Dessenne * @perm: visibility in sysfs. 269b6d0531eSFabien Dessenne * 270b6d0531eSFabien Dessenne * The ops can have NULL set or get functions. 271b6d0531eSFabien Dessenne */ 272026cee00SPawel Moll #define late_param_cb(name, ops, arg, perm) \ 273026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 7) 274546970bcSRusty Russell 27591d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into 27691d35dd9SIvan Kokshaysky read-only sections (which is part of respective UNIX ABI on these 27791d35dd9SIvan Kokshaysky platforms). So 'const' makes no sense and even causes compile failures 27891d35dd9SIvan Kokshaysky with some compilers. */ 27991d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64) 28091d35dd9SIvan Kokshaysky #define __moduleparam_const 28191d35dd9SIvan Kokshaysky #else 28291d35dd9SIvan Kokshaysky #define __moduleparam_const const 28391d35dd9SIvan Kokshaysky #endif 28491d35dd9SIvan Kokshaysky 2851da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module 286546970bcSRusty Russell parameters. */ 28791f9d330SJani Nikula #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \ 2889774a1f5SAlexey Dobriyan /* Default value instead of permissions? */ \ 28922e48eafSJan Beulich static const char __param_str_##name[] = prefix #name; \ 29091d35dd9SIvan Kokshaysky static struct kernel_param __moduleparam_const __param_##name \ 291fe2f4fe1SJohan Hovold __used __section("__param") \ 292fe2f4fe1SJohan Hovold __aligned(__alignof__(struct kernel_param)) \ 293b51d23e4SDan Streetman = { __param_str_##name, THIS_MODULE, ops, \ 294b51d23e4SDan Streetman VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } } 2951da177e4SLinus Torvalds 296*2c7ccb3cSKees Cook /* 297*2c7ccb3cSKees Cook * Useful for describing a set/get pair used only once (i.e. for this 298*2c7ccb3cSKees Cook * parameter). For repeated set/get pairs (i.e. the same struct 299*2c7ccb3cSKees Cook * kernel_param_ops), use module_param_cb() instead. 300*2c7ccb3cSKees Cook */ 301ece1996aSKees Cook #define module_param_call(name, _set, _get, arg, perm) \ 3029c27847dSLuis R. Rodriguez static const struct kernel_param_ops __param_ops_##name = \ 303ece1996aSKees Cook { .flags = 0, .set = _set, .get = _get }; \ 304fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, \ 305b2f270e8SKees Cook name, &__param_ops_##name, arg, perm, -1, 0) 3069bbb9e5aSRusty Russell 307907b29ebSRusty Russell #ifdef CONFIG_SYSFS 308b51d23e4SDan Streetman extern void kernel_param_lock(struct module *mod); 309b51d23e4SDan Streetman extern void kernel_param_unlock(struct module *mod); 310907b29ebSRusty Russell #else 311b51d23e4SDan Streetman static inline void kernel_param_lock(struct module *mod) 312907b29ebSRusty Russell { 313907b29ebSRusty Russell } 314b51d23e4SDan Streetman static inline void kernel_param_unlock(struct module *mod) 315907b29ebSRusty Russell { 316907b29ebSRusty Russell } 317907b29ebSRusty Russell #endif 318907b29ebSRusty Russell 31967e67ceaSRusty Russell #ifndef MODULE 32067e67ceaSRusty Russell /** 32167e67ceaSRusty Russell * core_param - define a historical core kernel parameter. 32267e67ceaSRusty Russell * @name: the name of the cmdline and sysfs parameter (often the same as var) 32367e67ceaSRusty Russell * @var: the variable 324546970bcSRusty Russell * @type: the type of the parameter 32567e67ceaSRusty Russell * @perm: visibility in sysfs 32667e67ceaSRusty Russell * 32767e67ceaSRusty Russell * core_param is just like module_param(), but cannot be modular and 32867e67ceaSRusty Russell * doesn't add a prefix (such as "printk."). This is for compatibility 32967e67ceaSRusty Russell * with __setup(), and it makes sense as truly core parameters aren't 33067e67ceaSRusty Russell * tied to the particular file they're in. 33167e67ceaSRusty Russell */ 33267e67ceaSRusty Russell #define core_param(name, var, type, perm) \ 33367e67ceaSRusty Russell param_check_##type(name, &(var)); \ 33491f9d330SJani Nikula __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0) 335ec0ccc16SDmitry Torokhov 336ec0ccc16SDmitry Torokhov /** 337ec0ccc16SDmitry Torokhov * core_param_unsafe - same as core_param but taints kernel 338b6d0531eSFabien Dessenne * @name: the name of the cmdline and sysfs parameter (often the same as var) 339b6d0531eSFabien Dessenne * @var: the variable 340b6d0531eSFabien Dessenne * @type: the type of the parameter 341b6d0531eSFabien Dessenne * @perm: visibility in sysfs 342ec0ccc16SDmitry Torokhov */ 343ec0ccc16SDmitry Torokhov #define core_param_unsafe(name, var, type, perm) \ 344ec0ccc16SDmitry Torokhov param_check_##type(name, &(var)); \ 345ec0ccc16SDmitry Torokhov __module_param_call("", name, ¶m_ops_##type, &var, perm, \ 346ec0ccc16SDmitry Torokhov -1, KERNEL_PARAM_FL_UNSAFE) 347ec0ccc16SDmitry Torokhov 34867e67ceaSRusty Russell #endif /* !MODULE */ 34967e67ceaSRusty Russell 350546970bcSRusty Russell /** 351546970bcSRusty Russell * module_param_string - a char array parameter 352546970bcSRusty Russell * @name: the name of the parameter 353546970bcSRusty Russell * @string: the string variable 354546970bcSRusty Russell * @len: the maximum length of the string, incl. terminator 355546970bcSRusty Russell * @perm: visibility in sysfs. 356546970bcSRusty Russell * 357546970bcSRusty Russell * This actually copies the string when it's set (unlike type charp). 358546970bcSRusty Russell * @len is usually just sizeof(string). 359546970bcSRusty Russell */ 3601da177e4SLinus Torvalds #define module_param_string(name, string, len, perm) \ 36122e48eafSJan Beulich static const struct kparam_string __param_string_##name \ 3621da177e4SLinus Torvalds = { len, string }; \ 363fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 3649bbb9e5aSRusty Russell ¶m_ops_string, \ 36591f9d330SJani Nikula .str = &__param_string_##name, perm, -1, 0);\ 3661da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "string") 3671da177e4SLinus Torvalds 368b1e4d20cSMichal Schmidt /** 369b1e4d20cSMichal Schmidt * parameq - checks if two parameter names match 370b1e4d20cSMichal Schmidt * @name1: parameter name 1 371b1e4d20cSMichal Schmidt * @name2: parameter name 2 372b1e4d20cSMichal Schmidt * 373b1e4d20cSMichal Schmidt * Returns true if the two parameter names are equal. 374b1e4d20cSMichal Schmidt * Dashes (-) are considered equal to underscores (_). 375b1e4d20cSMichal Schmidt */ 376b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2); 377b1e4d20cSMichal Schmidt 378b1e4d20cSMichal Schmidt /** 379b1e4d20cSMichal Schmidt * parameqn - checks if two parameter names match 380b1e4d20cSMichal Schmidt * @name1: parameter name 1 381b1e4d20cSMichal Schmidt * @name2: parameter name 2 382b1e4d20cSMichal Schmidt * @n: the length to compare 383b1e4d20cSMichal Schmidt * 384b1e4d20cSMichal Schmidt * Similar to parameq(), except it compares @n characters. 385b1e4d20cSMichal Schmidt */ 386b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n); 387b1e4d20cSMichal Schmidt 3881da177e4SLinus Torvalds /* Called on module insert or kernel boot */ 38951e158c1SRusty Russell extern char *parse_args(const char *name, 3901da177e4SLinus Torvalds char *args, 391914dcaa8SRusty Russell const struct kernel_param *params, 3921da177e4SLinus Torvalds unsigned num, 393026cee00SPawel Moll s16 level_min, 394026cee00SPawel Moll s16 level_max, 395ecc86170SLuis R. Rodriguez void *arg, 3969fb48c74SJim Cromie int (*unknown)(char *param, char *val, 397ecc86170SLuis R. Rodriguez const char *doing, void *arg)); 3981da177e4SLinus Torvalds 399e180a6b7SRusty Russell /* Called by module remove. */ 400e180a6b7SRusty Russell #ifdef CONFIG_SYSFS 401e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num); 402e180a6b7SRusty Russell #else 403e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params, 404e180a6b7SRusty Russell unsigned num) 405e180a6b7SRusty Russell { 406e180a6b7SRusty Russell } 407e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */ 408e180a6b7SRusty Russell 4091da177e4SLinus Torvalds /* All the helper functions */ 4101da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub 4111da177e4SLinus Torvalds Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ 4121da177e4SLinus Torvalds #define __param_check(name, p, type) \ 4130283f9a5SMark Charlebois static inline type __always_unused *__check_##name(void) { return(p); } 4141da177e4SLinus Torvalds 4159c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_byte; 4169bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp); 4179bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp); 4181da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char) 4191da177e4SLinus Torvalds 4209c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_short; 4219bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp); 4229bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp); 4231da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short) 4241da177e4SLinus Torvalds 4259c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ushort; 4269bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp); 4279bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp); 4281da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short) 4291da177e4SLinus Torvalds 4309c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_int; 4319bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp); 4329bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp); 4331da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int) 4341da177e4SLinus Torvalds 4359c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_uint; 4369bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp); 4379bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp); 4382a14c9aeSSagi Grimberg int param_set_uint_minmax(const char *val, const struct kernel_param *kp, 4392a14c9aeSSagi Grimberg unsigned int min, unsigned int max); 4401da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int) 4411da177e4SLinus Torvalds 4429c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_long; 4439bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp); 4449bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp); 4451da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long) 4461da177e4SLinus Torvalds 4479c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ulong; 4489bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp); 4499bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp); 4501da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long) 4511da177e4SLinus Torvalds 4529c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ullong; 453b4210b81SHannes Reinecke extern int param_set_ullong(const char *val, const struct kernel_param *kp); 454b4210b81SHannes Reinecke extern int param_get_ullong(char *buffer, const struct kernel_param *kp); 455b4210b81SHannes Reinecke #define param_check_ullong(name, p) __param_check(name, p, unsigned long long) 456b4210b81SHannes Reinecke 4577d836577SPaul Menzel extern const struct kernel_param_ops param_ops_hexint; 4587d836577SPaul Menzel extern int param_set_hexint(const char *val, const struct kernel_param *kp); 4597d836577SPaul Menzel extern int param_get_hexint(char *buffer, const struct kernel_param *kp); 4607d836577SPaul Menzel #define param_check_hexint(name, p) param_check_uint(name, p) 4617d836577SPaul Menzel 4629c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_charp; 4639bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp); 4649bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp); 4653d9c637fSDan Streetman extern void param_free_charp(void *arg); 4661da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *) 4671da177e4SLinus Torvalds 46872db395fSRusty Russell /* We used to allow int as well as bool. We're taking that away! */ 4699c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bool; 4709bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp); 4719bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp); 47272db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool) 4731da177e4SLinus Torvalds 474d19f05d8SLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bool_enable_only; 475d19f05d8SLuis R. Rodriguez extern int param_set_bool_enable_only(const char *val, 476d19f05d8SLuis R. Rodriguez const struct kernel_param *kp); 477d19f05d8SLuis R. Rodriguez /* getter is the same as for the regular bool */ 478d19f05d8SLuis R. Rodriguez #define param_check_bool_enable_only param_check_bool 479d19f05d8SLuis R. Rodriguez 4809c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_invbool; 4819bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp); 4829bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp); 4839a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool) 4841da177e4SLinus Torvalds 48569116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */ 4869c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bint; 48769116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp); 48869116f27SRusty Russell #define param_get_bint param_get_int 48969116f27SRusty Russell #define param_check_bint param_check_int 49069116f27SRusty Russell 491546970bcSRusty Russell /** 492546970bcSRusty Russell * module_param_array - a parameter which is an array of some type 493546970bcSRusty Russell * @name: the name of the array variable 494546970bcSRusty Russell * @type: the type, as per module_param() 495546970bcSRusty Russell * @nump: optional pointer filled in with the number written 496546970bcSRusty Russell * @perm: visibility in sysfs 497546970bcSRusty Russell * 498546970bcSRusty Russell * Input and output are as comma-separated values. Commas inside values 499546970bcSRusty Russell * don't work properly (eg. an array of charp). 500546970bcSRusty Russell * 501546970bcSRusty Russell * ARRAY_SIZE(@name) is used to determine the number of elements in the 502546970bcSRusty Russell * array, so the definition must be visible. 503546970bcSRusty Russell */ 504546970bcSRusty Russell #define module_param_array(name, type, nump, perm) \ 505546970bcSRusty Russell module_param_array_named(name, name, type, nump, perm) 506546970bcSRusty Russell 507546970bcSRusty Russell /** 508546970bcSRusty Russell * module_param_array_named - renamed parameter which is an array of some type 509546970bcSRusty Russell * @name: a valid C identifier which is the parameter name 510546970bcSRusty Russell * @array: the name of the array variable 511546970bcSRusty Russell * @type: the type, as per module_param() 512546970bcSRusty Russell * @nump: optional pointer filled in with the number written 513546970bcSRusty Russell * @perm: visibility in sysfs 514546970bcSRusty Russell * 515546970bcSRusty Russell * This exposes a different name than the actual variable name. See 516546970bcSRusty Russell * module_param_named() for why this might be necessary. 517546970bcSRusty Russell */ 5181da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm) \ 519bafeafeaSRusty Russell param_check_##type(name, &(array)[0]); \ 52022e48eafSJan Beulich static const struct kparam_array __param_arr_##name \ 521c5be0b2eSRichard Kennedy = { .max = ARRAY_SIZE(array), .num = nump, \ 522c5be0b2eSRichard Kennedy .ops = ¶m_ops_##type, \ 523c5be0b2eSRichard Kennedy .elemsize = sizeof(array[0]), .elem = array }; \ 524fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 5259bbb9e5aSRusty Russell ¶m_array_ops, \ 526fddd5201SRusty Russell .arr = &__param_arr_##name, \ 52791f9d330SJani Nikula perm, -1, 0); \ 5281da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "array of " #type) 5291da177e4SLinus Torvalds 530bf616d21SDavid Howells enum hwparam_type { 531bf616d21SDavid Howells hwparam_ioport, /* Module parameter configures an I/O port */ 532bf616d21SDavid Howells hwparam_iomem, /* Module parameter configures an I/O mem address */ 533bf616d21SDavid Howells hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */ 534401e000aSSylvain 'ythier' Hitier hwparam_irq, /* Module parameter configures an IRQ */ 535bf616d21SDavid Howells hwparam_dma, /* Module parameter configures a DMA channel */ 536bf616d21SDavid Howells hwparam_dma_addr, /* Module parameter configures a DMA buffer address */ 537bf616d21SDavid Howells hwparam_other, /* Module parameter configures some other value */ 538bf616d21SDavid Howells }; 539bf616d21SDavid Howells 540bf616d21SDavid Howells /** 541bf616d21SDavid Howells * module_param_hw_named - A parameter representing a hw parameters 542bf616d21SDavid Howells * @name: a valid C identifier which is the parameter name. 543bf616d21SDavid Howells * @value: the actual lvalue to alter. 544bf616d21SDavid Howells * @type: the type of the parameter 545bf616d21SDavid Howells * @hwtype: what the value represents (enum hwparam_type) 546bf616d21SDavid Howells * @perm: visibility in sysfs. 547bf616d21SDavid Howells * 548bf616d21SDavid Howells * Usually it's a good idea to have variable names and user-exposed names the 549bf616d21SDavid Howells * same, but that's harder if the variable must be non-static or is inside a 550bf616d21SDavid Howells * structure. This allows exposure under a different name. 551bf616d21SDavid Howells */ 552bf616d21SDavid Howells #define module_param_hw_named(name, value, type, hwtype, perm) \ 553bf616d21SDavid Howells param_check_##type(name, &(value)); \ 554bf616d21SDavid Howells __module_param_call(MODULE_PARAM_PREFIX, name, \ 555bf616d21SDavid Howells ¶m_ops_##type, &value, \ 556bf616d21SDavid Howells perm, -1, \ 557bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ 558bf616d21SDavid Howells __MODULE_PARM_TYPE(name, #type) 559bf616d21SDavid Howells 560bf616d21SDavid Howells #define module_param_hw(name, type, hwtype, perm) \ 561bf616d21SDavid Howells module_param_hw_named(name, name, type, hwtype, perm) 562bf616d21SDavid Howells 563bf616d21SDavid Howells /** 564bf616d21SDavid Howells * module_param_hw_array - A parameter representing an array of hw parameters 565bf616d21SDavid Howells * @name: the name of the array variable 566bf616d21SDavid Howells * @type: the type, as per module_param() 567bf616d21SDavid Howells * @hwtype: what the value represents (enum hwparam_type) 568bf616d21SDavid Howells * @nump: optional pointer filled in with the number written 569bf616d21SDavid Howells * @perm: visibility in sysfs 570bf616d21SDavid Howells * 571bf616d21SDavid Howells * Input and output are as comma-separated values. Commas inside values 572bf616d21SDavid Howells * don't work properly (eg. an array of charp). 573bf616d21SDavid Howells * 574bf616d21SDavid Howells * ARRAY_SIZE(@name) is used to determine the number of elements in the 575bf616d21SDavid Howells * array, so the definition must be visible. 576bf616d21SDavid Howells */ 577bf616d21SDavid Howells #define module_param_hw_array(name, type, hwtype, nump, perm) \ 578bf616d21SDavid Howells param_check_##type(name, &(name)[0]); \ 579bf616d21SDavid Howells static const struct kparam_array __param_arr_##name \ 580bf616d21SDavid Howells = { .max = ARRAY_SIZE(name), .num = nump, \ 581bf616d21SDavid Howells .ops = ¶m_ops_##type, \ 582bf616d21SDavid Howells .elemsize = sizeof(name[0]), .elem = name }; \ 583bf616d21SDavid Howells __module_param_call(MODULE_PARAM_PREFIX, name, \ 584bf616d21SDavid Howells ¶m_array_ops, \ 585bf616d21SDavid Howells .arr = &__param_arr_##name, \ 586bf616d21SDavid Howells perm, -1, \ 587bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ 588bf616d21SDavid Howells __MODULE_PARM_TYPE(name, "array of " #type) 589bf616d21SDavid Howells 590bf616d21SDavid Howells 5919c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_array_ops; 5921da177e4SLinus Torvalds 5939c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_string; 5949bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *); 5959bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp); 5961da177e4SLinus Torvalds 597b634d130SJean Delvare /* for exporting parameters in /sys/module/.../parameters */ 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds struct module; 6001da177e4SLinus Torvalds 601ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 6021da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod, 6039bbb9e5aSRusty Russell const struct kernel_param *kparam, 6041da177e4SLinus Torvalds unsigned int num_params); 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod); 607ef665c1aSRandy Dunlap #else 608ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod, 6099bbb9e5aSRusty Russell const struct kernel_param *kparam, 610ef665c1aSRandy Dunlap unsigned int num_params) 611ef665c1aSRandy Dunlap { 612ef665c1aSRandy Dunlap return 0; 613ef665c1aSRandy Dunlap } 614ef665c1aSRandy Dunlap 615ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod) 616ef665c1aSRandy Dunlap { } 617ef665c1aSRandy Dunlap #endif 6181da177e4SLinus Torvalds 6191da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */ 620