blob: 1e5423db7d1b13af66696a3619506c72d0a73cd9 [file] [log] [blame]
Varun Wadekar7a269e22015-06-10 14:04:32 +05301/*
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -08002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Varun Wadekar7a269e22015-06-10 14:04:32 +05303 *
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
Varun Wadekar0f3baa02015-07-16 11:36:33 +053031#include <arch.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053032#include <arch_helpers.h>
33#include <assert.h>
34#include <bl_common.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053035#include <debug.h>
36#include <errno.h>
37#include <memctrl.h>
38#include <runtime_svc.h>
39#include <tegra_private.h>
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080040#include <tegra_platform.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053041
Varun Wadekar0f3baa02015-07-16 11:36:33 +053042/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080043 * Common Tegra SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053044 ******************************************************************************/
Varun Wadekar7a269e22015-06-10 14:04:32 +053045#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003
Varun Wadekardc799302015-12-28 16:36:42 -080046#define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005
47#define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080048#define TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND 0xC2000007
Varun Wadekar7a269e22015-06-10 14:04:32 +053049
50/*******************************************************************************
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080051 * Fake system suspend mode control var
52 ******************************************************************************/
53extern uint8_t tegra_fake_system_suspend;
54
55
56/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080057 * SoC specific SiP handler
58 ******************************************************************************/
59#pragma weak plat_sip_handler
60int plat_sip_handler(uint32_t smc_fid,
61 uint64_t x1,
62 uint64_t x2,
63 uint64_t x3,
64 uint64_t x4,
65 void *cookie,
66 void *handle,
67 uint64_t flags)
68{
69 return -ENOTSUP;
70}
71
72/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070073 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053074 ******************************************************************************/
Varun Wadekar923d04a2015-12-09 18:18:53 -080075uint64_t tegra_sip_handler(uint32_t smc_fid,
Varun Wadekar7a269e22015-06-10 14:04:32 +053076 uint64_t x1,
77 uint64_t x2,
78 uint64_t x3,
79 uint64_t x4,
80 void *cookie,
81 void *handle,
82 uint64_t flags)
83{
Varun Wadekar7a269e22015-06-10 14:04:32 +053084 int err;
85
Varun Wadekar923d04a2015-12-09 18:18:53 -080086 /* Check if this is a SoC specific SiP */
87 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
88 if (err == 0)
Varun Wadekar14f39572017-04-17 11:54:33 -070089 SMC_RET1(handle, (uint64_t)err);
Varun Wadekar923d04a2015-12-09 18:18:53 -080090
Varun Wadekar7a269e22015-06-10 14:04:32 +053091 switch (smc_fid) {
92
93 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
94
Varun Wadekar0f3baa02015-07-16 11:36:33 +053095 /* clean up the high bits */
Varun Wadekar0f3baa02015-07-16 11:36:33 +053096 x2 = (uint32_t)x2;
97
Varun Wadekar7a269e22015-06-10 14:04:32 +053098 /*
99 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
100 * or falls outside of the valid DRAM range
101 */
102 err = bl31_check_ns_address(x1, x2);
103 if (err)
104 SMC_RET1(handle, err);
105
106 /*
107 * Check if Video Memory is aligned to 1MB.
108 */
109 if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) {
110 ERROR("Unaligned Video Memory base address!\n");
111 SMC_RET1(handle, -ENOTSUP);
112 }
113
114 /* new video memory carveout settings */
115 tegra_memctrl_videomem_setup(x1, x2);
116
117 SMC_RET1(handle, 0);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530118 break;
Varun Wadekar7a269e22015-06-10 14:04:32 +0530119
Varun Wadekardc799302015-12-28 16:36:42 -0800120 /*
121 * The NS world registers the address of its handler to be
122 * used for processing the FIQ. This is normally used by the
123 * NS FIQ debugger driver to detect system hangs by programming
124 * a watchdog timer to fire a FIQ interrupt.
125 */
126 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
127
128 if (!x1)
129 SMC_RET1(handle, SMC_UNK);
130
131 /*
132 * TODO: Check if x1 contains a valid DRAM address
133 */
134
135 /* store the NS world's entrypoint */
136 tegra_fiq_set_ns_entrypoint(x1);
137
138 SMC_RET1(handle, 0);
139 break;
140
141 /*
142 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
143 * CPU context when the FIQ interrupt was triggered. This allows the
144 * NS world to understand the CPU state when the watchdog interrupt
145 * triggered.
146 */
147 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
148
149 /* retrieve context registers when FIQ triggered */
150 tegra_fiq_get_intr_context();
151
152 SMC_RET0(handle);
153 break;
154
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800155 case TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND:
156 /*
157 * System suspend fake mode is set if we are on VDK and we make
158 * a debug SIP call. This mode ensures that we excercise debug
159 * path instead of the regular code path to suit the pre-silicon
160 * platform needs. These include replacing the call to WFI by
161 * a warm reset request.
162 */
163 if (tegra_platform_is_emulation() != 0U) {
164
165 tegra_fake_system_suspend = 1;
166 SMC_RET1(handle, 0);
167 }
168
169 /*
170 * We return to the external world as if this SIP is not
171 * implemented in case, we are not running on VDK.
172 */
173 break;
174
Varun Wadekar7a269e22015-06-10 14:04:32 +0530175 default:
176 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
177 break;
178 }
179
180 SMC_RET1(handle, SMC_UNK);
181}
182
183/* Define a runtime service descriptor for fast SMC calls */
184DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800185 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530186
187 OEN_SIP_START,
188 OEN_SIP_END,
189 SMC_TYPE_FAST,
190 NULL,
Varun Wadekar923d04a2015-12-09 18:18:53 -0800191 tegra_sip_handler
Varun Wadekar7a269e22015-06-10 14:04:32 +0530192);