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 191da177e4SLinus Torvalds #define ___module_cat(a,b) __mod_ ## a ## b 201da177e4SLinus Torvalds #define __module_cat(a,b) ___module_cat(a,b) 21b75be420SLinus Walleij #ifdef MODULE 221da177e4SLinus Torvalds #define __MODULE_INFO(tag, name, info) \ 231da177e4SLinus Torvalds static const char __module_cat(name,__LINE__)[] \ 24b6472776SJan Beulich __used __attribute__((section(".modinfo"), unused, aligned(1))) \ 25b6472776SJan Beulich = __stringify(tag) "=" info 261da177e4SLinus Torvalds #else /* !MODULE */ 27b75be420SLinus Walleij /* This struct is here for syntactic coherency, it is not used */ 28b75be420SLinus Walleij #define __MODULE_INFO(tag, name, info) \ 29b75be420SLinus Walleij struct __module_cat(name,__LINE__) {} 301da177e4SLinus Torvalds #endif 311da177e4SLinus Torvalds #define __MODULE_PARM_TYPE(name, _type) \ 321da177e4SLinus Torvalds __MODULE_INFO(parmtype, name##type, #name ":" _type) 331da177e4SLinus Torvalds 34639938ebSPaul Gortmaker /* One for each parameter, describing how to use it. Some files do 35639938ebSPaul Gortmaker multiple of these per line, so can't just use MODULE_INFO. */ 36639938ebSPaul Gortmaker #define MODULE_PARM_DESC(_parm, desc) \ 37639938ebSPaul Gortmaker __MODULE_INFO(parm, _parm, #_parm ":" desc) 38639938ebSPaul Gortmaker 391da177e4SLinus Torvalds struct kernel_param; 401da177e4SLinus Torvalds 419bbb9e5aSRusty Russell struct kernel_param_ops { 421da177e4SLinus Torvalds /* Returns 0, or -errno. arg is in kp->arg. */ 439bbb9e5aSRusty Russell int (*set)(const char *val, const struct kernel_param *kp); 441da177e4SLinus Torvalds /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 459bbb9e5aSRusty Russell int (*get)(char *buffer, const struct kernel_param *kp); 46e6df34a4SRusty Russell /* Optional function to free kp->arg when module unloaded. */ 47e6df34a4SRusty Russell void (*free)(void *arg); 489bbb9e5aSRusty Russell }; 491da177e4SLinus Torvalds 5045fcc70cSRusty Russell /* Flag bits for kernel_param.flags */ 51fddd5201SRusty Russell #define KPARAM_ISBOOL 2 5245fcc70cSRusty Russell 531da177e4SLinus Torvalds struct kernel_param { 541da177e4SLinus Torvalds const char *name; 559bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 5645fcc70cSRusty Russell u16 perm; 5745fcc70cSRusty Russell u16 flags; 5822e48eafSJan Beulich union { 591da177e4SLinus Torvalds void *arg; 6022e48eafSJan Beulich const struct kparam_string *str; 6122e48eafSJan Beulich const struct kparam_array *arr; 6222e48eafSJan Beulich }; 631da177e4SLinus Torvalds }; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Special one for strings we want to copy into */ 661da177e4SLinus Torvalds struct kparam_string { 671da177e4SLinus Torvalds unsigned int maxlen; 681da177e4SLinus Torvalds char *string; 691da177e4SLinus Torvalds }; 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* Special one for arrays */ 721da177e4SLinus Torvalds struct kparam_array 731da177e4SLinus Torvalds { 741da177e4SLinus Torvalds unsigned int max; 75c5be0b2eSRichard Kennedy unsigned int elemsize; 761da177e4SLinus Torvalds unsigned int *num; 779bbb9e5aSRusty Russell const struct kernel_param_ops *ops; 781da177e4SLinus Torvalds void *elem; 791da177e4SLinus Torvalds }; 801da177e4SLinus Torvalds 81546970bcSRusty Russell /** 82546970bcSRusty Russell * module_param - typesafe helper for a module/cmdline parameter 83546970bcSRusty Russell * @value: the variable to alter, and exposed parameter name. 84546970bcSRusty Russell * @type: the type of the parameter 85546970bcSRusty Russell * @perm: visibility in sysfs. 86546970bcSRusty Russell * 87546970bcSRusty Russell * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a 88546970bcSRusty Russell * ".") the kernel commandline parameter. Note that - is changed to _, so 89546970bcSRusty Russell * the user can use "foo-bar=1" even for variable "foo_bar". 90546970bcSRusty Russell * 91546970bcSRusty Russell * @perm is 0 if the the variable is not to appear in sysfs, or 0444 92546970bcSRusty Russell * for world-readable, 0644 for root-writable, etc. Note that if it 93546970bcSRusty Russell * is writable, you may need to use kparam_block_sysfs_write() around 94546970bcSRusty Russell * accesses (esp. charp, which can be kfreed when it changes). 95546970bcSRusty Russell * 96546970bcSRusty Russell * The @type is simply pasted to refer to a param_ops_##type and a 97546970bcSRusty Russell * param_check_##type: for convenience many standard types are provided but 98546970bcSRusty Russell * you can create your own by defining those variables. 99546970bcSRusty Russell * 100546970bcSRusty Russell * Standard types are: 101546970bcSRusty Russell * byte, short, ushort, int, uint, long, ulong 102546970bcSRusty Russell * charp: a character pointer 103546970bcSRusty Russell * bool: a bool, values 0/1, y/n, Y/N. 104546970bcSRusty Russell * invbool: the above, only sense-reversed (N = true). 105546970bcSRusty Russell */ 106546970bcSRusty Russell #define module_param(name, type, perm) \ 107546970bcSRusty Russell module_param_named(name, name, type, perm) 108546970bcSRusty Russell 109546970bcSRusty Russell /** 110546970bcSRusty Russell * module_param_named - typesafe helper for a renamed module/cmdline parameter 111546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 112546970bcSRusty Russell * @value: the actual lvalue to alter. 113546970bcSRusty Russell * @type: the type of the parameter 114546970bcSRusty Russell * @perm: visibility in sysfs. 115546970bcSRusty Russell * 116546970bcSRusty Russell * Usually it's a good idea to have variable names and user-exposed names the 117546970bcSRusty Russell * same, but that's harder if the variable must be non-static or is inside a 118546970bcSRusty Russell * structure. This allows exposure under a different name. 119546970bcSRusty Russell */ 120546970bcSRusty Russell #define module_param_named(name, value, type, perm) \ 121546970bcSRusty Russell param_check_##type(name, &(value)); \ 122546970bcSRusty Russell module_param_cb(name, ¶m_ops_##type, &value, perm); \ 123546970bcSRusty Russell __MODULE_PARM_TYPE(name, #type) 124546970bcSRusty Russell 125546970bcSRusty Russell /** 126546970bcSRusty Russell * module_param_cb - general callback for a module/cmdline parameter 127546970bcSRusty Russell * @name: a valid C identifier which is the parameter name. 128546970bcSRusty Russell * @ops: the set & get operations for this parameter. 129546970bcSRusty Russell * @perm: visibility in sysfs. 130546970bcSRusty Russell * 131546970bcSRusty Russell * The ops can have NULL set or get functions. 132546970bcSRusty Russell */ 133546970bcSRusty Russell #define module_param_cb(name, ops, arg, perm) \ 134546970bcSRusty Russell __module_param_call(MODULE_PARAM_PREFIX, \ 135a6de51b2SRusty Russell name, ops, arg, __same_type((arg), bool *), perm) 136546970bcSRusty Russell 13791d35dd9SIvan Kokshaysky /* On alpha, ia64 and ppc64 relocations to global data cannot go into 13891d35dd9SIvan Kokshaysky read-only sections (which is part of respective UNIX ABI on these 13991d35dd9SIvan Kokshaysky platforms). So 'const' makes no sense and even causes compile failures 14091d35dd9SIvan Kokshaysky with some compilers. */ 14191d35dd9SIvan Kokshaysky #if defined(CONFIG_ALPHA) || defined(CONFIG_IA64) || defined(CONFIG_PPC64) 14291d35dd9SIvan Kokshaysky #define __moduleparam_const 14391d35dd9SIvan Kokshaysky #else 14491d35dd9SIvan Kokshaysky #define __moduleparam_const const 14591d35dd9SIvan Kokshaysky #endif 14691d35dd9SIvan Kokshaysky 1471da177e4SLinus Torvalds /* This is the fundamental function for registering boot/module 148546970bcSRusty Russell parameters. */ 1499bbb9e5aSRusty Russell #define __module_param_call(prefix, name, ops, arg, isbool, perm) \ 1509774a1f5SAlexey Dobriyan /* Default value instead of permissions? */ \ 1519774a1f5SAlexey Dobriyan static int __param_perm_check_##name __attribute__((unused)) = \ 152730b69d2SRusty Russell BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ 153730b69d2SRusty Russell + BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN); \ 15422e48eafSJan Beulich static const char __param_str_##name[] = prefix #name; \ 15591d35dd9SIvan Kokshaysky static struct kernel_param __moduleparam_const __param_##name \ 1563ff6eeccSAdrian Bunk __used \ 1571da177e4SLinus Torvalds __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ 1589bbb9e5aSRusty Russell = { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0, \ 1599bbb9e5aSRusty Russell { arg } } 1601da177e4SLinus Torvalds 1619bbb9e5aSRusty Russell /* Obsolete - use module_param_cb() */ 1621da177e4SLinus Torvalds #define module_param_call(name, set, get, arg, perm) \ 1639bbb9e5aSRusty Russell static struct kernel_param_ops __param_ops_##name = \ 1649bbb9e5aSRusty Russell { (void *)set, (void *)get }; \ 165fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, \ 1669bbb9e5aSRusty Russell name, &__param_ops_##name, arg, \ 167a6de51b2SRusty Russell __same_type(arg, bool *), \ 1689bbb9e5aSRusty Russell (perm) + sizeof(__check_old_set_param(set))*0) 1691da177e4SLinus Torvalds 1709bbb9e5aSRusty Russell /* We don't get oldget: it's often a new-style param_get_uint, etc. */ 1719bbb9e5aSRusty Russell static inline int 1729bbb9e5aSRusty Russell __check_old_set_param(int (*oldset)(const char *, struct kernel_param *)) 1739bbb9e5aSRusty Russell { 1749bbb9e5aSRusty Russell return 0; 1759bbb9e5aSRusty Russell } 1769bbb9e5aSRusty Russell 177907b29ebSRusty Russell /** 178907b29ebSRusty Russell * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs. 179907b29ebSRusty Russell * @name: the name of the parameter 180907b29ebSRusty Russell * 181907b29ebSRusty Russell * There's no point blocking write on a paramter that isn't writable via sysfs! 182907b29ebSRusty Russell */ 183907b29ebSRusty Russell #define kparam_block_sysfs_write(name) \ 184907b29ebSRusty Russell do { \ 185907b29ebSRusty Russell BUG_ON(!(__param_##name.perm & 0222)); \ 186907b29ebSRusty Russell __kernel_param_lock(); \ 187907b29ebSRusty Russell } while (0) 188907b29ebSRusty Russell 189907b29ebSRusty Russell /** 190907b29ebSRusty Russell * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again. 191907b29ebSRusty Russell * @name: the name of the parameter 192907b29ebSRusty Russell */ 193907b29ebSRusty Russell #define kparam_unblock_sysfs_write(name) \ 194907b29ebSRusty Russell do { \ 195907b29ebSRusty Russell BUG_ON(!(__param_##name.perm & 0222)); \ 196907b29ebSRusty Russell __kernel_param_unlock(); \ 197907b29ebSRusty Russell } while (0) 198907b29ebSRusty Russell 199907b29ebSRusty Russell /** 200907b29ebSRusty Russell * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs. 201907b29ebSRusty Russell * @name: the name of the parameter 202907b29ebSRusty Russell * 203907b29ebSRusty Russell * This also blocks sysfs writes. 204907b29ebSRusty Russell */ 205907b29ebSRusty Russell #define kparam_block_sysfs_read(name) \ 206907b29ebSRusty Russell do { \ 207907b29ebSRusty Russell BUG_ON(!(__param_##name.perm & 0444)); \ 208907b29ebSRusty Russell __kernel_param_lock(); \ 209907b29ebSRusty Russell } while (0) 210907b29ebSRusty Russell 211907b29ebSRusty Russell /** 212907b29ebSRusty Russell * kparam_unblock_sysfs_read - allows sysfs to read a parameter again. 213907b29ebSRusty Russell * @name: the name of the parameter 214907b29ebSRusty Russell */ 215907b29ebSRusty Russell #define kparam_unblock_sysfs_read(name) \ 216907b29ebSRusty Russell do { \ 217907b29ebSRusty Russell BUG_ON(!(__param_##name.perm & 0444)); \ 218907b29ebSRusty Russell __kernel_param_unlock(); \ 219907b29ebSRusty Russell } while (0) 220907b29ebSRusty Russell 221907b29ebSRusty Russell #ifdef CONFIG_SYSFS 222907b29ebSRusty Russell extern void __kernel_param_lock(void); 223907b29ebSRusty Russell extern void __kernel_param_unlock(void); 224907b29ebSRusty Russell #else 225907b29ebSRusty Russell static inline void __kernel_param_lock(void) 226907b29ebSRusty Russell { 227907b29ebSRusty Russell } 228907b29ebSRusty Russell static inline void __kernel_param_unlock(void) 229907b29ebSRusty Russell { 230907b29ebSRusty Russell } 231907b29ebSRusty Russell #endif 232907b29ebSRusty Russell 23367e67ceaSRusty Russell #ifndef MODULE 23467e67ceaSRusty Russell /** 23567e67ceaSRusty Russell * core_param - define a historical core kernel parameter. 23667e67ceaSRusty Russell * @name: the name of the cmdline and sysfs parameter (often the same as var) 23767e67ceaSRusty Russell * @var: the variable 238546970bcSRusty Russell * @type: the type of the parameter 23967e67ceaSRusty Russell * @perm: visibility in sysfs 24067e67ceaSRusty Russell * 24167e67ceaSRusty Russell * core_param is just like module_param(), but cannot be modular and 24267e67ceaSRusty Russell * doesn't add a prefix (such as "printk."). This is for compatibility 24367e67ceaSRusty Russell * with __setup(), and it makes sense as truly core parameters aren't 24467e67ceaSRusty Russell * tied to the particular file they're in. 24567e67ceaSRusty Russell */ 24667e67ceaSRusty Russell #define core_param(name, var, type, perm) \ 24767e67ceaSRusty Russell param_check_##type(name, &(var)); \ 2489bbb9e5aSRusty Russell __module_param_call("", name, ¶m_ops_##type, \ 249fddd5201SRusty Russell &var, __same_type(var, bool), perm) 25067e67ceaSRusty Russell #endif /* !MODULE */ 25167e67ceaSRusty Russell 252546970bcSRusty Russell /** 253546970bcSRusty Russell * module_param_string - a char array parameter 254546970bcSRusty Russell * @name: the name of the parameter 255546970bcSRusty Russell * @string: the string variable 256546970bcSRusty Russell * @len: the maximum length of the string, incl. terminator 257546970bcSRusty Russell * @perm: visibility in sysfs. 258546970bcSRusty Russell * 259546970bcSRusty Russell * This actually copies the string when it's set (unlike type charp). 260546970bcSRusty Russell * @len is usually just sizeof(string). 261546970bcSRusty Russell */ 2621da177e4SLinus Torvalds #define module_param_string(name, string, len, perm) \ 26322e48eafSJan Beulich static const struct kparam_string __param_string_##name \ 2641da177e4SLinus Torvalds = { len, string }; \ 265fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 2669bbb9e5aSRusty Russell ¶m_ops_string, \ 267fddd5201SRusty Russell .str = &__param_string_##name, 0, perm); \ 2681da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "string") 2691da177e4SLinus Torvalds 270b1e4d20cSMichal Schmidt /** 271b1e4d20cSMichal Schmidt * parameq - checks if two parameter names match 272b1e4d20cSMichal Schmidt * @name1: parameter name 1 273b1e4d20cSMichal Schmidt * @name2: parameter name 2 274b1e4d20cSMichal Schmidt * 275b1e4d20cSMichal Schmidt * Returns true if the two parameter names are equal. 276b1e4d20cSMichal Schmidt * Dashes (-) are considered equal to underscores (_). 277b1e4d20cSMichal Schmidt */ 278b1e4d20cSMichal Schmidt extern bool parameq(const char *name1, const char *name2); 279b1e4d20cSMichal Schmidt 280b1e4d20cSMichal Schmidt /** 281b1e4d20cSMichal Schmidt * parameqn - checks if two parameter names match 282b1e4d20cSMichal Schmidt * @name1: parameter name 1 283b1e4d20cSMichal Schmidt * @name2: parameter name 2 284b1e4d20cSMichal Schmidt * @n: the length to compare 285b1e4d20cSMichal Schmidt * 286b1e4d20cSMichal Schmidt * Similar to parameq(), except it compares @n characters. 287b1e4d20cSMichal Schmidt */ 288b1e4d20cSMichal Schmidt extern bool parameqn(const char *name1, const char *name2, size_t n); 289b1e4d20cSMichal Schmidt 2901da177e4SLinus Torvalds /* Called on module insert or kernel boot */ 2911da177e4SLinus Torvalds extern int parse_args(const char *name, 2921da177e4SLinus Torvalds char *args, 293914dcaa8SRusty Russell const struct kernel_param *params, 2941da177e4SLinus Torvalds unsigned num, 2951da177e4SLinus Torvalds int (*unknown)(char *param, char *val)); 2961da177e4SLinus Torvalds 297e180a6b7SRusty Russell /* Called by module remove. */ 298e180a6b7SRusty Russell #ifdef CONFIG_SYSFS 299e180a6b7SRusty Russell extern void destroy_params(const struct kernel_param *params, unsigned num); 300e180a6b7SRusty Russell #else 301e180a6b7SRusty Russell static inline void destroy_params(const struct kernel_param *params, 302e180a6b7SRusty Russell unsigned num) 303e180a6b7SRusty Russell { 304e180a6b7SRusty Russell } 305e180a6b7SRusty Russell #endif /* !CONFIG_SYSFS */ 306e180a6b7SRusty Russell 3071da177e4SLinus Torvalds /* All the helper functions */ 3081da177e4SLinus Torvalds /* The macros to do compile-time type checking stolen from Jakub 3091da177e4SLinus Torvalds Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ 3101da177e4SLinus Torvalds #define __param_check(name, p, type) \ 3111da177e4SLinus Torvalds static inline type *__check_##name(void) { return(p); } 3121da177e4SLinus Torvalds 3139bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_byte; 3149bbb9e5aSRusty Russell extern int param_set_byte(const char *val, const struct kernel_param *kp); 3159bbb9e5aSRusty Russell extern int param_get_byte(char *buffer, const struct kernel_param *kp); 3161da177e4SLinus Torvalds #define param_check_byte(name, p) __param_check(name, p, unsigned char) 3171da177e4SLinus Torvalds 3189bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_short; 3199bbb9e5aSRusty Russell extern int param_set_short(const char *val, const struct kernel_param *kp); 3209bbb9e5aSRusty Russell extern int param_get_short(char *buffer, const struct kernel_param *kp); 3211da177e4SLinus Torvalds #define param_check_short(name, p) __param_check(name, p, short) 3221da177e4SLinus Torvalds 3239bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ushort; 3249bbb9e5aSRusty Russell extern int param_set_ushort(const char *val, const struct kernel_param *kp); 3259bbb9e5aSRusty Russell extern int param_get_ushort(char *buffer, const struct kernel_param *kp); 3261da177e4SLinus Torvalds #define param_check_ushort(name, p) __param_check(name, p, unsigned short) 3271da177e4SLinus Torvalds 3289bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_int; 3299bbb9e5aSRusty Russell extern int param_set_int(const char *val, const struct kernel_param *kp); 3309bbb9e5aSRusty Russell extern int param_get_int(char *buffer, const struct kernel_param *kp); 3311da177e4SLinus Torvalds #define param_check_int(name, p) __param_check(name, p, int) 3321da177e4SLinus Torvalds 3339bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_uint; 3349bbb9e5aSRusty Russell extern int param_set_uint(const char *val, const struct kernel_param *kp); 3359bbb9e5aSRusty Russell extern int param_get_uint(char *buffer, const struct kernel_param *kp); 3361da177e4SLinus Torvalds #define param_check_uint(name, p) __param_check(name, p, unsigned int) 3371da177e4SLinus Torvalds 3389bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_long; 3399bbb9e5aSRusty Russell extern int param_set_long(const char *val, const struct kernel_param *kp); 3409bbb9e5aSRusty Russell extern int param_get_long(char *buffer, const struct kernel_param *kp); 3411da177e4SLinus Torvalds #define param_check_long(name, p) __param_check(name, p, long) 3421da177e4SLinus Torvalds 3439bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_ulong; 3449bbb9e5aSRusty Russell extern int param_set_ulong(const char *val, const struct kernel_param *kp); 3459bbb9e5aSRusty Russell extern int param_get_ulong(char *buffer, const struct kernel_param *kp); 3461da177e4SLinus Torvalds #define param_check_ulong(name, p) __param_check(name, p, unsigned long) 3471da177e4SLinus Torvalds 3489bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_charp; 3499bbb9e5aSRusty Russell extern int param_set_charp(const char *val, const struct kernel_param *kp); 3509bbb9e5aSRusty Russell extern int param_get_charp(char *buffer, const struct kernel_param *kp); 3511da177e4SLinus Torvalds #define param_check_charp(name, p) __param_check(name, p, char *) 3521da177e4SLinus Torvalds 353*72db395fSRusty Russell /* We used to allow int as well as bool. We're taking that away! */ 3549bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_bool; 3559bbb9e5aSRusty Russell extern int param_set_bool(const char *val, const struct kernel_param *kp); 3569bbb9e5aSRusty Russell extern int param_get_bool(char *buffer, const struct kernel_param *kp); 357*72db395fSRusty Russell #define param_check_bool(name, p) __param_check(name, p, bool) 3581da177e4SLinus Torvalds 3599bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_invbool; 3609bbb9e5aSRusty Russell extern int param_set_invbool(const char *val, const struct kernel_param *kp); 3619bbb9e5aSRusty Russell extern int param_get_invbool(char *buffer, const struct kernel_param *kp); 3629a71af2cSRusty Russell #define param_check_invbool(name, p) __param_check(name, p, bool) 3631da177e4SLinus Torvalds 36469116f27SRusty Russell /* An int, which can only be set like a bool (though it shows as an int). */ 36569116f27SRusty Russell extern struct kernel_param_ops param_ops_bint; 36669116f27SRusty Russell extern int param_set_bint(const char *val, const struct kernel_param *kp); 36769116f27SRusty Russell #define param_get_bint param_get_int 36869116f27SRusty Russell #define param_check_bint param_check_int 36969116f27SRusty Russell 370546970bcSRusty Russell /** 371546970bcSRusty Russell * module_param_array - a parameter which is an array of some type 372546970bcSRusty Russell * @name: the name of the array variable 373546970bcSRusty Russell * @type: the type, as per module_param() 374546970bcSRusty Russell * @nump: optional pointer filled in with the number written 375546970bcSRusty Russell * @perm: visibility in sysfs 376546970bcSRusty Russell * 377546970bcSRusty Russell * Input and output are as comma-separated values. Commas inside values 378546970bcSRusty Russell * don't work properly (eg. an array of charp). 379546970bcSRusty Russell * 380546970bcSRusty Russell * ARRAY_SIZE(@name) is used to determine the number of elements in the 381546970bcSRusty Russell * array, so the definition must be visible. 382546970bcSRusty Russell */ 383546970bcSRusty Russell #define module_param_array(name, type, nump, perm) \ 384546970bcSRusty Russell module_param_array_named(name, name, type, nump, perm) 385546970bcSRusty Russell 386546970bcSRusty Russell /** 387546970bcSRusty Russell * module_param_array_named - renamed parameter which is an array of some type 388546970bcSRusty Russell * @name: a valid C identifier which is the parameter name 389546970bcSRusty Russell * @array: the name of the array variable 390546970bcSRusty Russell * @type: the type, as per module_param() 391546970bcSRusty Russell * @nump: optional pointer filled in with the number written 392546970bcSRusty Russell * @perm: visibility in sysfs 393546970bcSRusty Russell * 394546970bcSRusty Russell * This exposes a different name than the actual variable name. See 395546970bcSRusty Russell * module_param_named() for why this might be necessary. 396546970bcSRusty Russell */ 3971da177e4SLinus Torvalds #define module_param_array_named(name, array, type, nump, perm) \ 398bafeafeaSRusty Russell param_check_##type(name, &(array)[0]); \ 39922e48eafSJan Beulich static const struct kparam_array __param_arr_##name \ 400c5be0b2eSRichard Kennedy = { .max = ARRAY_SIZE(array), .num = nump, \ 401c5be0b2eSRichard Kennedy .ops = ¶m_ops_##type, \ 402c5be0b2eSRichard Kennedy .elemsize = sizeof(array[0]), .elem = array }; \ 403fddd5201SRusty Russell __module_param_call(MODULE_PARAM_PREFIX, name, \ 4049bbb9e5aSRusty Russell ¶m_array_ops, \ 405fddd5201SRusty Russell .arr = &__param_arr_##name, \ 406fddd5201SRusty Russell __same_type(array[0], bool), perm); \ 4071da177e4SLinus Torvalds __MODULE_PARM_TYPE(name, "array of " #type) 4081da177e4SLinus Torvalds 4099bbb9e5aSRusty Russell extern struct kernel_param_ops param_array_ops; 4101da177e4SLinus Torvalds 4119bbb9e5aSRusty Russell extern struct kernel_param_ops param_ops_string; 4129bbb9e5aSRusty Russell extern int param_set_copystring(const char *val, const struct kernel_param *); 4139bbb9e5aSRusty Russell extern int param_get_string(char *buffer, const struct kernel_param *kp); 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds /* for exporting parameters in /sys/parameters */ 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds struct module; 4181da177e4SLinus Torvalds 419ef665c1aSRandy Dunlap #if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 4201da177e4SLinus Torvalds extern int module_param_sysfs_setup(struct module *mod, 4219bbb9e5aSRusty Russell const struct kernel_param *kparam, 4221da177e4SLinus Torvalds unsigned int num_params); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds extern void module_param_sysfs_remove(struct module *mod); 425ef665c1aSRandy Dunlap #else 426ef665c1aSRandy Dunlap static inline int module_param_sysfs_setup(struct module *mod, 4279bbb9e5aSRusty Russell const struct kernel_param *kparam, 428ef665c1aSRandy Dunlap unsigned int num_params) 429ef665c1aSRandy Dunlap { 430ef665c1aSRandy Dunlap return 0; 431ef665c1aSRandy Dunlap } 432ef665c1aSRandy Dunlap 433ef665c1aSRandy Dunlap static inline void module_param_sysfs_remove(struct module *mod) 434ef665c1aSRandy Dunlap { } 435ef665c1aSRandy Dunlap #endif 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds #endif /* _LINUX_MODULE_PARAMS_H */ 438