Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 1 | /* |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 76afaac | 2018-05-17 10:14:30 -0700 | [diff] [blame] | 3 | * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 8 | #include <assert.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 9 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 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 Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 18 | #include <memctrl.h> |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 19 | #include <tegra_platform.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 20 | #include <tegra_private.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 21 | |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 22 | /******************************************************************************* |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 23 | * Common Tegra SiP SMCs |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 24 | ******************************************************************************/ |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 25 | #define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003 |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 26 | #define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005 |
| 27 | #define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006 |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 28 | |
| 29 | /******************************************************************************* |
Wayne Lin | 2330edd | 2016-03-31 13:49:09 -0700 | [diff] [blame] | 30 | * This function is responsible for handling all SiP calls |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 31 | ******************************************************************************/ |
Masahiro Yamada | 5ac9d96 | 2018-04-19 01:18:48 +0900 | [diff] [blame] | 32 | uintptr_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 Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 40 | { |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 41 | uint32_t regval, local_x2_32 = (uint32_t)x2; |
Anthony Zhou | e5bd345 | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 42 | int32_t err; |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 43 | |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 44 | /* Check if this is a SoC specific SiP */ |
| 45 | err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 46 | if (err == 0) { |
| 47 | |
Varun Wadekar | 14f3957 | 2017-04-17 11:54:33 -0700 | [diff] [blame] | 48 | SMC_RET1(handle, (uint64_t)err); |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 49 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 50 | } else { |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 51 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 52 | switch (smc_fid) { |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 53 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 54 | case TEGRA_SIP_NEW_VIDEOMEM_REGION: |
Anthony Zhou | 41eac8a | 2019-12-04 14:58:23 +0800 | [diff] [blame] | 55 | /* Check whether Video memory resize is enabled */ |
| 56 | if (mmio_read_32(TEGRA_MC_BASE + MC_VIDEO_PROTECT_REG_CTRL) |
| 57 | != MC_VIDEO_PROTECT_WRITE_ACCESS_ENABLED) { |
| 58 | ERROR("Video Memory Resize isn't enabled! \n"); |
| 59 | SMC_RET1(handle, (uint64_t)-ENOTSUP); |
| 60 | } |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 61 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 62 | /* |
| 63 | * Check if Video Memory overlaps TZDRAM (contains bl31/bl32) |
| 64 | * or falls outside of the valid DRAM range |
| 65 | */ |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 66 | err = bl31_check_ns_address(x1, local_x2_32); |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 67 | if (err != 0) { |
| 68 | SMC_RET1(handle, (uint64_t)err); |
| 69 | } |
Varun Wadekar | a59a7c5 | 2017-04-26 08:31:50 -0700 | [diff] [blame] | 70 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 71 | /* |
| 72 | * Check if Video Memory is aligned to 1MB. |
| 73 | */ |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 74 | if (((x1 & 0xFFFFFU) != 0U) || ((local_x2_32 & 0xFFFFFU) != 0U)) { |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 75 | ERROR("Unaligned Video Memory base address!\n"); |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 76 | SMC_RET1(handle, (uint64_t)-ENOTSUP); |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 77 | } |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 78 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 79 | /* |
| 80 | * The GPU is the user of the Video Memory region. In order to |
| 81 | * transition to the new memory region smoothly, we program the |
| 82 | * new base/size ONLY if the GPU is in reset mode. |
| 83 | */ |
| 84 | regval = mmio_read_32(TEGRA_CAR_RESET_BASE + |
| 85 | TEGRA_GPU_RESET_REG_OFFSET); |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 86 | if ((regval & GPU_RESET_BIT) == 0U) { |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 87 | ERROR("GPU not in reset! Video Memory setup failed\n"); |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 88 | SMC_RET1(handle, (uint64_t)-ENOTSUP); |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 89 | } |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 90 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 91 | /* new video memory carveout settings */ |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 92 | tegra_memctrl_videomem_setup(x1, local_x2_32); |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 93 | |
Jeetesh Burman | 48fef88 | 2018-01-22 15:40:08 +0530 | [diff] [blame] | 94 | /* |
| 95 | * Ensure again that GPU is still in reset after VPR resize |
| 96 | */ |
| 97 | regval = mmio_read_32(TEGRA_CAR_RESET_BASE + |
| 98 | TEGRA_GPU_RESET_REG_OFFSET); |
| 99 | if ((regval & GPU_RESET_BIT) == 0U) { |
| 100 | mmio_write_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_GPU_SET_OFFSET, |
| 101 | GPU_SET_BIT); |
| 102 | } |
| 103 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 104 | SMC_RET1(handle, 0); |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 105 | |
| 106 | /* |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 107 | * The NS world registers the address of its handler to be |
| 108 | * used for processing the FIQ. This is normally used by the |
| 109 | * NS FIQ debugger driver to detect system hangs by programming |
| 110 | * a watchdog timer to fire a FIQ interrupt. |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 111 | */ |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 112 | case TEGRA_SIP_FIQ_NS_ENTRYPOINT: |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 113 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 114 | if (x1 == 0U) { |
| 115 | SMC_RET1(handle, SMC_UNK); |
| 116 | } |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 117 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 118 | /* |
| 119 | * TODO: Check if x1 contains a valid DRAM address |
| 120 | */ |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 121 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 122 | /* store the NS world's entrypoint */ |
| 123 | tegra_fiq_set_ns_entrypoint(x1); |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 124 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 125 | SMC_RET1(handle, 0); |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 126 | |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 127 | /* |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 128 | * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0 |
| 129 | * CPU context when the FIQ interrupt was triggered. This allows the |
| 130 | * NS world to understand the CPU state when the watchdog interrupt |
| 131 | * triggered. |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 132 | */ |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 133 | case TEGRA_SIP_FIQ_NS_GET_CONTEXT: |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 134 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 135 | /* retrieve context registers when FIQ triggered */ |
| 136 | (void)tegra_fiq_get_intr_context(); |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 137 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 138 | SMC_RET0(handle); |
| 139 | |
Anthony Zhou | 035f24b | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 140 | default: |
| 141 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 142 | break; |
| 143 | } |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | SMC_RET1(handle, SMC_UNK); |
| 147 | } |
| 148 | |
| 149 | /* Define a runtime service descriptor for fast SMC calls */ |
| 150 | DECLARE_RT_SVC( |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 151 | tegra_sip_fast, |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 152 | |
Anthony Zhou | e5bd345 | 2017-03-01 12:47:37 +0800 | [diff] [blame] | 153 | (OEN_SIP_START), |
| 154 | (OEN_SIP_END), |
| 155 | (SMC_TYPE_FAST), |
| 156 | (NULL), |
| 157 | (tegra_sip_handler) |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 158 | ); |