11da177e4SLinus Torvalds #ifndef _LINUX_MODULE_PARAMS_H 21da177e4SLinus Torvalds #define _LINUX_MODULE_PARAMS_H 31da177e4SLinus Torvalds /* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */ 41da177e4SLinus Torvalds #include <linux/init.h> 51da177e4SLinus Torvalds #include <linux/stringify.h> 61da177e4SLinus Torvalds #include <linux/kernel.h> 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds /* You can override this manually, but generally this should match the 91da177e4SLinus Torvalds module name. */ 101da177e4SLinus Torvalds #ifdef MODULE 111da177e4SLinus Torvalds #define MODULE_PARAM_PREFIX /* empty */ 121da177e4SLinus Torvalds #else 13367cb704SSam Ravnborg #define MODULE_PARAM_PREFIX KBUILD_MODNAME "." 141da177e4SLinus Torvalds #endif 151da177e4SLinus Torvalds 16730b69d2SRusty Russell /* Chosen so that structs with an unsigned long line up. */ 17730b69d2SRusty Russell #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) 18730b69d2SRusty Russell 19b75be420SLinus Walleij #ifdef MODULE 201da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info) \ 2134182eeaSRusty Russell static const char __UNIQUE_ID(name)[] \ 22b6472776SJan Beulich __used __attribute__((section(".modinfo"), unused, aligned(1))) \ 23b6472776SJan Beulich = __stringify(tag) "=" info 241da177e4SLinus Torvalds #else /* !MODULE */ 25b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */ 26b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info) \ 2734182eeaSRusty Russell struct __UNIQUE_ID(name) {} 281da177e4SLinus Torvalds #endif 291da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type) \ 301da177e4SLinus Torvalds __MODULE_INFO(parmtype, name##type, #name ":" _type) 311da177e4SLinus Torvalds 32639938ebSPaul Gortmaker /* One for each parameter, describing how to use it. Some files do 33639938ebSPaul Gortmaker multiple of these per line, so can't just use MODULE_INFO. */ 34639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \ 35639938ebSPaul Gortmaker __MODULE_INFO(parm, _parm, #_parm ":" desc) 36639938ebSPaul Gortmaker 371da177e4SLinus Torvalds struct kernel_param; 381da177e4SLinus Torvalds 39ab013c5fSSteven Rostedt /* 40ab013c5fSSteven Rostedt * Flags available for kernel_param_ops 41ab013c5fSSteven Rostedt * 42ab013c5fSSteven Rostedt * NOARG - the parameter allows for no argument (foo instead of foo=1) 43ab013c5fSSteven Rostedt */ 44ab013c5fSSteven Rostedt enum { 456a4c2643SJani Nikula KERNEL_PARAM_OPS_FL_NOARG = (1 << 0) 46ab013c5fSSteven Rostedt }; 47ab013c5fSSteven Rostedt 489bbb9e5aSRusty Russell struct kernel_param_ops { 49ab013c5fSSteven Rostedt /* How the ops should behave */ 50ab013c5fSSteven Rostedt unsigned int flags; 511da177e4SLinus Torvalds /* Returns 0, or -errno. arg is in kp->arg. */ 529bbb9e5aSRusty Russell int (*set)(const char *val, const struct kernel_param *kp); 531da177e4SLinus Torvalds /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 549bbb9e5aSRusty Russell int (*get)(char *buffer, const struct kernel_param *kp); 55e6df34a4SRusty Russell /* Optional function to free kp->arg when module unloaded. */ 56e6df34a4SRusty Russell void (*free)(void *arg); 579bbb9e5aSRusty Russell }; 581da177e4SLinus Torvalds 5991f9d330SJani Nikula /* 6091f9d330SJani Nikula * Flags available for kernel_param 6191f9d330SJani Nikula * 6291f9d330SJani Nikula * UNSAFE - the parameter is dangerous and setting it will taint the kernel 63bf616d21SDavid Howells * HWPARAM - Hardware param not permitted in lockdown mode 6491f9d330SJani Nikula */ 6591f9d330SJani Nikula enum { 66bf616d21SDavid Howells KERNEL_PARAM_FL_UNSAFE = (1 << 0), 67bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM = (1 << 1), 6891f9d330SJani Nikula }; 6991f9d330SJani Nikula 701da177e4SLinus Torvalds struct kernel_param { 711da177e4SLinus Torvalds const char *name; 72b51d23e4SDan Streetman struct module *mod; 739bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 745104b7d7SDan Streetman const u16 perm; 7591f9d330SJani Nikula s8 level; 7691f9d330SJani Nikula u8 flags; 7722e48eafSJan Beulich union { 781da177e4SLinus Torvalds void *arg; 7922e48eafSJan Beulich const struct kparam_string *str; 8022e48eafSJan Beulich const struct kparam_array *arr; 8122e48eafSJan Beulich }; 821da177e4SLinus Torvalds }; 831da177e4SLinus Torvalds 8463a12d9dSGeert Uytterhoeven extern const struct kernel_param __start___param[], __stop___param[]; 8563a12d9dSGeert Uytterhoeven 861da177e4SLinus Torvalds /* Special one for strings we want to copy into */ 871da177e4SLinus Torvalds struct kparam_string { 881da177e4SLinus Torvalds unsigned int maxlen; 891da177e4SLinus Torvalds char *string; 901da177e4SLinus Torvalds }; 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds /* Special one for arrays */ 931da177e4SLinus Torvalds struct kparam_array 941da177e4SLinus Torvalds { 951da177e4SLinus Torvalds unsigned int max; 96c5be0b2eSRichard Kennedy unsigned int elemsize; 971da177e4SLinus Torvalds unsigned int *num; 989bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 991da177e4SLinus Torvalds void *elem; 1001da177e4SLinus Torvalds }; 1011da177e4SLinus Torvalds 102546970bcSRusty Russell /** 103546970bcSRusty Russell * module_param - typesafe helper for a module/cmdline parameter 104546970bcSRusty Russell * @value: the variable to alter, and exposed parameter name. 105546970bcSRusty Russell * @type: the type of the parameter 106546970bcSRusty Russell * @perm: visibility in sysfs. 107546970bcSRusty Russell * 108546970bcSRusty Russell * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a 109546970bcSRusty Russell * ".") the kernel commandline parameter. Note that - is changed to _, so 110546970bcSRusty Russell * the user can use "foo-bar=1" even for variable "foo_bar". 111546970bcSRusty Russell * 112546970bcSRusty Russell * @perm is 0 if the the variable is not to appear in sysfs, or 0444 113546970bcSRusty Russell * for world-readable, 0644 for root-writable, etc. Note that if it 114b51d23e4SDan Streetman * is writable, you may need to use kernel_param_lock() around 115546970bcSRusty Russell * accesses (esp. charp, which can be kfreed when it changes). 116546970bcSRusty Russell * 117546970bcSRusty Russell * The @type is simply pasted to refer to a param_ops_##type and a 118546970bcSRusty Russell * param_check_##type: for convenience many standard types are provided but 119546970bcSRusty Russell * you can create your own by defining those variables. 120546970bcSRusty Russell * 121546970bcSRusty Russell * Standard types are: 122546970bcSRusty Russell * byte, short, ushort, int, uint, long, ulong 123546970bcSRusty Russell * charp: a character pointer 124546970bcSRusty Russell * bool: a bool, values 0/1, y/n, Y/N. 125546970bcSRusty Russell * invbool: the above, only sense-reversed (N = true). 126546970bcSRusty Russell */ 127546970bcSRusty Russell #define module_param(name, type, perm) \ 128546970bcSRusty Russell module_param_named(name, name, type, perm) 129546970bcSRusty Russell 130546970bcSRusty Russell /** 1313baee201SJani Nikula * module_param_unsafe - same as module_param but taints kernel 1323baee201SJani Nikula */ 1333baee201SJani Nikula #define module_param_unsafe(name, type, perm) \ 1343baee201SJani Nikula module_param_named_unsafe(name, name, type, perm) 1353baee201SJani Nikula 1363baee201SJani Nikula /** 137546970bcSRusty Russell * module_param_named - typesafe helper for a renamed module/cmdline parameter 138546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 139546970bcSRusty Russell * @value: the actual lvalue to alter. 140546970bcSRusty Russell * @type: the type of the parameter 141546970bcSRusty Russell * @perm: visibility in sysfs. 142546970bcSRusty Russell * 143546970bcSRusty Russell * Usually it's a good idea to have variable names and user-exposed names the 144546970bcSRusty Russell * same, but that's harder if the variable must be non-static or is inside a 145546970bcSRusty Russell * structure. This allows exposure under a different name. 146546970bcSRusty Russell */ 147546970bcSRusty Russell #define module_param_named(name, value, type, perm) \ 148546970bcSRusty Russell param_check_##type(name, &(value)); \ 149546970bcSRusty Russell module_param_cb(name, ¶m_ops_##type, &value, perm); \ 150546970bcSRusty Russell __MODULE_PARM_TYPE(name, #type) 151546970bcSRusty Russell 152546970bcSRusty Russell /** 1533baee201SJani Nikula * module_param_named_unsafe - same as module_param_named but taints kernel 1543baee201SJani Nikula */ 1553baee201SJani Nikula #define module_param_named_unsafe(name, value, type, perm) \ 1563baee201SJani Nikula param_check_##type(name, &(value)); \ 1573baee201SJani Nikula module_param_cb_unsafe(name, ¶m_ops_##type, &value, perm); \ 1583baee201SJani Nikula __MODULE_PARM_TYPE(name, #type) 1593baee201SJani Nikula 1603baee201SJani Nikula /** 161546970bcSRusty Russell * module_param_cb - general callback for a module/cmdline parameter 162546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 163546970bcSRusty Russell * @ops: the set & get operations for this parameter. 164546970bcSRusty Russell * @perm: visibility in sysfs. 165546970bcSRusty Russell * 166546970bcSRusty Russell * The ops can have NULL set or get functions. 167546970bcSRusty Russell */ 168546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm) \ 16991f9d330SJani Nikula __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0) 170026cee00SPawel Moll 1713baee201SJani Nikula #define module_param_cb_unsafe(name, ops, arg, perm) \ 1723baee201SJani Nikula __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \ 1733baee201SJani Nikula KERNEL_PARAM_FL_UNSAFE) 1743baee201SJani Nikula 175026cee00SPawel Moll /** 176026cee00SPawel Moll * <level>_param_cb - general callback for a module/cmdline parameter 177026cee00SPawel Moll * to be evaluated before certain initcall level 178026cee00SPawel Moll * @name: a valid C identifier which is the parameter name. 179026cee00SPawel Moll * @ops: the set & get operations for this parameter. 180026cee00SPawel Moll * @perm: visibility in sysfs. 181026cee00SPawel Moll * 182026cee00SPawel Moll * The ops can have NULL set or get functions. 183026cee00SPawel Moll */ 184026cee00SPawel Moll #define __level_param_cb(name, ops, arg, perm, level) \ 18591f9d330SJani Nikula __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) 186026cee00SPawel Moll 187026cee00SPawel Moll #define core_param_cb(name, ops, arg, perm) \ 188026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 1) 189026cee00SPawel Moll 190026cee00SPawel Moll #define postcore_param_cb(name, ops, arg, perm) \ 191026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 2) 192026cee00SPawel Moll 193026cee00SPawel Moll #define arch_param_cb(name, ops, arg, perm) \ 194026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 3) 195026cee00SPawel Moll 196026cee00SPawel Moll #define subsys_param_cb(name, ops, arg, perm) \ 197026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 4) 198026cee00SPawel Moll 199026cee00SPawel Moll #define fs_param_cb(name, ops, arg, perm) \ 200026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 5) 201026cee00SPawel Moll 202026cee00SPawel Moll #define device_param_cb(name, ops, arg, perm) \ 203026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 6) 204026cee00SPawel Moll 205026cee00SPawel Moll #define late_param_cb(name, ops, arg, perm) \ 206026cee00SPawel Moll __level_param_cb(name, ops, arg, perm, 7) 207546970bcSRusty Russell 20891d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into 20991d35dd9SIvan Kokshaysky read-only sections (which is part of respective UNIX ABI on these 21091d35dd9SIvan Kokshaysky platforms). So 'const' makes no sense and even causes compile failures 21191d35dd9SIvan Kokshaysky with some compilers. */ 21291d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64) 21391d35dd9SIvan Kokshaysky #define __moduleparam_const 21491d35dd9SIvan Kokshaysky #else 21591d35dd9SIvan Kokshaysky #define __moduleparam_const const 21691d35dd9SIvan Kokshaysky #endif 21791d35dd9SIvan Kokshaysky 2181da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module 219546970bcSRusty Russell parameters. */ 22091f9d330SJani Nikula #define __module_param_call(prefix, name, ops, arg, perm, level, flags) \ 2219774a1f5SAlexey Dobriyan /* Default value instead of permissions? */ \ 22222e48eafSJan Beulich static const char __param_str_##name[] = prefix #name; \ 22391d35dd9SIvan Kokshaysky static struct kernel_param __moduleparam_const __param_##name \ 2243ff6eeccSAdrian Bunk __used \ 2251da177e4SLinus Torvalds __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ 226b51d23e4SDan Streetman = { __param_str_##name, THIS_MODULE, ops, \ 227b51d23e4SDan Streetman VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } } 2281da177e4SLinus Torvalds 2299bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */ 2301da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm) \ 2319c27847dSLuis R. Rodriguez static const struct kernel_param_ops __param_ops_##name = \ 232184c3fc3SMark Rustad { .flags = 0, (void *)set, (void *)get }; \ 233fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, \ 2349bbb9e5aSRusty Russell name, &__param_ops_##name, arg, \ 23591f9d330SJani Nikula (perm) + sizeof(__check_old_set_param(set))*0, -1, 0) 2361da177e4SLinus Torvalds 2379bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */ 2389bbb9e5aSRusty Russell static inline int 2399bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *)) 2409bbb9e5aSRusty Russell { 2419bbb9e5aSRusty Russell return 0; 2429bbb9e5aSRusty Russell } 2439bbb9e5aSRusty Russell 244907b29ebSRusty Russell #ifdef CONFIG_SYSFS 245b51d23e4SDan Streetman extern void kernel_param_lock(struct module *mod); 246b51d23e4SDan Streetman extern void kernel_param_unlock(struct module *mod); 247907b29ebSRusty Russell #else 248b51d23e4SDan Streetman static inline void kernel_param_lock(struct module *mod) 249907b29ebSRusty Russell { 250907b29ebSRusty Russell } 251b51d23e4SDan Streetman static inline void kernel_param_unlock(struct module *mod) 252907b29ebSRusty Russell { 253907b29ebSRusty Russell } 254907b29ebSRusty Russell #endif 255907b29ebSRusty Russell 25667e67ceaSRusty Russell #ifndef MODULE 25767e67ceaSRusty Russell /** 25867e67ceaSRusty Russell * core_param - define a historical core kernel parameter. 25967e67ceaSRusty Russell * @name: the name of the cmdline and sysfs parameter (often the same as var) 26067e67ceaSRusty Russell * @var: the variable 261546970bcSRusty Russell * @type: the type of the parameter 26267e67ceaSRusty Russell * @perm: visibility in sysfs 26367e67ceaSRusty Russell * 26467e67ceaSRusty Russell * core_param is just like module_param(), but cannot be modular and 26567e67ceaSRusty Russell * doesn't add a prefix (such as "printk."). This is for compatibility 26667e67ceaSRusty Russell * with __setup(), and it makes sense as truly core parameters aren't 26767e67ceaSRusty Russell * tied to the particular file they're in. 26867e67ceaSRusty Russell */ 26967e67ceaSRusty Russell #define core_param(name, var, type, perm) \ 27067e67ceaSRusty Russell param_check_##type(name, &(var)); \ 27191f9d330SJani Nikula __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0) 272ec0ccc16SDmitry Torokhov 273ec0ccc16SDmitry Torokhov /** 274ec0ccc16SDmitry Torokhov * core_param_unsafe - same as core_param but taints kernel 275ec0ccc16SDmitry Torokhov */ 276ec0ccc16SDmitry Torokhov #define core_param_unsafe(name, var, type, perm) \ 277ec0ccc16SDmitry Torokhov param_check_##type(name, &(var)); \ 278ec0ccc16SDmitry Torokhov __module_param_call("", name, ¶m_ops_##type, &var, perm, \ 279ec0ccc16SDmitry Torokhov -1, KERNEL_PARAM_FL_UNSAFE) 280ec0ccc16SDmitry Torokhov 28167e67ceaSRusty Russell #endif /* !MODULE */ 28267e67ceaSRusty Russell 283546970bcSRusty Russell /** 284546970bcSRusty Russell * module_param_string - a char array parameter 285546970bcSRusty Russell * @name: the name of the parameter 286546970bcSRusty Russell * @string: the string variable 287546970bcSRusty Russell * @len: the maximum length of the string, incl. terminator 288546970bcSRusty Russell * @perm: visibility in sysfs. 289546970bcSRusty Russell * 290546970bcSRusty Russell * This actually copies the string when it's set (unlike type charp). 291546970bcSRusty Russell * @len is usually just sizeof(string). 292546970bcSRusty Russell */ 2931da177e4SLinus Torvalds #define module_param_string(name, string, len, perm) \ 29422e48eafSJan Beulich static const struct kparam_string __param_string_##name \ 2951da177e4SLinus Torvalds = { len, string }; \ 296fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 2979bbb9e5aSRusty Russell ¶m_ops_string, \ 29891f9d330SJani Nikula .str = &__param_string_##name, perm, -1, 0);\ 2991da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "string") 3001da177e4SLinus Torvalds 301b1e4d20cSMichal Schmidt /** 302b1e4d20cSMichal Schmidt * parameq - checks if two parameter names match 303b1e4d20cSMichal Schmidt * @name1: parameter name 1 304b1e4d20cSMichal Schmidt * @name2: parameter name 2 305b1e4d20cSMichal Schmidt * 306b1e4d20cSMichal Schmidt * Returns true if the two parameter names are equal. 307b1e4d20cSMichal Schmidt * Dashes (-) are considered equal to underscores (_). 308b1e4d20cSMichal Schmidt */ 309b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2); 310b1e4d20cSMichal Schmidt 311b1e4d20cSMichal Schmidt /** 312b1e4d20cSMichal Schmidt * parameqn - checks if two parameter names match 313b1e4d20cSMichal Schmidt * @name1: parameter name 1 314b1e4d20cSMichal Schmidt * @name2: parameter name 2 315b1e4d20cSMichal Schmidt * @n: the length to compare 316b1e4d20cSMichal Schmidt * 317b1e4d20cSMichal Schmidt * Similar to parameq(), except it compares @n characters. 318b1e4d20cSMichal Schmidt */ 319b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n); 320b1e4d20cSMichal Schmidt 3211da177e4SLinus Torvalds /* Called on module insert or kernel boot */ 32251e158c1SRusty Russell extern char *parse_args(const char *name, 3231da177e4SLinus Torvalds char *args, 324914dcaa8SRusty Russell const struct kernel_param *params, 3251da177e4SLinus Torvalds unsigned num, 326026cee00SPawel Moll s16 level_min, 327026cee00SPawel Moll s16 level_max, 328ecc86170SLuis R. Rodriguez void *arg, 3299fb48c74SJim Cromie int (*unknown)(char *param, char *val, 330ecc86170SLuis R. Rodriguez const char *doing, void *arg)); 3311da177e4SLinus Torvalds 332e180a6b7SRusty Russell /* Called by module remove. */ 333e180a6b7SRusty Russell #ifdef CONFIG_SYSFS 334e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num); 335e180a6b7SRusty Russell #else 336e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params, 337e180a6b7SRusty Russell unsigned num) 338e180a6b7SRusty Russell { 339e180a6b7SRusty Russell } 340e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */ 341e180a6b7SRusty Russell 3421da177e4SLinus Torvalds /* All the helper functions */ 3431da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub 3441da177e4SLinus Torvalds Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ 3451da177e4SLinus Torvalds #define __param_check(name, p, type) \ 3460283f9a5SMark Charlebois static inline type __always_unused *__check_##name(void) { return(p); } 3471da177e4SLinus Torvalds 3489c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_byte; 3499bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp); 3509bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp); 3511da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char) 3521da177e4SLinus Torvalds 3539c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_short; 3549bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp); 3559bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp); 3561da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short) 3571da177e4SLinus Torvalds 3589c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ushort; 3599bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp); 3609bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp); 3611da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short) 3621da177e4SLinus Torvalds 3639c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_int; 3649bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp); 3659bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp); 3661da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int) 3671da177e4SLinus Torvalds 3689c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_uint; 3699bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp); 3709bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp); 3711da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int) 3721da177e4SLinus Torvalds 3739c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_long; 3749bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp); 3759bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp); 3761da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long) 3771da177e4SLinus Torvalds 3789c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ulong; 3799bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp); 3809bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp); 3811da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long) 3821da177e4SLinus Torvalds 3839c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_ullong; 384b4210b81SHannes Reinecke extern int param_set_ullong(const char *val, const struct kernel_param *kp); 385b4210b81SHannes Reinecke extern int param_get_ullong(char *buffer, const struct kernel_param *kp); 386b4210b81SHannes Reinecke #define param_check_ullong(name, p) __param_check(name, p, unsigned long long) 387b4210b81SHannes Reinecke 3889c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_charp; 3899bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp); 3909bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp); 3913d9c637fSDan Streetman extern void param_free_charp(void *arg); 3921da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *) 3931da177e4SLinus Torvalds 39472db395fSRusty Russell /* We used to allow int as well as bool. We're taking that away! */ 3959c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bool; 3969bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp); 3979bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp); 39872db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool) 3991da177e4SLinus Torvalds 400d19f05d8SLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bool_enable_only; 401d19f05d8SLuis R. Rodriguez extern int param_set_bool_enable_only(const char *val, 402d19f05d8SLuis R. Rodriguez const struct kernel_param *kp); 403d19f05d8SLuis R. Rodriguez /* getter is the same as for the regular bool */ 404d19f05d8SLuis R. Rodriguez #define param_check_bool_enable_only param_check_bool 405d19f05d8SLuis R. Rodriguez 4069c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_invbool; 4079bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp); 4089bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp); 4099a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool) 4101da177e4SLinus Torvalds 41169116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */ 4129c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_bint; 41369116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp); 41469116f27SRusty Russell #define param_get_bint param_get_int 41569116f27SRusty Russell #define param_check_bint param_check_int 41669116f27SRusty Russell 417546970bcSRusty Russell /** 418546970bcSRusty Russell * module_param_array - a parameter which is an array of some type 419546970bcSRusty Russell * @name: the name of the array variable 420546970bcSRusty Russell * @type: the type, as per module_param() 421546970bcSRusty Russell * @nump: optional pointer filled in with the number written 422546970bcSRusty Russell * @perm: visibility in sysfs 423546970bcSRusty Russell * 424546970bcSRusty Russell * Input and output are as comma-separated values. Commas inside values 425546970bcSRusty Russell * don't work properly (eg. an array of charp). 426546970bcSRusty Russell * 427546970bcSRusty Russell * ARRAY_SIZE(@name) is used to determine the number of elements in the 428546970bcSRusty Russell * array, so the definition must be visible. 429546970bcSRusty Russell */ 430546970bcSRusty Russell #define module_param_array(name, type, nump, perm) \ 431546970bcSRusty Russell module_param_array_named(name, name, type, nump, perm) 432546970bcSRusty Russell 433546970bcSRusty Russell /** 434546970bcSRusty Russell * module_param_array_named - renamed parameter which is an array of some type 435546970bcSRusty Russell * @name: a valid C identifier which is the parameter name 436546970bcSRusty Russell * @array: the name of the array variable 437546970bcSRusty Russell * @type: the type, as per module_param() 438546970bcSRusty Russell * @nump: optional pointer filled in with the number written 439546970bcSRusty Russell * @perm: visibility in sysfs 440546970bcSRusty Russell * 441546970bcSRusty Russell * This exposes a different name than the actual variable name. See 442546970bcSRusty Russell * module_param_named() for why this might be necessary. 443546970bcSRusty Russell */ 4441da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm) \ 445bafeafeaSRusty Russell param_check_##type(name, &(array)[0]); \ 44622e48eafSJan Beulich static const struct kparam_array __param_arr_##name \ 447c5be0b2eSRichard Kennedy = { .max = ARRAY_SIZE(array), .num = nump, \ 448c5be0b2eSRichard Kennedy .ops = ¶m_ops_##type, \ 449c5be0b2eSRichard Kennedy .elemsize = sizeof(array[0]), .elem = array }; \ 450fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 4519bbb9e5aSRusty Russell ¶m_array_ops, \ 452fddd5201SRusty Russell .arr = &__param_arr_##name, \ 45391f9d330SJani Nikula perm, -1, 0); \ 4541da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "array of " #type) 4551da177e4SLinus Torvalds 456bf616d21SDavid Howells enum hwparam_type { 457bf616d21SDavid Howells hwparam_ioport, /* Module parameter configures an I/O port */ 458bf616d21SDavid Howells hwparam_iomem, /* Module parameter configures an I/O mem address */ 459bf616d21SDavid Howells hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */ 460*401e000aSSylvain 'ythier' Hitier hwparam_irq, /* Module parameter configures an IRQ */ 461bf616d21SDavid Howells hwparam_dma, /* Module parameter configures a DMA channel */ 462bf616d21SDavid Howells hwparam_dma_addr, /* Module parameter configures a DMA buffer address */ 463bf616d21SDavid Howells hwparam_other, /* Module parameter configures some other value */ 464bf616d21SDavid Howells }; 465bf616d21SDavid Howells 466bf616d21SDavid Howells /** 467bf616d21SDavid Howells * module_param_hw_named - A parameter representing a hw parameters 468bf616d21SDavid Howells * @name: a valid C identifier which is the parameter name. 469bf616d21SDavid Howells * @value: the actual lvalue to alter. 470bf616d21SDavid Howells * @type: the type of the parameter 471bf616d21SDavid Howells * @hwtype: what the value represents (enum hwparam_type) 472bf616d21SDavid Howells * @perm: visibility in sysfs. 473bf616d21SDavid Howells * 474bf616d21SDavid Howells * Usually it's a good idea to have variable names and user-exposed names the 475bf616d21SDavid Howells * same, but that's harder if the variable must be non-static or is inside a 476bf616d21SDavid Howells * structure. This allows exposure under a different name. 477bf616d21SDavid Howells */ 478bf616d21SDavid Howells #define module_param_hw_named(name, value, type, hwtype, perm) \ 479bf616d21SDavid Howells param_check_##type(name, &(value)); \ 480bf616d21SDavid Howells __module_param_call(MODULE_PARAM_PREFIX, name, \ 481bf616d21SDavid Howells ¶m_ops_##type, &value, \ 482bf616d21SDavid Howells perm, -1, \ 483bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ 484bf616d21SDavid Howells __MODULE_PARM_TYPE(name, #type) 485bf616d21SDavid Howells 486bf616d21SDavid Howells #define module_param_hw(name, type, hwtype, perm) \ 487bf616d21SDavid Howells module_param_hw_named(name, name, type, hwtype, perm) 488bf616d21SDavid Howells 489bf616d21SDavid Howells /** 490bf616d21SDavid Howells * module_param_hw_array - A parameter representing an array of hw parameters 491bf616d21SDavid Howells * @name: the name of the array variable 492bf616d21SDavid Howells * @type: the type, as per module_param() 493bf616d21SDavid Howells * @hwtype: what the value represents (enum hwparam_type) 494bf616d21SDavid Howells * @nump: optional pointer filled in with the number written 495bf616d21SDavid Howells * @perm: visibility in sysfs 496bf616d21SDavid Howells * 497bf616d21SDavid Howells * Input and output are as comma-separated values. Commas inside values 498bf616d21SDavid Howells * don't work properly (eg. an array of charp). 499bf616d21SDavid Howells * 500bf616d21SDavid Howells * ARRAY_SIZE(@name) is used to determine the number of elements in the 501bf616d21SDavid Howells * array, so the definition must be visible. 502bf616d21SDavid Howells */ 503bf616d21SDavid Howells #define module_param_hw_array(name, type, hwtype, nump, perm) \ 504bf616d21SDavid Howells param_check_##type(name, &(name)[0]); \ 505bf616d21SDavid Howells static const struct kparam_array __param_arr_##name \ 506bf616d21SDavid Howells = { .max = ARRAY_SIZE(name), .num = nump, \ 507bf616d21SDavid Howells .ops = ¶m_ops_##type, \ 508bf616d21SDavid Howells .elemsize = sizeof(name[0]), .elem = name }; \ 509bf616d21SDavid Howells __module_param_call(MODULE_PARAM_PREFIX, name, \ 510bf616d21SDavid Howells ¶m_array_ops, \ 511bf616d21SDavid Howells .arr = &__param_arr_##name, \ 512bf616d21SDavid Howells perm, -1, \ 513bf616d21SDavid Howells KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \ 514bf616d21SDavid Howells __MODULE_PARM_TYPE(name, "array of " #type) 515bf616d21SDavid Howells 516bf616d21SDavid Howells 5179c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_array_ops; 5181da177e4SLinus Torvalds 5199c27847dSLuis R. Rodriguez extern const struct kernel_param_ops param_ops_string; 5209bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *); 5219bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp); 5221da177e4SLinus Torvalds 523b634d130SJean Delvare /* for exporting parameters in /sys/module/.../parameters */ 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds struct module; 5261da177e4SLinus Torvalds 527ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 5281da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod, 5299bbb9e5aSRusty Russell const struct kernel_param *kparam, 5301da177e4SLinus Torvalds unsigned int num_params); 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod); 533ef665c1aSRandy Dunlap #else 534ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod, 5359bbb9e5aSRusty Russell const struct kernel_param *kparam, 536ef665c1aSRandy Dunlap unsigned int num_params) 537ef665c1aSRandy Dunlap { 538ef665c1aSRandy Dunlap return 0; 539ef665c1aSRandy Dunlap } 540ef665c1aSRandy Dunlap 541ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod) 542ef665c1aSRandy Dunlap { } 543ef665c1aSRandy Dunlap #endif 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */ 546