blob: a8184531f7b7c68b4670a7ef357cc782daef8fcf [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 Wadekar0f3baa02015-07-16 11:36:33 +05307#include <arch.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +05308#include <arch_helpers.h>
9#include <assert.h>
10#include <bl_common.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053011#include <debug.h>
12#include <errno.h>
13#include <memctrl.h>
Varun Wadekara59a7c52017-04-26 08:31:50 -070014#include <mmio.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053015#include <runtime_svc.h>
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080016#include <tegra_platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010017#include <tegra_private.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053018
Varun Wadekar0f3baa02015-07-16 11:36:33 +053019/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080020 * Common Tegra SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053021 ******************************************************************************/
Varun Wadekar7a269e22015-06-10 14:04:32 +053022#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003
Varun Wadekardc799302015-12-28 16:36:42 -080023#define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005
24#define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080025#define TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND 0xC2000007
Varun Wadekar7a269e22015-06-10 14:04:32 +053026
27/*******************************************************************************
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080028 * Fake system suspend mode control var
29 ******************************************************************************/
30extern uint8_t tegra_fake_system_suspend;
31
32
33/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080034 * SoC specific SiP handler
35 ******************************************************************************/
36#pragma weak plat_sip_handler
37int plat_sip_handler(uint32_t smc_fid,
38 uint64_t x1,
39 uint64_t x2,
40 uint64_t x3,
41 uint64_t x4,
42 void *cookie,
43 void *handle,
44 uint64_t flags)
45{
46 return -ENOTSUP;
47}
48
49/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070050 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053051 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090052uintptr_t tegra_sip_handler(uint32_t smc_fid,
53 u_register_t x1,
54 u_register_t x2,
55 u_register_t x3,
56 u_register_t x4,
57 void *cookie,
58 void *handle,
59 u_register_t flags)
Varun Wadekar7a269e22015-06-10 14:04:32 +053060{
Varun Wadekara59a7c52017-04-26 08:31:50 -070061 uint32_t regval;
Varun Wadekar7a269e22015-06-10 14:04:32 +053062 int err;
63
Varun Wadekar923d04a2015-12-09 18:18:53 -080064 /* Check if this is a SoC specific SiP */
65 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
66 if (err == 0)
Varun Wadekar14f39572017-04-17 11:54:33 -070067 SMC_RET1(handle, (uint64_t)err);
Varun Wadekar923d04a2015-12-09 18:18:53 -080068
Varun Wadekar7a269e22015-06-10 14:04:32 +053069 switch (smc_fid) {
70
71 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
72
Varun Wadekar0f3baa02015-07-16 11:36:33 +053073 /* clean up the high bits */
Varun Wadekar0f3baa02015-07-16 11:36:33 +053074 x2 = (uint32_t)x2;
75
Varun Wadekar7a269e22015-06-10 14:04:32 +053076 /*
77 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
78 * or falls outside of the valid DRAM range
79 */
80 err = bl31_check_ns_address(x1, x2);
81 if (err)
82 SMC_RET1(handle, err);
83
84 /*
85 * Check if Video Memory is aligned to 1MB.
86 */
87 if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) {
88 ERROR("Unaligned Video Memory base address!\n");
89 SMC_RET1(handle, -ENOTSUP);
90 }
91
Varun Wadekara59a7c52017-04-26 08:31:50 -070092 /*
93 * The GPU is the user of the Video Memory region. In order to
94 * transition to the new memory region smoothly, we program the
95 * new base/size ONLY if the GPU is in reset mode.
96 */
97 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
98 TEGRA_GPU_RESET_REG_OFFSET);
99 if ((regval & GPU_RESET_BIT) == 0U) {
100 ERROR("GPU not in reset! Video Memory setup failed\n");
101 SMC_RET1(handle, -ENOTSUP);
102 }
103
Varun Wadekar7a269e22015-06-10 14:04:32 +0530104 /* new video memory carveout settings */
105 tegra_memctrl_videomem_setup(x1, x2);
106
107 SMC_RET1(handle, 0);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530108 break;
Varun Wadekar7a269e22015-06-10 14:04:32 +0530109
Varun Wadekardc799302015-12-28 16:36:42 -0800110 /*
111 * The NS world registers the address of its handler to be
112 * used for processing the FIQ. This is normally used by the
113 * NS FIQ debugger driver to detect system hangs by programming
114 * a watchdog timer to fire a FIQ interrupt.
115 */
116 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
117
118 if (!x1)
119 SMC_RET1(handle, SMC_UNK);
120
121 /*
122 * TODO: Check if x1 contains a valid DRAM address
123 */
124
125 /* store the NS world's entrypoint */
126 tegra_fiq_set_ns_entrypoint(x1);
127
128 SMC_RET1(handle, 0);
129 break;
130
131 /*
132 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
133 * CPU context when the FIQ interrupt was triggered. This allows the
134 * NS world to understand the CPU state when the watchdog interrupt
135 * triggered.
136 */
137 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
138
139 /* retrieve context registers when FIQ triggered */
140 tegra_fiq_get_intr_context();
141
142 SMC_RET0(handle);
143 break;
144
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800145 case TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND:
146 /*
147 * System suspend fake mode is set if we are on VDK and we make
148 * a debug SIP call. This mode ensures that we excercise debug
149 * path instead of the regular code path to suit the pre-silicon
150 * platform needs. These include replacing the call to WFI by
151 * a warm reset request.
152 */
153 if (tegra_platform_is_emulation() != 0U) {
154
155 tegra_fake_system_suspend = 1;
156 SMC_RET1(handle, 0);
157 }
158
159 /*
160 * We return to the external world as if this SIP is not
161 * implemented in case, we are not running on VDK.
162 */
163 break;
164
Varun Wadekar7a269e22015-06-10 14:04:32 +0530165 default:
166 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
167 break;
168 }
169
170 SMC_RET1(handle, SMC_UNK);
171}
172
173/* Define a runtime service descriptor for fast SMC calls */
174DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800175 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530176
177 OEN_SIP_START,
178 OEN_SIP_END,
179 SMC_TYPE_FAST,
180 NULL,
Varun Wadekar923d04a2015-12-09 18:18:53 -0800181 tegra_sip_handler
Varun Wadekar7a269e22015-06-10 14:04:32 +0530182);