Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
#ifndef _LINUX_MODULE_PARAMS_H
2
#define _LINUX_MODULE_PARAMS_H
3
/* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
4
#include <linux/init.h>
5
#include <linux/stringify.h>
6
#include <linux/kernel.h>
7
 
8
/* You can override this manually, but generally this should match the
9
   module name. */
10
#ifdef MODULE
11
#define MODULE_PARAM_PREFIX /* empty */
12
#else
13
#define MODULE_PARAM_PREFIX __stringify(KBUILD_MODNAME) "."
14
#endif
15
 
16
struct kernel_param;
17
 
18
/* Returns 0, or -errno.  arg is in kp->arg. */
19
typedef int (*param_set_fn)(const char *val, struct kernel_param *kp);
20
/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
21
typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp);
22
 
23
struct kernel_param {
24
        const char *name;
25
        unsigned int perm;
26
        param_set_fn set;
27
        param_get_fn get;
28
        void *arg;
29
};
30
 
31
/* Special one for strings we want to copy into */
32
struct kparam_string {
33
        unsigned int maxlen;
34
        char *string;
35
};
36
 
37
/* Special one for arrays */
38
struct kparam_array
39
{
40
        unsigned int max;
41
        unsigned int *num;
42
        param_set_fn set;
43
        param_get_fn get;
44
        unsigned int elemsize;
45
        void *elem;
46
};
47
 
48
/* This is the fundamental function for registering boot/module
49
   parameters.  perm sets the visibility in driverfs: 000 means it's
50
   not there, read bits mean it's readable, write bits mean it's
51
   writable. */
52
#define __module_param_call(prefix, name, set, get, arg, perm)          \
53
        static char __param_str_##name[] __initdata = prefix #name;     \
54
        static struct kernel_param const __param_##name                 \
55
    __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
56
        = { __param_str_##name, perm, set, get, arg }
57
 
58
#define module_param_call(name, set, get, arg, perm)                          \
59
        __module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm)
60
 
61
/* Helper functions: type is byte, short, ushort, int, uint, long,
62
   ulong, charp, bool or invbool, or XXX if you define param_get_XXX,
63
   param_set_XXX and param_check_XXX. */
64
#define module_param_named(name, value, type, perm)                        \
65
        param_check_##type(name, &(value));                                \
66
        module_param_call(name, param_set_##type, param_get_##type, &value, perm)
67
 
68
#define module_param(name, type, perm)                          \
69
        module_param_named(name, name, type, perm)
70
 
71
/* Actually copy string: maxlen param is usually sizeof(string). */
72
#define module_param_string(name, string, len, perm)                    \
73
        static struct kparam_string __param_string_##name __initdata    \
74
                = { len, string };                                      \
75
        module_param_call(name, param_set_copystring, param_get_charp,  \
76
                   &__param_string_##name, perm)
77
 
78
/* Called on module insert or kernel boot */
79
extern int parse_args(const char *name,
80
                      char *args,
81
                      struct kernel_param *params,
82
                      unsigned num,
83
                      int (*unknown)(char *param, char *val));
84
 
85
/* All the helper functions */
86
/* The macros to do compile-time type checking stolen from Jakub
87
   Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
88
#define __param_check(name, p, type) \
89
        static inline type *__check_##name(void) { return(p); }
90
 
91
extern int param_set_short(const char *val, struct kernel_param *kp);
92
extern int param_get_short(char *buffer, struct kernel_param *kp);
93
#define param_check_short(name, p) __param_check(name, p, short)
94
 
95
extern int param_set_ushort(const char *val, struct kernel_param *kp);
96
extern int param_get_ushort(char *buffer, struct kernel_param *kp);
97
#define param_check_ushort(name, p) __param_check(name, p, unsigned short)
98
 
99
extern int param_set_int(const char *val, struct kernel_param *kp);
100
extern int param_get_int(char *buffer, struct kernel_param *kp);
101
#define param_check_int(name, p) __param_check(name, p, int)
102
 
103
extern int param_set_uint(const char *val, struct kernel_param *kp);
104
extern int param_get_uint(char *buffer, struct kernel_param *kp);
105
#define param_check_uint(name, p) __param_check(name, p, unsigned int)
106
 
107
extern int param_set_long(const char *val, struct kernel_param *kp);
108
extern int param_get_long(char *buffer, struct kernel_param *kp);
109
#define param_check_long(name, p) __param_check(name, p, long)
110
 
111
extern int param_set_ulong(const char *val, struct kernel_param *kp);
112
extern int param_get_ulong(char *buffer, struct kernel_param *kp);
113
#define param_check_ulong(name, p) __param_check(name, p, unsigned long)
114
 
115
extern int param_set_charp(const char *val, struct kernel_param *kp);
116
extern int param_get_charp(char *buffer, struct kernel_param *kp);
117
#define param_check_charp(name, p) __param_check(name, p, char *)
118
 
119
extern int param_set_bool(const char *val, struct kernel_param *kp);
120
extern int param_get_bool(char *buffer, struct kernel_param *kp);
121
#define param_check_bool(name, p) __param_check(name, p, int)
122
 
123
extern int param_set_invbool(const char *val, struct kernel_param *kp);
124
extern int param_get_invbool(char *buffer, struct kernel_param *kp);
125
#define param_check_invbool(name, p) __param_check(name, p, int)
126
 
127
/* Comma-separated array: num is set to number they actually specified. */
128
#define module_param_array(name, type, num, perm)                       \
129
        static struct kparam_array __param_arr_##name                   \
130
        = { ARRAY_SIZE(name), &num, param_set_##type, param_get_##type, \
131
            sizeof(name[0]), name };                                    \
132
        module_param_call(name, param_array_set, param_array_get,       \
133
                          &__param_arr_##name, perm)
134
 
135
extern int param_array_set(const char *val, struct kernel_param *kp);
136
extern int param_array_get(char *buffer, struct kernel_param *kp);
137
 
138
extern int param_set_copystring(const char *val, struct kernel_param *kp);
139
 
140
int param_array(const char *name,
141
                const char *val,
142
                unsigned int min, unsigned int max,
143
                void *elem, int elemsize,
144
                int (*set)(const char *, struct kernel_param *kp),
145
                int *num);
146
#endif /* _LINUX_MODULE_PARAM_TYPES_H */