]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/splat-ctl.h
More build fixes, I have the kernel module almost building and its
[FreeBSD/FreeBSD.git] / include / splat-ctl.h
1 #ifndef _SPLAT_CTL_H
2 #define _SPLAY_CTL_H
3
4 #ifdef _KERNEL
5 #include <asm/ioctls.h>
6 #include <asm/uaccess.h>
7 #include <linux/list.h>
8 #endif /* _KERNEL */
9
10 #define KZT_VERSION                     "v1.0"
11 #define KZT_VERSION_SIZE                64
12
13 #define KZT_MAJOR                       229 /* XXX - Arbitrary */
14 #define KZT_MINORS                      1
15 #define KZT_DEV                         "/dev/kztctl"
16
17 #define KZT_NAME_SIZE                   12
18 #define KZT_DESC_SIZE                   60
19
20 typedef struct kzt_user {
21         char name[KZT_NAME_SIZE];       /* short name */
22         char desc[KZT_DESC_SIZE];       /* short description */
23         int id;                         /* unique numeric id */
24 } kzt_user_t;
25
26 #define KZT_CFG_MAGIC                   0x15263748U
27 typedef struct kzt_cfg {
28         unsigned int cfg_magic;         /* Unique magic */
29         int cfg_cmd;                    /* Config command */
30         int cfg_arg1;                   /* Config command arg 1 */
31         int cfg_rc1;                    /* Config response 1 */
32         union {
33                 struct {
34                         int size;
35                         kzt_user_t descs[0];
36                 } kzt_subsystems;
37                 struct {
38                         int size;
39                         kzt_user_t descs[0];
40                 } kzt_tests;
41         } cfg_data;
42 } kzt_cfg_t;
43
44 #define KZT_CMD_MAGIC                   0x9daebfc0U
45 typedef struct kzt_cmd {
46         unsigned int cmd_magic;         /* Unique magic */
47         int cmd_subsystem;              /* Target subsystem */
48         int cmd_test;                   /* Subsystem test */
49         int cmd_data_size;              /* Extra opaque data */
50         char cmd_data_str[0];           /* Opaque data region */
51 } kzt_cmd_t;
52
53 /* Valid ioctls */
54 #define KZT_CFG                         _IOWR('f', 101, long)
55 #define KZT_CMD                         _IOWR('f', 102, long)
56
57 /* Valid configuration commands */
58 #define KZT_CFG_BUFFER_CLEAR            0x001   /* Clear text buffer */
59 #define KZT_CFG_BUFFER_SIZE             0x002   /* Resize text buffer */
60 #define KZT_CFG_SUBSYSTEM_COUNT         0x101   /* Number of subsystem */
61 #define KZT_CFG_SUBSYSTEM_LIST          0x102   /* List of N subsystems */
62 #define KZT_CFG_TEST_COUNT              0x201   /* Number of tests */
63 #define KZT_CFG_TEST_LIST               0x202   /* List of N tests */
64
65 /* Valid subsystem and test commands defined in each subsystem, we do
66  * need to be careful to avoid colisions.  That alone may argue to define
67  * them all here, for now we just define the global error codes.
68  */
69 #define KZT_SUBSYSTEM_UNKNOWN           0xF00
70 #define KZT_TEST_UNKNOWN                0xFFF
71
72
73 #ifdef _KERNEL
74 #define KZT_SUBSYSTEM_INIT(type)                                        \
75 ({      kzt_subsystem_t *_sub_;                                         \
76                                                                         \
77         _sub_ = (kzt_subsystem_t *)kzt_##type##_init();                 \
78         if (_sub_ == NULL) {                                            \
79                 printk(KERN_ERR "Error initializing: " #type "\n");     \
80         } else {                                                        \
81                 spin_lock(&kzt_module_lock);                            \
82                 list_add_tail(&(_sub_->subsystem_list),                 \
83                               &kzt_module_list);                        \
84                 spin_unlock(&kzt_module_lock);                          \
85         }                                                               \
86 })
87
88 #define KZT_SUBSYSTEM_FINI(type)                                        \
89 ({      kzt_subsystem_t *_sub_, *_tmp_;                                 \
90         int _id_, _flag_ = 0;                                           \
91                                                                         \
92         _id_ = kzt_##type##_id();                                       \
93         spin_lock(&kzt_module_lock);                                    \
94         list_for_each_entry_safe(_sub_, _tmp_,  &kzt_module_list,       \
95                                  subsystem_list) {                      \
96                 if (_sub_->desc.id == _id_) {                           \
97                         list_del_init(&(_sub_->subsystem_list));        \
98                         spin_unlock(&kzt_module_lock);                  \
99                         kzt_##type##_fini(_sub_);                       \
100                         spin_lock(&kzt_module_lock);                    \
101                         _flag_ = 1;                                     \
102                 }                                                       \
103         }                                                               \
104         spin_unlock(&kzt_module_lock);                                  \
105                                                                         \
106         if (!_flag_)                                                    \
107                 printk(KERN_ERR "Error finalizing: " #type "\n");       \
108 })
109
110 #define KZT_TEST_INIT(sub, n, d, tid, func)                             \
111 ({      kzt_test_t *_test_;                                             \
112                                                                         \
113         _test_ = (kzt_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL);    \
114         if (_test_ == NULL) {                                           \
115                 printk(KERN_ERR "Error initializing: " n "/" #tid" \n");\
116         } else {                                                        \
117                 memset(_test_, 0, sizeof(*_test_));                     \
118                 strncpy(_test_->desc.name, n, KZT_NAME_SIZE);           \
119                 strncpy(_test_->desc.desc, d, KZT_DESC_SIZE);           \
120                 _test_->desc.id = tid;                                  \
121                 _test_->test = func;                                    \
122                 INIT_LIST_HEAD(&(_test_->test_list));                   \
123                 spin_lock(&((sub)->test_lock));                         \
124                 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
125                 spin_unlock(&((sub)->test_lock));                       \
126         }                                                               \
127 })
128
129 #define KZT_TEST_FINI(sub, tid)                                         \
130 ({      kzt_test_t *_test_, *_tmp_;                                     \
131         int _flag_ = 0;                                                 \
132                                                                         \
133         spin_lock(&((sub)->test_lock));                                 \
134         list_for_each_entry_safe(_test_, _tmp_,                         \
135                                  &((sub)->test_list), test_list) {      \
136                 if (_test_->desc.id == tid) {                           \
137                         list_del_init(&(_test_->test_list));            \
138                         _flag_ = 1;                                     \
139                 }                                                       \
140         }                                                               \
141         spin_unlock(&((sub)->test_lock));                               \
142                                                                         \
143         if (!_flag_)                                                    \
144                 printk(KERN_ERR "Error finalizing: " #tid "\n");        \
145 })
146
147 typedef int (*kzt_test_func_t)(struct file *, void *);
148
149 typedef struct kzt_test {
150         struct list_head test_list;
151         kzt_user_t desc;
152         kzt_test_func_t test;
153 } kzt_test_t;
154
155 typedef struct kzt_subsystem {
156         struct list_head subsystem_list;/* List had to chain entries */
157         kzt_user_t desc;
158         spinlock_t test_lock;
159         struct list_head test_list;
160 } kzt_subsystem_t;
161
162 #define KZT_INFO_BUFFER_SIZE            65536
163 #define KZT_INFO_BUFFER_REDZONE         256
164
165 typedef struct kzt_info {
166         spinlock_t info_lock;
167         int info_size;
168         char *info_buffer;
169         char *info_head;        /* Internal kernel use only */
170 } kzt_info_t;
171
172 #define sym2str(sym)                    (char *)(#sym)
173
174 #define kzt_print(file, format, args...)                                \
175 ({      kzt_info_t *_info_ = (kzt_info_t *)file->private_data;          \
176         int _rc_;                                                       \
177                                                                         \
178         ASSERT(_info_);                                                 \
179         ASSERT(_info_->info_buffer);                                    \
180                                                                         \
181         spin_lock(&_info_->info_lock);                                  \
182                                                                         \
183         /* Don't allow the kernel to start a write in the red zone */   \
184         if ((int)(_info_->info_head - _info_->info_buffer) >            \
185             (KZT_INFO_BUFFER_SIZE -KZT_INFO_BUFFER_REDZONE)) {          \
186                 _rc_ = -EOVERFLOW;                                      \
187         } else {                                                        \
188                 _rc_ = sprintf(_info_->info_head, format, args);        \
189                 if (_rc_ >= 0)                                          \
190                         _info_->info_head += _rc_;                      \
191         }                                                               \
192                                                                         \
193         spin_unlock(&_info_->info_lock);                                \
194         _rc_;                                                           \
195 })
196
197 #define kzt_vprint(file, test, format, args...)                         \
198         kzt_print(file, "%*s: " format, KZT_NAME_SIZE, test, args)
199
200 kzt_subsystem_t * kzt_condvar_init(void);
201 kzt_subsystem_t * kzt_kmem_init(void);
202 kzt_subsystem_t * kzt_mutex_init(void);
203 kzt_subsystem_t * kzt_krng_init(void);
204 kzt_subsystem_t * kzt_rwlock_init(void);
205 kzt_subsystem_t * kzt_taskq_init(void);
206 kzt_subsystem_t * kzt_thread_init(void);
207 kzt_subsystem_t * kzt_time_init(void);
208
209 #endif /* _KERNEL */
210
211 #endif /* _SPLAY_CTL_H */