mce.c 7.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <arch_helpers.h>
#include <assert.h>
#include <common/bl_common.h>
#include <context.h>
#include <lib/el3_runtime/context_mgmt.h>
#include <common/debug.h>
#include <denver.h>
#include <mce.h>
#include <mce_private.h>
#include <mmio.h>
Steven Kao's avatar
Steven Kao committed
18
#include <platform_def.h>
19
#include <stdbool.h>
20
21
#include <string.h>
#include <errno.h>
Steven Kao's avatar
Steven Kao committed
22
#include <t194_nvg.h>
23
24
25
#include <tegra_def.h>
#include <tegra_platform.h>

26
27
28
29
30
31
32
33
34
35
36
37
/* Handler to check if MCE firmware is supported */
static bool mce_firmware_not_supported(void)
{
	bool status;

	/* these platforms do not load MCE firmware */
	status = tegra_platform_is_linsim() || tegra_platform_is_qt() ||
		 tegra_platform_is_virt_dev_kit();

	return status;
}

38
39
40
/*******************************************************************************
 * Common handler for all MCE commands
 ******************************************************************************/
41
int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
42
43
44
			uint64_t arg2)
{
	uint64_t ret64 = 0, arg3, arg4, arg5;
Steven Kao's avatar
Steven Kao committed
45
	int32_t ret = 0;
46
47
48
	cpu_context_t *ctx = cm_get_context(NON_SECURE);
	gp_regs_t *gp_regs = get_gpregs_ctx(ctx);

49
50
	assert(ctx != NULL);
	assert(gp_regs != NULL);
51
52

	switch (cmd) {
53
	case (uint64_t)MCE_CMD_ENTER_CSTATE:
Steven Kao's avatar
Steven Kao committed
54
55
56
57
58
		ret = nvg_enter_cstate((uint32_t)arg0, (uint32_t)arg1);
		if (ret < 0) {
			ERROR("%s: enter_cstate failed(%d)\n", __func__, ret);
		}

59
60
		break;

61
	case (uint64_t)MCE_CMD_UPDATE_CSTATE_INFO:
62
63
64
65
		/*
		 * get the parameters required for the update cstate info
		 * command
		 */
66
67
68
		arg3 = read_ctx_reg(gp_regs, CTX_GPREG_X4);
		arg4 = read_ctx_reg(gp_regs, CTX_GPREG_X5);
		arg5 = read_ctx_reg(gp_regs, CTX_GPREG_X6);
Steven Kao's avatar
Steven Kao committed
69
70
71
72
73
74
75
76
77
78

		/* arg0 cluster
		 * arg1 ccplex
		 * arg2 system
		 * arg3 sys_state_force => T19x not support
		 * arg4 wake_mask
		 * arg5 update_wake_mask
		 */
		nvg_update_cstate_info((uint32_t)arg0, (uint32_t)arg1,
				(uint32_t)arg2, (uint32_t)arg4, (uint8_t)arg5);
79

80
81
82
		write_ctx_reg(gp_regs, CTX_GPREG_X4, arg3);
		write_ctx_reg(gp_regs, CTX_GPREG_X5, arg4);
		write_ctx_reg(gp_regs, CTX_GPREG_X6, arg5);
83
84
85

		break;

86
	case (uint64_t)MCE_CMD_UPDATE_CROSSOVER_TIME:
Steven Kao's avatar
Steven Kao committed
87
88
89
90
91
		ret = nvg_update_crossover_time((uint32_t)arg0, (uint32_t)arg1);
		if (ret < 0) {
			ERROR("%s: update_crossover_time failed(%d)\n",
				__func__, ret);
		}
92
93
94

		break;

95
	case (uint64_t)MCE_CMD_READ_CSTATE_STATS:
Steven Kao's avatar
Steven Kao committed
96
		ret64 = nvg_get_cstate_stat_query_value();
97
98

		/* update context to return cstate stats value */
99
100
		write_ctx_reg(gp_regs, CTX_GPREG_X1, ret64);
		write_ctx_reg(gp_regs, CTX_GPREG_X2, ret64);
101
102
103

		break;

104
	case (uint64_t)MCE_CMD_WRITE_CSTATE_STATS:
Steven Kao's avatar
Steven Kao committed
105
		ret = nvg_set_cstate_stat_query_value(arg0);
106
107
108

		break;

109
	case (uint64_t)MCE_CMD_IS_SC7_ALLOWED:
Steven Kao's avatar
Steven Kao committed
110
111
112
113
114
		ret = nvg_is_sc7_allowed();
		if (ret < 0) {
			ERROR("%s: is_sc7_allowed failed(%d)\n", __func__, ret);
			break;
		}
115
116

		/* update context to return SC7 status value */
117
118
		write_ctx_reg(gp_regs, CTX_GPREG_X1, (uint64_t)ret);
		write_ctx_reg(gp_regs, CTX_GPREG_X3, (uint64_t)ret);
119
120
121

		break;

122
	case (uint64_t)MCE_CMD_ONLINE_CORE:
Steven Kao's avatar
Steven Kao committed
123
124
125
126
		ret = nvg_online_core((uint32_t)arg0);
		if (ret < 0) {
			ERROR("%s: online_core failed(%d)\n", __func__, ret);
		}
127
128
129

		break;

130
	case (uint64_t)MCE_CMD_CC3_CTRL:
Steven Kao's avatar
Steven Kao committed
131
132
133
134
		ret = nvg_cc3_ctrl((uint32_t)arg0, (uint8_t)arg2);
		if (ret < 0) {
			ERROR("%s: cc3_ctrl failed(%d)\n", __func__, ret);
		}
135
136
137

		break;

138
	case (uint64_t)MCE_CMD_READ_VERSIONS:
139
		/* get the MCE firmware version */
Steven Kao's avatar
Steven Kao committed
140
		ret64 = nvg_get_version();
141
142
143
144
145

		/*
		 * version = minor(63:32) | major(31:0). Update context
		 * to return major and minor version number.
		 */
146
147
		write_ctx_reg(gp_regs, CTX_GPREG_X1, (ret64 & 0xFFFFULL));
		write_ctx_reg(gp_regs, CTX_GPREG_X2, (ret64 >> 32U));
148
149
150

		break;

151
	case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
Steven Kao's avatar
Steven Kao committed
152
153
154
155
156
		ret = nvg_roc_clean_cache_trbits();
		if (ret < 0) {
			ERROR("%s: flush cache_trbits failed(%d)\n", __func__,
				ret);
		}
157
158
159

		break;

160
	case (uint64_t)MCE_CMD_ROC_FLUSH_CACHE:
Steven Kao's avatar
Steven Kao committed
161
162
163
164
		ret = nvg_roc_flush_cache();
		if (ret < 0) {
			ERROR("%s: flush cache failed(%d)\n", __func__, ret);
		}
165
166
167

		break;

168
	case (uint64_t)MCE_CMD_ROC_CLEAN_CACHE:
Steven Kao's avatar
Steven Kao committed
169
170
171
172
		ret = nvg_roc_clean_cache();
		if (ret < 0) {
			ERROR("%s: clean cache failed(%d)\n", __func__, ret);
		}
173
174
175
176

		break;

	default:
177
		ERROR("unknown MCE command (%llu)\n", cmd);
Steven Kao's avatar
Steven Kao committed
178
179
		ret = EINVAL;
		break;
180
181
182
183
184
185
186
187
	}

	return ret;
}

