blob: 021511e0d1488e6ca58b0b1e099caab7e3da3d2e [file] [log] [blame]
developer65014b82015-04-13 14:47:57 +08001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#include <assert.h>
developer14f3fe32016-04-28 14:07:42 +080031#include <console.h>
developer65014b82015-04-13 14:47:57 +080032#include <debug.h>
developer14f3fe32016-04-28 14:07:42 +080033#include <mmio.h>
34#include <mtk_plat_common.h>
developer65014b82015-04-13 14:47:57 +080035#include <mtk_sip_svc.h>
developer73b982f2016-05-11 18:04:09 +080036#include <plat_sip_calls.h>
developer65014b82015-04-13 14:47:57 +080037#include <runtime_svc.h>
38#include <uuid.h>
39
40/* Mediatek SiP Service UUID */
41DEFINE_SVC_UUID(mtk_sip_svc_uid,
42 0xf7582ba4, 0x4262, 0x4d7d, 0x80, 0xe5,
43 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d);
44
developer14f3fe32016-04-28 14:07:42 +080045#pragma weak mediatek_plat_sip_handler
46uint64_t mediatek_plat_sip_handler(uint32_t smc_fid,
47 uint64_t x1,
48 uint64_t x2,
49 uint64_t x3,
50 uint64_t x4,
51 void *cookie,
52 void *handle,
53 uint64_t flags)
54{
55 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
56 SMC_RET1(handle, SMC_UNK);
57}
58
developer65014b82015-04-13 14:47:57 +080059/*
60 * This function handles Mediatek defined SiP Calls */
developer14f3fe32016-04-28 14:07:42 +080061uint64_t mediatek_sip_handler(uint32_t smc_fid,
62 uint64_t x1,
63 uint64_t x2,
64 uint64_t x3,
65 uint64_t x4,
66 void *cookie,
67 void *handle,
68 uint64_t flags)
developer65014b82015-04-13 14:47:57 +080069{
developer14f3fe32016-04-28 14:07:42 +080070 uint32_t ns;
developerb8925a22015-11-16 14:38:40 +080071
developer14f3fe32016-04-28 14:07:42 +080072 /* if parameter is sent from SMC32. Clean top 32 bits */
73 clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4);
developerb8925a22015-11-16 14:38:40 +080074
developer14f3fe32016-04-28 14:07:42 +080075 /* Determine which security state this SMC originated from */
76 ns = is_caller_non_secure(flags);
77 if (!ns) {
78 /* SiP SMC service secure world's call */
79 ;
80 } else {
81 /* SiP SMC service normal world's call */
82 switch (smc_fid) {
83#if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE
84 case MTK_SIP_SET_AUTHORIZED_SECURE_REG: {
85 /* only use ret here */
86 uint64_t ret;
developerb8925a22015-11-16 14:38:40 +080087
developer14f3fe32016-04-28 14:07:42 +080088 ret = mt_sip_set_authorized_sreg((uint32_t)x1,
89 (uint32_t)x2);
90 SMC_RET1(handle, ret);
91 }
92#endif
93#if MTK_SIP_KERNEL_BOOT_ENABLE
94 case MTK_SIP_KERNEL_BOOT_AARCH32:
95 boot_to_kernel(x1, x2, x3, x4);
96 SMC_RET0(handle);
97#endif
98 }
developer65014b82015-04-13 14:47:57 +080099 }
100
developer14f3fe32016-04-28 14:07:42 +0800101 return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4,
102 cookie, handle, flags);
103
developer65014b82015-04-13 14:47:57 +0800104}
105
106/*
107 * This function is responsible for handling all SiP calls from the NS world
108 */
109uint64_t sip_smc_handler(uint32_t smc_fid,
110 uint64_t x1,
111 uint64_t x2,
112 uint64_t x3,
113 uint64_t x4,
114 void *cookie,
115 void *handle,
116 uint64_t flags)
117{
developer65014b82015-04-13 14:47:57 +0800118 switch (smc_fid) {
119 case SIP_SVC_CALL_COUNT:
120 /* Return the number of Mediatek SiP Service Calls. */
developer73b982f2016-05-11 18:04:09 +0800121 SMC_RET1(handle,
122 MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS);
developer65014b82015-04-13 14:47:57 +0800123
124 case SIP_SVC_UID:
125 /* Return UID to the caller */
126 SMC_UUID_RET(handle, mtk_sip_svc_uid);
127
128 case SIP_SVC_VERSION:
129 /* Return the version of current implementation */
130 SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR,
131 MTK_SIP_SVC_VERSION_MINOR);
132
133 default:
134 return mediatek_sip_handler(smc_fid, x1, x2, x3, x4,
developer14f3fe32016-04-28 14:07:42 +0800135 cookie, handle, flags);
developer65014b82015-04-13 14:47:57 +0800136 }
137}
138
139/* Define a runtime service descriptor for fast SMC calls */
140DECLARE_RT_SVC(
141 mediatek_sip_svc,
142 OEN_SIP_START,
143 OEN_SIP_END,
144 SMC_TYPE_FAST,
145 NULL,
146 sip_smc_handler
147);