blob: 1d48cc01b40064746896a20b52ce89a6205d9fb7 [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 Wadekar76afaac2018-05-17 10:14:30 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar7a269e22015-06-10 14:04:32 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar7a269e22015-06-10 14:04:32 +05306 */
7
Varun Wadekar7a269e22015-06-10 14:04:32 +05308#include <assert.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +05309#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch.h>
12#include <arch_helpers.h>
13#include <common/bl_common.h>
14#include <common/debug.h>
15#include <common/runtime_svc.h>
16#include <lib/mmio.h>
17
Varun Wadekar7a269e22015-06-10 14:04:32 +053018#include <memctrl.h>
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080019#include <tegra_platform.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010020#include <tegra_private.h>
Varun Wadekar7a269e22015-06-10 14:04:32 +053021
Varun Wadekar0f3baa02015-07-16 11:36:33 +053022/*******************************************************************************
Varun Wadekar923d04a2015-12-09 18:18:53 -080023 * Common Tegra SiP SMCs
Varun Wadekar0f3baa02015-07-16 11:36:33 +053024 ******************************************************************************/
Varun Wadekar7a269e22015-06-10 14:04:32 +053025#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003
Varun Wadekardc799302015-12-28 16:36:42 -080026#define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005
27#define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006
Varun Wadekar7a269e22015-06-10 14:04:32 +053028
29/*******************************************************************************
Wayne Lin2330edd2016-03-31 13:49:09 -070030 * This function is responsible for handling all SiP calls
Varun Wadekar7a269e22015-06-10 14:04:32 +053031 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090032uintptr_t tegra_sip_handler(uint32_t smc_fid,
33 u_register_t x1,
34 u_register_t x2,
35 u_register_t x3,
36 u_register_t x4,
37 void *cookie,
38 void *handle,
39 u_register_t flags)
Varun Wadekar7a269e22015-06-10 14:04:32 +053040{
Anthony Zhou4408e882017-07-07 14:29:51 +080041 uint32_t regval, local_x2_32 = (uint32_t)x2;
Anthony Zhoue5bd3452017-03-01 12:47:37 +080042 int32_t err;
Varun Wadekar7a269e22015-06-10 14:04:32 +053043
Varun Wadekar923d04a2015-12-09 18:18:53 -080044 /* Check if this is a SoC specific SiP */
45 err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
Anthony Zhou035f24b2017-03-01 12:47:37 +080046 if (err == 0) {
47
Varun Wadekar14f39572017-04-17 11:54:33 -070048 SMC_RET1(handle, (uint64_t)err);
Varun Wadekar923d04a2015-12-09 18:18:53 -080049
Anthony Zhou035f24b2017-03-01 12:47:37 +080050 } else {
Varun Wadekar7a269e22015-06-10 14:04:32 +053051
Anthony Zhou035f24b2017-03-01 12:47:37 +080052 switch (smc_fid) {
Varun Wadekar7a269e22015-06-10 14:04:32 +053053
Anthony Zhou035f24b2017-03-01 12:47:37 +080054 case TEGRA_SIP_NEW_VIDEOMEM_REGION:
Varun Wadekar0f3baa02015-07-16 11:36:33 +053055
Anthony Zhou035f24b2017-03-01 12:47:37 +080056 /*
57 * Check if Video Memory overlaps TZDRAM (contains bl31/bl32)
58 * or falls outside of the valid DRAM range
59 */
Anthony Zhou4408e882017-07-07 14:29:51 +080060 err = bl31_check_ns_address(x1, local_x2_32);
Anthony Zhou035f24b2017-03-01 12:47:37 +080061 if (err != 0) {
62 SMC_RET1(handle, (uint64_t)err);
63 }
Varun Wadekara59a7c52017-04-26 08:31:50 -070064
Anthony Zhou035f24b2017-03-01 12:47:37 +080065 /*
66 * Check if Video Memory is aligned to 1MB.
67 */
Anthony Zhou4408e882017-07-07 14:29:51 +080068 if (((x1 & 0xFFFFFU) != 0U) || ((local_x2_32 & 0xFFFFFU) != 0U)) {
Anthony Zhou035f24b2017-03-01 12:47:37 +080069 ERROR("Unaligned Video Memory base address!\n");
Anthony Zhou0e07e452017-07-26 17:16:54 +080070 SMC_RET1(handle, (uint64_t)-ENOTSUP);
Anthony Zhou035f24b2017-03-01 12:47:37 +080071 }
Varun Wadekar7a269e22015-06-10 14:04:32 +053072
Anthony Zhou035f24b2017-03-01 12:47:37 +080073 /*
74 * The GPU is the user of the Video Memory region. In order to
75 * transition to the new memory region smoothly, we program the
76 * new base/size ONLY if the GPU is in reset mode.
77 */
78 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
79 TEGRA_GPU_RESET_REG_OFFSET);
Anthony Zhou0e07e452017-07-26 17:16:54 +080080 if ((regval & GPU_RESET_BIT) == 0U) {
Anthony Zhou035f24b2017-03-01 12:47:37 +080081 ERROR("GPU not in reset! Video Memory setup failed\n");
Anthony Zhou0e07e452017-07-26 17:16:54 +080082 SMC_RET1(handle, (uint64_t)-ENOTSUP);
Anthony Zhou035f24b2017-03-01 12:47:37 +080083 }
Varun Wadekar7a269e22015-06-10 14:04:32 +053084
Anthony Zhou035f24b2017-03-01 12:47:37 +080085 /* new video memory carveout settings */
Anthony Zhou4408e882017-07-07 14:29:51 +080086 tegra_memctrl_videomem_setup(x1, local_x2_32);
Varun Wadekardc799302015-12-28 16:36:42 -080087
Jeetesh Burman48fef882018-01-22 15:40:08 +053088 /*
89 * Ensure again that GPU is still in reset after VPR resize
90 */
91 regval = mmio_read_32(TEGRA_CAR_RESET_BASE +
92 TEGRA_GPU_RESET_REG_OFFSET);
93 if ((regval & GPU_RESET_BIT) == 0U) {
94 mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_GPU_SET_OFFSET,
95 GPU_SET_BIT);
96 }
97
Anthony Zhou035f24b2017-03-01 12:47:37 +080098 SMC_RET1(handle, 0);
Varun Wadekardc799302015-12-28 16:36:42 -080099
100 /*
Anthony Zhou035f24b2017-03-01 12:47:37 +0800101 * The NS world registers the address of its handler to be
102 * used for processing the FIQ. This is normally used by the
103 * NS FIQ debugger driver to detect system hangs by programming
104 * a watchdog timer to fire a FIQ interrupt.
Varun Wadekardc799302015-12-28 16:36:42 -0800105 */
Anthony Zhou035f24b2017-03-01 12:47:37 +0800106 case TEGRA_SIP_FIQ_NS_ENTRYPOINT:
Varun Wadekardc799302015-12-28 16:36:42 -0800107
Anthony Zhou035f24b2017-03-01 12:47:37 +0800108 if (x1 == 0U) {
109 SMC_RET1(handle, SMC_UNK);
110 }
Varun Wadekardc799302015-12-28 16:36:42 -0800111
Anthony Zhou035f24b2017-03-01 12:47:37 +0800112 /*
113 * TODO: Check if x1 contains a valid DRAM address
114 */
Varun Wadekardc799302015-12-28 16:36:42 -0800115
Anthony Zhou035f24b2017-03-01 12:47:37 +0800116 /* store the NS world's entrypoint */
117 tegra_fiq_set_ns_entrypoint(x1);
Varun Wadekardc799302015-12-28 16:36:42 -0800118
Anthony Zhou035f24b2017-03-01 12:47:37 +0800119 SMC_RET1(handle, 0);
Varun Wadekardc799302015-12-28 16:36:42 -0800120
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800121 /*
Anthony Zhou035f24b2017-03-01 12:47:37 +0800122 * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0
123 * CPU context when the FIQ interrupt was triggered. This allows the
124 * NS world to understand the CPU state when the watchdog interrupt
125 * triggered.
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800126 */
Anthony Zhou035f24b2017-03-01 12:47:37 +0800127 case TEGRA_SIP_FIQ_NS_GET_CONTEXT:
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800128
Anthony Zhou035f24b2017-03-01 12:47:37 +0800129 /* retrieve context registers when FIQ triggered */
130 (void)tegra_fiq_get_intr_context();
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800131
Anthony Zhou035f24b2017-03-01 12:47:37 +0800132 SMC_RET0(handle);
133
Anthony Zhou035f24b2017-03-01 12:47:37 +0800134 default:
135 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
136 break;
137 }
Varun Wadekar7a269e22015-06-10 14:04:32 +0530138 }
139
140 SMC_RET1(handle, SMC_UNK);
141}
142
143/* Define a runtime service descriptor for fast SMC calls */
144DECLARE_RT_SVC(
Varun Wadekar923d04a2015-12-09 18:18:53 -0800145 tegra_sip_fast,
Varun Wadekar7a269e22015-06-10 14:04:32 +0530146
Anthony Zhoue5bd3452017-03-01 12:47:37 +0800147 (OEN_SIP_START),
148 (OEN_SIP_END),
149 (SMC_TYPE_FAST),
150 (NULL),
151 (tegra_sip_handler)
Varun Wadekar7a269e22015-06-10 14:04:32 +0530152);