/*******************************************************************************
 * Handler to update carveout values for Video Memory Carveout region
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
188
int32_t mce_update_gsc_videomem(void)
189
{
190
191
192
193
194
195
196
197
198
199
200
201
	int32_t ret;

	/*
	 * MCE firmware is not running on simulation platforms.
	 */
	if (mce_firmware_not_supported()) {
		ret = -EINVAL;
	} else {
		ret = nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_VPR);
	}

	return ret;
202
203
204
205
206
}

/*******************************************************************************
 * Handler to update carveout values for TZDRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
207
int32_t mce_update_gsc_tzdram(void)
208
{
209
210
211
212
213
214
215
216
217
218
219
220
	int32_t ret;

	/*
	 * MCE firmware is not running on simulation platforms.
	 */
	if (mce_firmware_not_supported()) {
		ret = -EINVAL;
	} else {
		ret = nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_TZ_DRAM);
	}

	return ret;
221
222
223
224
225
}

/*******************************************************************************
 * Handler to update carveout values for TZ SysRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
226
int32_t mce_update_gsc_tzram(void)
227
{
228
229
230
231
232
233
234
235
236
237
238
239
	int32_t ret;

	/*
	 * MCE firmware is not running on simulation platforms.
	 */
	if (mce_firmware_not_supported()) {
		ret = -EINVAL;
	} else {
		ret = nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_TZRAM);
	}

	return ret;
240
241
242
243
244
}

/*******************************************************************************
 * Handler to issue the UPDATE_CSTATE_INFO request
 ******************************************************************************/
245
void mce_update_cstate_info(const mce_cstate_info_t *cstate)
246
247
{
	/* issue the UPDATE_CSTATE_INFO request */
Steven Kao's avatar
Steven Kao committed
248
249
	nvg_update_cstate_info(cstate->cluster, cstate->ccplex, cstate->system,
		cstate->wake_mask, cstate->update_wake_mask);
250
251
252
253
254
255
256
257
258
259
260
261
262
263
}

/*******************************************************************************
 * Handler to read the MCE firmware version and check if it is compatible
 * with interface header the BL3-1 was compiled against
 ******************************************************************************/
void mce_verify_firmware_version(void)
{
	uint64_t version;
	uint32_t major, minor;

	/*
	 * MCE firmware is not running on simulation platforms.
	 */
264
	if (mce_firmware_not_supported()) {
265
		return;
Steven Kao's avatar
Steven Kao committed
266
	}
267
268
269
270
271

	/*
	 * Read the MCE firmware version and extract the major and minor
	 * version fields
	 */
Steven Kao's avatar
Steven Kao committed
272
273
274
	version = nvg_get_version();
	minor = (uint32_t)version;
	major = (uint32_t)(version >> 32);
275
276
277
278
279
280
281
282

	INFO("MCE Version - HW=%d:%d, SW=%d:%d\n", major, minor,
		0, 0);

	/*
	 * Verify that the MCE firmware version and the interface header
	 * match
	 */
Steven Kao's avatar
Steven Kao committed
283
	if (major != (uint32_t)TEGRA_NVG_VERSION_MAJOR) {
284
285
286
287
		ERROR("MCE major version mismatch\n");
		panic();
	}

Steven Kao's avatar
Steven Kao committed
288
	if (minor < (uint32_t)TEGRA_NVG_VERSION_MINOR) {
289
290
291
292
		ERROR("MCE minor version mismatch\n");
		panic();
	}
}