xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2010-2014, 2016-2017 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 <linux/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  */
ump_get_api_version_wrapper(u32 __user * argument,struct ump_session_data * session_data)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 		MSG_ERR(("NULL parameter in ump_ioctl_get_api_version()\n"));
34 		return -ENOTTY;
35 	}
36 
37 	/* Copy the user space memory to kernel space (so we safely can read it) */
38 	if (0 != copy_from_user(&version_info, argument, sizeof(version_info))) {
39 		MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
40 		return -EFAULT;
41 	}
42 
43 	version_info.ctx = (void *) session_data;
44 	err = _ump_uku_get_api_version(&version_info);
45 	if (_MALI_OSK_ERR_OK != err) {
46 		MSG_ERR(("_ump_uku_get_api_version() failed in ump_ioctl_get_api_version()\n"));
47 		return ump_map_errcode(err);
48 	}
49 
50 	version_info.ctx = NULL;
51 
52 	/* Copy ouput data back to user space */
53 	if (0 != copy_to_user(argument, &version_info, sizeof(version_info))) {
54 		MSG_ERR(("copy_to_user() failed in ump_ioctl_get_api_version()\n"));
55 		return -EFAULT;
56 	}
57 
58 	return 0; /* success */
59 }
60 
61 
62 /*
63  * IOCTL operation; Release reference to specified UMP memory.
64  */
ump_release_wrapper(u32 __user * argument,struct ump_session_data * session_data)65 int ump_release_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
66 {
67 	_ump_uk_release_s release_args;
68 	_mali_osk_errcode_t err;
69 
70 	/* Sanity check input parameters */
71 	if (NULL == session_data) {
72 		MSG_ERR(("NULL parameter in ump_ioctl_release()\n"));
73 		return -ENOTTY;
74 	}
75 
76 	/* Copy the user space memory to kernel space (so we safely can read it) */
77 	if (0 != copy_from_user(&release_args, argument, sizeof(release_args))) {
78 		MSG_ERR(("copy_from_user() in ump_ioctl_get_api_version()\n"));
79 		return -EFAULT;
80 	}
81 
82 	release_args.ctx = (void *) session_data;
83 	err = _ump_ukk_release(&release_args);
84 	if (_MALI_OSK_ERR_OK != err) {
85 		MSG_ERR(("_ump_ukk_release() failed in ump_ioctl_release()\n"));
86 		return ump_map_errcode(err);
87 	}
88 
89 
90 	return 0; /* success */
91 }
92 
93 /*
94  * IOCTL operation; Return size for specified UMP memory.
95  */
ump_size_get_wrapper(u32 __user * argument,struct ump_session_data * session_data)96 int ump_size_get_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
97 {
98 	_ump_uk_size_get_s user_interaction;
99 	_mali_osk_errcode_t err;
100 
101 	/* Sanity check input parameters */
102 	if (NULL == argument || NULL == session_data) {
103 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
104 		return -ENOTTY;
105 	}
106 
107 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
108 		MSG_ERR(("copy_from_user() in ump_ioctl_size_get()\n"));
109 		return -EFAULT;
110 	}
111 
112 	user_interaction.ctx = (void *) session_data;
113 	err = _ump_ukk_size_get(&user_interaction);
114 	if (_MALI_OSK_ERR_OK != err) {
115 		MSG_ERR(("_ump_ukk_size_get() failed in ump_ioctl_size_get()\n"));
116 		return ump_map_errcode(err);
117 	}
118 
119 	user_interaction.ctx = NULL;
120 
121 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
122 		MSG_ERR(("copy_to_user() failed in ump_ioctl_size_get()\n"));
123 		return -EFAULT;
124 	}
125 
126 	return 0; /* success */
127 }
128 
129 /*
130  * IOCTL operation; Do cache maintenance on specified UMP memory.
131  */
ump_msync_wrapper(u32 __user * argument,struct ump_session_data * session_data)132 int ump_msync_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
133 {
134 	_ump_uk_msync_s user_interaction;
135 
136 	/* Sanity check input parameters */
137 	if (NULL == argument || NULL == session_data) {
138 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
139 		return -ENOTTY;
140 	}
141 
142 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
143 		MSG_ERR(("copy_from_user() in ump_ioctl_msync()\n"));
144 		return -EFAULT;
145 	}
146 
147 	user_interaction.ctx = (void *) session_data;
148 
149 	_ump_ukk_msync(&user_interaction);
150 
151 	user_interaction.ctx = NULL;
152 
153 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
154 		MSG_ERR(("copy_to_user() failed in ump_ioctl_msync()\n"));
155 		return -EFAULT;
156 	}
157 
158 	return 0; /* success */
159 }
ump_cache_operations_control_wrapper(u32 __user * argument,struct ump_session_data * session_data)160 int ump_cache_operations_control_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
161 {
162 	_ump_uk_cache_operations_control_s user_interaction;
163 
164 	/* Sanity check input parameters */
165 	if (NULL == argument || NULL == session_data) {
166 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
167 		return -ENOTTY;
168 	}
169 
170 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
171 		MSG_ERR(("copy_from_user() in ump_ioctl_cache_operations_control()\n"));
172 		return -EFAULT;
173 	}
174 
175 	user_interaction.ctx = (void *) session_data;
176 
177 	_ump_ukk_cache_operations_control((_ump_uk_cache_operations_control_s *) &user_interaction);
178 
179 	user_interaction.ctx = NULL;
180 
181 #if 0  /* No data to copy back */
182 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
183 		MSG_ERR(("copy_to_user() failed in ump_ioctl_cache_operations_control()\n"));
184 		return -EFAULT;
185 	}
186 #endif
187 	return 0; /* success */
188 }
189 
ump_switch_hw_usage_wrapper(u32 __user * argument,struct ump_session_data * session_data)190 int ump_switch_hw_usage_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
191 {
192 	_ump_uk_switch_hw_usage_s user_interaction;
193 
194 	/* Sanity check input parameters */
195 	if (NULL == argument || NULL == session_data) {
196 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
197 		return -ENOTTY;
198 	}
199 
200 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
201 		MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
202 		return -EFAULT;
203 	}
204 
205 	user_interaction.ctx = (void *) session_data;
206 
207 	_ump_ukk_switch_hw_usage(&user_interaction);
208 
209 	user_interaction.ctx = NULL;
210 
211 #if 0  /* No data to copy back */
212 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
213 		MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
214 		return -EFAULT;
215 	}
216 #endif
217 	return 0; /* success */
218 }
219 
ump_lock_wrapper(u32 __user * argument,struct ump_session_data * session_data)220 int ump_lock_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
221 {
222 	_ump_uk_lock_s user_interaction;
223 
224 	/* Sanity check input parameters */
225 	if (NULL == argument || NULL == session_data) {
226 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
227 		return -ENOTTY;
228 	}
229 
230 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
231 		MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
232 		return -EFAULT;
233 	}
234 
235 	user_interaction.ctx = (void *) session_data;
236 
237 	_ump_ukk_lock(&user_interaction);
238 
239 	user_interaction.ctx = NULL;
240 
241 #if 0  /* No data to copy back */
242 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
243 		MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
244 		return -EFAULT;
245 	}
246 #endif
247 
248 	return 0; /* success */
249 }
250 
ump_unlock_wrapper(u32 __user * argument,struct ump_session_data * session_data)251 int ump_unlock_wrapper(u32 __user *argument, struct ump_session_data   *session_data)
252 {
253 	_ump_uk_unlock_s user_interaction;
254 
255 	/* Sanity check input parameters */
256 	if (NULL == argument || NULL == session_data) {
257 		MSG_ERR(("NULL parameter in ump_ioctl_size_get()\n"));
258 		return -ENOTTY;
259 	}
260 
261 	if (0 != copy_from_user(&user_interaction, argument, sizeof(user_interaction))) {
262 		MSG_ERR(("copy_from_user() in ump_ioctl_switch_hw_usage()\n"));
263 		return -EFAULT;
264 	}
265 
266 	user_interaction.ctx = (void *) session_data;
267 
268 	_ump_ukk_unlock(&user_interaction);
269 
270 	user_interaction.ctx = NULL;
271 
272 #if 0  /* No data to copy back */
273 	if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
274 		MSG_ERR(("copy_to_user() failed in ump_ioctl_switch_hw_usage()\n"));
275 		return -EFAULT;
276 	}
277 #endif
278 
279 	return 0; /* success */
280 }
281