blob: 54d3b2ccdcc5748bca0c64cdf885dd7b33d4e827 [file] [log] [blame]
Varun Wadekara0352ab2017-03-14 14:24:35 -07001/*
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Varun Wadekar5a700942019-01-23 16:54:12 -08003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekara0352ab2017-03-14 14:24:35 -07004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekara0352ab2017-03-14 14:24:35 -07006 */
7
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <assert.h>
9#include <errno.h>
10#include <string.h>
11
Varun Wadekara0352ab2017-03-14 14:24:35 -070012#include <arch.h>
13#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <common/bl_common.h>
15#include <common/debug.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070016#include <context.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070017#include <denver.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000018#include <lib/el3_runtime/context_mgmt.h>
19#include <lib/mmio.h>
20
Varun Wadekara0352ab2017-03-14 14:24:35 -070021#include <mce.h>
Varun Wadekarb5568282016-12-13 18:04:35 -080022#include <mce_private.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070023#include <t18x_ari.h>
24#include <tegra_def.h>
Varun Wadekarefa66d42016-07-18 17:42:02 -070025#include <tegra_platform.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070026
27/* NVG functions handlers */
28static arch_mce_ops_t nvg_mce_ops = {
29 .enter_cstate = nvg_enter_cstate,
30 .update_cstate_info = nvg_update_cstate_info,
31 .update_crossover_time = nvg_update_crossover_time,
32 .read_cstate_stats = nvg_read_cstate_stats,
33 .write_cstate_stats = nvg_write_cstate_stats,
34 .call_enum_misc = ari_enumeration_misc,
35 .is_ccx_allowed = nvg_is_ccx_allowed,
36 .is_sc7_allowed = nvg_is_sc7_allowed,
37 .online_core = nvg_online_core,
38 .cc3_ctrl = nvg_cc3_ctrl,
39 .update_reset_vector = ari_reset_vector_update,
40 .roc_flush_cache = ari_roc_flush_cache,
41 .roc_flush_cache_trbits = ari_roc_flush_cache_trbits,
42 .roc_clean_cache = ari_roc_clean_cache,
43 .read_write_mca = ari_read_write_mca,
44 .update_ccplex_gsc = ari_update_ccplex_gsc,
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070045 .enter_ccplex_state = ari_enter_ccplex_state,
Krishna Sitaramanb429d562016-07-19 16:36:13 -070046 .read_write_uncore_perfmon = ari_read_write_uncore_perfmon,
47 .misc_ccplex = ari_misc_ccplex
Varun Wadekara0352ab2017-03-14 14:24:35 -070048};
49
50/* ARI functions handlers */
51static arch_mce_ops_t ari_mce_ops = {
52 .enter_cstate = ari_enter_cstate,
53 .update_cstate_info = ari_update_cstate_info,
54 .update_crossover_time = ari_update_crossover_time,
55 .read_cstate_stats = ari_read_cstate_stats,
56 .write_cstate_stats = ari_write_cstate_stats,
57 .call_enum_misc = ari_enumeration_misc,
58 .is_ccx_allowed = ari_is_ccx_allowed,
59 .is_sc7_allowed = ari_is_sc7_allowed,
60 .online_core = ari_online_core,
61 .cc3_ctrl = ari_cc3_ctrl,
62 .update_reset_vector = ari_reset_vector_update,
63 .roc_flush_cache = ari_roc_flush_cache,
64 .roc_flush_cache_trbits = ari_roc_flush_cache_trbits,
65 .roc_clean_cache = ari_roc_clean_cache,
66 .read_write_mca = ari_read_write_mca,
67 .update_ccplex_gsc = ari_update_ccplex_gsc,
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070068 .enter_ccplex_state = ari_enter_ccplex_state,
Krishna Sitaramanb429d562016-07-19 16:36:13 -070069 .read_write_uncore_perfmon = ari_read_write_uncore_perfmon,
70 .misc_ccplex = ari_misc_ccplex
Varun Wadekara0352ab2017-03-14 14:24:35 -070071};
72
Anthony Zhou1ab31402017-03-06 16:06:45 +080073typedef struct {
Varun Wadekara0352ab2017-03-14 14:24:35 -070074 uint32_t ari_base;
75 arch_mce_ops_t *ops;
76} mce_config_t;
77
78/* Table to hold the per-CPU ARI base address and function handlers */
79static mce_config_t mce_cfg_table[MCE_ARI_APERTURES_MAX] = {
80 {
81 /* A57 Core 0 */
82 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_0_OFFSET,
83 .ops = &ari_mce_ops,
84 },
85 {
86 /* A57 Core 1 */
87 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_1_OFFSET,
88 .ops = &ari_mce_ops,
89 },
90 {
91 /* A57 Core 2 */
92 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_2_OFFSET,
93 .ops = &ari_mce_ops,
94 },
95 {
96 /* A57 Core 3 */
97 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_3_OFFSET,
98 .ops = &ari_mce_ops,
99 },
100 {
101 /* D15 Core 0 */
102 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_4_OFFSET,
103 .ops = &nvg_mce_ops,
104 },
105 {
106 /* D15 Core 1 */
107 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_5_OFFSET,
108 .ops = &nvg_mce_ops,
109 }
110};
111
112static uint32_t mce_get_curr_cpu_ari_base(void)
113{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800114 uint64_t mpidr = read_mpidr();
Anthony Zhou3b804502017-06-26 20:33:34 +0800115 uint64_t cpuid = mpidr & MPIDR_CPU_MASK;
116 uint64_t impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700117
118 /*
119 * T186 has 2 CPU clusters, one with Denver CPUs and the other with
120 * ARM CortexA-57 CPUs. Each cluster consists of 4 CPUs and the CPU
121 * numbers start from 0. In order to get the proper arch_mce_ops_t
122 * struct, we have to convert the Denver CPU ids to the corresponding
123 * indices in the mce_ops_table array.
124 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800125 if (impl == DENVER_IMPL) {
126 cpuid |= 0x4U;
127 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700128
129 return mce_cfg_table[cpuid].ari_base;
130}
131
132static arch_mce_ops_t *mce_get_curr_cpu_ops(void)
133{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800134 uint64_t mpidr = read_mpidr();
Anthony Zhou3b804502017-06-26 20:33:34 +0800135 uint64_t cpuid = mpidr & MPIDR_CPU_MASK;
136 uint64_t impl = (read_midr() >> MIDR_IMPL_SHIFT) &
137 MIDR_IMPL_MASK;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700138
139 /*
140 * T186 has 2 CPU clusters, one with Denver CPUs and the other with
141 * ARM CortexA-57 CPUs. Each cluster consists of 4 CPUs and the CPU
142 * numbers start from 0. In order to get the proper arch_mce_ops_t
143 * struct, we have to convert the Denver CPU ids to the corresponding
144 * indices in the mce_ops_table array.
145 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800146 if (impl == DENVER_IMPL) {
147 cpuid |= 0x4U;
148 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700149
150 return mce_cfg_table[cpuid].ops;
151}
152
153/*******************************************************************************
154 * Common handler for all MCE commands
155 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800156int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700157 uint64_t arg2)
158{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800159 const arch_mce_ops_t *ops;
160 gp_regs_t *gp_regs = get_gpregs_ctx(cm_get_context(NON_SECURE));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700161 uint32_t cpu_ari_base;
162 uint64_t ret64 = 0, arg3, arg4, arg5;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800163 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700164
Anthony Zhou1ab31402017-03-06 16:06:45 +0800165 assert(gp_regs != NULL);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700166
167 /* get a pointer to the CPU's arch_mce_ops_t struct */
168 ops = mce_get_curr_cpu_ops();
169
170 /* get the CPU's ARI base address */
171 cpu_ari_base = mce_get_curr_cpu_ari_base();
172
173 switch (cmd) {
Anthony Zhou0e07e452017-07-26 17:16:54 +0800174 case (uint64_t)MCE_CMD_ENTER_CSTATE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700175 ret = ops->enter_cstate(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700176
177 break;
178
Anthony Zhou0e07e452017-07-26 17:16:54 +0800179 case (uint64_t)MCE_CMD_UPDATE_CSTATE_INFO:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700180 /*
181 * get the parameters required for the update cstate info
182 * command
183 */
Anthony Zhou3b804502017-06-26 20:33:34 +0800184 arg3 = read_ctx_reg(gp_regs, CTX_GPREG_X4);
185 arg4 = read_ctx_reg(gp_regs, CTX_GPREG_X5);
186 arg5 = read_ctx_reg(gp_regs, CTX_GPREG_X6);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700187
188 ret = ops->update_cstate_info(cpu_ari_base, (uint32_t)arg0,
189 (uint32_t)arg1, (uint32_t)arg2, (uint8_t)arg3,
190 (uint32_t)arg4, (uint8_t)arg5);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700191
Anthony Zhou3b804502017-06-26 20:33:34 +0800192 write_ctx_reg(gp_regs, CTX_GPREG_X4, (0ULL));
193 write_ctx_reg(gp_regs, CTX_GPREG_X5, (0ULL));
194 write_ctx_reg(gp_regs, CTX_GPREG_X6, (0ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700195
196 break;
197
Anthony Zhou0e07e452017-07-26 17:16:54 +0800198 case (uint64_t)MCE_CMD_UPDATE_CROSSOVER_TIME:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700199 ret = ops->update_crossover_time(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700200
201 break;
202
Anthony Zhou0e07e452017-07-26 17:16:54 +0800203 case (uint64_t)MCE_CMD_READ_CSTATE_STATS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700204 ret64 = ops->read_cstate_stats(cpu_ari_base, arg0);
205
206 /* update context to return cstate stats value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800207 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
208 write_ctx_reg(gp_regs, CTX_GPREG_X2, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700209
210 break;
211
Anthony Zhou0e07e452017-07-26 17:16:54 +0800212 case (uint64_t)MCE_CMD_WRITE_CSTATE_STATS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700213 ret = ops->write_cstate_stats(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700214
215 break;
216
Anthony Zhou0e07e452017-07-26 17:16:54 +0800217 case (uint64_t)MCE_CMD_IS_CCX_ALLOWED:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700218 ret = ops->is_ccx_allowed(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700219
220 /* update context to return CCx status value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800221 write_ctx_reg(gp_regs, CTX_GPREG_X1, (uint64_t)(ret));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700222
223 break;
224
Anthony Zhou0e07e452017-07-26 17:16:54 +0800225 case (uint64_t)MCE_CMD_IS_SC7_ALLOWED:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700226 ret = ops->is_sc7_allowed(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700227
228 /* update context to return SC7 status value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800229 write_ctx_reg(gp_regs, CTX_GPREG_X1, (uint64_t)(ret));
230 write_ctx_reg(gp_regs, CTX_GPREG_X3, (uint64_t)(ret));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700231
232 break;
233
Anthony Zhou0e07e452017-07-26 17:16:54 +0800234 case (uint64_t)MCE_CMD_ONLINE_CORE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700235 ret = ops->online_core(cpu_ari_base, arg0);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700236
237 break;
238
Anthony Zhou0e07e452017-07-26 17:16:54 +0800239 case (uint64_t)MCE_CMD_CC3_CTRL:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700240 ret = ops->cc3_ctrl(cpu_ari_base, arg0, arg1, arg2);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700241
242 break;
243
Anthony Zhou0e07e452017-07-26 17:16:54 +0800244 case (uint64_t)MCE_CMD_ECHO_DATA:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700245 ret64 = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_ECHO,
246 arg0);
247
248 /* update context to return if echo'd data matched source */
Anthony Zhou3b804502017-06-26 20:33:34 +0800249 write_ctx_reg(gp_regs, CTX_GPREG_X1, ((ret64 == arg0) ?
250 1ULL : 0ULL));
251 write_ctx_reg(gp_regs, CTX_GPREG_X2, ((ret64 == arg0) ?
252 1ULL : 0ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700253
254 break;
255
Anthony Zhou0e07e452017-07-26 17:16:54 +0800256 case (uint64_t)MCE_CMD_READ_VERSIONS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700257 ret64 = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_VERSION,
258 arg0);
259
260 /*
261 * version = minor(63:32) | major(31:0). Update context
262 * to return major and minor version number.
263 */
Anthony Zhou3b804502017-06-26 20:33:34 +0800264 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
265 write_ctx_reg(gp_regs, CTX_GPREG_X2, (ret64 >> 32ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700266
267 break;
268
Anthony Zhou0e07e452017-07-26 17:16:54 +0800269 case (uint64_t)MCE_CMD_ENUM_FEATURES:
Krishna Sitaramanfc2ec162016-07-27 16:26:45 -0700270 ret64 = ops->call_enum_misc(cpu_ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700271 TEGRA_ARI_MISC_FEATURE_LEAF_0, arg0);
272
273 /* update context to return features value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800274 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700275
Varun Wadekara0352ab2017-03-14 14:24:35 -0700276 break;
277
Anthony Zhou0e07e452017-07-26 17:16:54 +0800278 case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700279 ret = ops->roc_flush_cache_trbits(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700280
281 break;
282
Anthony Zhou0e07e452017-07-26 17:16:54 +0800283 case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700284 ret = ops->roc_flush_cache(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700285
286 break;
287
Anthony Zhou0e07e452017-07-26 17:16:54 +0800288 case (uint64_t)MCE_CMD_ROC_CLEAN_CACHE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700289 ret = ops->roc_clean_cache(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700290
291 break;
292
Anthony Zhou0e07e452017-07-26 17:16:54 +0800293 case (uint64_t)MCE_CMD_ENUM_READ_MCA:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800294 ret64 = ops->read_write_mca(cpu_ari_base, arg0, &arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700295
296 /* update context to return MCA data/error */
Anthony Zhou3b804502017-06-26 20:33:34 +0800297 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
298 write_ctx_reg(gp_regs, CTX_GPREG_X2, (arg1));
299 write_ctx_reg(gp_regs, CTX_GPREG_X3, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700300
301 break;
302
Anthony Zhou0e07e452017-07-26 17:16:54 +0800303 case (uint64_t)MCE_CMD_ENUM_WRITE_MCA:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800304 ret64 = ops->read_write_mca(cpu_ari_base, arg0, &arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700305
306 /* update context to return MCA error */
Anthony Zhou3b804502017-06-26 20:33:34 +0800307 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
308 write_ctx_reg(gp_regs, CTX_GPREG_X3, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700309
310 break;
311
Varun Wadekarad2824f2016-03-28 13:44:35 -0700312#if ENABLE_CHIP_VERIFICATION_HARNESS
Anthony Zhou0e07e452017-07-26 17:16:54 +0800313 case (uint64_t)MCE_CMD_ENABLE_LATIC:
Varun Wadekarad2824f2016-03-28 13:44:35 -0700314 /*
315 * This call is not for production use. The constant value,
316 * 0xFFFF0000, is specific to allowing for enabling LATIC on
317 * pre-production parts for the chip verification harness.
318 *
319 * Enabling LATIC allows S/W to read the MINI ISPs in the
320 * CCPLEX. The ISMs are used for various measurements relevant
321 * to particular locations in the Silicon. They are small
322 * counters which can be polled to determine how fast a
323 * particular location in the Silicon is.
324 */
325 ops->enter_ccplex_state(mce_get_curr_cpu_ari_base(),
326 0xFFFF0000);
327
328 break;
329#endif
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700330
Anthony Zhou0e07e452017-07-26 17:16:54 +0800331 case (uint64_t)MCE_CMD_UNCORE_PERFMON_REQ:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800332 ret = ops->read_write_uncore_perfmon(cpu_ari_base, arg0, &arg1);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700333
334 /* update context to return data */
Anthony Zhou3b804502017-06-26 20:33:34 +0800335 write_ctx_reg(gp_regs, CTX_GPREG_X1, (arg1));
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700336 break;
337
Anthony Zhou0e07e452017-07-26 17:16:54 +0800338 case (uint64_t)MCE_CMD_MISC_CCPLEX:
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700339 ops->misc_ccplex(cpu_ari_base, arg0, arg1);
340
341 break;
342
Varun Wadekara0352ab2017-03-14 14:24:35 -0700343 default:
Masahiro Yamadae93a0f42018-02-02 15:09:36 +0900344 ERROR("unknown MCE command (%llu)\n", cmd);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800345 ret = EINVAL;
346 break;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700347 }
348
349 return ret;
350}
351
352/*******************************************************************************
353 * Handler to update the reset vector for CPUs
354 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800355int32_t mce_update_reset_vector(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700356{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800357 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700358
Krishna Sitaramand007f762016-09-02 16:53:04 -0700359 ops->update_reset_vector(mce_get_curr_cpu_ari_base());
Varun Wadekara0352ab2017-03-14 14:24:35 -0700360
361 return 0;
362}
363
Anthony Zhou1ab31402017-03-06 16:06:45 +0800364static int32_t mce_update_ccplex_gsc(tegra_ari_gsc_index_t gsc_idx)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700365{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800366 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700367
368 ops->update_ccplex_gsc(mce_get_curr_cpu_ari_base(), gsc_idx);
369
370 return 0;
371}
372
373/*******************************************************************************
374 * Handler to update carveout values for Video Memory Carveout region
375 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800376int32_t mce_update_gsc_videomem(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700377{
378 return mce_update_ccplex_gsc(TEGRA_ARI_GSC_VPR_IDX);
379}
380
381/*******************************************************************************
382 * Handler to update carveout values for TZDRAM aperture
383 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800384int32_t mce_update_gsc_tzdram(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700385{
386 return mce_update_ccplex_gsc(TEGRA_ARI_GSC_TZ_DRAM_IDX);
387}
388
389/*******************************************************************************
Varun Wadekara0352ab2017-03-14 14:24:35 -0700390 * Handler to shutdown/reset the entire system
391 ******************************************************************************/
392__dead2 void mce_enter_ccplex_state(uint32_t state_idx)
393{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800394 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700395
396 /* sanity check state value */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800397 if ((state_idx != TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) &&
398 (state_idx != TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700399 panic();
Anthony Zhou1ab31402017-03-06 16:06:45 +0800400 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700401
402 ops->enter_ccplex_state(mce_get_curr_cpu_ari_base(), state_idx);
403
404 /* wait till the CCPLEX powers down */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800405 for (;;) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700406 ;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800407 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700408
Varun Wadekara0352ab2017-03-14 14:24:35 -0700409}
Varun Wadekar47ddd002016-03-28 16:00:02 -0700410
411/*******************************************************************************
Varun Wadekarc47504f2017-03-23 17:32:20 -0700412 * Handler to issue the UPDATE_CSTATE_INFO request
413 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800414void mce_update_cstate_info(const mce_cstate_info_t *cstate)
Varun Wadekarc47504f2017-03-23 17:32:20 -0700415{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800416 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekarc47504f2017-03-23 17:32:20 -0700417
418 /* issue the UPDATE_CSTATE_INFO request */
419 ops->update_cstate_info(mce_get_curr_cpu_ari_base(), cstate->cluster,
420 cstate->ccplex, cstate->system, cstate->system_state_force,
421 cstate->wake_mask, cstate->update_wake_mask);
422}
423
424/*******************************************************************************
Varun Wadekar47ddd002016-03-28 16:00:02 -0700425 * Handler to read the MCE firmware version and check if it is compatible
426 * with interface header the BL3-1 was compiled against
427 ******************************************************************************/
428void mce_verify_firmware_version(void)
429{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800430 const arch_mce_ops_t *ops;
Varun Wadekar47ddd002016-03-28 16:00:02 -0700431 uint32_t cpu_ari_base;
432 uint64_t version;
Varun Wadekarefa66d42016-07-18 17:42:02 -0700433 uint32_t major, minor;
434
435 /*
Varun Wadekarb5568282016-12-13 18:04:35 -0800436 * MCE firmware is not supported on simulation platforms.
Varun Wadekarefa66d42016-07-18 17:42:02 -0700437 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800438 if (tegra_platform_is_emulation()) {
Varun Wadekar47ddd002016-03-28 16:00:02 -0700439
Anthony Zhou1ab31402017-03-06 16:06:45 +0800440 INFO("MCE firmware is not supported\n");
Varun Wadekar47ddd002016-03-28 16:00:02 -0700441
Anthony Zhou1ab31402017-03-06 16:06:45 +0800442 } else {
443 /* get a pointer to the CPU's arch_mce_ops_t struct */
444 ops = mce_get_curr_cpu_ops();
Varun Wadekar47ddd002016-03-28 16:00:02 -0700445
Anthony Zhou1ab31402017-03-06 16:06:45 +0800446 /* get the CPU's ARI base address */
447 cpu_ari_base = mce_get_curr_cpu_ari_base();
Varun Wadekar47ddd002016-03-28 16:00:02 -0700448
Anthony Zhou1ab31402017-03-06 16:06:45 +0800449 /*
450 * Read the MCE firmware version and extract the major and minor
451 * version fields
452 */
453 version = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_VERSION, 0);
454 major = (uint32_t)version;
455 minor = (uint32_t)(version >> 32);
Varun Wadekar47ddd002016-03-28 16:00:02 -0700456
Anthony Zhou1ab31402017-03-06 16:06:45 +0800457 INFO("MCE Version - HW=%d:%d, SW=%d:%d\n", major, minor,
458 TEGRA_ARI_VERSION_MAJOR, TEGRA_ARI_VERSION_MINOR);
Varun Wadekar47ddd002016-03-28 16:00:02 -0700459
Anthony Zhou1ab31402017-03-06 16:06:45 +0800460 /*
461 * Verify that the MCE firmware version and the interface header
462 * match
463 */
464 if (major != TEGRA_ARI_VERSION_MAJOR) {
465 ERROR("ARI major version mismatch\n");
466 panic();
467 }
468
469 if (minor < TEGRA_ARI_VERSION_MINOR) {
470 ERROR("ARI minor version mismatch\n");
471 panic();
472 }
Varun Wadekar47ddd002016-03-28 16:00:02 -0700473 }
474}