blob: aebacebf290ddfb1663eede7061cc6522690ecf6 [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>
Scott Brandene5dcf982020-08-25 13:49:32 -070010#include <inttypes.h>
11#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <string.h>
13
Varun Wadekara0352ab2017-03-14 14:24:35 -070014#include <arch.h>
15#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <common/bl_common.h>
17#include <common/debug.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070018#include <context.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070019#include <denver.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000020#include <lib/el3_runtime/context_mgmt.h>
21#include <lib/mmio.h>
22
Varun Wadekara0352ab2017-03-14 14:24:35 -070023#include <mce.h>
Varun Wadekarb5568282016-12-13 18:04:35 -080024#include <mce_private.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070025#include <t18x_ari.h>
26#include <tegra_def.h>
Varun Wadekarefa66d42016-07-18 17:42:02 -070027#include <tegra_platform.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070028
29/* NVG functions handlers */
30static arch_mce_ops_t nvg_mce_ops = {
31 .enter_cstate = nvg_enter_cstate,
32 .update_cstate_info = nvg_update_cstate_info,
33 .update_crossover_time = nvg_update_crossover_time,
34 .read_cstate_stats = nvg_read_cstate_stats,
35 .write_cstate_stats = nvg_write_cstate_stats,
36 .call_enum_misc = ari_enumeration_misc,
37 .is_ccx_allowed = nvg_is_ccx_allowed,
38 .is_sc7_allowed = nvg_is_sc7_allowed,
39 .online_core = nvg_online_core,
40 .cc3_ctrl = nvg_cc3_ctrl,
41 .update_reset_vector = ari_reset_vector_update,
42 .roc_flush_cache = ari_roc_flush_cache,
43 .roc_flush_cache_trbits = ari_roc_flush_cache_trbits,
44 .roc_clean_cache = ari_roc_clean_cache,
45 .read_write_mca = ari_read_write_mca,
46 .update_ccplex_gsc = ari_update_ccplex_gsc,
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070047 .enter_ccplex_state = ari_enter_ccplex_state,
Krishna Sitaramanb429d562016-07-19 16:36:13 -070048 .read_write_uncore_perfmon = ari_read_write_uncore_perfmon,
49 .misc_ccplex = ari_misc_ccplex
Varun Wadekara0352ab2017-03-14 14:24:35 -070050};
51
52/* ARI functions handlers */
53static arch_mce_ops_t ari_mce_ops = {
54 .enter_cstate = ari_enter_cstate,
55 .update_cstate_info = ari_update_cstate_info,
56 .update_crossover_time = ari_update_crossover_time,
57 .read_cstate_stats = ari_read_cstate_stats,
58 .write_cstate_stats = ari_write_cstate_stats,
59 .call_enum_misc = ari_enumeration_misc,
60 .is_ccx_allowed = ari_is_ccx_allowed,
61 .is_sc7_allowed = ari_is_sc7_allowed,
62 .online_core = ari_online_core,
63 .cc3_ctrl = ari_cc3_ctrl,
64 .update_reset_vector = ari_reset_vector_update,
65 .roc_flush_cache = ari_roc_flush_cache,
66 .roc_flush_cache_trbits = ari_roc_flush_cache_trbits,
67 .roc_clean_cache = ari_roc_clean_cache,
68 .read_write_mca = ari_read_write_mca,
69 .update_ccplex_gsc = ari_update_ccplex_gsc,
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070070 .enter_ccplex_state = ari_enter_ccplex_state,
Krishna Sitaramanb429d562016-07-19 16:36:13 -070071 .read_write_uncore_perfmon = ari_read_write_uncore_perfmon,
72 .misc_ccplex = ari_misc_ccplex
Varun Wadekara0352ab2017-03-14 14:24:35 -070073};
74
Anthony Zhou1ab31402017-03-06 16:06:45 +080075typedef struct {
Varun Wadekara0352ab2017-03-14 14:24:35 -070076 uint32_t ari_base;
77 arch_mce_ops_t *ops;
78} mce_config_t;
79
80/* Table to hold the per-CPU ARI base address and function handlers */
81static mce_config_t mce_cfg_table[MCE_ARI_APERTURES_MAX] = {
82 {
83 /* A57 Core 0 */
84 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_0_OFFSET,
85 .ops = &ari_mce_ops,
86 },
87 {
88 /* A57 Core 1 */
89 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_1_OFFSET,
90 .ops = &ari_mce_ops,
91 },
92 {
93 /* A57 Core 2 */
94 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_2_OFFSET,
95 .ops = &ari_mce_ops,
96 },
97 {
98 /* A57 Core 3 */
99 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_3_OFFSET,
100 .ops = &ari_mce_ops,
101 },
102 {
103 /* D15 Core 0 */
104 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_4_OFFSET,
105 .ops = &nvg_mce_ops,
106 },
107 {
108 /* D15 Core 1 */
109 .ari_base = TEGRA_MMCRAB_BASE + MCE_ARI_APERTURE_5_OFFSET,
110 .ops = &nvg_mce_ops,
111 }
112};
113
114static uint32_t mce_get_curr_cpu_ari_base(void)
115{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800116 uint64_t mpidr = read_mpidr();
Anthony Zhou3b804502017-06-26 20:33:34 +0800117 uint64_t cpuid = mpidr & MPIDR_CPU_MASK;
118 uint64_t impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700119
120 /*
121 * T186 has 2 CPU clusters, one with Denver CPUs and the other with
122 * ARM CortexA-57 CPUs. Each cluster consists of 4 CPUs and the CPU
123 * numbers start from 0. In order to get the proper arch_mce_ops_t
124 * struct, we have to convert the Denver CPU ids to the corresponding
125 * indices in the mce_ops_table array.
126 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800127 if (impl == DENVER_IMPL) {
128 cpuid |= 0x4U;
129 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700130
131 return mce_cfg_table[cpuid].ari_base;
132}
133
134static arch_mce_ops_t *mce_get_curr_cpu_ops(void)
135{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800136 uint64_t mpidr = read_mpidr();
Anthony Zhou3b804502017-06-26 20:33:34 +0800137 uint64_t cpuid = mpidr & MPIDR_CPU_MASK;
138 uint64_t impl = (read_midr() >> MIDR_IMPL_SHIFT) &
139 MIDR_IMPL_MASK;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700140
141 /*
142 * T186 has 2 CPU clusters, one with Denver CPUs and the other with
143 * ARM CortexA-57 CPUs. Each cluster consists of 4 CPUs and the CPU
144 * numbers start from 0. In order to get the proper arch_mce_ops_t
145 * struct, we have to convert the Denver CPU ids to the corresponding
146 * indices in the mce_ops_table array.
147 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800148 if (impl == DENVER_IMPL) {
149 cpuid |= 0x4U;
150 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700151
152 return mce_cfg_table[cpuid].ops;
153}
154
155/*******************************************************************************
156 * Common handler for all MCE commands
157 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800158int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700159 uint64_t arg2)
160{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800161 const arch_mce_ops_t *ops;
162 gp_regs_t *gp_regs = get_gpregs_ctx(cm_get_context(NON_SECURE));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700163 uint32_t cpu_ari_base;
164 uint64_t ret64 = 0, arg3, arg4, arg5;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800165 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700166
Anthony Zhou1ab31402017-03-06 16:06:45 +0800167 assert(gp_regs != NULL);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700168
169 /* get a pointer to the CPU's arch_mce_ops_t struct */
170 ops = mce_get_curr_cpu_ops();
171
172 /* get the CPU's ARI base address */
173 cpu_ari_base = mce_get_curr_cpu_ari_base();
174
175 switch (cmd) {
Anthony Zhou0e07e452017-07-26 17:16:54 +0800176 case (uint64_t)MCE_CMD_ENTER_CSTATE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700177 ret = ops->enter_cstate(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700178
179 break;
180
Anthony Zhou0e07e452017-07-26 17:16:54 +0800181 case (uint64_t)MCE_CMD_UPDATE_CSTATE_INFO:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700182 /*
183 * get the parameters required for the update cstate info
184 * command
185 */
Anthony Zhou3b804502017-06-26 20:33:34 +0800186 arg3 = read_ctx_reg(gp_regs, CTX_GPREG_X4);
187 arg4 = read_ctx_reg(gp_regs, CTX_GPREG_X5);
188 arg5 = read_ctx_reg(gp_regs, CTX_GPREG_X6);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700189
190 ret = ops->update_cstate_info(cpu_ari_base, (uint32_t)arg0,
191 (uint32_t)arg1, (uint32_t)arg2, (uint8_t)arg3,
192 (uint32_t)arg4, (uint8_t)arg5);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700193
Anthony Zhou3b804502017-06-26 20:33:34 +0800194 write_ctx_reg(gp_regs, CTX_GPREG_X4, (0ULL));
195 write_ctx_reg(gp_regs, CTX_GPREG_X5, (0ULL));
196 write_ctx_reg(gp_regs, CTX_GPREG_X6, (0ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700197
198 break;
199
Anthony Zhou0e07e452017-07-26 17:16:54 +0800200 case (uint64_t)MCE_CMD_UPDATE_CROSSOVER_TIME:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700201 ret = ops->update_crossover_time(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700202
203 break;
204
Anthony Zhou0e07e452017-07-26 17:16:54 +0800205 case (uint64_t)MCE_CMD_READ_CSTATE_STATS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700206 ret64 = ops->read_cstate_stats(cpu_ari_base, arg0);
207
208 /* update context to return cstate stats value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800209 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
210 write_ctx_reg(gp_regs, CTX_GPREG_X2, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700211
212 break;
213
Anthony Zhou0e07e452017-07-26 17:16:54 +0800214 case (uint64_t)MCE_CMD_WRITE_CSTATE_STATS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700215 ret = ops->write_cstate_stats(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700216
217 break;
218
Anthony Zhou0e07e452017-07-26 17:16:54 +0800219 case (uint64_t)MCE_CMD_IS_CCX_ALLOWED:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700220 ret = ops->is_ccx_allowed(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700221
222 /* update context to return CCx status value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800223 write_ctx_reg(gp_regs, CTX_GPREG_X1, (uint64_t)(ret));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700224
225 break;
226
Anthony Zhou0e07e452017-07-26 17:16:54 +0800227 case (uint64_t)MCE_CMD_IS_SC7_ALLOWED:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700228 ret = ops->is_sc7_allowed(cpu_ari_base, arg0, arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700229
230 /* update context to return SC7 status value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800231 write_ctx_reg(gp_regs, CTX_GPREG_X1, (uint64_t)(ret));
232 write_ctx_reg(gp_regs, CTX_GPREG_X3, (uint64_t)(ret));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700233
234 break;
235
Anthony Zhou0e07e452017-07-26 17:16:54 +0800236 case (uint64_t)MCE_CMD_ONLINE_CORE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700237 ret = ops->online_core(cpu_ari_base, arg0);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700238
239 break;
240
Anthony Zhou0e07e452017-07-26 17:16:54 +0800241 case (uint64_t)MCE_CMD_CC3_CTRL:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700242 ret = ops->cc3_ctrl(cpu_ari_base, arg0, arg1, arg2);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700243
244 break;
245
Anthony Zhou0e07e452017-07-26 17:16:54 +0800246 case (uint64_t)MCE_CMD_ECHO_DATA:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700247 ret64 = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_ECHO,
248 arg0);
249
250 /* update context to return if echo'd data matched source */
Anthony Zhou3b804502017-06-26 20:33:34 +0800251 write_ctx_reg(gp_regs, CTX_GPREG_X1, ((ret64 == arg0) ?
252 1ULL : 0ULL));
253 write_ctx_reg(gp_regs, CTX_GPREG_X2, ((ret64 == arg0) ?
254 1ULL : 0ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700255
256 break;
257
Anthony Zhou0e07e452017-07-26 17:16:54 +0800258 case (uint64_t)MCE_CMD_READ_VERSIONS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700259 ret64 = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_VERSION,
260 arg0);
261
262 /*
263 * version = minor(63:32) | major(31:0). Update context
264 * to return major and minor version number.
265 */
Anthony Zhou3b804502017-06-26 20:33:34 +0800266 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
267 write_ctx_reg(gp_regs, CTX_GPREG_X2, (ret64 >> 32ULL));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700268
269 break;
270
Anthony Zhou0e07e452017-07-26 17:16:54 +0800271 case (uint64_t)MCE_CMD_ENUM_FEATURES:
Krishna Sitaramanfc2ec162016-07-27 16:26:45 -0700272 ret64 = ops->call_enum_misc(cpu_ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700273 TEGRA_ARI_MISC_FEATURE_LEAF_0, arg0);
274
275 /* update context to return features value */
Anthony Zhou3b804502017-06-26 20:33:34 +0800276 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700277
Varun Wadekara0352ab2017-03-14 14:24:35 -0700278 break;
279
Anthony Zhou0e07e452017-07-26 17:16:54 +0800280 case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700281 ret = ops->roc_flush_cache_trbits(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700282
283 break;
284
Anthony Zhou0e07e452017-07-26 17:16:54 +0800285 case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700286 ret = ops->roc_flush_cache(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700287
288 break;
289
Anthony Zhou0e07e452017-07-26 17:16:54 +0800290 case (uint64_t)MCE_CMD_ROC_CLEAN_CACHE:
Varun Wadekara0352ab2017-03-14 14:24:35 -0700291 ret = ops->roc_clean_cache(cpu_ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700292
293 break;
294
Anthony Zhou0e07e452017-07-26 17:16:54 +0800295 case (uint64_t)MCE_CMD_ENUM_READ_MCA:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800296 ret64 = ops->read_write_mca(cpu_ari_base, arg0, &arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700297
298 /* update context to return MCA data/error */
Anthony Zhou3b804502017-06-26 20:33:34 +0800299 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
300 write_ctx_reg(gp_regs, CTX_GPREG_X2, (arg1));
301 write_ctx_reg(gp_regs, CTX_GPREG_X3, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700302
303 break;
304
Anthony Zhou0e07e452017-07-26 17:16:54 +0800305 case (uint64_t)MCE_CMD_ENUM_WRITE_MCA:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800306 ret64 = ops->read_write_mca(cpu_ari_base, arg0, &arg1);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700307
308 /* update context to return MCA error */
Anthony Zhou3b804502017-06-26 20:33:34 +0800309 write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64));
310 write_ctx_reg(gp_regs, CTX_GPREG_X3, (ret64));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700311
312 break;
313
Varun Wadekarad2824f2016-03-28 13:44:35 -0700314#if ENABLE_CHIP_VERIFICATION_HARNESS
Anthony Zhou0e07e452017-07-26 17:16:54 +0800315 case (uint64_t)MCE_CMD_ENABLE_LATIC:
Varun Wadekarad2824f2016-03-28 13:44:35 -0700316 /*
317 * This call is not for production use. The constant value,
318 * 0xFFFF0000, is specific to allowing for enabling LATIC on
319 * pre-production parts for the chip verification harness.
320 *
321 * Enabling LATIC allows S/W to read the MINI ISPs in the
322 * CCPLEX. The ISMs are used for various measurements relevant
323 * to particular locations in the Silicon. They are small
324 * counters which can be polled to determine how fast a
325 * particular location in the Silicon is.
326 */
327 ops->enter_ccplex_state(mce_get_curr_cpu_ari_base(),
328 0xFFFF0000);
329
330 break;
331#endif
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700332
Anthony Zhou0e07e452017-07-26 17:16:54 +0800333 case (uint64_t)MCE_CMD_UNCORE_PERFMON_REQ:
Anthony Zhou1ab31402017-03-06 16:06:45 +0800334 ret = ops->read_write_uncore_perfmon(cpu_ari_base, arg0, &arg1);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700335
336 /* update context to return data */
Anthony Zhou3b804502017-06-26 20:33:34 +0800337 write_ctx_reg(gp_regs, CTX_GPREG_X1, (arg1));
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700338 break;
339
Anthony Zhou0e07e452017-07-26 17:16:54 +0800340 case (uint64_t)MCE_CMD_MISC_CCPLEX:
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700341 ops->misc_ccplex(cpu_ari_base, arg0, arg1);
342
343 break;
344
Varun Wadekara0352ab2017-03-14 14:24:35 -0700345 default:
Scott Brandene5dcf982020-08-25 13:49:32 -0700346 ERROR("unknown MCE command (%" PRIu64 ")\n", cmd);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800347 ret = EINVAL;
348 break;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700349 }
350
351 return ret;
352}
353
354/*******************************************************************************
355 * Handler to update the reset vector for CPUs
356 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800357int32_t mce_update_reset_vector(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700358{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800359 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700360
Krishna Sitaramand007f762016-09-02 16:53:04 -0700361 ops->update_reset_vector(mce_get_curr_cpu_ari_base());
Varun Wadekara0352ab2017-03-14 14:24:35 -0700362
363 return 0;
364}
365
Anthony Zhou1ab31402017-03-06 16:06:45 +0800366static int32_t mce_update_ccplex_gsc(tegra_ari_gsc_index_t gsc_idx)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700367{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800368 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700369
370 ops->update_ccplex_gsc(mce_get_curr_cpu_ari_base(), gsc_idx);
371
372 return 0;
373}
374
375/*******************************************************************************
376 * Handler to update carveout values for Video Memory Carveout region
377 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800378int32_t mce_update_gsc_videomem(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700379{
380 return mce_update_ccplex_gsc(TEGRA_ARI_GSC_VPR_IDX);
381}
382
383/*******************************************************************************
384 * Handler to update carveout values for TZDRAM aperture
385 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800386int32_t mce_update_gsc_tzdram(void)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700387{
388 return mce_update_ccplex_gsc(TEGRA_ARI_GSC_TZ_DRAM_IDX);
389}
390
391/*******************************************************************************
Varun Wadekara0352ab2017-03-14 14:24:35 -0700392 * Handler to shutdown/reset the entire system
393 ******************************************************************************/
394__dead2 void mce_enter_ccplex_state(uint32_t state_idx)
395{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800396 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekara0352ab2017-03-14 14:24:35 -0700397
398 /* sanity check state value */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800399 if ((state_idx != TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) &&
400 (state_idx != TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700401 panic();
Anthony Zhou1ab31402017-03-06 16:06:45 +0800402 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700403
404 ops->enter_ccplex_state(mce_get_curr_cpu_ari_base(), state_idx);
405
406 /* wait till the CCPLEX powers down */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800407 for (;;) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700408 ;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800409 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700410
Varun Wadekara0352ab2017-03-14 14:24:35 -0700411}
Varun Wadekar47ddd002016-03-28 16:00:02 -0700412
413/*******************************************************************************
Varun Wadekarc47504f2017-03-23 17:32:20 -0700414 * Handler to issue the UPDATE_CSTATE_INFO request
415 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +0800416void mce_update_cstate_info(const mce_cstate_info_t *cstate)
Varun Wadekarc47504f2017-03-23 17:32:20 -0700417{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800418 const arch_mce_ops_t *ops = mce_get_curr_cpu_ops();
Varun Wadekarc47504f2017-03-23 17:32:20 -0700419
420 /* issue the UPDATE_CSTATE_INFO request */
421 ops->update_cstate_info(mce_get_curr_cpu_ari_base(), cstate->cluster,
422 cstate->ccplex, cstate->system, cstate->system_state_force,
423 cstate->wake_mask, cstate->update_wake_mask);
424}
425
426/*******************************************************************************
Varun Wadekar47ddd002016-03-28 16:00:02 -0700427 * Handler to read the MCE firmware version and check if it is compatible
428 * with interface header the BL3-1 was compiled against
429 ******************************************************************************/
430void mce_verify_firmware_version(void)
431{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800432 const arch_mce_ops_t *ops;
Varun Wadekar47ddd002016-03-28 16:00:02 -0700433 uint32_t cpu_ari_base;
434 uint64_t version;
Varun Wadekarefa66d42016-07-18 17:42:02 -0700435 uint32_t major, minor;
436
437 /*
Varun Wadekarb5568282016-12-13 18:04:35 -0800438 * MCE firmware is not supported on simulation platforms.
Varun Wadekarefa66d42016-07-18 17:42:02 -0700439 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800440 if (tegra_platform_is_emulation()) {
Varun Wadekar47ddd002016-03-28 16:00:02 -0700441
Anthony Zhou1ab31402017-03-06 16:06:45 +0800442 INFO("MCE firmware is not supported\n");
Varun Wadekar47ddd002016-03-28 16:00:02 -0700443
Anthony Zhou1ab31402017-03-06 16:06:45 +0800444 } else {
445 /* get a pointer to the CPU's arch_mce_ops_t struct */
446 ops = mce_get_curr_cpu_ops();
Varun Wadekar47ddd002016-03-28 16:00:02 -0700447
Anthony Zhou1ab31402017-03-06 16:06:45 +0800448 /* get the CPU's ARI base address */
449 cpu_ari_base = mce_get_curr_cpu_ari_base();
Varun Wadekar47ddd002016-03-28 16:00:02 -0700450
Anthony Zhou1ab31402017-03-06 16:06:45 +0800451 /*
452 * Read the MCE firmware version and extract the major and minor
453 * version fields
454 */
455 version = ops->call_enum_misc(cpu_ari_base, TEGRA_ARI_MISC_VERSION, 0);
456 major = (uint32_t)version;
457 minor = (uint32_t)(version >> 32);
Varun Wadekar47ddd002016-03-28 16:00:02 -0700458
Anthony Zhou1ab31402017-03-06 16:06:45 +0800459 INFO("MCE Version - HW=%d:%d, SW=%d:%d\n", major, minor,
460 TEGRA_ARI_VERSION_MAJOR, TEGRA_ARI_VERSION_MINOR);
Varun Wadekar47ddd002016-03-28 16:00:02 -0700461
Anthony Zhou1ab31402017-03-06 16:06:45 +0800462 /*
463 * Verify that the MCE firmware version and the interface header
464 * match
465 */
466 if (major != TEGRA_ARI_VERSION_MAJOR) {
467 ERROR("ARI major version mismatch\n");
468 panic();
469 }
470
471 if (minor < TEGRA_ARI_VERSION_MINOR) {
472 ERROR("ARI minor version mismatch\n");
473 panic();
474 }
Varun Wadekar47ddd002016-03-28 16:00:02 -0700475 }
476}