mce.c 6.53 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
20
#include <string.h>
#include <errno.h>
Steven Kao's avatar
Steven Kao committed
21
#include <t194_nvg.h>
22
23
24
25
26
27
#include <tegra_def.h>
#include <tegra_platform.h>

/*******************************************************************************
 * Common handler for all MCE commands
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
28
int32_t mce_command_handler(mce_cmd_t cmd, uint64_t arg0, uint64_t arg1,
29
30
31
			uint64_t arg2)
{
	uint64_t ret64 = 0, arg3, arg4, arg5;
Steven Kao's avatar
Steven Kao committed
32
	int32_t ret = 0;
33
34
35
36
37
38
39
40
	cpu_context_t *ctx = cm_get_context(NON_SECURE);
	gp_regs_t *gp_regs = get_gpregs_ctx(ctx);

	assert(ctx);
	assert(gp_regs);

	switch (cmd) {
	case MCE_CMD_ENTER_CSTATE:
Steven Kao's avatar
Steven Kao committed
41
42
43
44
45
		ret = nvg_enter_cstate((uint32_t)arg0, (uint32_t)arg1);
		if (ret < 0) {
			ERROR("%s: enter_cstate failed(%d)\n", __func__, ret);
		}

46
47
48
49
50
51
52
		break;

	case MCE_CMD_UPDATE_CSTATE_INFO:
		/*
		 * get the parameters required for the update cstate info
		 * command
		 */
Steven Kao's avatar
Steven Kao committed
53
54
55
56
57
58
59
60
61
62
63
64
65
		arg3 = read_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X4));
		arg4 = read_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X5));
		arg5 = read_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X6));

		/* 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);
66

Steven Kao's avatar
Steven Kao committed
67
68
69
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X4), (arg3));
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X5), (arg4));
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X6), (arg5));
70
71
72
73

		break;

	case MCE_CMD_UPDATE_CROSSOVER_TIME:
Steven Kao's avatar
Steven Kao committed
74
75
76
77
78
		ret = nvg_update_crossover_time((uint32_t)arg0, (uint32_t)arg1);
		if (ret < 0) {
			ERROR("%s: update_crossover_time failed(%d)\n",
				__func__, ret);
		}
79
80
81
82

		break;

	case MCE_CMD_READ_CSTATE_STATS:
Steven Kao's avatar
Steven Kao committed
83
		ret64 = nvg_get_cstate_stat_query_value();
84
85

		/* update context to return cstate stats value */
Steven Kao's avatar
Steven Kao committed
86
87
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X1), (ret64));
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X2), (ret64));
88
89
90
91

		break;

	case MCE_CMD_WRITE_CSTATE_STATS:
Steven Kao's avatar
Steven Kao committed
92
		ret = nvg_set_cstate_stat_query_value(arg0);
93
94
95
96

		break;

	case MCE_CMD_IS_SC7_ALLOWED:
Steven Kao's avatar
Steven Kao committed
97
98
99
100
101
		ret = nvg_is_sc7_allowed();
		if (ret < 0) {
			ERROR("%s: is_sc7_allowed failed(%d)\n", __func__, ret);
			break;
		}
102
103

		/* update context to return SC7 status value */
Steven Kao's avatar
Steven Kao committed
104
105
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X1), ((uint64_t)ret));
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X3), ((uint64_t)ret));
106
107
108
109

		break;

	case MCE_CMD_ONLINE_CORE:
Steven Kao's avatar
Steven Kao committed
110
111
112
113
		ret = nvg_online_core((uint32_t)arg0);
		if (ret < 0) {
			ERROR("%s: online_core failed(%d)\n", __func__, ret);
		}
114
115
116
117

		break;

	case MCE_CMD_CC3_CTRL:
Steven Kao's avatar
Steven Kao committed
118
119
120
121
		ret = nvg_cc3_ctrl((uint32_t)arg0, (uint8_t)arg2);
		if (ret < 0) {
			ERROR("%s: cc3_ctrl failed(%d)\n", __func__, ret);
		}
122
123
124
125
126

		break;

	case MCE_CMD_READ_VERSIONS:
		/* get the MCE firmware version */
Steven Kao's avatar
Steven Kao committed
127
		ret64 = nvg_get_version();
