Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Variables
moduleparam.h File Reference
#include <linux/init.h>
#include <linux/stringify.h>
#include <linux/kernel.h>

Go to the source code of this file.

Data Structures

struct  kernel_param_ops
 
struct  kernel_param
 
struct  kparam_string
 
struct  kparam_array
 

Macros

#define MODULE_PARAM_PREFIX   KBUILD_MODNAME "."
 
#define MAX_PARAM_PREFIX_LEN   (64 - sizeof(unsigned long))
 
#define ___module_cat(a, b)   __mod_ ## a ## b
 
#define __module_cat(a, b)   ___module_cat(a,b)
 
#define __MODULE_INFO(tag, name, info)   struct __module_cat(name,__LINE__) {}
 
#define __MODULE_PARM_TYPE(name, _type)   __MODULE_INFO(parmtype, name##type, #name ":" _type)
 
#define MODULE_PARM_DESC(_parm, desc)   __MODULE_INFO(parm, _parm, #_parm ":" desc)
 
#define module_param(name, type, perm)   module_param_named(name, name, type, perm)
 
: the name of the cmdline and sysfs parameter (often the same as var)

core_param - define a historical core kernel parameter.

#define core_param(name, var, type, perm)
 
) is used to determine the number of elements in the

array, so the definition must be visible.

#define module_param_array(name, type, nump, perm)   module_param_array_named(name, name, type, nump, perm)
 

Variables

struct kernel_param_ops __attribute__
 

: a valid C identifier which is the parameter name.

<level>_param_cb - general callback for a module/cmdline parameter to be evaluated before certain initcall level

: the set & get operations for this parameter. : visibility in sysfs.

The ops can have NULL set or get functions.

#define module_param_named(name, value, type, perm)
 
#define module_param_cb(name, ops, arg, perm)   __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1)
 
#define __level_param_cb(name, ops, arg, perm, level)   __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)
 
#define core_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 1)
 
#define postcore_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 2)
 
#define arch_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 3)
 
#define subsys_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 4)
 
#define fs_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 5)
 
#define device_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 6)
 
#define late_param_cb(name, ops, arg, perm)   __level_param_cb(name, ops, arg, perm, 7)
 
#define __moduleparam_const   const
 
#define __module_param_call(prefix, name, ops, arg, perm, level)
 
#define module_param_call(name, set, get, arg, perm)
 

: the name of the parameter

module_param_string - a char array parameter

: the string variable : the maximum length of the string, incl. terminator : visibility in sysfs.

This actually copies the string when it's set (unlike type charp). is usually just sizeof(string).

#define kparam_block_sysfs_write(name)
 
#define kparam_unblock_sysfs_write(name)
 
#define kparam_block_sysfs_read(name)
 
#define kparam_unblock_sysfs_read(name)
 
#define module_param_string(name, string, len, perm)
 

2: parameter name 2


: the length to compare

Similar to parameq(), except it compares
characters.

#define __param_check(name, p, type)   static inline type *__check_##name(void) { return(p); }
 
#define param_check_byte(name, p)   __param_check(name, p, unsigned char)
 
#define param_check_short(name, p)   __param_check(name, p, short)
 
#define param_check_ushort(name, p)   __param_check(name, p, unsigned short)
 
#define param_check_int(name, p)   __param_check(name, p, int)
 
#define param_check_uint(name, p)   __param_check(name, p, unsigned int)
 
#define param_check_long(name, p)   __param_check(name, p, long)
 
#define param_check_ulong(name, p)   __param_check(name, p, unsigned long)
 
#define param_check_charp(name, p)   __param_check(name, p, char *)
 
#define param_check_bool(name, p)   __param_check(name, p, bool)
 
#define param_check_invbool(name, p)   __param_check(name, p, bool)
 
#define param_get_bint   param_get_int
 
#define param_check_bint   param_check_int
 
struct kernel_param_ops param_ops_byte
 
struct kernel_param_ops param_ops_short
 
struct kernel_param_ops param_ops_ushort
 
struct kernel_param_ops param_ops_int
 
struct kernel_param_ops param_ops_uint
 
struct kernel_param_ops param_ops_long
 
struct kernel_param_ops param_ops_ulong
 
struct kernel_param_ops param_ops_charp
 
struct kernel_param_ops param_ops_bool
 
struct kernel_param_ops param_ops_invbool
 
struct kernel_param_ops param_ops_bint
 
bool parameq (const char *name1, const char *name2)
 
bool parameqn (const char *name1, const char *name2, size_t n)
 
