tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / ump / linux / ump_ukk_wrappers.c
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 /**
12  * @file ump_ukk_wrappers.c
13  * Defines the wrapper functions which turn Linux IOCTL calls into _ukk_ calls
14  */
15
16 #include <asm/uaccess.h>             /* user space access */
17
18 #include "ump_osk.h"
19 #include "ump_uk_types.h"
20 #include "ump_ukk.h"
21 #include "ump_kernel_common.h"
22
23 /*
24  * IOCTL operation; Negotiate version of IOCTL API
25  */
26 int ump_get_api_version_wrapper(u32 __user * argument, struct ump_session_data * session_data)
27 {
28         _ump_uk_api_version_s version_info;
29         _mali_osk_errcode_t err;
30
31         /* Sanity check input parameters */
32         if (NULL == argument || NULL == session_data)
33         {
34                 MSG_ERR(("NULL parameter in ump_ioctl_get_api_version()\n"));
35                 return -ENOTTY;
36         }
37
38         /* Copy the user space memory to kernel space (so we safely can read it) */
39         if (0 != copy_from_user(&version_info, argument, sizeof(version_info)))
40         {
41                 MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
42                 return -EFAULT;
43         }
44
45         version_info.ctx = (void*) session_data;
46         err = _ump_uku_get_api_version( &version_info );
47         if( _MALI_OSK_ERR_OK != err )
48         {
49                 MSG_ERR(("_ump_uku_get_api_version() failed in ump_ioctl_get_api_version()\n"));
50                 return map_errcode(err);
51         }
52
53         version_info.ctx = NULL;
54
55         /* Copy ouput data back to user space */
56         if (0 != copy_to_user(argument, &version_info, sizeof(version_info)))
57         {
58                 MSG_ERR(("copy_to_user() failed in ump_ioctl_get_api_version()\n"));
59                 return -EFAULT;
60         }
61
62         return 0; /* success */
63 }
64
65
66 /*
67  * IOCTL operation; Release reference to specified UMP memory.
68  */
69 int ump_release_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
70 {
71         _ump_uk_release_s release_args;
72         _mali_osk_errcode_t err;
73
74         /* Sanity check input parameters */
75         if (NULL == session_data)
76         {
77                 MSG_ERR(("NULL parameter in ump_ioctl_release()\n"));
78                 return -ENOTTY;
79         }
80
81         /* Copy the user space memory to kernel space (so we safely can read it) */
82         if (0 != copy_from_user(&release_args, argument, sizeof(release_args)))
83         {
84                 MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
85                 return -EFAULT;
86         }
87
88         release_args.ctx = (void*) session_data;
89         err = _ump_ukk_release( &release_args );
90         if( _MALI_OSK_ERR_OK != err )
91         {
92                 MSG_ERR(("_ump_ukk_release() failed in ump_ioctl_release()\n"));
93                 return map_errcode(err);
94         }
95
96
97         return 0; /* success */
98 }
99
100 /*
101  * IOCTL operation; Return size for specified UMP memory.
102  */
103 int ump_size_get_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
104 {
105         _ump_uk_size_get_s user_interaction;
106         _mali_osk_errcode_t err;
107
108         /* Sanity check input parameters */
109         if (NULL == argument || NULL == session_data)
110         {
111                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
112                 return -ENOTTY;
113         }
114
115         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
116         {
117                 MSG_ERR(("copy_from_user() in ump_ioctl_size_get()\n"));
118                 return -EFAULT;
119         }
120
121         user_interaction.ctx = (void *) session_data;
122         err = _ump_ukk_size_get( &user_interaction );
123         if( _MALI_OSK_ERR_OK != err )
124         {
125                 MSG_ERR(("_ump_ukk_size_get() failed in ump_ioctl_size_get()\n"));
126                 return map_errcode(err);
127         }
128
129         user_interaction.ctx = NULL;
130
131         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
132         {
133                 MSG_ERR(("copy_to_user() failed in ump_ioctl_size_get()\n"));
134                 return -EFAULT;
135         }
136
137         return 0; /* success */
138 }
139
140 /*
141  * IOCTL operation; Do cache maintenance on specified UMP memory.
142  */
143 int ump_msync_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
144 {
145         _ump_uk_msync_s user_interaction;
146
147         /* Sanity check input parameters */
148         if (NULL == argument || NULL == session_data)
149         {
150                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
151                 return -ENOTTY;
152         }
153
154         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
155         {
156                 MSG_ERR(("copy_from_user() in ump_ioctl_msync()\n"));
157                 return -EFAULT;
158         }
159
160         user_interaction.ctx = (void *) session_data;
161
162         _ump_ukk_msync( &user_interaction );
163
164         user_interaction.ctx = NULL;
165
166         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
167         {
168                 MSG_ERR(("copy_to_user() failed in ump_ioctl_msync()\n"));
169                 return -EFAULT;
170         }
171
172         return 0; /* success */
173 }
174 int ump_cache_operations_control_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
175 {
176         _ump_uk_cache_operations_control_s user_interaction;
177
178         /* Sanity check input parameters */
179         if (NULL == argument || NULL == session_data)
180         {
181                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
182                 return -ENOTTY;
183         }
184
185         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
186         {
187                 MSG_ERR(("copy_from_user() in ump_ioctl_cache_operations_control()\n"));
188                 return -EFAULT;
189         }
190
191         user_interaction.ctx = (void *) session_data;
192
193         _ump_ukk_cache_operations_control((_ump_uk_cache_operations_control_s*) &user_interaction );
194
195         user_interaction.ctx = NULL;
196
197 #if 0  /* No data to copy back */
198         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
199         {
200                 MSG_ERR(("copy_to_user() failed in ump_ioctl_cache_operations_control()\n"));
201                 return -EFAULT;
202         }
203 #endif
204         return 0; /* success */
205 }
206
207 int ump_switch_hw_usage_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
208 {
209         _ump_uk_switch_hw_usage_s user_interaction;
210
211         /* Sanity check input parameters */
212         if (NULL == argument || NULL == session_data)
213         {
214                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
215                 return -ENOTTY;
216         }
217
218         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
219         {
220                 MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
221                 return -EFAULT;
222         }
223
224         user_interaction.ctx = (void *) session_data;
225
226         _ump_ukk_switch_hw_usage( &user_interaction );
227
228         user_interaction.ctx = NULL;
229
230 #if 0  /* No data to copy back */
231         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
232         {
233                 MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
234                 return -EFAULT;
235         }
236 #endif
237         return 0; /* success */
238 }
239
240 int ump_lock_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
241 {
242         _ump_uk_lock_s user_interaction;
243
244         /* Sanity check input parameters */
245         if (NULL == argument || NULL == session_data)
246         {
247                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
248                 return -ENOTTY;
249         }
250
251         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
252         {
253                 MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
254                 return -EFAULT;
255         }
256
257         user_interaction.ctx = (void *) session_data;
258
259         _ump_ukk_lock( &user_interaction );
260
261         user_interaction.ctx = NULL;
262
263 #if 0  /* No data to copy back */
264         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
265         {
266                 MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
267                 return -EFAULT;
268         }
269 #endif
270
271         return 0; /* success */
272 }
273
274 int ump_unlock_wrapper(u32 __user * argument, struct ump_session_data  * session_data)
275 {
276         _ump_uk_unlock_s user_interaction;
277
278         /* Sanity check input parameters */
279         if (NULL == argument || NULL == session_data)
280         {
281                 MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
282                 return -ENOTTY;
283         }
284
285         if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction)))
286         {
287                 MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
288                 return -EFAULT;
289         }
290
291         user_interaction.ctx = (void *) session_data;
292
293         _ump_ukk_unlock( &user_interaction );
294
295         user_interaction.ctx = NULL;
296
297 #if 0  /* No data to copy back */
298         if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction)))
299         {
300                 MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
301                 return -EFAULT;
302         }
303 #endif
304
305         return 0; /* success */
306 }