blob: 2c3be60f76e545f2665aa00886156e18f0134d51 [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 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar7a269e22015-06-10 14:04:32 +05305 */
6
Varun Wadekar7a269e22015-06-10 14:04:32 +05307#include <assert.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +05308#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch.h>
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <common/runtime_svc.h>
15#include <lib/mmio.h>
16
Varun Wadekar7a269e22015-06-10 14:04:32 +053017#include <memctrl.h>
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080018#include <tegra_platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010019#include <tegra_private.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053020
Varun Wadekar0f3baa02015-07-16 11:36:33 +053021/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080022 * Common Tegra SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053023 ******************************************************************************/
Varun Wadekar7a269e22015-06-10 14:04:32 +053024#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003
Varun Wadekardc799302015-12-28 16:36:42 -080025#define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005
26#define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080027#define TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND 0xC2000007
Varun Wadekar7a269e22015-06-10 14:04:32 +053028
29/*******************************************************************************
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080030 * Fake system suspend mode control var
31 ******************************************************************************/
32extern uint8_t tegra_fake_system_suspend;
33
34
35/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080036 * SoC specific SiP handler
37 ******************************************************************************/
38#pragma weak plat_sip_handler
39int plat_sip_handler(uint32_t smc_fid,
40 uint64_t x1,
41 uint64_t x2,
42 uint64_t x3,
43 uint64_t x4,
Anthony Zhoue5bd3452017-03-01 12:47:37 +080044 const void *cookie,
Varun Wadekar923d04a2015-12-09 18:18:53 -080045 void *handle,
46 uint64_t flags)
47{
Anthony Zhoue5bd3452017-03-01 12:47:37 +080048 /* unused parameters */
49 (void)smc_fid;
50 (void)x1;
51 (void)x2;
52 (void)x3;
53 (void)x4;
54 (void)cookie;
55 (void)handle;
56 (void)flags;
57
Varun Wadekar923d04a2015-12-09 18:18:53 -080058 return -ENOTSUP;
59}
60
61/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070062 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053063 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090064uintptr_t tegra_sip_handler(uint32_t smc_fid,
65 u_register_t x1,
66 u_register_t x2,
67 u_register_t x3,
68 u_register_t x4,
69 void *cookie,
70 void *handle,
71 u_register_t flags)
Varun Wadekar7a269e22015-06-10 14:04:32 +053072{
Varun Wadekara59a7c52017-04-26 08:31:50 -070073 uint32_t regval;
Anthony Zhoue5bd3452017-03-01 12:47:37 +080074 int32_t err;
Varun Wadekar7a269e22015-06-10 14:04:32 +053075
Varun Wadekar923d04a2015-12-09 18:18:53 -080076 /* Check if this is a SoC specific SiP */
77 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
78 if (err == 0)
Varun Wadekar14f39572017-04-17 11:54:33 -070079 SMC_RET1(handle, (uint64_t)err);
Varun Wadekar923d04a2015-12-09 18:18:53 -080080
Varun Wadekar7a269e22015-06-10 14:04:32 +053081 switch (smc_fid) {
82
83 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
84
Varun Wadekar0f3baa02015-07-16 11:36:33 +053085 /* clean up the high bits */
Varun Wadekar0f3baa02015-07-16 11:36:33 +053086 x2 = (uint32_t)x2;
87
Varun Wadekar7a269e22015-06-10 14:04:32 +053088 /*
89 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
90 * or falls outside of the valid DRAM range
91 */
92 err = bl31_check_ns_address(x1, x2);
93 if (err)
94 SMC_RET1(handle, err);
95
96 /*
97 * Check if Video Memory is aligned to 1MB.
98 */
99 if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) {
100 ERROR("Unaligned Video Memory base address!\n");
101 SMC_RET1(handle, -ENOTSUP);
102 }
103
Varun Wadekara59a7c52017-04-26 08:31:50 -0700104 /*
105 * The GPU is the user of the Video Memory region. In order to
106 * transition to the new memory region smoothly, we program the
107 * new base/size ONLY if the GPU is in reset mode.
108 */
109 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
110 TEGRA_GPU_RESET_REG_OFFSET);
111 if ((regval & GPU_RESET_BIT) == 0U) {
112 ERROR("GPU not in reset! Video Memory setup failed\n");
113 SMC_RET1(handle, -ENOTSUP);
114 }
115
Varun Wadekar7a269e22015-06-10 14:04:32 +0530116 /* new video memory carveout settings */
117 tegra_memctrl_videomem_setup(x1, x2);
118
119 SMC_RET1(handle, 0);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530120 break;
Varun Wadekar7a269e22015-06-10 14:04:32 +0530121
Varun Wadekardc799302015-12-28 16:36:42 -0800122 /*
123 * The NS world registers the address of its handler to be
124 * used for processing the FIQ. This is normally used by the
125 * NS FIQ debugger driver to detect system hangs by programming
126 * a watchdog timer to fire a FIQ interrupt.
127 */
128 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
129
130 if (!x1)
131 SMC_RET1(handle, SMC_UNK);
132
133 /*
134 * TODO: Check if x1 contains a valid DRAM address
135 */
136
137 /* store the NS world's entrypoint */
138 tegra_fiq_set_ns_entrypoint(x1);
139
140 SMC_RET1(handle, 0);
141 break;
142
143 /*
144 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
145 * CPU context when the FIQ interrupt was triggered. This allows the
146 * NS world to understand the CPU state when the watchdog interrupt
147 * triggered.
148 */
149 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
150
151 /* retrieve context registers when FIQ triggered */
152 tegra_fiq_get_intr_context();
153
154 SMC_RET0(handle);
155 break;
156
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800157 case TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND:
158 /*
159 * System suspend fake mode is set if we are on VDK and we make
160 * a debug SIP call. This mode ensures that we excercise debug
161 * path instead of the regular code path to suit the pre-silicon
162 * platform needs. These include replacing the call to WFI by
163 * a warm reset request.
164 */
165 if (tegra_platform_is_emulation() != 0U) {
166
167 tegra_fake_system_suspend = 1;
168 SMC_RET1(handle, 0);
169 }
170
171 /*
172 * We return to the external world as if this SIP is not
173 * implemented in case, we are not running on VDK.
174 */
175 break;
176
Varun Wadekar7a269e22015-06-10 14:04:32 +0530177 default:
178 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
179 break;
180 }
181
182 SMC_RET1(handle, SMC_UNK);
183}
184
185/* Define a runtime service descriptor for fast SMC calls */
186DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800187 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530188
Anthony Zhoue5bd3452017-03-01 12:47:37 +0800189 (OEN_SIP_START),
190 (OEN_SIP_END),
191 (SMC_TYPE_FAST),
192 (NULL),
193 (tegra_sip_handler)
Varun Wadekar7a269e22015-06-10 14:04:32 +0530194);