int parse_args (const char *name, char *args, const struct kernel_param *params, unsigned num, s16 level_min, s16 level_max, int(*unknown)(char *param, char *val, const char *doing))
 
int param_set_byte (const char *val, const struct kernel_param *kp)
 
int param_get_byte (char *buffer, const struct kernel_param *kp)
 
int param_set_short (const char *val, const struct kernel_param *kp)
 
int param_get_short (char *buffer, const struct kernel_param *kp)
 
int param_set_ushort (const char *val, const struct kernel_param *kp)
 
int param_get_ushort (char *buffer, const struct kernel_param *kp)
 
int param_set_int (const char *val, const struct kernel_param *kp)
 
int param_get_int (char *buffer, const struct kernel_param *kp)
 
int param_set_uint (const char *val, const struct kernel_param *kp)
 
int param_get_uint (char *buffer, const struct kernel_param *kp)
 
int param_set_long (const char *val, const struct kernel_param *kp)
 
int param_get_long (char *buffer, const struct kernel_param *kp)
 
int param_set_ulong (const char *val, const struct kernel_param *kp)
 
int param_get_ulong (char *buffer, const struct kernel_param *kp)
 
int param_set_charp (const char *val, const struct kernel_param *kp)
 
int param_get_charp (char *buffer, const struct kernel_param *kp)
 
int param_set_bool (const char *val, const struct kernel_param *kp)
 
int param_get_bool (char *buffer, const struct kernel_param *kp)
 
int param_set_invbool (const char *val, const struct kernel_param *kp)
 
int param_get_invbool (char *buffer, const struct kernel_param *kp)
 
int param_set_bint (const char *val, const struct kernel_param *kp)
 

: a valid C identifier which is the parameter name

module_param_array_named - renamed parameter which is an array of some type

: the name of the array variable : the type, as per module_param() : optional pointer filled in with the number written : visibility in sysfs

This exposes a different name than the actual variable name. See module_param_named() for why this might be necessary.

#define module_param_array_named(name, array, type, nump, perm)
 
struct kernel_param_ops param_array_ops
 
struct kernel_param_ops param_ops_string
 
int param_set_copystring (const char *val, const struct kernel_param *)
 
int param_get_string (char *buffer, const struct kernel_param *kp)
 

Macro Definition Documentation

#define ___module_cat (   a,
  b 
)    __mod_ ## a ## b

Definition at line 19 of file moduleparam.h.

#define __level_param_cb (   name,
  ops,
  arg,
  perm,
  level 
)    __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)

Definition at line 142 of file moduleparam.h.

#define __module_cat (   a,
  b 
)    ___module_cat(a,b)

Definition at line 20 of file moduleparam.h.

#define __MODULE_INFO (   tag,
  name,
  info 
)    struct __module_cat(name,__LINE__) {}

Definition at line 28 of file moduleparam.h.

#define __module_param_call (   prefix,
  name,
  ops,
  arg,
  perm,
  level 
)
Value:
/* Default value instead of permissions? */ \
static int __param_perm_check_##name __attribute__((unused)) = \
BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \
static const char __param_str_##name[] = prefix #name; \
static struct kernel_param __moduleparam_const __param_##name \
__attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
= { __param_str_##name, ops, perm, level, { arg } }

Definition at line 178 of file moduleparam.h.

#define __MODULE_PARM_TYPE (   name,
  _type 
)    __MODULE_INFO(parmtype, name##type, #name ":" _type)

Definition at line 31 of file moduleparam.h.

#define __moduleparam_const   const

Definition at line 173 of file moduleparam.h.

#define __param_check (   name,
  p,
  type 
)    static inline type *__check_##name(void) { return(p); }

Definition at line 339 of file moduleparam.h.

#define arch_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 3)

Definition at line 151 of file moduleparam.h.

