blob: 12dd6cb09fe31cf2a70c846c025768b3f467a01b [file] [log] [blame]
Varun Wadekarecd6a5a2018-04-09 17:48:58 -07001/*
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <common/debug.h>
10#include <denver.h>
Steven Kao2cdb6782017-01-05 17:04:40 +080011#include <errno.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070012#include <lib/mmio.h>
13#include <mce_private.h>
Steven Kao2cdb6782017-01-05 17:04:40 +080014#include <platform_def.h>
15#include <t194_nvg.h>
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070016
17extern void nvg_set_request_data(uint64_t req, uint64_t data);
18extern void nvg_set_request(uint64_t req);
19extern uint64_t nvg_get_result(void);
20
Steven Kao2cdb6782017-01-05 17:04:40 +080021/*
22 * Reports the major and minor version of this interface.
23 *
24 * NVGDATA[0:31]: SW(R) Minor Version
25 * NVGDATA[32:63]: SW(R) Major Version
26 */
27uint64_t nvg_get_version(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070028{
Steven Kao2cdb6782017-01-05 17:04:40 +080029 nvg_set_request(TEGRA_NVG_CHANNEL_VERSION);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070030
Steven Kao2cdb6782017-01-05 17:04:40 +080031 return (uint64_t)nvg_get_result();
32}
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070033
Steven Kao2cdb6782017-01-05 17:04:40 +080034/*
35 * Enable the perf per watt mode.
36 *
37 * NVGDATA[0]: SW(RW), 1 = enable perf per watt mode
38 */
39int32_t nvg_enable_power_perf_mode(void)
40{
41 nvg_set_request_data(TEGRA_NVG_CHANNEL_POWER_PERF, 1U);
42
43 return 0;
44}
45
46/*
47 * Disable the perf per watt mode.
48 *
49 * NVGDATA[0]: SW(RW), 0 = disable perf per watt mode
50 */
51int32_t nvg_disable_power_perf_mode(void)
52{
53 nvg_set_request_data(TEGRA_NVG_CHANNEL_POWER_PERF, 0U);
54
55 return 0;
56}
57
58/*
59 * Enable the battery saver mode.
60 *
61 * NVGDATA[2]: SW(RW), 1 = enable battery saver mode
62 */
63int32_t nvg_enable_power_saver_modes(void)
64{
65 nvg_set_request_data(TEGRA_NVG_CHANNEL_POWER_MODES, 1U);
66
67 return 0;
68}
69
70/*
71 * Disable the battery saver mode.
72 *
73 * NVGDATA[2]: SW(RW), 0 = disable battery saver mode
74 */
75int32_t nvg_disable_power_saver_modes(void)
76{
77 nvg_set_request_data(TEGRA_NVG_CHANNEL_POWER_MODES, 0U);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070078
79 return 0;
80}
81
82/*
Steven Kao2cdb6782017-01-05 17:04:40 +080083 * Set the expected wake time in TSC ticks for the next low-power state the
84 * core enters.
85 *
86 * NVGDATA[0:31]: SW(RW), WAKE_TIME
87 */
88void nvg_set_wake_time(uint32_t wake_time)
89{
90 /* time (TSC ticks) until the core is expected to get a wake event */
91 nvg_set_request_data(TEGRA_NVG_CHANNEL_WAKE_TIME, (uint64_t)wake_time);
92}
93
94/*
Varun Wadekarecd6a5a2018-04-09 17:48:58 -070095 * This request allows updating of CLUSTER_CSTATE, CCPLEX_CSTATE and
96 * SYSTEM_CSTATE values.
Steven Kao2cdb6782017-01-05 17:04:40 +080097 *
98 * NVGDATA[0:2]: SW(RW), CLUSTER_CSTATE
99 * NVGDATA[7]: SW(W), update cluster flag
100 * NVGDATA[8:9]: SW(RW), CG_CSTATE
101 * NVGDATA[15]: SW(W), update ccplex flag
102 * NVGDATA[16:19]: SW(RW), SYSTEM_CSTATE
103 * NVGDATA[23]: SW(W), update system flag
104 * NVGDATA[31]: SW(W), update wake mask flag
105 * NVGDATA[32:63]: SW(RW), WAKE_MASK
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700106 */
Steven Kao2cdb6782017-01-05 17:04:40 +0800107void nvg_update_cstate_info(uint32_t cluster, uint32_t ccplex,
108 uint32_t system, uint32_t wake_mask, uint8_t update_wake_mask)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700109{
110 uint64_t val = 0;
111
112 /* update CLUSTER_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +0800113 if (cluster != 0U) {
114 val |= ((uint64_t)cluster & CLUSTER_CSTATE_MASK) |
115 CLUSTER_CSTATE_UPDATE_BIT;
116 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700117
118 /* update CCPLEX_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +0800119 if (ccplex != 0U) {
120 val |= (((uint64_t)ccplex & CCPLEX_CSTATE_MASK) << CCPLEX_CSTATE_SHIFT) |
121 CCPLEX_CSTATE_UPDATE_BIT;
122 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700123
124 /* update SYSTEM_CSTATE? */
Steven Kao2cdb6782017-01-05 17:04:40 +0800125 if (system != 0U) {
126 val |= (((uint64_t)system & SYSTEM_CSTATE_MASK) << SYSTEM_CSTATE_SHIFT) |
127 SYSTEM_CSTATE_UPDATE_BIT;
128 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700129
130 /* update wake mask value? */
Steven Kao2cdb6782017-01-05 17:04:40 +0800131 if (update_wake_mask != 0U) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700132 val |= CSTATE_WAKE_MASK_UPDATE_BIT;
Steven Kao2cdb6782017-01-05 17:04:40 +0800133 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700134
135 /* set the wake mask */
Steven Kao2cdb6782017-01-05 17:04:40 +0800136 val |= ((uint64_t)wake_mask & CSTATE_WAKE_MASK_CLEAR) << CSTATE_WAKE_MASK_SHIFT;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700137
138 /* set the updated cstate info */
139 nvg_set_request_data(TEGRA_NVG_CHANNEL_CSTATE_INFO, val);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700140}
141
Steven Kao2cdb6782017-01-05 17:04:40 +0800142/*
143 * Indices gives MTS the crossover point in TSC ticks for when it becomes
144 * no longer viable to enter the named state
145 *
146 * Type 0 : NVGDATA[0:31]: C6 Lower bound
147 * Type 1 : NVGDATA[0:31]: CC6 Lower bound
148 * Type 2 : NVGDATA[0:31]: CG7 Lower bound
149 */
150int32_t nvg_update_crossover_time(uint32_t type, uint32_t time)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700151{
Steven Kao2cdb6782017-01-05 17:04:40 +0800152 int32_t ret = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700153
Steven Kao2cdb6782017-01-05 17:04:40 +0800154 switch (type) {
155 case TEGRA_NVG_CROSSOVER_C6:
156 nvg_set_request_data(TEGRA_NVG_CHANNEL_CROSSOVER_C6_LOWER_BOUND,
157 (uint64_t)time);
158 break;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700159
Steven Kao2cdb6782017-01-05 17:04:40 +0800160 case TEGRA_NVG_CROSSOVER_CC6:
161 nvg_set_request_data(TEGRA_NVG_CHANNEL_CROSSOVER_CC6_LOWER_BOUND,
162 (uint64_t)time);
163 break;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700164
Steven Kao2cdb6782017-01-05 17:04:40 +0800165 case TEGRA_NVG_CROSSOVER_CG7:
166 nvg_set_request_data(TEGRA_NVG_CHANNEL_CROSSOVER_CG7_LOWER_BOUND,
167 (uint64_t)time);
168 break;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700169
Steven Kao2cdb6782017-01-05 17:04:40 +0800170 default:
171 ERROR("%s: unknown crossover type (%d)\n", __func__, type);
172 ret = EINVAL;
173 break;
174 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700175
Steven Kao2cdb6782017-01-05 17:04:40 +0800176 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700177}
178
Steven Kao2cdb6782017-01-05 17:04:40 +0800179/*
180 * These NVG calls allow ARM SW to access CSTATE statistical information
181 *
182 * NVGDATA[0:3]: SW(RW) Core/cluster/cg id
183 * NVGDATA[16:31]: SW(RW) Stat id
184 */
185int32_t nvg_set_cstate_stat_query_value(uint64_t data)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700186{
Steven Kao2cdb6782017-01-05 17:04:40 +0800187 int32_t ret = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700188
Steven Kao2cdb6782017-01-05 17:04:40 +0800189 /* sanity check stat id */
190 if (data > (uint64_t)NVG_STAT_QUERY_C7_RESIDENCY_SUM) {
191 ERROR("%s: unknown stat id (%d)\n", __func__, (uint32_t)data);
192 ret = EINVAL;
193 } else {
194 nvg_set_request_data(TEGRA_NVG_CHANNEL_CSTATE_STAT_QUERY_REQUEST, data);
195 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700196
Steven Kao2cdb6782017-01-05 17:04:40 +0800197 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700198}
199
Steven Kao2cdb6782017-01-05 17:04:40 +0800200/*
201 * The read-only value associated with the CSTATE_STAT_QUERY_REQUEST
202 *
203 * NVGDATA[0:63]: SW(R) Stat count
204 */
205uint64_t nvg_get_cstate_stat_query_value(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700206{
Steven Kao2cdb6782017-01-05 17:04:40 +0800207 nvg_set_request(TEGRA_NVG_CHANNEL_CSTATE_STAT_QUERY_VALUE);
208
209 return (uint64_t)nvg_get_result();
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700210}
211
Steven Kao2cdb6782017-01-05 17:04:40 +0800212/*
213 * Return a non-zero value if the CCPLEX is able to enter SC7
214 *
215 * NVGDATA[0]: SW(R), Is allowed result
216 */
217int32_t nvg_is_sc7_allowed(void)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700218{
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700219 /* issue command to check if SC7 is allowed */
Steven Kao2cdb6782017-01-05 17:04:40 +0800220 nvg_set_request(TEGRA_NVG_CHANNEL_IS_SC7_ALLOWED);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700221
222 /* 1 = SC7 allowed, 0 = SC7 not allowed */
Steven Kao2cdb6782017-01-05 17:04:40 +0800223 return (int32_t)nvg_get_result();
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700224}
225
Steven Kao2cdb6782017-01-05 17:04:40 +0800226/*
227 * Wake an offlined logical core. Note that a core is offlined by entering
228 * a C-state where the WAKE_MASK is all 0.
229 *
230 * NVGDATA[0:3]: SW(W) logical core to online
231 */
232int32_t nvg_online_core(uint32_t core)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700233{
Steven Kao2cdb6782017-01-05 17:04:40 +0800234 int32_t ret = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700235
Steven Kao2cdb6782017-01-05 17:04:40 +0800236 /* sanity check the core ID value */
237 if (core > (uint32_t)PLATFORM_CORE_COUNT) {
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700238 ERROR("%s: unknown core id (%d)\n", __func__, core);
Steven Kao2cdb6782017-01-05 17:04:40 +0800239 ret = EINVAL;
240 } else {
241 /* get a core online */
242 nvg_set_request_data(TEGRA_NVG_CHANNEL_ONLINE_CORE,
243 (uint64_t)core & MCE_CORE_ID_MASK);
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700244 }
245
Steven Kao2cdb6782017-01-05 17:04:40 +0800246 return ret;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700247}
248
Steven Kao2cdb6782017-01-05 17:04:40 +0800249/*
250 * Enables and controls the voltage/frequency hint for CC3. CC3 is disabled
251 * by default.
252 *
253 * NVGDATA[7:0] SW(RW) frequency request
254 * NVGDATA[31:31] SW(RW) enable bit
255 */
256int32_t nvg_cc3_ctrl(uint32_t freq, uint8_t enable)
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700257{
Steven Kao2cdb6782017-01-05 17:04:40 +0800258 uint64_t val = 0;
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700259
260 /*
261 * If the enable bit is cleared, Auto-CC3 will be disabled by setting
Steven Kao2cdb6782017-01-05 17:04:40 +0800262 * the SW visible frequency request registers for all non
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700263 * floorswept cores valid independent of StandbyWFI and disabling
Steven Kao2cdb6782017-01-05 17:04:40 +0800264 * the IDLE frequency request register. If set, Auto-CC3
265 * will be enabled by setting the ARM SW visible frequency
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700266 * request registers for all non floorswept cores to be enabled by
267 * StandbyWFI or the equivalent signal, and always keeping the IDLE
Steven Kao2cdb6782017-01-05 17:04:40 +0800268 * frequency request register enabled.
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700269 */
Steven Kao2cdb6782017-01-05 17:04:40 +0800270 if (enable != 0U) {
271 val = ((uint64_t)freq & MCE_AUTO_CC3_FREQ_MASK) | MCE_AUTO_CC3_ENABLE_BIT;
272 }
Varun Wadekarecd6a5a2018-04-09 17:48:58 -0700273 nvg_set_request_data(TEGRA_NVG_CHANNEL_CC3_CTRL, val);
274
275 return 0;
276}
Steven Kao2cdb6782017-01-05 17:04:40 +0800277
278/*
279 * MC GSC (General Security Carveout) register values are expected to be
280 * changed by TrustZone ARM code after boot.
281 *
282 * NVGDATA[0:15] SW(R) GSC enun
283 */
284int32_t nvg_update_ccplex_gsc(uint32_t gsc_idx)
285{
286 int32_t ret = 0;
287
288 /* sanity check GSC ID */
289 if (gsc_idx > (uint32_t)TEGRA_NVG_GSC_VPR_IDX) {
290 ERROR("%s: unknown gsc_idx (%d)\n", __func__, gsc_idx);
291 ret = EINVAL;
292 } else {
293 nvg_set_request_data(TEGRA_NVG_CHANNEL_UPDATE_CCPLEX_GSC,
294 (uint64_t)gsc_idx);
295 }
296
297 return ret;
298}
299
300/*
301 * Cache clean operation for all CCPLEX caches.
302 *
303 * NVGDATA[0] cache_clean
304 */
305int32_t nvg_roc_clean_cache(void)
306{
307 nvg_set_request_data(TEGRA_NVG_CHANNEL_CCPLEX_CACHE_INVAL,
308 (uint64_t)CACHE_CLEAN_SET);
309
310 return 0;
311}
312
313/*
314 * Cache clean and invalidate operation for all CCPLEX caches.
315 *
316 * NVGDATA[1] cache_clean_inval
317 */
318int32_t nvg_roc_flush_cache(void)
319{
320 nvg_set_request_data(TEGRA_NVG_CHANNEL_CCPLEX_CACHE_INVAL,
321 (uint64_t)CACHE_CLEAN_INVAL_SET);
322
323 return 0;
324}
325
326/*
327 * Cache clean and invalidate, clear TR-bit operation for all CCPLEX caches.
328 *
329 * NVGDATA[2] cache_clean_inval_tr
330 */
331int32_t nvg_roc_clean_cache_trbits(void)
332{
333 nvg_set_request_data(TEGRA_NVG_CHANNEL_CCPLEX_CACHE_INVAL,
334 (uint64_t)CACHE_CLEAN_INVAL_TR_SET);
335
336 return 0;
337}
338
339/*
340 * Set the power state for a core
341 */
342int32_t nvg_enter_cstate(uint32_t state, uint32_t wake_time)
343{
344 int32_t ret = 0;
345
346 /* check for allowed power state */
347 if ((state != (uint32_t)TEGRA_NVG_CORE_C0) &&
348 (state != (uint32_t)TEGRA_NVG_CORE_C1) &&
349 (state != (uint32_t)TEGRA_NVG_CORE_C6) &&
350 (state != (uint32_t)TEGRA_NVG_CORE_C7))
351 {
352 ERROR("%s: unknown cstate (%d)\n", __func__, state);
353 ret = EINVAL;
354 } else {
355 /* time (TSC ticks) until the core is expected to get a wake event */
356 nvg_set_wake_time(wake_time);
357
358 /* set the core cstate */
359 write_actlr_el1(state);
360 }
361
362 return ret;
363}