mce.c 4.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * 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>
Steven Kao's avatar
Steven Kao committed
17
#include <platform_def.h>
18
#include <stdbool.h>
19
20
#include <string.h>
#include <errno.h>
Steven Kao's avatar
Steven Kao committed
21
#include <t194_nvg.h>
22
23
24
#include <tegra_def.h>
#include <tegra_platform.h>

25
26
27
28
29
30
31
32
33
34
35
36
/* 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;
}

37
38
39
/*******************************************************************************
 * Common handler for all MCE commands
 ******************************************************************************/
40
int32_t mce_command_handler(uint64_t cmd, uint64_t arg0, uint64_t arg1,
41
42
			uint64_t arg2)
{
Steven Kao's avatar
Steven Kao committed
43
	int32_t ret = 0;
44
45

	switch (cmd) {
46
	case (uint64_t)MCE_CMD_ENTER_CSTATE:
Steven Kao's avatar
Steven Kao committed
47
48
49
50
51
		ret = nvg_enter_cstate((uint32_t)arg0, (uint32_t)arg1);
		if (ret < 0) {
			ERROR("%s: enter_cstate failed(%d)\n", __func__, ret);
		}

52
53
		break;

54
	case (uint64_t)MCE_CMD_IS_SC7_ALLOWED:
Steven Kao's avatar
Steven Kao committed
55
56
57
58
		ret = nvg_is_sc7_allowed();
		if (ret < 0) {
			ERROR("%s: is_sc7_allowed failed(%d)\n", __func__, ret);
		}
59
60
61

		break;

62
	case (uint64_t)MCE_CMD_ONLINE_CORE:
Steven Kao's avatar
Steven Kao committed
63
64
65
66
		ret = nvg_online_core((uint32_t)arg0);
		if (ret < 0) {
			ERROR("%s: online_core failed(%d)\n", __func__, ret);
		}
67
68
69
70

		break;

	default:
71
		ERROR("unknown MCE command (%llu)\n", cmd);
72
		ret = -EINVAL;
Steven Kao's avatar
Steven Kao committed
73
		break;
74
75
76
77
78
79
80
81
	}

	return ret;
}

/*******************************************************************************
 * Handler to update carveout values for Video Memory Carveout region
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
82
int32_t mce_update_gsc_videomem(void)
83
{
84
85
86
87
88
89
90
91
92
93
94
95
	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;
96
97
98
99
100
}

/*******************************************************************************
 * Handler to update carveout values for TZDRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
101
int32_t mce_update_gsc_tzdram(void)
102
{
103
104
105
106
107
108
109
110
111
112
113
114
	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;
115
116
117
118
119
}

/*******************************************************************************
 * Handler to update carveout values for TZ SysRAM aperture
 ******************************************************************************/
Steven Kao's avatar
Steven Kao committed
120
int32_t mce_update_gsc_tzram(void)
121
{
122
123
124
125
126
127
128
129
130
131
132
133
	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;
134
135
136
137
138
}

/*******************************************************************************
 * Handler to issue the UPDATE_CSTATE_INFO request
 ******************************************************************************/
139
void mce_update_cstate_info(const mce_cstate_info_t *cstate)
140
141
{
	/* issue the UPDATE_CSTATE_INFO request */
Steven Kao's avatar
Steven Kao committed
142
143
	nvg_update_cstate_info(cstate->cluster, cstate->ccplex, cstate->system,
		cstate->wake_mask, cstate->update_wake_mask);
144
145
146
147
148
149
150
151
152
153
154
155
156
157
}

/*******************************************************************************
 * 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.
	 */
158
	if (mce_firmware_not_supported()) {
159
		return;
Steven Kao's avatar
Steven Kao committed
160
	}
161
162
163
164
165

	/*
	 * Read the MCE firmware version and extract the major and minor
	 * version fields
	 */
Steven Kao's avatar
Steven Kao committed
166
167
168
	version = nvg_get_version();
	minor = (uint32_t)version;
	major = (uint32_t)(version >> 32);
169
170
171
172
173
174
175
176

	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
177
	if (major != (uint32_t)TEGRA_NVG_VERSION_MAJOR) {
178
179
180
181
		ERROR("MCE major version mismatch\n");
		panic();
	}

Steven Kao's avatar
Steven Kao committed
182
	if (minor < (uint32_t)TEGRA_NVG_VERSION_MINOR) {
183
184
185
186
		ERROR("MCE minor version mismatch\n");
		panic();
	}
}