MALI: midgard: RK: add separate src dir of Midgard driver for RK Linux device
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard_for_linux / mali_kbase_smc.c
1 /*
2  *
3  * (C) COPYRIGHT 2015 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 #ifdef CONFIG_ARM64
19
20 #include <mali_kbase.h>
21 #include <mali_kbase_smc.h>
22
23 #include <linux/compiler.h>
24
25 static noinline u64 invoke_smc_fid(u64 function_id,
26                 u64 arg0, u64 arg1, u64 arg2)
27 {
28         register u64 x0 asm("x0") = function_id;
29         register u64 x1 asm("x1") = arg0;
30         register u64 x2 asm("x2") = arg1;
31         register u64 x3 asm("x3") = arg2;
32
33         asm volatile(
34                         __asmeq("%0", "x0")
35                         __asmeq("%1", "x1")
36                         __asmeq("%2", "x2")
37                         __asmeq("%3", "x3")
38                         "smc    #0\n"
39                         : "+r" (x0)
40                         : "r" (x1), "r" (x2), "r" (x3));
41
42         return x0;
43 }
44
45 u64 kbase_invoke_smc_fid(u32 fid, u64 arg0, u64 arg1, u64 arg2)
46 {
47         /* Is fast call (bit 31 set) */
48         KBASE_DEBUG_ASSERT(fid & ~SMC_FAST_CALL);
49         /* bits 16-23 must be zero for fast calls */
50         KBASE_DEBUG_ASSERT((fid & (0xFF << 16)) == 0);
51
52         return invoke_smc_fid(fid, arg0, arg1, arg2);
53 }
54
55 u64 kbase_invoke_smc(u32 oen, u16 function_number, bool smc64,
56                 u64 arg0, u64 arg1, u64 arg2)
57 {
58         u32 fid = 0;
59
60         /* Only the six bits allowed should be used. */
61         KBASE_DEBUG_ASSERT((oen & ~SMC_OEN_MASK) == 0);
62
63         fid |= SMC_FAST_CALL; /* Bit 31: Fast call */
64         if (smc64)
65                 fid |= SMC_64; /* Bit 30: 1=SMC64, 0=SMC32 */
66         fid |= oen; /* Bit 29:24: OEN */
67         /* Bit 23:16: Must be zero for fast calls */
68         fid |= (function_number); /* Bit 15:0: function number */
69
70         return kbase_invoke_smc_fid(fid, arg0, arg1, arg2);
71 }
72
73 #endif /* CONFIG_ARM64 */
74