tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_ukk_timeline.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_timeline.h"
21 #include "mali_timeline_fence_wait.h"
22 #include "mali_timeline_sync_fence.h"
23
24 int timeline_get_latest_point_wrapper(struct mali_session_data *session, _mali_uk_timeline_get_latest_point_s __user *uargs)
25 {
26         u32 val;
27         mali_timeline_id timeline;
28         mali_timeline_point point;
29
30         MALI_DEBUG_ASSERT_POINTER(session);
31
32         if (0 != get_user(val, &uargs->timeline)) return -EFAULT;
33
34         if (MALI_UK_TIMELINE_MAX <= val) {
35                 return -EINVAL;
36         }
37
38         timeline = (mali_timeline_id)val;
39
40         point = mali_timeline_system_get_latest_point(session->timeline_system, timeline);
41
42         if (0 != put_user(point, &uargs->point)) return -EFAULT;
43
44         return 0;
45 }
46
47 int timeline_wait_wrapper(struct mali_session_data *session, _mali_uk_timeline_wait_s __user *uargs)
48 {
49         u32 timeout, status;
50         mali_bool ret;
51         _mali_uk_fence_t uk_fence;
52         struct mali_timeline_fence fence;
53
54         MALI_DEBUG_ASSERT_POINTER(session);
55
56         if (0 != copy_from_user(&uk_fence, &uargs->fence, sizeof(_mali_uk_fence_t))) return -EFAULT;
57         if (0 != get_user(timeout, &uargs->timeout)) return -EFAULT;
58
59         mali_timeline_fence_copy_uk_fence(&fence, &uk_fence);
60
61         ret = mali_timeline_fence_wait(session->timeline_system, &fence, timeout);
62         status = (MALI_TRUE == ret ? 1 : 0);
63
64         if (0 != put_user(status, &uargs->status)) return -EFAULT;
65
66         return 0;
67 }
68
69 int timeline_create_sync_fence_wrapper(struct mali_session_data *session, _mali_uk_timeline_create_sync_fence_s __user *uargs)
70 {
71         s32 sync_fd = -1;
72         _mali_uk_fence_t uk_fence;
73         struct mali_timeline_fence fence;
74
75         MALI_DEBUG_ASSERT_POINTER(session);
76
77         if (0 != copy_from_user(&uk_fence, &uargs->fence, sizeof(_mali_uk_fence_t))) return -EFAULT;
78         mali_timeline_fence_copy_uk_fence(&fence, &uk_fence);
79
80 #if defined(CONFIG_SYNC)
81         sync_fd = mali_timeline_sync_fence_create(session->timeline_system, &fence);
82 #else
83         sync_fd = -1;
84 #endif /* defined(CONFIG_SYNC) */
85
86         if (0 != put_user(sync_fd, &uargs->sync_fd)) return -EFAULT;
87
88         return 0;
89 }