blob: 3b54243b2fee3cc79dc5b8479365b28707511ea4 [file] [log] [blame]
Sathish Ambley69e1ab02016-10-18 10:28:15 -07001/*
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +05302 * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
Sathish Ambley69e1ab02016-10-18 10:28:15 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
Sathish Ambley69e1ab02016-10-18 10:28:15 -070014#include <linux/compat.h>
15#include <linux/fs.h>
16#include <linux/uaccess.h>
17#include <linux/msm_ion.h>
18
19#include "adsprpc_compat.h"
20#include "adsprpc_shared.h"
21
22#define COMPAT_FASTRPC_IOCTL_INVOKE \
23 _IOWR('R', 1, struct compat_fastrpc_ioctl_invoke)
24#define COMPAT_FASTRPC_IOCTL_MMAP \
25 _IOWR('R', 2, struct compat_fastrpc_ioctl_mmap)
26#define COMPAT_FASTRPC_IOCTL_MUNMAP \
27 _IOWR('R', 3, struct compat_fastrpc_ioctl_munmap)
28#define COMPAT_FASTRPC_IOCTL_INVOKE_FD \
29 _IOWR('R', 4, struct compat_fastrpc_ioctl_invoke_fd)
30#define COMPAT_FASTRPC_IOCTL_INIT \
31 _IOWR('R', 6, struct compat_fastrpc_ioctl_init)
32#define COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS \
33 _IOWR('R', 7, struct compat_fastrpc_ioctl_invoke_attrs)
Sathish Ambleya21b5b52017-01-11 16:11:01 -080034#define COMPAT_FASTRPC_IOCTL_GETPERF \
35 _IOWR('R', 9, struct compat_fastrpc_ioctl_perf)
Sathish Ambleyd6300c32017-01-18 09:50:43 -080036#define COMPAT_FASTRPC_IOCTL_INIT_ATTRS \
37 _IOWR('R', 10, struct compat_fastrpc_ioctl_init_attrs)
Sathish Ambleybae51902017-07-03 15:00:49 -070038#define COMPAT_FASTRPC_IOCTL_INVOKE_CRC \
39 _IOWR('R', 11, struct compat_fastrpc_ioctl_invoke_crc)
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +053040#define COMPAT_FASTRPC_IOCTL_CONTROL \
41 _IOWR('R', 12, struct compat_fastrpc_ioctl_control)
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +053042#define COMPAT_FASTRPC_IOCTL_MMAP_64 \
43 _IOWR('R', 14, struct compat_fastrpc_ioctl_mmap_64)
44#define COMPAT_FASTRPC_IOCTL_MUNMAP_64 \
45 _IOWR('R', 15, struct compat_fastrpc_ioctl_munmap_64)
Sathish Ambley69e1ab02016-10-18 10:28:15 -070046
47struct compat_remote_buf {
48 compat_uptr_t pv; /* buffer pointer */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +053049 compat_size_t len; /* length of buffer */
Sathish Ambley69e1ab02016-10-18 10:28:15 -070050};
51
52union compat_remote_arg {
53 struct compat_remote_buf buf;
54 compat_uint_t h;
55};
56
57struct compat_fastrpc_ioctl_invoke {
58 compat_uint_t handle; /* remote handle */
59 compat_uint_t sc; /* scalars describing the data */
60 compat_uptr_t pra; /* remote arguments list */
61};
62
63struct compat_fastrpc_ioctl_invoke_fd {
64 struct compat_fastrpc_ioctl_invoke inv;
65 compat_uptr_t fds; /* fd list */
66};
67
68struct compat_fastrpc_ioctl_invoke_attrs {
69 struct compat_fastrpc_ioctl_invoke inv;
70 compat_uptr_t fds; /* fd list */
71 compat_uptr_t attrs; /* attribute list */
72};
73
Sathish Ambleybae51902017-07-03 15:00:49 -070074struct compat_fastrpc_ioctl_invoke_crc {
75 struct compat_fastrpc_ioctl_invoke inv;
76 compat_uptr_t fds; /* fd list */
77 compat_uptr_t attrs; /* attribute list */
78 compat_uptr_t crc; /* crc list */
79};
80
Sathish Ambley69e1ab02016-10-18 10:28:15 -070081struct compat_fastrpc_ioctl_mmap {
82 compat_int_t fd; /* ion fd */
83 compat_uint_t flags; /* flags for dsp to map with */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +053084 compat_uptr_t vaddrin; /* optional virtual address */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +053085 compat_size_t size; /* size */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +053086 compat_uptr_t vaddrout; /* dsps virtual address */
Sathish Ambley69e1ab02016-10-18 10:28:15 -070087};
88
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +053089struct compat_fastrpc_ioctl_mmap_64 {
90 compat_int_t fd; /* ion fd */
91 compat_uint_t flags; /* flags for dsp to map with */
92 compat_u64 vaddrin; /* optional virtual address */
93 compat_size_t size; /* size */
94 compat_u64 vaddrout; /* dsps virtual address */
95};
96
Sathish Ambley69e1ab02016-10-18 10:28:15 -070097struct compat_fastrpc_ioctl_munmap {
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +053098 compat_uptr_t vaddrout; /* address to unmap */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +053099 compat_size_t size; /* size */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700100};
101
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530102struct compat_fastrpc_ioctl_munmap_64 {
103 compat_u64 vaddrout; /* address to unmap */
104 compat_size_t size; /* size */
105};
106
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700107struct compat_fastrpc_ioctl_init {
108 compat_uint_t flags; /* one of FASTRPC_INIT_* macros */
109 compat_uptr_t file; /* pointer to elf file */
110 compat_int_t filelen; /* elf file length */
111 compat_int_t filefd; /* ION fd for the file */
112 compat_uptr_t mem; /* mem for the PD */
113 compat_int_t memlen; /* mem length */
114 compat_int_t memfd; /* ION fd for the mem */
115};
116
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800117struct compat_fastrpc_ioctl_init_attrs {
118 struct compat_fastrpc_ioctl_init init;
119 compat_int_t attrs; /* attributes to init process */
120 compat_int_t siglen; /* test signature file length */
121};
122
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800123struct compat_fastrpc_ioctl_perf { /* kernel performance data */
124 compat_uptr_t data;
125 compat_int_t numkeys;
126 compat_uptr_t keys;
127};
128
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530129#define FASTRPC_CONTROL_LATENCY (1)
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530130struct compat_fastrpc_ctrl_latency {
131 compat_uint_t enable; /* latency control enable */
132 compat_uint_t level; /* level of control */
133};
134
Tharun Kumar Merugu0c14c0b2018-12-18 13:04:52 +0530135#define FASTRPC_CONTROL_SMMU (2)
136struct compat_fastrpc_ctrl_smmu {
137 compat_uint_t sharedcb;
138};
139
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530140#define FASTRPC_CONTROL_KALLOC (3)
141struct compat_fastrpc_ctrl_kalloc {
142 compat_uint_t kalloc_support; /* Remote memory allocation from kernel */
143};
144
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530145struct compat_fastrpc_ioctl_control {
146 compat_uint_t req;
147 union {
148 struct compat_fastrpc_ctrl_latency lp;
Tharun Kumar Merugu0c14c0b2018-12-18 13:04:52 +0530149 struct compat_fastrpc_ctrl_smmu smmu;
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530150 struct compat_fastrpc_ctrl_kalloc kalloc;
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530151 };
152};
153
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700154static int compat_get_fastrpc_ioctl_invoke(
Sathish Ambleybae51902017-07-03 15:00:49 -0700155 struct compat_fastrpc_ioctl_invoke_crc __user *inv32,
156 struct fastrpc_ioctl_invoke_crc __user **inva,
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700157 unsigned int cmd)
158{
159 compat_uint_t u, sc;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530160 compat_size_t s;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700161 compat_uptr_t p;
Sathish Ambleybae51902017-07-03 15:00:49 -0700162 struct fastrpc_ioctl_invoke_crc *inv;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700163 union compat_remote_arg *pra32;
164 union remote_arg *pra;
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800165 int err, len, j;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700166
167 err = get_user(sc, &inv32->inv.sc);
168 if (err)
169 return err;
170
171 len = REMOTE_SCALARS_LENGTH(sc);
172 VERIFY(err, NULL != (inv = compat_alloc_user_space(
173 sizeof(*inv) + len * sizeof(*pra))));
174 if (err)
175 return -EFAULT;
176
177 pra = (union remote_arg *)(inv + 1);
178 err = put_user(pra, &inv->inv.pra);
179 err |= put_user(sc, &inv->inv.sc);
180 err |= get_user(u, &inv32->inv.handle);
181 err |= put_user(u, &inv->inv.handle);
182 err |= get_user(p, &inv32->inv.pra);
183 if (err)
184 return err;
185
186 pra32 = compat_ptr(p);
187 pra = (union remote_arg *)(inv + 1);
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800188 for (j = 0; j < len; j++) {
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700189 err |= get_user(p, &pra32[j].buf.pv);
190 err |= put_user(p, (uintptr_t *)&pra[j].buf.pv);
191 err |= get_user(s, &pra32[j].buf.len);
192 err |= put_user(s, &pra[j].buf.len);
193 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700194
195 err |= put_user(NULL, &inv->fds);
196 if (cmd != COMPAT_FASTRPC_IOCTL_INVOKE) {
197 err |= get_user(p, &inv32->fds);
198 err |= put_user(p, (compat_uptr_t *)&inv->fds);
199 }
200 err |= put_user(NULL, &inv->attrs);
Sathish Ambleybae51902017-07-03 15:00:49 -0700201 if ((cmd == COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS) ||
202 (cmd == COMPAT_FASTRPC_IOCTL_INVOKE_CRC)) {
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700203 err |= get_user(p, &inv32->attrs);
204 err |= put_user(p, (compat_uptr_t *)&inv->attrs);
205 }
Sathish Ambleybae51902017-07-03 15:00:49 -0700206 err |= put_user(NULL, (compat_uptr_t __user **)&inv->crc);
207 if (cmd == COMPAT_FASTRPC_IOCTL_INVOKE_CRC) {
208 err |= get_user(p, &inv32->crc);
209 err |= put_user(p, (compat_uptr_t __user *)&inv->crc);
210 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700211
212 *inva = inv;
213 return err;
214}
215
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700216static int compat_get_fastrpc_ioctl_mmap(
217 struct compat_fastrpc_ioctl_mmap __user *map32,
218 struct fastrpc_ioctl_mmap __user *map)
219{
220 compat_uint_t u;
221 compat_int_t i;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530222 compat_size_t s;
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530223 compat_uptr_t p;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700224 int err;
225
226 err = get_user(i, &map32->fd);
227 err |= put_user(i, &map->fd);
228 err |= get_user(u, &map32->flags);
229 err |= put_user(u, &map->flags);
230 err |= get_user(p, &map32->vaddrin);
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530231 err |= put_user(p, (uintptr_t *)&map->vaddrin);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700232 err |= get_user(s, &map32->size);
233 err |= put_user(s, &map->size);
234
235 return err;
236}
237
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530238static int compat_get_fastrpc_ioctl_mmap_64(
239 struct compat_fastrpc_ioctl_mmap_64 __user *map32,
240 struct fastrpc_ioctl_mmap __user *map)
241{
242 compat_uint_t u;
243 compat_int_t i;
244 compat_size_t s;
245 compat_u64 p;
246 int err;
247
248 err = get_user(i, &map32->fd);
249 err |= put_user(i, &map->fd);
250 err |= get_user(u, &map32->flags);
251 err |= put_user(u, &map->flags);
252 err |= get_user(p, &map32->vaddrin);
253 err |= put_user(p, &map->vaddrin);
254 err |= get_user(s, &map32->size);
255 err |= put_user(s, &map->size);
256
257 return err;
258}
259
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700260static int compat_put_fastrpc_ioctl_mmap(
261 struct compat_fastrpc_ioctl_mmap __user *map32,
262 struct fastrpc_ioctl_mmap __user *map)
263{
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530264 compat_uptr_t p;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700265 int err;
266
267 err = get_user(p, &map->vaddrout);
268 err |= put_user(p, &map32->vaddrout);
269
270 return err;
271}
272
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530273static int compat_put_fastrpc_ioctl_mmap_64(
274 struct compat_fastrpc_ioctl_mmap_64 __user *map32,
275 struct fastrpc_ioctl_mmap __user *map)
276{
277 compat_u64 p;
278 int err;
279
280 err = get_user(p, &map->vaddrout);
281 err |= put_user(p, &map32->vaddrout);
282
283 return err;
284}
285
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700286static int compat_get_fastrpc_ioctl_munmap(
287 struct compat_fastrpc_ioctl_munmap __user *unmap32,
288 struct fastrpc_ioctl_munmap __user *unmap)
289{
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530290 compat_uptr_t p;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530291 compat_size_t s;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700292 int err;
293
294 err = get_user(p, &unmap32->vaddrout);
295 err |= put_user(p, &unmap->vaddrout);
296 err |= get_user(s, &unmap32->size);
297 err |= put_user(s, &unmap->size);
298
299 return err;
300}
301
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530302static int compat_get_fastrpc_ioctl_munmap_64(
303 struct compat_fastrpc_ioctl_munmap_64 __user *unmap32,
304 struct fastrpc_ioctl_munmap __user *unmap)
305{
306 compat_u64 p;
307 compat_size_t s;
308 int err;
309
310 err = get_user(p, &unmap32->vaddrout);
311 err |= put_user(p, &unmap->vaddrout);
312 err |= get_user(s, &unmap32->size);
313 err |= put_user(s, &unmap->size);
314
315 return err;
316}
317
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800318static int compat_get_fastrpc_ioctl_perf(
319 struct compat_fastrpc_ioctl_perf __user *perf32,
320 struct fastrpc_ioctl_perf __user *perf)
321{
322 compat_uptr_t p;
323 int err;
324
325 err = get_user(p, &perf32->data);
326 err |= put_user(p, &perf->data);
327 err |= get_user(p, &perf32->keys);
328 err |= put_user(p, &perf->keys);
329
330 return err;
331}
332
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530333static int compat_get_fastrpc_ioctl_control(
334 struct compat_fastrpc_ioctl_control __user *ctrl32,
335 struct fastrpc_ioctl_control __user *ctrl)
336{
337 compat_uptr_t p;
338 int err;
339
340 err = get_user(p, &ctrl32->req);
341 err |= put_user(p, &ctrl->req);
342 if (p == FASTRPC_CONTROL_LATENCY) {
343 err |= get_user(p, &ctrl32->lp.enable);
344 err |= put_user(p, &ctrl->lp.enable);
345 err |= get_user(p, &ctrl32->lp.level);
346 err |= put_user(p, &ctrl->lp.level);
347 }
348
349 return err;
350}
351
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700352static int compat_get_fastrpc_ioctl_init(
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800353 struct compat_fastrpc_ioctl_init_attrs __user *init32,
354 struct fastrpc_ioctl_init_attrs __user *init,
355 unsigned int cmd)
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700356{
357 compat_uint_t u;
358 compat_uptr_t p;
359 compat_int_t i;
360 int err;
361
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800362 err = get_user(u, &init32->init.flags);
363 err |= put_user(u, &init->init.flags);
364 err |= get_user(p, &init32->init.file);
365 err |= put_user(p, &init->init.file);
366 err |= get_user(i, &init32->init.filelen);
367 err |= put_user(i, &init->init.filelen);
368 err |= get_user(i, &init32->init.filefd);
369 err |= put_user(i, &init->init.filefd);
370 err |= get_user(p, &init32->init.mem);
371 err |= put_user(p, &init->init.mem);
372 err |= get_user(i, &init32->init.memlen);
373 err |= put_user(i, &init->init.memlen);
374 err |= get_user(i, &init32->init.memfd);
375 err |= put_user(i, &init->init.memfd);
376
377 err |= put_user(0, &init->attrs);
378 if (cmd == COMPAT_FASTRPC_IOCTL_INIT_ATTRS) {
379 err |= get_user(i, &init32->attrs);
380 err |= put_user(i, (compat_uptr_t *)&init->attrs);
381 }
382
383 err |= put_user(0, &init->siglen);
384 if (cmd == COMPAT_FASTRPC_IOCTL_INIT_ATTRS) {
385 err |= get_user(i, &init32->siglen);
386 err |= put_user(i, (compat_uptr_t *)&init->siglen);
387 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700388
389 return err;
390}
391
392long compat_fastrpc_device_ioctl(struct file *filp, unsigned int cmd,
393 unsigned long arg)
394{
395 int err = 0;
396
397 if (!filp->f_op || !filp->f_op->unlocked_ioctl)
398 return -ENOTTY;
399
400 switch (cmd) {
401 case COMPAT_FASTRPC_IOCTL_INVOKE:
402 case COMPAT_FASTRPC_IOCTL_INVOKE_FD:
403 case COMPAT_FASTRPC_IOCTL_INVOKE_ATTRS:
Sathish Ambleybae51902017-07-03 15:00:49 -0700404 case COMPAT_FASTRPC_IOCTL_INVOKE_CRC:
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700405 {
Sathish Ambleybae51902017-07-03 15:00:49 -0700406 struct compat_fastrpc_ioctl_invoke_crc __user *inv32;
407 struct fastrpc_ioctl_invoke_crc __user *inv;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700408
409 inv32 = compat_ptr(arg);
410 VERIFY(err, 0 == compat_get_fastrpc_ioctl_invoke(inv32,
411 &inv, cmd));
412 if (err)
413 return err;
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800414 return filp->f_op->unlocked_ioctl(filp,
Sathish Ambleybae51902017-07-03 15:00:49 -0700415 FASTRPC_IOCTL_INVOKE_CRC, (unsigned long)inv);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700416 }
417 case COMPAT_FASTRPC_IOCTL_MMAP:
418 {
419 struct compat_fastrpc_ioctl_mmap __user *map32;
420 struct fastrpc_ioctl_mmap __user *map;
421 long ret;
422
423 map32 = compat_ptr(arg);
424 VERIFY(err, NULL != (map = compat_alloc_user_space(
425 sizeof(*map))));
426 if (err)
427 return -EFAULT;
428 VERIFY(err, 0 == compat_get_fastrpc_ioctl_mmap(map32, map));
429 if (err)
430 return err;
431 ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MMAP,
432 (unsigned long)map);
433 if (ret)
434 return ret;
435 VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap(map32, map));
436 return err;
437 }
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530438 case COMPAT_FASTRPC_IOCTL_MMAP_64:
439 {
440 struct compat_fastrpc_ioctl_mmap_64 __user *map32;
441 struct fastrpc_ioctl_mmap __user *map;
442 long ret;
443
444 map32 = compat_ptr(arg);
445 VERIFY(err, NULL != (map = compat_alloc_user_space(
446 sizeof(*map))));
447 if (err)
448 return -EFAULT;
449 VERIFY(err, 0 == compat_get_fastrpc_ioctl_mmap_64(map32, map));
450 if (err)
451 return err;
452 ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MMAP_64,
453 (unsigned long)map);
454 if (ret)
455 return ret;
456 VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap_64(map32, map));
457 return err;
458 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700459 case COMPAT_FASTRPC_IOCTL_MUNMAP:
460 {
461 struct compat_fastrpc_ioctl_munmap __user *unmap32;
462 struct fastrpc_ioctl_munmap __user *unmap;
463
464 unmap32 = compat_ptr(arg);
465 VERIFY(err, NULL != (unmap = compat_alloc_user_space(
466 sizeof(*unmap))));
467 if (err)
468 return -EFAULT;
469 VERIFY(err, 0 == compat_get_fastrpc_ioctl_munmap(unmap32,
470 unmap));
471 if (err)
472 return err;
473 return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP,
474 (unsigned long)unmap);
475 }
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530476 case COMPAT_FASTRPC_IOCTL_MUNMAP_64:
477 {
478 struct compat_fastrpc_ioctl_munmap_64 __user *unmap32;
479 struct fastrpc_ioctl_munmap __user *unmap;
480
481 unmap32 = compat_ptr(arg);
482 VERIFY(err, NULL != (unmap = compat_alloc_user_space(
483 sizeof(*unmap))));
484 if (err)
485 return -EFAULT;
486 VERIFY(err, 0 == compat_get_fastrpc_ioctl_munmap_64(unmap32,
487 unmap));
488 if (err)
489 return err;
490 return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP_64,
491 (unsigned long)unmap);
492 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700493 case COMPAT_FASTRPC_IOCTL_INIT:
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800494 /* fall through */
495 case COMPAT_FASTRPC_IOCTL_INIT_ATTRS:
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700496 {
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800497 struct compat_fastrpc_ioctl_init_attrs __user *init32;
498 struct fastrpc_ioctl_init_attrs __user *init;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700499
500 init32 = compat_ptr(arg);
501 VERIFY(err, NULL != (init = compat_alloc_user_space(
502 sizeof(*init))));
503 if (err)
504 return -EFAULT;
505 VERIFY(err, 0 == compat_get_fastrpc_ioctl_init(init32,
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800506 init, cmd));
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700507 if (err)
508 return err;
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800509 return filp->f_op->unlocked_ioctl(filp,
510 FASTRPC_IOCTL_INIT_ATTRS, (unsigned long)init);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700511 }
512 case FASTRPC_IOCTL_GETINFO:
513 {
514 compat_uptr_t __user *info32;
515 uint32_t __user *info;
516 compat_uint_t u;
517 long ret;
518
519 info32 = compat_ptr(arg);
520 VERIFY(err, NULL != (info = compat_alloc_user_space(
521 sizeof(*info))));
522 if (err)
523 return -EFAULT;
Sathish Ambley36849af2017-02-02 09:35:55 -0800524 err = get_user(u, info32);
525 err |= put_user(u, info);
526 if (err)
527 return err;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700528 ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_GETINFO,
529 (unsigned long)info);
530 if (ret)
531 return ret;
532 err = get_user(u, info);
533 err |= put_user(u, info32);
534 return err;
535 }
536 case FASTRPC_IOCTL_SETMODE:
537 return filp->f_op->unlocked_ioctl(filp, cmd,
538 (unsigned long)compat_ptr(arg));
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530539 case COMPAT_FASTRPC_IOCTL_CONTROL:
540 {
541 struct compat_fastrpc_ioctl_control __user *ctrl32;
542 struct fastrpc_ioctl_control __user *ctrl;
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530543 compat_uptr_t p;
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530544
545 ctrl32 = compat_ptr(arg);
546 VERIFY(err, NULL != (ctrl = compat_alloc_user_space(
547 sizeof(*ctrl))));
548 if (err)
549 return -EFAULT;
550 VERIFY(err, 0 == compat_get_fastrpc_ioctl_control(ctrl32,
551 ctrl));
552 if (err)
553 return err;
554 err = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_CONTROL,
555 (unsigned long)ctrl);
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530556 if (err)
557 return err;
558 err = get_user(p, &ctrl32->req);
559 if (err)
560 return err;
561 if (p == FASTRPC_CONTROL_KALLOC) {
562 err = get_user(p, &ctrl->kalloc.kalloc_support);
563 err |= put_user(p, &ctrl32->kalloc.kalloc_support);
564 }
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530565 return err;
566 }
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800567 case COMPAT_FASTRPC_IOCTL_GETPERF:
568 {
569 struct compat_fastrpc_ioctl_perf __user *perf32;
570 struct fastrpc_ioctl_perf *perf;
571 compat_uint_t u;
572 long ret;
573
574 perf32 = compat_ptr(arg);
575 VERIFY(err, NULL != (perf = compat_alloc_user_space(
576 sizeof(*perf))));
577 if (err)
578 return -EFAULT;
579 VERIFY(err, 0 == compat_get_fastrpc_ioctl_perf(perf32,
580 perf));
581 if (err)
582 return err;
583 ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_GETPERF,
584 (unsigned long)perf);
585 if (ret)
586 return ret;
587 err = get_user(u, &perf->numkeys);
588 err |= put_user(u, &perf32->numkeys);
589 return err;
590 }
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700591 default:
592 return -ENOIOCTLCMD;
593 }
594}