#define core_param (   name,
  var,
  type,
  perm 
)
Value:
param_check_##type(name, &(var)); \
__module_param_call("", name, &param_ops_##type, &var, perm, -1)

Definition at line 273 of file moduleparam.h.

#define core_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 1)

Definition at line 145 of file moduleparam.h.

#define device_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 6)

Definition at line 160 of file moduleparam.h.

#define fs_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 5)

Definition at line 157 of file moduleparam.h.

#define kparam_block_sysfs_read (   name)
Value:
do { \
BUG_ON(!(__param_##name.perm & 0444)); \
__kernel_param_lock(); \
} while (0)

Definition at line 232 of file moduleparam.h.

#define kparam_block_sysfs_write (   name)
Value:
do { \
BUG_ON(!(__param_##name.perm & 0222)); \
__kernel_param_lock(); \
} while (0)

Definition at line 210 of file moduleparam.h.

#define kparam_unblock_sysfs_read (   name)
Value:
do { \
BUG_ON(!(__param_##name.perm & 0444)); \
__kernel_param_unlock(); \
} while (0)

Definition at line 242 of file moduleparam.h.

#define kparam_unblock_sysfs_write (   name)
Value:
do { \
BUG_ON(!(__param_##name.perm & 0222)); \
__kernel_param_unlock(); \
} while (0)

Definition at line 220 of file moduleparam.h.

#define late_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 7)

Definition at line 163 of file moduleparam.h.

#define MAX_PARAM_PREFIX_LEN   (64 - sizeof(unsigned long))

Definition at line 17 of file moduleparam.h.

#define module_param (   name,
  type,
  perm 
)    module_param_named(name, name, type, perm)

module_param - typesafe helper for a module/cmdline parameter : the variable to alter, and exposed parameter name. : the type of the parameter : visibility in sysfs.

becomes the module parameter, or (prefixed by KBUILD_MODNAME and a ".") the kernel commandline parameter. Note that - is changed to _, so the user can use "foo-bar=1" even for variable "foo_bar".

is 0 if the the variable is not to appear in sysfs, or 0444 for world-readable, 0644 for root-writable, etc. Note that if it is writable, you may need to use kparam_block_sysfs_write() around accesses (esp. charp, which can be kfreed when it changes).

The is simply pasted to refer to a param_ops_#type and a param_check_#type: for convenience many standard types are provided but you can create your own by defining those variables.

Standard types are: byte, short, ushort, int, uint, long, ulong charp: a character pointer bool: a bool, values 0/1, y/n, Y/N. invbool: the above, only sense-reversed (N = true).

Definition at line 103 of file moduleparam.h.

#define module_param_array (   name,
  type,
  nump,
  perm 
)    module_param_array_named(name, name, type, nump, perm)

Definition at line 412 of file moduleparam.h.

#define module_param_array_named (   name,
  array,
  type,
  nump,
  perm 
)
Value:
param_check_##type(name, &(array)[0]); \
static const struct kparam_array __param_arr_##name \
= { .max = ARRAY_SIZE(array), .num = nump, \
.ops = &param_ops_##type, \
.elemsize = sizeof(array[0]), .elem = array }; \
__module_param_call(MODULE_PARAM_PREFIX, name, \
.arr = &__param_arr_##name, \
perm, -1); \
__MODULE_PARM_TYPE(name, "array of " #type)

Definition at line 426 of file moduleparam.h.

#define module_param_call (   name,
  set,
  get,
  arg,
  perm 
)
Value:
static struct kernel_param_ops __param_ops_##name = \
{ (void *)set, (void *)get }; \
__module_param_call(MODULE_PARAM_PREFIX, \
name, &__param_ops_##name, arg, \
(perm) + sizeof(__check_old_set_param(set))*0, -1)

Definition at line 190 of file moduleparam.h.

#define module_param_cb (   name,
  ops,
  arg,
  perm 
)    __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1)

Definition at line 130 of file moduleparam.h.

#define module_param_named (   name,
  value,
  type,
  perm 
)
Value:
param_check_##type(name, &(value)); \
module_param_cb(name, &param_ops_##type, &value, perm); \
__MODULE_PARM_TYPE(name, #type)

Definition at line 117 of file moduleparam.h.

#define MODULE_PARAM_PREFIX   KBUILD_MODNAME "."

Definition at line 13 of file moduleparam.h.

#define module_param_string (   name,
  string,
  len,
  perm 
)
Value:
static const struct kparam_string __param_string_##name \
= { len, string }; \
__module_param_call(MODULE_PARAM_PREFIX, name, \
.str = &__param_string_##name, perm, -1); \
__MODULE_PARM_TYPE(name, "string")

Definition at line 288 of file moduleparam.h.

#define MODULE_PARM_DESC (   _parm,
  desc 
)    __MODULE_INFO(parm, _parm, #_parm ":" desc)

Definition at line 36 of file moduleparam.h.

#define param_check_bint   param_check_int

Definition at line 397 of file moduleparam.h.

#define param_check_bool (   name,
  p 
)    __param_check(name, p, bool)

Definition at line 386 of file moduleparam.h.

#define param_check_byte (   name,
  p 
)    __param_check(name, p, unsigned char)

Definition at line 345 of file moduleparam.h.

#define param_check_charp (   name,
  p 
)    __param_check(name, p, char *)

Definition at line 380 of file moduleparam.h.

#define param_check_int (   name,
  p 
)    __param_check(name, p, int)

Definition at line 360 of file moduleparam.h.

#define param_check_invbool (   name,
  p 
)    __param_check(name, p, bool)

