tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / linux / mali_ukk_core.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 #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 #include "mali_sync.h"
20
21 int get_api_version_wrapper(struct mali_session_data *session_data, _mali_uk_get_api_version_s __user *uargs)
22 {
23         _mali_uk_get_api_version_s kargs;
24     _mali_osk_errcode_t err;
25
26     MALI_CHECK_NON_NULL(uargs, -EINVAL);
27
28     if (0 != get_user(kargs.version, &uargs->version)) return -EFAULT;
29
30     kargs.ctx = session_data;
31     err = _mali_ukk_get_api_version(&kargs);
32     if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
33
34     if (0 != put_user(kargs.version, &uargs->version)) return -EFAULT;
35     if (0 != put_user(kargs.compatible, &uargs->compatible)) return -EFAULT;
36
37     return 0;
38 }
39
40 int wait_for_notification_wrapper(struct mali_session_data *session_data, _mali_uk_wait_for_notification_s __user *uargs)
41 {
42     _mali_uk_wait_for_notification_s kargs;
43     _mali_osk_errcode_t err;
44
45     MALI_CHECK_NON_NULL(uargs, -EINVAL);
46
47     kargs.ctx = session_data;
48     err = _mali_ukk_wait_for_notification(&kargs);
49     if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
50
51         if(_MALI_NOTIFICATION_CORE_SHUTDOWN_IN_PROGRESS != kargs.type)
52         {
53                 kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
54                 if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_wait_for_notification_s))) return -EFAULT;
55         }
56         else
57         {
58                 if (0 != put_user(kargs.type, &uargs->type)) return -EFAULT;
59         }
60
61     return 0;
62 }
63
64 int post_notification_wrapper(struct mali_session_data *session_data, _mali_uk_post_notification_s __user *uargs)
65 {
66         _mali_uk_post_notification_s kargs;
67         _mali_osk_errcode_t err;
68
69         MALI_CHECK_NON_NULL(uargs, -EINVAL);
70
71         kargs.ctx = session_data;
72
73         if (0 != get_user(kargs.type, &uargs->type))
74         {
75                 return -EFAULT;
76         }
77
78         err = _mali_ukk_post_notification(&kargs);
79         if (_MALI_OSK_ERR_OK != err)
80         {
81                 return map_errcode(err);
82         }
83
84         return 0;
85 }
86
87 int get_user_settings_wrapper(struct mali_session_data *session_data, _mali_uk_get_user_settings_s __user *uargs)
88 {
89         _mali_uk_get_user_settings_s kargs;
90         _mali_osk_errcode_t err;
91
92         MALI_CHECK_NON_NULL(uargs, -EINVAL);
93
94         kargs.ctx = session_data;
95         err = _mali_ukk_get_user_settings(&kargs);
96         if (_MALI_OSK_ERR_OK != err)
97         {
98                 return map_errcode(err);
99         }
100
101         kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
102         if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_get_user_settings_s))) return -EFAULT;
103
104         return 0;
105 }
106
107 #ifdef CONFIG_SYNC
108 /* MALI_SEC */
109 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
110 int stream_create_wrapper(struct mali_session_data *session_data, _mali_uk_stream_create_s __user *uargs)
111 {
112         _mali_uk_stream_create_s kargs;
113         _mali_osk_errcode_t err;
114         char name[32];
115
116         MALI_CHECK_NON_NULL(uargs, -EINVAL);
117
118         snprintf(name, 32, "mali-%u", _mali_osk_get_pid());
119
120         kargs.ctx = session_data;
121         err = mali_stream_create(name, &kargs.fd);
122         if (_MALI_OSK_ERR_OK != err)
123         {
124                 return map_errcode(err);
125         }
126
127         kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
128         if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_stream_create_s))) return -EFAULT;
129
130         return 0;
131 }
132
133 int sync_fence_validate_wrapper(struct mali_session_data *session, _mali_uk_fence_validate_s __user *uargs)
134 {
135         int fd;
136         _mali_osk_errcode_t err;
137
138         if (0 != get_user(fd, &uargs->fd))
139         {
140                 return -EFAULT;
141         }
142
143         err = mali_fence_validate(fd);
144
145         if (_MALI_OSK_ERR_OK == err)
146         {
147                 return 0;
148         }
149
150         return -EINVAL;
151 }
152 #endif
153 #endif