blob: e3d5bd513ac97e02e47a3e49ed9d8bbf2fc5531e [file] [log] [blame]
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07001/*
Steven Kao8f4f1022017-12-13 06:39:15 +08002 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <assert.h>
10#include <common/bl_common.h>
11#include <context.h>
12#include <lib/el3_runtime/context_mgmt.h>
13#include <common/debug.h>
14#include <denver.h>
15#include <mce.h>
16#include <mce_private.h>
Steven Kao2cdb6782017-01-05 17:04:40 +080017#include <platform_def.h>
Steven Kao6f373a22017-09-29 18:09:17 +080018#include <stdbool.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070019#include <string.h>
20#include <errno.h>
Steven Kao2cdb6782017-01-05 17:04:40 +080021#include <t194_nvg.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070022#include <tegra_def.h>
23#include <tegra_platform.h>
Dilan Lee4e7a63c2017-08-10 16:01:42 +080024#include <tegra_private.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070025
Steven Kao6f373a22017-09-29 18:09:17 +080026/* Handler to check if MCE firmware is supported */
27static bool mce_firmware_not_supported(void)
28{
29 bool status;
30
31 /* these platforms do not load MCE firmware */
32 status = tegra_platform_is_linsim() || tegra_platform_is_qt() ||
33 tegra_platform_is_virt_dev_kit();
34
35 return status;
36}
37
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070038/*******************************************************************************
39 * Common handler for all MCE commands
40 ******************************************************************************/
Anthony Zhou5e890b32017-04-28 13:52:58 +080041int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070042 uint64_t arg2)
43{
Steven Kao2cdb6782017-01-05 17:04:40 +080044 int32_t ret = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070045
46 switch (cmd) {
Anthony Zhouc46150f2017-09-20 17:18:56 +080047 case (uint64_t)MCE_CMD_ENTER_CSTATE:
Steven Kao2cdb6782017-01-05 17:04:40 +080048 ret = nvg_enter_cstate((uint32_t)arg0, (uint32_t)arg1);
49 if (ret < 0) {
50 ERROR("%s: enter_cstate failed(%d)\n", __func__, ret);
51 }
52
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070053 break;
54
Anthony Zhouc46150f2017-09-20 17:18:56 +080055 case (uint64_t)MCE_CMD_IS_SC7_ALLOWED:
Steven Kao2cdb6782017-01-05 17:04:40 +080056 ret = nvg_is_sc7_allowed();
57 if (ret < 0) {
58 ERROR("%s: is_sc7_allowed failed(%d)\n", __func__, ret);
Steven Kao2cdb6782017-01-05 17:04:40 +080059 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070060
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070061 break;
62
Anthony Zhouc46150f2017-09-20 17:18:56 +080063 case (uint64_t)MCE_CMD_ONLINE_CORE:
Steven Kao2cdb6782017-01-05 17:04:40 +080064 ret = nvg_online_core((uint32_t)arg0);
65 if (ret < 0) {
66 ERROR("%s: online_core failed(%d)\n", __func__, ret);
67 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070068
69 break;
70
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070071 default:
Anthony Zhou5e890b32017-04-28 13:52:58 +080072 ERROR("unknown MCE command (%llu)\n", cmd);
Varun Wadekar7aa6c032017-10-19 12:02:17 -070073 ret = -EINVAL;
Steven Kao2cdb6782017-01-05 17:04:40 +080074 break;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070075 }
76
77 return ret;
78}
79
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070080/*******************************************************************************
81 * Handler to update carveout values for Video Memory Carveout region
82 ******************************************************************************/
Steven Kao2cdb6782017-01-05 17:04:40 +080083int32_t mce_update_gsc_videomem(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070084{
Steven Kao6f373a22017-09-29 18:09:17 +080085 int32_t ret;
86
87 /*
88 * MCE firmware is not running on simulation platforms.
89 */
90 if (mce_firmware_not_supported()) {
91 ret = -EINVAL;
92 } else {
93 ret = nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_VPR);
94 }
95
96 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070097}
98
99/*******************************************************************************
100 * Handler to update carveout values for TZDRAM aperture
101 ******************************************************************************/
Steven Kao2cdb6782017-01-05 17:04:40 +0800102int32_t mce_update_gsc_tzdram(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700103{
Steven Kao6f373a22017-09-29 18:09:17 +0800104 int32_t ret;
105
106 /*
107 * MCE firmware is not running on simulation platforms.
108 */
109 if (mce_firmware_not_supported()) {
110 ret = -EINVAL;
111 } else {
112 ret = nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_TZ_DRAM);
113 }
114
115 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700116}
117
118/*******************************************************************************
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700119 * Handler to issue the UPDATE_CSTATE_INFO request
120 ******************************************************************************/
Anthony Zhou5e890b32017-04-28 13:52:58 +0800121void mce_update_cstate_info(const mce_cstate_info_t *cstate)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700122{
123 /* issue the UPDATE_CSTATE_INFO request */
Steven Kao2cdb6782017-01-05 17:04:40 +0800124 nvg_update_cstate_info(cstate->cluster, cstate->ccplex, cstate->system,
125 cstate->wake_mask, cstate->update_wake_mask);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700126}
127
128/*******************************************************************************
129 * Handler to read the MCE firmware version and check if it is compatible
130 * with interface header the BL3-1 was compiled against
131 ******************************************************************************/
132void mce_verify_firmware_version(void)
133{
134 uint64_t version;
135 uint32_t major, minor;
136
137 /*
138 * MCE firmware is not running on simulation platforms.
139 */
Steven Kao6f373a22017-09-29 18:09:17 +0800140 if (mce_firmware_not_supported()) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700141 return;
Steven Kao2cdb6782017-01-05 17:04:40 +0800142 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700143
144 /*
145 * Read the MCE firmware version and extract the major and minor
146 * version fields
147 */
Steven Kao2cdb6782017-01-05 17:04:40 +0800148 version = nvg_get_version();
149 minor = (uint32_t)version;
150 major = (uint32_t)(version >> 32);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700151
Varun Wadekar093bfaa2017-11-07 08:50:55 -0800152 INFO("MCE Version - HW=%u:%u, SW=%u:%u\n", major, minor,
153 TEGRA_NVG_VERSION_MAJOR, TEGRA_NVG_VERSION_MINOR);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700154
155 /*
156 * Verify that the MCE firmware version and the interface header
157 * match
158 */
Steven Kao2cdb6782017-01-05 17:04:40 +0800159 if (major != (uint32_t)TEGRA_NVG_VERSION_MAJOR) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700160 ERROR("MCE major version mismatch\n");
161 panic();
162 }
163
Steven Kao2cdb6782017-01-05 17:04:40 +0800164 if (minor < (uint32_t)TEGRA_NVG_VERSION_MINOR) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700165 ERROR("MCE minor version mismatch\n");
166 panic();
167 }
168}
Dilan Lee4e7a63c2017-08-10 16:01:42 +0800169
Steven Kao8f4f1022017-12-13 06:39:15 +0800170#if ENABLE_STRICT_CHECKING_MODE
Dilan Lee4e7a63c2017-08-10 16:01:42 +0800171/*******************************************************************************
172 * Handler to enable the strict checking mode
173 ******************************************************************************/
174void mce_enable_strict_checking(void)
175{
176 uint64_t sctlr = read_sctlr_el3();
177 int32_t ret = 0;
178
179 if (tegra_platform_is_silicon() || tegra_platform_is_fpga()) {
180 /*
181 * Step1: TZ-DRAM and TZRAM should be setup before the MMU is
182 * enabled.
183 *
184 * The common code makes sure that TZDRAM/TZRAM are already
185 * enabled before calling into this handler. If this is not the
186 * case, the following sequence must be executed before moving
187 * on to step 2.
188 *
189 * tlbialle1is();
190 * tlbialle3is();
191 * dsbsy();
192 * isb();
193 *
194 */
195 if ((sctlr & (uint64_t)SCTLR_M_BIT) == (uint64_t)SCTLR_M_BIT) {
196 tlbialle1is();
197 tlbialle3is();
198 dsbsy();
199 isb();
200 }
201
202 /*
203 * Step2: SCF flush - Clean and invalidate caches and clear the
204 * TR-bits
205 */
206 ret = nvg_roc_clean_cache_trbits();
207 if (ret < 0) {
208 ERROR("%s: flush cache_trbits failed(%d)\n", __func__,
209 ret);
210 return;
211 }
212
213 /*
214 * Step3: Issue the SECURITY_CONFIG request to MCE to enable
215 * strict checking mode.
216 */
217 nvg_enable_strict_checking_mode();
218 }
219}
Anthony Zhou10b970c2020-02-05 20:42:36 +0800220void mce_verify_strict_checking(void)
221{
222 bool is_silicon = tegra_platform_is_silicon();
223 bool is_fpga = tegra_platform_is_fpga();
224
225 if (is_silicon || is_fpga) {
226 nvg_verify_strict_checking_mode();
227 }
228}
Steven Kao8f4f1022017-12-13 06:39:15 +0800229#endif
Vignesh Radhakrishnan3ad79832017-12-11 13:17:58 -0800230
231/*******************************************************************************
232 * Handler to power down the entire system
233 ******************************************************************************/
234void mce_system_shutdown(void)
235{
236 nvg_system_shutdown();
237}
238
239/*******************************************************************************
240 * Handler to reboot the entire system
241 ******************************************************************************/
242void mce_system_reboot(void)
243{
244 nvg_system_reboot();
245}
Varun Wadekar67188422019-03-21 08:23:05 -0700246
247/*******************************************************************************
248 * Handler to clear CCPLEX->HSM correctable RAS error signal.
249 ******************************************************************************/
250void mce_clear_hsm_corr_status(void)
251{
252 nvg_clear_hsm_corr_status();
253}