tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_ukk_core.c
1 /*
2  * Copyright (C) 2010-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 #include <linux/fs.h>       /* file system operations */
11 #include <linux/slab.h>     /* memort allocation functions */
12 #include <asm/uaccess.h>    /* user space access */
13
14 #include "mali_ukk.h"
15 #include "mali_osk.h"
16 #include "mali_kernel_common.h"
17 #include "mali_session.h"
18 #include "mali_ukk_wrappers.h"
19
20 int get_api_version_wrapper(struct mali_session_data *session_data, _mali_uk_get_api_version_s __user *uargs)
21 {
22         _mali_uk_get_api_version_s kargs;
23         _mali_osk_errcode_t err;
24
25         MALI_CHECK_NON_NULL(uargs, -EINVAL);
26
27         if (0 != get_user(kargs.version, &uargs->version)) return -EFAULT;
28
29         kargs.ctx = session_data;
30         err = _mali_ukk_get_api_version(&kargs);
31         if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
32
33         if (0 != put_user(kargs.version, &uargs->version)) return -EFAULT;
34         if (0 != put_user(kargs.compatible, &uargs->compatible)) return -EFAULT;
35
36         return 0;
37 }
38
39 int wait_for_notification_wrapper(struct mali_session_data *session_data, _mali_uk_wait_for_notification_s __user *uargs)
40 {
41         _mali_uk_wait_for_notification_s kargs;
42         _mali_osk_errcode_t err;
43
44         MALI_CHECK_NON_NULL(uargs, -EINVAL);
45
46         kargs.ctx = session_data;
47         err = _mali_ukk_wait_for_notification(&kargs);
48         if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
49
50         if(_MALI_NOTIFICATION_CORE_SHUTDOWN_IN_PROGRESS != kargs.type) {
51                 kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
52                 if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_wait_for_notification_s))) return -EFAULT;
53         } else {
54                 if (0 != put_user(kargs.type, &uargs->type)) return -EFAULT;
55         }
56
57         return 0;
58 }
59
60 int post_notification_wrapper(struct mali_session_data *session_data, _mali_uk_post_notification_s __user *uargs)
61 {
62         _mali_uk_post_notification_s kargs;
63         _mali_osk_errcode_t err;
64
65         MALI_CHECK_NON_NULL(uargs, -EINVAL);
66
67         kargs.ctx = session_data;
68
69         if (0 != get_user(kargs.type, &uargs->type)) {
70                 return -EFAULT;
71         }
72
73         err = _mali_ukk_post_notification(&kargs);
74         if (_MALI_OSK_ERR_OK != err) {
75                 return map_errcode(err);
76         }
77
78         return 0;
79 }
80
81 int get_user_settings_wrapper(struct mali_session_data *session_data, _mali_uk_get_user_settings_s __user *uargs)
82 {
83         _mali_uk_get_user_settings_s kargs;
84         _mali_osk_errcode_t err;
85
86         MALI_CHECK_NON_NULL(uargs, -EINVAL);
87
88         kargs.ctx = session_data;
89         err = _mali_ukk_get_user_settings(&kargs);
90         if (_MALI_OSK_ERR_OK != err) {
91                 return map_errcode(err);
92         }
93
94         kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
95         if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_get_user_settings_s))) return -EFAULT;
96
97         return 0;
98 }
99
100 int request_high_priority_wrapper(struct mali_session_data *session_data, _mali_uk_request_high_priority_s __user *uargs)
101 {
102         _mali_uk_request_high_priority_s kargs;
103         _mali_osk_errcode_t err;
104
105         MALI_CHECK_NON_NULL(uargs, -EINVAL);
106
107         kargs.ctx = session_data;
108         err = _mali_ukk_request_high_priority(&kargs);
109
110         kargs.ctx = NULL;
111
112         return map_errcode(err);
113 }