tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_ukk_soft_job.c
1 /*
2  * Copyright (C) 2010-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
11 #include <linux/fs.h>       /* file system operations */
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
20 #include "mali_soft_job.h"
21 #include "mali_timeline.h"
22
23 int soft_job_start_wrapper(struct mali_session_data *session, _mali_uk_soft_job_start_s __user *uargs)
24 {
25         u32 type, user_job, point;
26         _mali_uk_fence_t uk_fence;
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 != get_user(type, &uargs->type))                 return -EFAULT;
40         if (0 != get_user(user_job, &uargs->user_job))         return -EFAULT;
41         if (0 != get_user(job_id_ptr, &uargs->job_id_ptr))     return -EFAULT;
42
43         if (0 != copy_from_user(&uk_fence, &uargs->fence, sizeof(_mali_uk_fence_t))) return -EFAULT;
44         mali_timeline_fence_copy_uk_fence(&fence, &uk_fence);
45
46         if (MALI_SOFT_JOB_TYPE_USER_SIGNALED < type) {
47                 MALI_DEBUG_PRINT_ERROR(("Invalid soft job type specified\n"));
48                 return -EINVAL;
49         }
50
51         /* Create soft job. */
52         job = mali_soft_job_create(session->soft_job_system, (enum mali_soft_job_type)type, user_job);
53         if (unlikely(NULL == job)) {
54                 return map_errcode(_MALI_OSK_ERR_NOMEM);
55         }
56
57         /* Write job id back to user space. */
58         if (0 != put_user(job->id, job_id_ptr)) {
59                 MALI_PRINT_ERROR(("Mali Soft Job: failed to put job id"));
60                 mali_soft_job_destroy(job);
61                 return map_errcode(_MALI_OSK_ERR_NOMEM);
62         }
63
64         /* Start soft job. */
65         point = mali_soft_job_start(job, &fence);
66
67         if (0 != put_user(point, &uargs->point)) {
68                 /* Let user space know that something failed after the job was started. */
69                 return -ENOENT;
70         }
71
72         return 0;
73 }
74
75 int soft_job_signal_wrapper(struct mali_session_data *session, _mali_uk_soft_job_signal_s __user *uargs)
76 {
77         u32 job_id;
78         _mali_osk_errcode_t err;
79
80         MALI_DEBUG_ASSERT_POINTER(session);
81
82         if (0 != get_user(job_id, &uargs->job_id)) return -EFAULT;
83
84         err = mali_soft_job_system_signal_job(session->soft_job_system, job_id);
85
86         return map_errcode(err);
87 }