blob: b8ba09562a94edf66be86f988a25aefa9db42bdd [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
Varun Wadekar7a269e22015-06-10 14:04:32 +053027
28/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080029 * SoC specific SiP handler
30 ******************************************************************************/
31#pragma weak plat_sip_handler
Anthony Zhou035f24b2017-03-01 12:47:37 +080032int32_t plat_sip_handler(uint32_t smc_fid,
Varun Wadekar923d04a2015-12-09 18:18:53 -080033 uint64_t x1,
34 uint64_t x2,
35 uint64_t x3,
36 uint64_t x4,
Anthony Zhoue5bd3452017-03-01 12:47:37 +080037 const void *cookie,
Varun Wadekar923d04a2015-12-09 18:18:53 -080038 void *handle,
39 uint64_t flags)
40{
Anthony Zhoue5bd3452017-03-01 12:47:37 +080041 /* unused parameters */
42 (void)smc_fid;
43 (void)x1;
44 (void)x2;
45 (void)x3;
46 (void)x4;
47 (void)cookie;
48 (void)handle;
49 (void)flags;
50
Varun Wadekar923d04a2015-12-09 18:18:53 -080051 return -ENOTSUP;
52}
53
54/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070055 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053056 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090057uintptr_t tegra_sip_handler(uint32_t smc_fid,
58 u_register_t x1,
59 u_register_t x2,
60 u_register_t x3,
61 u_register_t x4,
62 void *cookie,
63 void *handle,
64 u_register_t flags)
Varun Wadekar7a269e22015-06-10 14:04:32 +053065{
Anthony Zhou4408e882017-07-07 14:29:51 +080066 uint32_t regval, local_x2_32 = (uint32_t)x2;
Anthony Zhoue5bd3452017-03-01 12:47:37 +080067 int32_t err;
Varun Wadekar7a269e22015-06-10 14:04:32 +053068
Varun Wadekar923d04a2015-12-09 18:18:53 -080069 /* Check if this is a SoC specific SiP */
70 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
Anthony Zhou035f24b2017-03-01 12:47:37 +080071 if (err == 0) {
72
Varun Wadekar14f39572017-04-17 11:54:33 -070073 SMC_RET1(handle, (uint64_t)err);
Varun Wadekar923d04a2015-12-09 18:18:53 -080074
Anthony Zhou035f24b2017-03-01 12:47:37 +080075 } else {
Varun Wadekar7a269e22015-06-10 14:04:32 +053076
Anthony Zhou035f24b2017-03-01 12:47:37 +080077 switch (smc_fid) {
Varun Wadekar7a269e22015-06-10 14:04:32 +053078
Anthony Zhou035f24b2017-03-01 12:47:37 +080079 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
Varun Wadekar0f3baa02015-07-16 11:36:33 +053080
Anthony Zhou035f24b2017-03-01 12:47:37 +080081 /*
82 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
83 * or falls outside of the valid DRAM range
84 */
Anthony Zhou4408e882017-07-07 14:29:51 +080085 err = bl31_check_ns_address(x1, local_x2_32);
Anthony Zhou035f24b2017-03-01 12:47:37 +080086 if (err != 0) {
87 SMC_RET1(handle, (uint64_t)err);
88 }
Varun Wadekara59a7c52017-04-26 08:31:50 -070089
Anthony Zhou035f24b2017-03-01 12:47:37 +080090 /*
91 * Check if Video Memory is aligned to 1MB.
92 */
Anthony Zhou4408e882017-07-07 14:29:51 +080093 if (((x1 & 0xFFFFFU) != 0U) || ((local_x2_32 & 0xFFFFFU) != 0U)) {
Anthony Zhou035f24b2017-03-01 12:47:37 +080094 ERROR("Unaligned Video Memory base address!\n");
Anthony Zhou0e07e452017-07-26 17:16:54 +080095 SMC_RET1(handle, (uint64_t)-ENOTSUP);
Anthony Zhou035f24b2017-03-01 12:47:37 +080096 }
Varun Wadekar7a269e22015-06-10 14:04:32 +053097
Anthony Zhou035f24b2017-03-01 12:47:37 +080098 /*
99 * The GPU is the user of the Video Memory region. In order to
100 * transition to the new memory region smoothly, we program the
101 * new base/size ONLY if the GPU is in reset mode.
102 */
103 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
104 TEGRA_GPU_RESET_REG_OFFSET);
Anthony Zhou0e07e452017-07-26 17:16:54 +0800105 if ((regval & GPU_RESET_BIT) == 0U) {
Anthony Zhou035f24b2017-03-01 12:47:37 +0800106 ERROR("GPU not in reset! Video Memory setup failed\n");
Anthony Zhou0e07e452017-07-26 17:16:54 +0800107 SMC_RET1(handle, (uint64_t)-ENOTSUP);
Anthony Zhou035f24b2017-03-01 12:47:37 +0800108 }
Varun Wadekar7a269e22015-06-10 14:04:32 +0530109
Anthony Zhou035f24b2017-03-01 12:47:37 +0800110 /* new video memory carveout settings */
Anthony Zhou4408e882017-07-07 14:29:51 +0800111 tegra_memctrl_videomem_setup(x1, local_x2_32);
Varun Wadekardc799302015-12-28 16:36:42 -0800112
Jeetesh Burman48fef882018-01-22 15:40:08 +0530113 /*
114 * Ensure again that GPU is still in reset after VPR resize
115 */
116 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
117 TEGRA_GPU_RESET_REG_OFFSET);
118 if ((regval & GPU_RESET_BIT) == 0U) {
119 mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_GPU_SET_OFFSET,
120 GPU_SET_BIT);
121 }
122
Anthony Zhou035f24b2017-03-01 12:47:37 +0800123 SMC_RET1(handle, 0);
Varun Wadekardc799302015-12-28 16:36:42 -0800124
125 /*
Anthony Zhou035f24b2017-03-01 12:47:37 +0800126 * The NS world registers the address of its handler to be
127 * used for processing the FIQ. This is normally used by the
128 * NS FIQ debugger driver to detect system hangs by programming
129 * a watchdog timer to fire a FIQ interrupt.
Varun Wadekardc799302015-12-28 16:36:42 -0800130 */
Anthony Zhou035f24b2017-03-01 12:47:37 +0800131 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
Varun Wadekardc799302015-12-28 16:36:42 -0800132
Anthony Zhou035f24b2017-03-01 12:47:37 +0800133 if (x1 == 0U) {
134 SMC_RET1(handle, SMC_UNK);
135 }
Varun Wadekardc799302015-12-28 16:36:42 -0800136
Anthony Zhou035f24b2017-03-01 12:47:37 +0800137 /*
138 * TODO: Check if x1 contains a valid DRAM address
139 */
Varun Wadekardc799302015-12-28 16:36:42 -0800140
Anthony Zhou035f24b2017-03-01 12:47:37 +0800141 /* store the NS world's entrypoint */
142 tegra_fiq_set_ns_entrypoint(x1);
Varun Wadekardc799302015-12-28 16:36:42 -0800143
Anthony Zhou035f24b2017-03-01 12:47:37 +0800144 SMC_RET1(handle, 0);
Varun Wadekardc799302015-12-28 16:36:42 -0800145
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800146 /*
Anthony Zhou035f24b2017-03-01 12:47:37 +0800147 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
148 * CPU context when the FIQ interrupt was triggered. This allows the
149 * NS world to understand the CPU state when the watchdog interrupt
150 * triggered.
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800151 */
Anthony Zhou035f24b2017-03-01 12:47:37 +0800152 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800153
Anthony Zhou035f24b2017-03-01 12:47:37 +0800154 /* retrieve context registers when FIQ triggered */
155 (void)tegra_fiq_get_intr_context();
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800156
Anthony Zhou035f24b2017-03-01 12:47:37 +0800157 SMC_RET0(handle);
158
Anthony Zhou035f24b2017-03-01 12:47:37 +0800159 default:
160 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
161 break;
162 }
Varun Wadekar7a269e22015-06-10 14:04:32 +0530163 }
164
165 SMC_RET1(handle, SMC_UNK);
166}
167
168/* Define a runtime service descriptor for fast SMC calls */
169DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800170 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530171
Anthony Zhoue5bd3452017-03-01 12:47:37 +0800172 (OEN_SIP_START),
173 (OEN_SIP_END),
174 (SMC_TYPE_FAST),
175 (NULL),
176 (tegra_sip_handler)
Varun Wadekar7a269e22015-06-10 14:04:32 +0530177);