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 | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 31 | #include <arch.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 32 | #include <arch_helpers.h> |
| 33 | #include <assert.h> |
| 34 | #include <bl_common.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 35 | #include <debug.h> |
| 36 | #include <errno.h> |
| 37 | #include <memctrl.h> |
| 38 | #include <runtime_svc.h> |
| 39 | #include <tegra_private.h> |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 40 | #include <tegra_platform.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 41 | |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 42 | /******************************************************************************* |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 43 | * Common Tegra SiP SMCs |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 44 | ******************************************************************************/ |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 45 | #define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003 |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 46 | #define TEGRA_SIP_FIQ_NS_ENTRYPOINT 0x82000005 |
| 47 | #define TEGRA_SIP_FIQ_NS_GET_CONTEXT 0x82000006 |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 48 | #define TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND 0xC2000007 |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 49 | |
| 50 | /******************************************************************************* |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 51 | * Fake system suspend mode control var |
| 52 | ******************************************************************************/ |
| 53 | extern uint8_t tegra_fake_system_suspend; |
| 54 | |
| 55 | |
| 56 | /******************************************************************************* |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 57 | * SoC specific SiP handler |
| 58 | ******************************************************************************/ |
| 59 | #pragma weak plat_sip_handler |
| 60 | int plat_sip_handler(uint32_t smc_fid, |
| 61 | uint64_t x1, |
| 62 | uint64_t x2, |
| 63 | uint64_t x3, |
| 64 | uint64_t x4, |
| 65 | void *cookie, |
| 66 | void *handle, |
| 67 | uint64_t flags) |
| 68 | { |
| 69 | return -ENOTSUP; |
| 70 | } |
| 71 | |
| 72 | /******************************************************************************* |
Wayne Lin | 2330edd | 2016-03-31 13:49:09 -0700 | [diff] [blame] | 73 | * This function is responsible for handling all SiP calls |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 74 | ******************************************************************************/ |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 75 | uint64_t tegra_sip_handler(uint32_t smc_fid, |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 76 | uint64_t x1, |
| 77 | uint64_t x2, |
| 78 | uint64_t x3, |
| 79 | uint64_t x4, |
| 80 | void *cookie, |
| 81 | void *handle, |
| 82 | uint64_t flags) |
| 83 | { |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 84 | int err; |
| 85 | |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 86 | /* Check if this is a SoC specific SiP */ |
| 87 | err = plat_sip_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); |
| 88 | if (err == 0) |
Varun Wadekar | 14f3957 | 2017-04-17 11:54:33 -0700 | [diff] [blame] | 89 | SMC_RET1(handle, (uint64_t)err); |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 90 | |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 91 | switch (smc_fid) { |
| 92 | |
| 93 | case TEGRA_SIP_NEW_VIDEOMEM_REGION: |
| 94 | |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 95 | /* clean up the high bits */ |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 96 | x2 = (uint32_t)x2; |
| 97 | |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 98 | /* |
| 99 | * Check if Video Memory overlaps TZDRAM (contains bl31/bl32) |
| 100 | * or falls outside of the valid DRAM range |
| 101 | */ |
| 102 | err = bl31_check_ns_address(x1, x2); |
| 103 | if (err) |
| 104 | SMC_RET1(handle, err); |
| 105 | |
| 106 | /* |
| 107 | * Check if Video Memory is aligned to 1MB. |
| 108 | */ |
| 109 | if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) { |
| 110 | ERROR("Unaligned Video Memory base address!\n"); |
| 111 | SMC_RET1(handle, -ENOTSUP); |
| 112 | } |
| 113 | |
| 114 | /* new video memory carveout settings */ |
| 115 | tegra_memctrl_videomem_setup(x1, x2); |
| 116 | |
| 117 | SMC_RET1(handle, 0); |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 118 | break; |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 119 | |
Varun Wadekar | dc79930 | 2015-12-28 16:36:42 -0800 | [diff] [blame] | 120 | /* |
| 121 | * The NS world registers the address of its handler to be |
| 122 | * used for processing the FIQ. This is normally used by the |
| 123 | * NS FIQ debugger driver to detect system hangs by programming |
| 124 | * a watchdog timer to fire a FIQ interrupt. |
| 125 | */ |
| 126 | case TEGRA_SIP_FIQ_NS_ENTRYPOINT: |
| 127 | |
| 128 | if (!x1) |
| 129 | SMC_RET1(handle, SMC_UNK); |
| 130 | |
| 131 | /* |
| 132 | * TODO: Check if x1 contains a valid DRAM address |
| 133 | */ |
| 134 | |
| 135 | /* store the NS world's entrypoint */ |
| 136 | tegra_fiq_set_ns_entrypoint(x1); |
| 137 | |
| 138 | SMC_RET1(handle, 0); |
| 139 | break; |
| 140 | |
| 141 | /* |
| 142 | * The NS world's FIQ handler issues this SMC to get the NS EL1/EL0 |
| 143 | * CPU context when the FIQ interrupt was triggered. This allows the |
| 144 | * NS world to understand the CPU state when the watchdog interrupt |
| 145 | * triggered. |
| 146 | */ |
| 147 | case TEGRA_SIP_FIQ_NS_GET_CONTEXT: |
| 148 | |
| 149 | /* retrieve context registers when FIQ triggered */ |
| 150 | tegra_fiq_get_intr_context(); |
| 151 | |
| 152 | SMC_RET0(handle); |
| 153 | break; |
| 154 | |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 155 | case TEGRA_SIP_ENABLE_FAKE_SYSTEM_SUSPEND: |
| 156 | /* |
| 157 | * System suspend fake mode is set if we are on VDK and we make |
| 158 | * a debug SIP call. This mode ensures that we excercise debug |
| 159 | * path instead of the regular code path to suit the pre-silicon |
| 160 | * platform needs. These include replacing the call to WFI by |
| 161 | * a warm reset request. |
| 162 | */ |
| 163 | if (tegra_platform_is_emulation() != 0U) { |
| 164 | |
| 165 | tegra_fake_system_suspend = 1; |
| 166 | SMC_RET1(handle, 0); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * We return to the external world as if this SIP is not |
| 171 | * implemented in case, we are not running on VDK. |
| 172 | */ |
| 173 | break; |
| 174 | |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 175 | default: |
| 176 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | SMC_RET1(handle, SMC_UNK); |
| 181 | } |
| 182 | |
| 183 | /* Define a runtime service descriptor for fast SMC calls */ |
| 184 | DECLARE_RT_SVC( |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 185 | tegra_sip_fast, |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 186 | |
| 187 | OEN_SIP_START, |
| 188 | OEN_SIP_END, |
| 189 | SMC_TYPE_FAST, |
| 190 | NULL, |
Varun Wadekar | 923d04a | 2015-12-09 18:18:53 -0800 | [diff] [blame] | 191 | tegra_sip_handler |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 192 | ); |