Initial commit
[kernel/linux-3.0.git] / drivers / gpu / vithar_rev0 / uk / src / ukk / mali_ukk.c
1 /*
2  *
3  * (C) COPYRIGHT 2010-2011 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7  * 
8  * A copy of the licence is included with the program, and can also be obtained from Free Software
9  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
10  * 
11  */
12
13
14
15 #include <osk/mali_osk.h>
16 #include <uk/mali_ukk.h>
17 #include <plat/mali_ukk_os.h>
18
19 /* following OS specific includes can be removed when osk functions are implemented */
20 #if 0
21 #include <linux/module.h>       /* Kernel module definitions */
22 #include <linux/kernel.h>       /* Needed for KERN_INFO */
23 #endif
24
25 mali_error ukk_start(void)
26 {
27         return MALI_ERROR_NONE;
28 }
29
30 void ukk_stop(void)
31 {
32 }
33
34 void ukk_call_prepare(ukk_call_context * const ukk_ctx, ukk_session * const session, void * const thread_ctx)
35 {
36         OSK_ASSERT(NULL != ukk_ctx);
37         OSK_ASSERT(NULL != session);
38         /* NULL thread_ctx parameter is allowed */
39
40         ukk_ctx->ukk_session = session;
41         ukk_ctx->thread_ctx = thread_ctx;
42         ukk_ctx->data = 0;
43 }
44
45 void *ukk_session_get(ukk_call_context * const ukk_ctx)
46 {
47         OSK_ASSERT(NULL != ukk_ctx);
48         return ukk_ctx->ukk_session;
49 }
50
51 void ukk_call_data_set(ukk_call_context * const ukk_ctx, uintptr_t data)
52 {
53         OSK_ASSERT(NULL != ukk_ctx);
54         ukk_ctx->data = data;
55 }
56
57 uintptr_t ukk_call_data_get(ukk_call_context * const ukk_ctx)
58 {
59         OSK_ASSERT(NULL != ukk_ctx);
60         return ukk_ctx->data;
61 }
62
63 void *ukk_thread_ctx_get(ukk_call_context * const ukk_ctx)
64 {
65         OSK_ASSERT(NULL != ukk_ctx);
66         return ukk_ctx->thread_ctx;
67 }
68
69 static mali_error ukkp_dispatch_call(ukk_call_context *ukk_ctx, void *args, u32 args_size)
70 {
71         uk_header *header = (uk_header *)args;
72         mali_error ret = MALI_ERROR_NONE;
73
74         if(UKP_FUNC_ID_CHECK_VERSION == header->id)
75         {
76                 if (args_size == sizeof(uku_version_check_args))
77                 {
78                         ukk_session *ukk_session = ukk_session_get(ukk_ctx);
79                         uku_version_check_args *version_check = (uku_version_check_args *)args;
80
81                         version_check->major = ukk_session->version_major;
82                         version_check->minor = ukk_session->version_minor;
83                         header->ret = MALI_ERROR_NONE;
84                 }
85                 else
86                 {
87                         header->ret = MALI_ERROR_FUNCTION_FAILED;
88                 }
89         }
90         else
91         {
92                 ret = MALI_ERROR_FUNCTION_FAILED; /* not handled */
93         }
94         return ret;
95 }
96
97 mali_error ukk_dispatch(ukk_call_context * const ukk_ctx, void * const args, u32 args_size)
98 {
99         mali_error ret;
100         uk_header *header = (uk_header *)args;
101
102         OSK_ASSERT(NULL != ukk_ctx);
103         OSK_ASSERT(NULL != args);
104
105         /* Verify args_size both in debug and release builds */ 
106         OSK_ASSERT(args_size >= sizeof(uk_header));
107         if (args_size < sizeof(uk_header)) return MALI_ERROR_FUNCTION_FAILED;
108
109         if (header->id >= UK_FUNC_ID)
110         {
111                 ret = ukk_ctx->ukk_session->dispatch(ukk_ctx, args, args_size);
112         }
113         else
114         {
115                 ret = ukkp_dispatch_call(ukk_ctx, args, args_size);
116         }
117         return ret;
118 }