blob: f76ab14a6c64fc2f05daebfcea3aac0e9f01cdda [file] [log] [blame]
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07001/*
Varun Wadekar3abd3992020-01-03 14:21:03 -08002 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Anthony Zhou10b970c2020-02-05 20:42:36 +08007#include <assert.h>
8#include <errno.h>
9
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070010#include <arch.h>
11#include <arch_helpers.h>
12#include <common/debug.h>
13#include <denver.h>
14#include <lib/mmio.h>
Anthony Zhou10b970c2020-02-05 20:42:36 +080015
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070016#include <mce_private.h>
Steven Kao2cdb6782017-01-05 17:04:40 +080017#include <platform_def.h>
18#include <t194_nvg.h>
Steven Kao40359022017-06-22 12:54:06 +080019#include <tegra_private.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070020
Varun Wadekarfc463c52018-05-25 16:17:53 -070021#define ID_AFR0_EL1_CACHE_OPS_SHIFT U(12)
22#define ID_AFR0_EL1_CACHE_OPS_MASK U(0xF)
Steven Kao2cdb6782017-01-05 17:04:40 +080023/*
24 * Reports the major and minor version of this interface.
25 *
26 * NVGDATA[0:31]: SW(R) Minor Version
27 * NVGDATA[32:63]: SW(R) Major Version
28 */
29uint64_t nvg_get_version(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070030{
Anthony Zhouc46150f2017-09-20 17:18:56 +080031 nvg_set_request((uint64_t)TEGRA_NVG_CHANNEL_VERSION);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070032
Steven Kao2cdb6782017-01-05 17:04:40 +080033 return (uint64_t)nvg_get_result();
34}
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070035
Steven Kao2cdb6782017-01-05 17:04:40 +080036/*
Steven Kao2cdb6782017-01-05 17:04:40 +080037 * Set the expected wake time in TSC ticks for the next low-power state the
38 * core enters.
39 *
40 * NVGDATA[0:31]: SW(RW), WAKE_TIME
41 */
42void nvg_set_wake_time(uint32_t wake_time)
43{
44 /* time (TSC ticks) until the core is expected to get a wake event */
Anthony Zhouc46150f2017-09-20 17:18:56 +080045 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_WAKE_TIME, (uint64_t)wake_time);
Steven Kao2cdb6782017-01-05 17:04:40 +080046}
47
48/*
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070049 * This request allows updating of CLUSTER_CSTATE, CCPLEX_CSTATE and
50 * SYSTEM_CSTATE values.
Steven Kao2cdb6782017-01-05 17:04:40 +080051 *
52 * NVGDATA[0:2]: SW(RW), CLUSTER_CSTATE
53 * NVGDATA[7]: SW(W), update cluster flag
Vignesh Radhakrishnan706b9fe2017-11-04 16:36:23 -070054 * NVGDATA[8:10]: SW(RW), CG_CSTATE
Steven Kao2cdb6782017-01-05 17:04:40 +080055 * NVGDATA[15]: SW(W), update ccplex flag
56 * NVGDATA[16:19]: SW(RW), SYSTEM_CSTATE
57 * NVGDATA[23]: SW(W), update system flag
58 * NVGDATA[31]: SW(W), update wake mask flag
59 * NVGDATA[32:63]: SW(RW), WAKE_MASK
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070060 */
Steven Kao2cdb6782017-01-05 17:04:40 +080061void nvg_update_cstate_info(uint32_t cluster, uint32_t ccplex,
62 uint32_t system, uint32_t wake_mask, uint8_t update_wake_mask)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070063{
64 uint64_t val = 0;
65
66 /* update CLUSTER_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +080067 if (cluster != 0U) {
68 val |= ((uint64_t)cluster & CLUSTER_CSTATE_MASK) |
69 CLUSTER_CSTATE_UPDATE_BIT;
70 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070071
72 /* update CCPLEX_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +080073 if (ccplex != 0U) {
74 val |= (((uint64_t)ccplex & CCPLEX_CSTATE_MASK) << CCPLEX_CSTATE_SHIFT) |
75 CCPLEX_CSTATE_UPDATE_BIT;
76 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070077
78 /* update SYSTEM_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +080079 if (system != 0U) {
80 val |= (((uint64_t)system & SYSTEM_CSTATE_MASK) << SYSTEM_CSTATE_SHIFT) |
81 SYSTEM_CSTATE_UPDATE_BIT;
82 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070083
84 /* update wake mask value? */
Steven Kao2cdb6782017-01-05 17:04:40 +080085 if (update_wake_mask != 0U) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070086 val |= CSTATE_WAKE_MASK_UPDATE_BIT;
Steven Kao2cdb6782017-01-05 17:04:40 +080087 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070088
89 /* set the wake mask */
Steven Kao2cdb6782017-01-05 17:04:40 +080090 val |= ((uint64_t)wake_mask & CSTATE_WAKE_MASK_CLEAR) << CSTATE_WAKE_MASK_SHIFT;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070091
92 /* set the updated cstate info */
Anthony Zhouc46150f2017-09-20 17:18:56 +080093 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_CSTATE_INFO, val);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070094}
95
Steven Kao2cdb6782017-01-05 17:04:40 +080096/*
Steven Kao2cdb6782017-01-05 17:04:40 +080097 * Return a non-zero value if the CCPLEX is able to enter SC7
98 *
99 * NVGDATA[0]: SW(R), Is allowed result
100 */
101int32_t nvg_is_sc7_allowed(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700102{
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700103 /* issue command to check if SC7 is allowed */
Anthony Zhouc46150f2017-09-20 17:18:56 +0800104 nvg_set_request((uint64_t)TEGRA_NVG_CHANNEL_IS_SC7_ALLOWED);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700105
106 /* 1 = SC7 allowed, 0 = SC7 not allowed */
Steven Kao2cdb6782017-01-05 17:04:40 +0800107 return (int32_t)nvg_get_result();
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700108}
109
Steven Kao2cdb6782017-01-05 17:04:40 +0800110/*
111 * Wake an offlined logical core. Note that a core is offlined by entering
112 * a C-state where the WAKE_MASK is all 0.
113 *
114 * NVGDATA[0:3]: SW(W) logical core to online
115 */
116int32_t nvg_online_core(uint32_t core)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700117{
Steven Kao2cdb6782017-01-05 17:04:40 +0800118 int32_t ret = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700119
Steven Kao2cdb6782017-01-05 17:04:40 +0800120 /* sanity check the core ID value */
121 if (core > (uint32_t)PLATFORM_CORE_COUNT) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700122 ERROR("%s: unknown core id (%d)\n", __func__, core);
Varun Wadekar3abd3992020-01-03 14:21:03 -0800123 ret = -EINVAL;
Steven Kao2cdb6782017-01-05 17:04:40 +0800124 } else {
125 /* get a core online */
Anthony Zhouc46150f2017-09-20 17:18:56 +0800126 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_ONLINE_CORE,
127 (uint64_t)core & MCE_CORE_ID_MASK);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700128 }
129
Steven Kao2cdb6782017-01-05 17:04:40 +0800130 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700131}
132
Steven Kao2cdb6782017-01-05 17:04:40 +0800133/*
Steven Kao2cdb6782017-01-05 17:04:40 +0800134 * MC GSC (General Security Carveout) register values are expected to be
135 * changed by TrustZone ARM code after boot.
136 *
137 * NVGDATA[0:15] SW(R) GSC enun
138 */
139int32_t nvg_update_ccplex_gsc(uint32_t gsc_idx)
140{
Varun Wadekar3abd3992020-01-03 14:21:03 -0800141 int32_t ret = 0;
Steven Kao2cdb6782017-01-05 17:04:40 +0800142
143 /* sanity check GSC ID */
Steven Kao6f373a22017-09-29 18:09:17 +0800144 if (gsc_idx > (uint32_t)TEGRA_NVG_CHANNEL_UPDATE_GSC_VPR) {
145 ERROR("%s: unknown gsc_idx (%u)\n", __func__, gsc_idx);
Varun Wadekar3abd3992020-01-03 14:21:03 -0800146 ret = -EINVAL;
Steven Kao2cdb6782017-01-05 17:04:40 +0800147 } else {
Anthony Zhouc46150f2017-09-20 17:18:56 +0800148 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_UPDATE_CCPLEX_GSC,
Varun Wadekar3abd3992020-01-03 14:21:03 -0800149 (uint64_t)gsc_idx);
Steven Kao2cdb6782017-01-05 17:04:40 +0800150 }
151
152 return ret;
153}
154
155/*
Steven Kao2cdb6782017-01-05 17:04:40 +0800156 * Cache clean and invalidate, clear TR-bit operation for all CCPLEX caches.
Steven Kao2cdb6782017-01-05 17:04:40 +0800157 */
158int32_t nvg_roc_clean_cache_trbits(void)
159{
Steven Kao238d6d22017-08-16 20:12:00 +0800160 int32_t ret = 0;
Steven Kao2cdb6782017-01-05 17:04:40 +0800161
Steven Kao238d6d22017-08-16 20:12:00 +0800162 /* check if cache flush through mts is supported */
163 if (((read_id_afr0_el1() >> ID_AFR0_EL1_CACHE_OPS_SHIFT) &
164 ID_AFR0_EL1_CACHE_OPS_MASK) == 1U) {
165 if (nvg_cache_inval_all() == 0U) {
166 ERROR("%s: failed\n", __func__);
Varun Wadekar3abd3992020-01-03 14:21:03 -0800167 ret = -ENODEV;
Steven Kao238d6d22017-08-16 20:12:00 +0800168 }
169 } else {
Varun Wadekar3abd3992020-01-03 14:21:03 -0800170 ret = -ENOTSUP;
Steven Kao238d6d22017-08-16 20:12:00 +0800171 }
Varun Wadekar3abd3992020-01-03 14:21:03 -0800172
Steven Kao238d6d22017-08-16 20:12:00 +0800173 return ret;
Steven Kao2cdb6782017-01-05 17:04:40 +0800174}
175
176/*
177 * Set the power state for a core
178 */
179int32_t nvg_enter_cstate(uint32_t state, uint32_t wake_time)
180{
181 int32_t ret = 0;
Steven Kao40359022017-06-22 12:54:06 +0800182 uint64_t val = 0ULL;
Steven Kao2cdb6782017-01-05 17:04:40 +0800183
184 /* check for allowed power state */
185 if ((state != (uint32_t)TEGRA_NVG_CORE_C0) &&
186 (state != (uint32_t)TEGRA_NVG_CORE_C1) &&
187 (state != (uint32_t)TEGRA_NVG_CORE_C6) &&
188 (state != (uint32_t)TEGRA_NVG_CORE_C7))
189 {
Varun Wadekar3abd3992020-01-03 14:21:03 -0800190 ERROR("%s: unknown cstate (%u)\n", __func__, state);
191 ret = -EINVAL;
Steven Kao2cdb6782017-01-05 17:04:40 +0800192 } else {
193 /* time (TSC ticks) until the core is expected to get a wake event */
194 nvg_set_wake_time(wake_time);
195
196 /* set the core cstate */
Steven Kao40359022017-06-22 12:54:06 +0800197 val = read_actlr_el1() & ~ACTLR_EL1_PMSTATE_MASK;
198 write_actlr_el1(val | (uint64_t)state);
Steven Kao2cdb6782017-01-05 17:04:40 +0800199 }
200
201 return ret;
202}
Dilan Lee4e7a63c2017-08-10 16:01:42 +0800203
Steven Kao8f4f1022017-12-13 06:39:15 +0800204#if ENABLE_STRICT_CHECKING_MODE
Dilan Lee4e7a63c2017-08-10 16:01:42 +0800205/*
206 * Enable strict checking mode
207 *
208 * NVGDATA[3] strict_check ON + lock
209 */
210void nvg_enable_strict_checking_mode(void)
211{
212 uint64_t params = (uint64_t)(STRICT_CHECKING_ENABLED_SET |
213 STRICT_CHECKING_LOCKED_SET);
214
Varun Wadekarfc463c52018-05-25 16:17:53 -0700215 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_SECURITY_CONFIG, params);
Dilan Lee4e7a63c2017-08-10 16:01:42 +0800216}
Anthony Zhou10b970c2020-02-05 20:42:36 +0800217
218void nvg_verify_strict_checking_mode(void)
219{
220 uint64_t params = (uint64_t)(STRICT_CHECKING_ENABLED_SET |
221 STRICT_CHECKING_LOCKED_SET);
222
223 nvg_set_request((uint64_t)TEGRA_NVG_CHANNEL_SECURITY_CONFIG);
224 assert(params == (uint64_t)nvg_get_result());
225}
Steven Kao8f4f1022017-12-13 06:39:15 +0800226#endif
Vignesh Radhakrishnan3ad79832017-12-11 13:17:58 -0800227
228/*
229 * Request a reboot
230 *
231 * NVGDATA[0]: reboot command
232 */
233void nvg_system_reboot(void)
234{
235 /* issue command for reboot */
Varun Wadekarfc463c52018-05-25 16:17:53 -0700236 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_SHUTDOWN,
237 (uint64_t)TEGRA_NVG_REBOOT);
Vignesh Radhakrishnan3ad79832017-12-11 13:17:58 -0800238}
239
240/*
241 * Request a shutdown
242 *
243 * NVGDATA[0]: shutdown command
244 */
245void nvg_system_shutdown(void)
246{
247 /* issue command for shutdown */
Varun Wadekarfc463c52018-05-25 16:17:53 -0700248 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_SHUTDOWN,
249 (uint64_t)TEGRA_NVG_SHUTDOWN);
Vignesh Radhakrishnan3ad79832017-12-11 13:17:58 -0800250}
Varun Wadekar67188422019-03-21 08:23:05 -0700251
252/*
253 * Request to clear CCPLEX->HSM correctable error signal.
254 * NVGDATA[1]: A write of 1 clears the CCPLEX->HSM correctable error signal,
255 * A write of 0 has no effect.
256 */
257void nvg_clear_hsm_corr_status(void)
258{
259 nvg_hsm_error_ctrl_channel_t status = { .bits = { .corr = 1U, }, };
260
261 nvg_set_request_data((uint64_t)TEGRA_NVG_CHANNEL_HSM_ERROR_CTRL, status.flat);
262}