Definition at line 391 of file moduleparam.h.

#define param_check_long (   name,
  p 
)    __param_check(name, p, long)

Definition at line 370 of file moduleparam.h.

#define param_check_short (   name,
  p 
)    __param_check(name, p, short)

Definition at line 350 of file moduleparam.h.

#define param_check_uint (   name,
  p 
)    __param_check(name, p, unsigned int)

Definition at line 365 of file moduleparam.h.

#define param_check_ulong (   name,
  p 
)    __param_check(name, p, unsigned long)

Definition at line 375 of file moduleparam.h.

#define param_check_ushort (   name,
  p 
)    __param_check(name, p, unsigned short)

Definition at line 355 of file moduleparam.h.

#define param_get_bint   param_get_int

Definition at line 396 of file moduleparam.h.

#define postcore_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 2)

Definition at line 148 of file moduleparam.h.

#define subsys_param_cb (   name,
  ops,
  arg,
  perm 
)    __level_param_cb(name, ops, arg, perm, 4)

Definition at line 154 of file moduleparam.h.

Function Documentation

int param_get_bool ( char buffer,
const struct kernel_param kp 
)

Definition at line 315 of file params.c.

int param_get_byte ( char buffer,
const struct kernel_param kp 
)
int param_get_charp ( char buffer,
const struct kernel_param kp 
)

Definition at line 286 of file params.c.

int param_get_int ( char buffer,
const struct kernel_param kp 
)
int param_get_invbool ( char buffer,
const struct kernel_param kp 
)

Definition at line 343 of file params.c.

int param_get_long ( char buffer,
const struct kernel_param kp 
)
int param_get_short ( char buffer,
const struct kernel_param kp 
)
int param_get_string ( char buffer,
const struct kernel_param kp 
)

Definition at line 489 of file params.c.

int param_get_uint ( char buffer,
const struct kernel_param kp 
)
int param_get_ulong ( char buffer,
const struct kernel_param kp 
)
int param_get_ushort ( char buffer,
const struct kernel_param kp 
)
int param_set_bint ( const char val,
const struct kernel_param kp 
)

Definition at line 355 of file params.c.

int param_set_bool ( const char val,
const struct kernel_param kp 
)

Definition at line 305 of file params.c.

int param_set_byte ( const char val,
const struct kernel_param kp 
)
int param_set_charp ( const char val,
const struct kernel_param kp 
)

Definition at line 263 of file params.c.

int param_set_copystring ( const char val,
const struct kernel_param  
)

Definition at line 475 of file params.c.

int param_set_int ( const char val,
const struct kernel_param kp 
)
int param_set_invbool ( const char val,
const struct kernel_param kp 
)

Definition at line 329 of file params.c.

int param_set_long ( const char val,
const struct kernel_param kp 
)
int param_set_short ( const char val,
const struct kernel_param kp 
)
int param_set_uint ( const char val,
const struct kernel_param kp 
)
int param_set_ulong ( const char val,
const struct kernel_param kp 
)
int param_set_ushort ( const char val,
const struct kernel_param kp 
)
bool parameq ( const char name1,
const char name2 
)

Definition at line 81 of file params.c.

bool parameqn ( const char name1,
const char name2,
size_t  n 
)

Definition at line 70 of file params.c.

int parse_args ( const char name,
char args,
const struct kernel_param params,
unsigned  num,
s16  level_min,
s16  level_max,
int(*)(char *param, char *val, const char *doing)  unknown 
)

Definition at line 180 of file params.c.

Variable Documentation

struct kernel_param_ops param_array_ops

Definition at line 468 of file params.c.

struct kernel_param_ops param_ops_bint

Definition at line 372 of file params.c.

struct kernel_param_ops param_ops_bool

Definition at line 322 of file params.c.

struct kernel_param_ops param_ops_byte
struct kernel_param_ops param_ops_charp

Definition at line 297 of file params.c.

struct kernel_param_ops param_ops_int
struct kernel_param_ops param_ops_invbool

Definition at line 349 of file params.c.

struct kernel_param_ops param_ops_long
struct kernel_param_ops param_ops_short
struct kernel_param_ops param_ops_string

Definition at line 496 of file params.c.

struct kernel_param_ops param_ops_uint
struct kernel_param_ops param_ops_ulong
struct kernel_param_ops param_ops_ushort