mali mess
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / mali / linux / mali_ukk_soft_job.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 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 #include <linux/fs.h> /* file system operations */
11 #include <asm/uaccess.h> /* user space access */
12
13 #include "mali_ukk.h"
14 #include "mali_osk.h"
15 #include "mali_kernel_common.h"
16 #include "mali_session.h"
17 #include "mali_ukk_wrappers.h"
18
19 #include "mali_soft_job.h"
20 #include "mali_timeline.h"
21
22 int soft_job_start_wrapper(struct mali_session_data *session, _mali_uk_soft_job_start_s __user *uargs)
23 {
24 _mali_uk_soft_job_start_s kargs;
25 u32 type, point;
26 u64 user_job;
27 struct mali_timeline_fence fence;
28 struct mali_soft_job *job = NULL;
29 u32 __user *job_id_ptr = NULL;
30
31 /* If the job was started successfully, 0 is returned. If there was an error, but the job
32 * was started, we return -ENOENT. For anything else returned, the job was not started. */
33
34 MALI_CHECK_NON_NULL(uargs, -EINVAL);
35 MALI_CHECK_NON_NULL(session, -EINVAL);
36
37 MALI_DEBUG_ASSERT_POINTER(session->soft_job_system);
38
39 if (0 != copy_from_user(&kargs, uargs, sizeof(kargs))) {
40 return -EFAULT;
41 }
42
43 type = kargs.type;
44 user_job = kargs.user_job;
45 job_id_ptr = (u32 __user *)(uintptr_t)kargs.job_id_ptr;
46
47 mali_timeline_fence_copy_uk_fence(&fence, &kargs.fence);
48
49 if ((MALI_SOFT_JOB_TYPE_USER_SIGNALED != type) && (MALI_SOFT_JOB_TYPE_SELF_SIGNALED != type)) {
50 MALI_DEBUG_PRINT_ERROR(("Invalid soft job type specified\n"));
51 return -EINVAL;
52 }
53
54 /* Create soft job. */
55 job = mali_soft_job_create(session->soft_job_system, (enum mali_soft_job_type)type, user_job);
56 if (unlikely(NULL == job)) {
57 return map_errcode(_MALI_OSK_ERR_NOMEM);
58 }
59
60 /* Write job id back to user space. */
61 if (0 != put_user(job->id, job_id_ptr)) {
62 MALI_PRINT_ERROR(("Mali Soft Job: failed to put job id"));
63 mali_soft_job_destroy(job);
64 return map_errcode(_MALI_OSK_ERR_NOMEM);
65 }
66
67 /* Start soft job. */
68 point = mali_soft_job_start(job, &fence);
69
70 if (0 != put_user(point, &uargs->point)) {
71 /* Let user space know that something failed after the job was started. */
72 return -ENOENT;
73 }
74
75 return 0;
76 }
77
78 int soft_job_signal_wrapper(struct mali_session_data *session, _mali_uk_soft_job_signal_s __user *uargs)
79 {
80 u32 job_id;
81 _mali_osk_errcode_t err;
82
83 MALI_DEBUG_ASSERT_POINTER(session);
84
85 if (0 != get_user(job_id, &uargs->job_id)) return -EFAULT;
86
87 err = mali_soft_job_system_signal_job(session->soft_job_system, job_id);
88
89 return map_errcode(err);
90 }