Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +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 | |
| 31 | #include <arch.h> |
| 32 | #include <arch_helpers.h> |
| 33 | #include <assert.h> |
| 34 | #include <bl_common.h> |
| 35 | #include <context_mgmt.h> |
| 36 | #include <debug.h> |
| 37 | #include <errno.h> |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 38 | #include <mce.h> |
Varun Wadekar | a7c1ea7 | 2016-02-03 09:51:25 -0800 | [diff] [blame] | 39 | #include <memctrl.h> |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 40 | #include <runtime_svc.h> |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 41 | #include <t18x_ari.h> |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 42 | #include <tegra_private.h> |
| 43 | |
Varun Wadekar | d66ee54 | 2016-02-29 10:24:30 -0800 | [diff] [blame] | 44 | extern uint32_t tegra186_system_powerdn_state; |
| 45 | |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 46 | /******************************************************************************* |
| 47 | * Tegra186 SiP SMCs |
| 48 | ******************************************************************************/ |
| 49 | #define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003 |
Varun Wadekar | d66ee54 | 2016-02-29 10:24:30 -0800 | [diff] [blame] | 50 | #define TEGRA_SIP_SYSTEM_SHUTDOWN_STATE 0x82FFFE01 |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 51 | #define TEGRA_SIP_MCE_CMD_ENTER_CSTATE 0x82FFFF00 |
| 52 | #define TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO 0x82FFFF01 |
| 53 | #define TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME 0x82FFFF02 |
| 54 | #define TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS 0x82FFFF03 |
| 55 | #define TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS 0x82FFFF04 |
| 56 | #define TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED 0x82FFFF05 |
| 57 | #define TEGRA_SIP_MCE_CMD_ONLINE_CORE 0x82FFFF06 |
| 58 | #define TEGRA_SIP_MCE_CMD_CC3_CTRL 0x82FFFF07 |
| 59 | #define TEGRA_SIP_MCE_CMD_ECHO_DATA 0x82FFFF08 |
| 60 | #define TEGRA_SIP_MCE_CMD_READ_VERSIONS 0x82FFFF09 |
| 61 | #define TEGRA_SIP_MCE_CMD_ENUM_FEATURES 0x82FFFF0A |
| 62 | #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS 0x82FFFF0B |
| 63 | #define TEGRA_SIP_MCE_CMD_ENUM_READ_MCA 0x82FFFF0C |
| 64 | #define TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA 0x82FFFF0D |
| 65 | #define TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE 0x82FFFF0E |
| 66 | #define TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE 0x82FFFF0F |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 67 | |
| 68 | /******************************************************************************* |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 69 | * This function is responsible for handling all T186 SiP calls |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 70 | ******************************************************************************/ |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 71 | int plat_sip_handler(uint32_t smc_fid, |
| 72 | uint64_t x1, |
| 73 | uint64_t x2, |
| 74 | uint64_t x3, |
| 75 | uint64_t x4, |
| 76 | void *cookie, |
| 77 | void *handle, |
| 78 | uint64_t flags) |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 79 | { |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 80 | int mce_ret; |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 81 | |
| 82 | switch (smc_fid) { |
| 83 | |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 84 | /* |
| 85 | * Micro Coded Engine (MCE) commands reside in the 0x82FFFF00 - |
| 86 | * 0x82FFFFFF SiP SMC space |
| 87 | */ |
| 88 | case TEGRA_SIP_MCE_CMD_ENTER_CSTATE: |
| 89 | case TEGRA_SIP_MCE_CMD_UPDATE_CSTATE_INFO: |
| 90 | case TEGRA_SIP_MCE_CMD_UPDATE_CROSSOVER_TIME: |
| 91 | case TEGRA_SIP_MCE_CMD_READ_CSTATE_STATS: |
| 92 | case TEGRA_SIP_MCE_CMD_WRITE_CSTATE_STATS: |
| 93 | case TEGRA_SIP_MCE_CMD_IS_SC7_ALLOWED: |
| 94 | case TEGRA_SIP_MCE_CMD_CC3_CTRL: |
| 95 | case TEGRA_SIP_MCE_CMD_ECHO_DATA: |
| 96 | case TEGRA_SIP_MCE_CMD_READ_VERSIONS: |
| 97 | case TEGRA_SIP_MCE_CMD_ENUM_FEATURES: |
| 98 | case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE_TRBITS: |
| 99 | case TEGRA_SIP_MCE_CMD_ENUM_READ_MCA: |
| 100 | case TEGRA_SIP_MCE_CMD_ENUM_WRITE_MCA: |
| 101 | case TEGRA_SIP_MCE_CMD_ROC_FLUSH_CACHE: |
| 102 | case TEGRA_SIP_MCE_CMD_ROC_CLEAN_CACHE: |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 103 | |
| 104 | /* clean up the high bits */ |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 105 | smc_fid &= MCE_CMD_MASK; |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 106 | |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 107 | /* execute the command and store the result */ |
| 108 | mce_ret = mce_command_handler(smc_fid, x1, x2, x3); |
| 109 | write_ctx_reg(get_gpregs_ctx(handle), CTX_GPREG_X0, mce_ret); |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 110 | |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 111 | return 0; |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 112 | |
Varun Wadekar | a7c1ea7 | 2016-02-03 09:51:25 -0800 | [diff] [blame] | 113 | case TEGRA_SIP_NEW_VIDEOMEM_REGION: |
| 114 | /* clean up the high bits */ |
| 115 | x1 = (uint32_t)x1; |
| 116 | x2 = (uint32_t)x2; |
| 117 | |
| 118 | /* |
| 119 | * Check if Video Memory overlaps TZDRAM (contains bl31/bl32) |
| 120 | * or falls outside of the valid DRAM range |
| 121 | */ |
| 122 | mce_ret = bl31_check_ns_address(x1, x2); |
| 123 | if (mce_ret) |
| 124 | return -ENOTSUP; |
| 125 | |
| 126 | /* |
| 127 | * Check if Video Memory is aligned to 1MB. |
| 128 | */ |
| 129 | if ((x1 & 0xFFFFF) || (x2 & 0xFFFFF)) { |
| 130 | ERROR("Unaligned Video Memory base address!\n"); |
| 131 | return -ENOTSUP; |
| 132 | } |
| 133 | |
| 134 | /* new video memory carveout settings */ |
| 135 | tegra_memctrl_videomem_setup(x1, x2); |
| 136 | |
| 137 | return 0; |
| 138 | |
Varun Wadekar | d66ee54 | 2016-02-29 10:24:30 -0800 | [diff] [blame] | 139 | case TEGRA_SIP_SYSTEM_SHUTDOWN_STATE: |
| 140 | |
| 141 | /* clean up the high bits */ |
| 142 | x1 = (uint32_t)x1; |
| 143 | |
| 144 | /* |
| 145 | * SC8 is a special Tegra186 system state where the CPUs and |
| 146 | * DRAM are powered down but the other subsystem is still |
| 147 | * alive. |
| 148 | */ |
| 149 | if ((x1 == TEGRA_ARI_SYSTEM_SC8) || |
| 150 | (x1 == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF)) { |
| 151 | |
| 152 | tegra186_system_powerdn_state = x1; |
| 153 | flush_dcache_range( |
| 154 | (uintptr_t)&tegra186_system_powerdn_state, |
| 155 | sizeof(tegra186_system_powerdn_state)); |
| 156 | |
| 157 | } else { |
| 158 | |
| 159 | ERROR("%s: unhandled powerdn state (%d)\n", __func__, |
| 160 | (uint32_t)x1); |
| 161 | return -ENOTSUP; |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 166 | default: |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 167 | break; |
| 168 | } |
| 169 | |
Varun Wadekar | 59c3aa0 | 2015-09-09 11:33:08 +0530 | [diff] [blame] | 170 | return -ENOTSUP; |
Varun Wadekar | 921b906 | 2015-08-25 17:03:14 +0530 | [diff] [blame] | 171 | } |