128
129
130
131
132

		/*
		 * version = minor(63:32) | major(31:0). Update context
		 * to return major and minor version number.
		 */
Steven Kao's avatar
Steven Kao committed
133
134
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X1), (ret64 & (uint64_t)0xFFFF));
		write_ctx_reg(gp_regs, ((uint64_t)CTX_GPREG_X2), (ret64 >> 32));
135
136
137
138

		break;

	case MCE_CMD_ROC_FLUSH_CACHE_TRBITS:
Steven Kao's avatar
Steven Kao committed
139
140
141
142
143
		ret = nvg_roc_clean_cache_trbits();
		if (ret < 0) {
			ERROR("%s: flush cache_trbits failed(%d)\n", __func__,
				ret);
		}
144
145
146
147

		break;

	case MCE_CMD_ROC_FLUSH_CACHE:
Steven Kao's avatar
Steven Kao committed
148
149
150
151
		ret = nvg_roc_flush_cache();
		if (ret < 0) {
			ERROR("%s: flush cache failed(%d)\n", __func__, ret);
		}
152
153
154
155

		break;

	case MCE_CMD_ROC_CLEAN_CACHE:
Steven Kao's avatar
Steven Kao committed
156
157
158
159
		ret = nvg_roc_clean_cache();
		if (ret < 0) {
			ERROR("%s: clean cache failed(%d)\n", __func__, ret);
		}
160
161
162
163
164

		break;

	default:
		ERROR("unknown MCE command (%lld)\n", cmd);
Steven Kao's avatar
Steven Kao committed
165
166
		ret = EINVAL;
		break;
167
168
169
170
171
172
173
174
	}

	return ret;
}

/*******************************************************************************
 * Handler to update carveout values for Video Memory Carveout region
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
175
int32_t mce_update_gsc_videomem(void)
176
{
Steven Kao's avatar
Steven Kao committed
177
	return nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_GSC_VPR_IDX);
178
179
180
181
182
}

/*******************************************************************************
 * Handler to update carveout values for TZDRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
183
int32_t mce_update_gsc_tzdram(void)
184
{
Steven Kao's avatar
Steven Kao committed
185
	return nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_GSC_TZ_DRAM_IDX);
186
187
188
189
190
}

/*******************************************************************************
 * Handler to update carveout values for TZ SysRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
191
int32_t mce_update_gsc_tzram(void)
192
{
Steven Kao's avatar
Steven Kao committed
193
	return nvg_update_ccplex_gsc((uint32_t)TEGRA_NVG_GSC_TZRAM);
194
195
196
197
198
199
200
201
}

/*******************************************************************************
 * Handler to issue the UPDATE_CSTATE_INFO request
 ******************************************************************************/
void mce_update_cstate_info(mce_cstate_info_t *cstate)
{
	/* issue the UPDATE_CSTATE_INFO request */
Steven Kao's avatar
Steven Kao committed
202
203
	nvg_update_cstate_info(cstate->cluster, cstate->ccplex, cstate->system,
		cstate->wake_mask, cstate->update_wake_mask);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
}

/*******************************************************************************
 * 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.
	 */
Steven Kao's avatar
Steven Kao committed
218
	if ((tegra_platform_is_linsim() == 1U) ||
219
220
		(tegra_platform_is_virt_dev_kit() == 1U) ||
		(tegra_platform_is_qt() == 1U)) {
221
		return;
Steven Kao's avatar
Steven Kao committed
222
	}
223
224
225
226
227

	/*
	 * Read the MCE firmware version and extract the major and minor
	 * version fields
	 */
Steven Kao's avatar
Steven Kao committed
228
229
230
	version = nvg_get_version();
	minor = (uint32_t)version;
	major = (uint32_t)(version >> 32);
231
232
233
234
235
236
237
238

	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
239
	if (major != (uint32_t)TEGRA_NVG_VERSION_MAJOR) {
240
241
242
243
		ERROR("MCE major version mismatch\n");
		panic();
	}

Steven Kao's avatar
Steven Kao committed
244
	if (minor < (uint32_t)TEGRA_NVG_VERSION_MINOR) {
245
246
247
248
		ERROR("MCE minor version mismatch\n");
		panic();
	}
}