2 * Copyright (C) 2005 Meilhaus Electronic GmbH (support@meilhaus.de)
4 * Source File : memain.h
5 * Author : GG (Guenter Gebhardt) <g.gebhardt@meilhaus.de>
11 #include "meinternal.h"
17 /*#include "me1000_device.h"
18 #include "me1400_device.h"
19 #include "me1600_device.h"*/
20 #include "me4600_device.h"
21 /*#include "me6000_device.h"
22 #include "me0600_device.h"
23 #include "me8100_device.h"
24 #include "me8200_device.h"
25 #include "me0900_device.h"*/
30 /*=============================================================================
32 ===========================================================================*/
34 #define ME_LOCK_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
35 static int CALL(struct file *filep, TYPE *arg){ \
38 struct list_head *pos; \
39 me_device_t *device; \
42 PDEBUG("executed.\n"); \
44 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
46 PERROR("Can't copy arguments to kernel space\n"); \
50 down_read(&me_rwsem); \
52 list_for_each(pos, &me_device_list){ \
53 if(k == karg.device){ \
54 device = list_entry(pos, me_device_t, list); \
60 if(pos == &me_device_list){ \
61 PERROR("Invalid device number specified\n"); \
62 karg.errno = ME_ERRNO_INVALID_DEVICE; \
65 spin_lock(&me_lock); \
66 if((me_filep != NULL) && (me_filep != filep)){ \
67 spin_unlock(&me_lock); \
68 PERROR("Resource is locked by another process\n"); \
69 if(karg.lock == ME_LOCK_SET) \
70 karg.errno = ME_ERRNO_LOCKED; \
71 else if(karg.lock == ME_LOCK_RELEASE) \
72 karg.errno = ME_ERRNO_SUCCESS; \
74 PERROR("Invalid lock specified\n"); \
75 karg.errno = ME_ERRNO_INVALID_LOCK; \
80 spin_unlock(&me_lock); \
82 karg.errno = device->DEV_CALL ARGS; \
84 spin_lock(&me_lock); \
86 spin_unlock(&me_lock); \
92 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
94 PERROR("Can't copy arguments back to user space\n"); \
98 return ME_ERRNO_SUCCESS; \
101 #define ME_IO_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
102 static int CALL(struct file *filep, TYPE *arg){ \
105 struct list_head *pos; \
106 me_device_t *device; \
109 PDEBUG("executed.\n"); \
111 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
113 PERROR("Can't copy arguments to kernel space\n"); \
117 down_read(&me_rwsem); \
119 list_for_each(pos, &me_device_list){ \
120 if(k == karg.device){ \
121 device = list_entry(pos, me_device_t, list); \
127 if(pos == &me_device_list){ \
128 PERROR("Invalid device number specified\n"); \
129 karg.errno = ME_ERRNO_INVALID_DEVICE; \
132 spin_lock(&me_lock); \
133 if((me_filep != NULL) && (me_filep != filep)){ \
134 spin_unlock(&me_lock); \
135 PERROR("Resource is locked by another process\n"); \
136 karg.errno = ME_ERRNO_LOCKED; \
140 spin_unlock(&me_lock); \
142 karg.errno = device->DEV_CALL ARGS; \
144 spin_lock(&me_lock); \
146 spin_unlock(&me_lock); \
150 up_read(&me_rwsem); \
152 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
154 PERROR("Can't copy arguments back to user space\n"); \
158 return ME_ERRNO_SUCCESS; \
161 #define ME_QUERY_MULTIPLEX_STR_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
162 static int CALL(struct file *filep, TYPE *arg){ \
165 struct list_head *pos; \
166 me_device_t *device; \
170 PDEBUG("executed.\n"); \
172 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
174 PERROR("Can't copy arguments to kernel space\n"); \
178 down_read(&me_rwsem); \
180 list_for_each(pos, &me_device_list){ \
181 if(k == karg.device){ \
182 device = list_entry(pos, me_device_t, list); \
188 if(pos == &me_device_list){ \
189 PERROR("Invalid device number specified\n"); \
190 karg.errno = ME_ERRNO_INVALID_DEVICE; \
193 karg.errno = device->DEV_CALL ARGS; \
195 if((strlen(msg) + 1) > karg.count){ \
196 PERROR("User buffer for device name is to little\n"); \
197 karg.errno = ME_ERRNO_USER_BUFFER_SIZE; \
200 err = copy_to_user(karg.name, msg, strlen(msg) + 1); \
202 PERROR("Can't copy device name to user space\n"); \
209 up_read(&me_rwsem); \
211 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
213 PERROR("Can't copy query back to user space\n"); \
217 return ME_ERRNO_SUCCESS; \
220 #define ME_QUERY_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
221 static int CALL(struct file *filep, TYPE *arg){ \
224 struct list_head *pos; \
225 me_device_t *device; \
228 PDEBUG("executed.\n"); \
230 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
232 PERROR("Can't copy arguments from user space\n"); \
236 down_read(&me_rwsem); \
238 list_for_each(pos, &me_device_list){ \
239 if(k == karg.device){ \
240 device = list_entry(pos, me_device_t, list); \
246 if(pos == &me_device_list){ \
247 PERROR("Invalid device number specified\n"); \
248 karg.errno = ME_ERRNO_INVALID_DEVICE; \
251 karg.errno = device->DEV_CALL ARGS; \
254 up_read(&me_rwsem); \
256 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
258 PERROR("Can't copy arguments to user space\n"); \
262 return ME_ERRNO_SUCCESS; \