import OT_8063_20170412 mali driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / ump / linux / ump_ukk_ref_wrappers.c
1 /*
2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2009-2010, 2013-2015 ARM Limited
5 * ALL RIGHTS RESERVED
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
9 */
10
11 /**
12 * @file ump_ukk_wrappers.c
13 * Defines the wrapper functions which turn Linux IOCTL calls into _ukk_ calls for the reference implementation
14 */
15
16
17 #include <asm/uaccess.h> /* user space access */
18
19 #include "ump_osk.h"
20 #include "ump_uk_types.h"
21 #include "ump_ukk.h"
22 #include "ump_kernel_common.h"
23
24 /*
25 * IOCTL operation; Allocate UMP memory
26 */
27 int ump_allocate_wrapper(u32 __user *argument, struct ump_session_data *session_data)
28 {
29 _ump_uk_allocate_s user_interaction;
30 _mali_osk_errcode_t err;
31
32 /* Sanity check input parameters */
33 if (NULL == argument || NULL == session_data) {
34 MSG_ERR(("NULL parameter in ump_ioctl_allocate()\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(&user_interaction, argument, sizeof(user_interaction))) {
40 MSG_ERR(("copy_from_user() in ump_ioctl_allocate()\n"));
41 return -EFAULT;
42 }
43
44 user_interaction.ctx = (void *) session_data;
45
46 err = _ump_ukk_allocate(&user_interaction);
47 if (_MALI_OSK_ERR_OK != err) {
48 DBG_MSG(1, ("_ump_ukk_allocate() failed in ump_ioctl_allocate()\n"));
49 return map_errcode(err);
50 }
51 user_interaction.ctx = NULL;
52
53 if (0 != copy_to_user(argument, &user_interaction, sizeof(user_interaction))) {
54 /* If the copy fails then we should release the memory. We can use the IOCTL release to accomplish this */
55 _ump_uk_release_s release_args;
56
57 MSG_ERR(("copy_to_user() failed in ump_ioctl_allocate()\n"));
58
59 release_args.ctx = (void *) session_data;
60 release_args.secure_id = user_interaction.secure_id;
61
62 err = _ump_ukk_release(&release_args);
63 if (_MALI_OSK_ERR_OK != err) {
64 MSG_ERR(("_ump_ukk_release() also failed when trying to release newly allocated memory in ump_ioctl_allocate()\n"));
65 }
66
67 return -EFAULT;
68 }
69
70 return 0; /* success */
71 }