blob: 9c4e57cae65c400d318611964adfc5348b5cfd83 [file] [log] [blame]
Varun Wadekara0352ab2017-03-14 14:24:35 -07001/*
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Varun Wadekara0352ab2017-03-14 14:24:35 -07003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekara0352ab2017-03-14 14:24:35 -07005 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <assert.h>
8#include <errno.h>
9
Varun Wadekara0352ab2017-03-14 14:24:35 -070010#include <arch.h>
11#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <common/debug.h>
13#include <drivers/delay_timer.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070014#include <denver.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/mmio.h>
16#include <plat/common/platform.h>
17
Varun Wadekarb5568282016-12-13 18:04:35 -080018#include <mce_private.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070019#include <t18x_ari.h>
20
21/*******************************************************************************
22 * Register offsets for ARI request/results
23 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080024#define ARI_REQUEST 0x0U
25#define ARI_REQUEST_EVENT_MASK 0x4U
26#define ARI_STATUS 0x8U
27#define ARI_REQUEST_DATA_LO 0xCU
28#define ARI_REQUEST_DATA_HI 0x10U
29#define ARI_RESPONSE_DATA_LO 0x14U
30#define ARI_RESPONSE_DATA_HI 0x18U
Varun Wadekara0352ab2017-03-14 14:24:35 -070031
32/* Status values for the current request */
Steven Kaod346dca2016-12-23 16:17:18 +080033#define ARI_REQ_PENDING 1U
34#define ARI_REQ_ONGOING 3U
35#define ARI_REQUEST_VALID_BIT (1U << 8)
36#define ARI_EVT_MASK_STANDBYWFI_BIT (1U << 7)
37
38/* default timeout (ms) to wait for ARI completion */
39#define ARI_MAX_RETRY_COUNT 2000
Varun Wadekara0352ab2017-03-14 14:24:35 -070040
41/*******************************************************************************
42 * ARI helper functions
43 ******************************************************************************/
44static inline uint32_t ari_read_32(uint32_t ari_base, uint32_t reg)
45{
Anthony Zhou1ab31402017-03-06 16:06:45 +080046 return mmio_read_32((uint64_t)ari_base + (uint64_t)reg);
Varun Wadekara0352ab2017-03-14 14:24:35 -070047}
48
49static inline void ari_write_32(uint32_t ari_base, uint32_t val, uint32_t reg)
50{
Anthony Zhou1ab31402017-03-06 16:06:45 +080051 mmio_write_32((uint64_t)ari_base + (uint64_t)reg, val);
Varun Wadekara0352ab2017-03-14 14:24:35 -070052}
53
54static inline uint32_t ari_get_request_low(uint32_t ari_base)
55{
56 return ari_read_32(ari_base, ARI_REQUEST_DATA_LO);
57}
58
59static inline uint32_t ari_get_request_high(uint32_t ari_base)
60{
61 return ari_read_32(ari_base, ARI_REQUEST_DATA_HI);
62}
63
64static inline uint32_t ari_get_response_low(uint32_t ari_base)
65{
66 return ari_read_32(ari_base, ARI_RESPONSE_DATA_LO);
67}
68
69static inline uint32_t ari_get_response_high(uint32_t ari_base)
70{
71 return ari_read_32(ari_base, ARI_RESPONSE_DATA_HI);
72}
73
74static inline void ari_clobber_response(uint32_t ari_base)
75{
76 ari_write_32(ari_base, 0, ARI_RESPONSE_DATA_LO);
77 ari_write_32(ari_base, 0, ARI_RESPONSE_DATA_HI);
78}
79
Anthony Zhou1ab31402017-03-06 16:06:45 +080080static int32_t ari_request_wait(uint32_t ari_base, uint32_t evt_mask, uint32_t req,
Varun Wadekara0352ab2017-03-14 14:24:35 -070081 uint32_t lo, uint32_t hi)
82{
Steven Kaod346dca2016-12-23 16:17:18 +080083 uint32_t retries = ARI_MAX_RETRY_COUNT;
84 uint32_t status;
Anthony Zhou1ab31402017-03-06 16:06:45 +080085 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -070086
87 /* program the request, event_mask, hi and lo registers */
88 ari_write_32(ari_base, lo, ARI_REQUEST_DATA_LO);
89 ari_write_32(ari_base, hi, ARI_REQUEST_DATA_HI);
90 ari_write_32(ari_base, evt_mask, ARI_REQUEST_EVENT_MASK);
91 ari_write_32(ari_base, req | ARI_REQUEST_VALID_BIT, ARI_REQUEST);
92
93 /*
94 * For commands that have an event trigger, we should bypass
95 * ARI_STATUS polling, since MCE is waiting for SW to trigger
96 * the event.
97 */
Anthony Zhou1ab31402017-03-06 16:06:45 +080098 if (evt_mask != 0U) {
99 ret = 0;
100 } else {
101 /* For shutdown/reboot commands, we dont have to check for timeouts */
Anthony Zhou3b804502017-06-26 20:33:34 +0800102 if ((req == TEGRA_ARI_MISC_CCPLEX) &&
103 ((lo == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) ||
104 (lo == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT))) {
Anthony Zhou1ab31402017-03-06 16:06:45 +0800105 ret = 0;
106 } else {
107 /*
108 * Wait for the command response for not more than the timeout
109 */
110 while (retries != 0U) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700111
Anthony Zhou1ab31402017-03-06 16:06:45 +0800112 /* read the command status */
113 status = ari_read_32(ari_base, ARI_STATUS);
114 if ((status & (ARI_REQ_ONGOING | ARI_REQ_PENDING)) == 0U) {
115 break;
116 }
Steven Kaod346dca2016-12-23 16:17:18 +0800117
Anthony Zhou1ab31402017-03-06 16:06:45 +0800118 /* delay 1 ms */
119 mdelay(1);
Steven Kaod346dca2016-12-23 16:17:18 +0800120
Anthony Zhou1ab31402017-03-06 16:06:45 +0800121 /* decrement the retry count */
122 retries--;
123 }
Steven Kaod346dca2016-12-23 16:17:18 +0800124
Anthony Zhou1ab31402017-03-06 16:06:45 +0800125 /* assert if the command timed out */
126 if (retries == 0U) {
127 ERROR("ARI request timed out: req %d on CPU %d\n",
128 req, plat_my_core_pos());
129 assert(retries != 0U);
130 }
131 }
Steven Kaod346dca2016-12-23 16:17:18 +0800132 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700133
Anthony Zhou1ab31402017-03-06 16:06:45 +0800134 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700135}
136
Anthony Zhou1ab31402017-03-06 16:06:45 +0800137int32_t ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700138{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800139 int32_t ret = 0;
140
Varun Wadekara0352ab2017-03-14 14:24:35 -0700141 /* check for allowed power state */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800142 if ((state != TEGRA_ARI_CORE_C0) &&
143 (state != TEGRA_ARI_CORE_C1) &&
144 (state != TEGRA_ARI_CORE_C6) &&
145 (state != TEGRA_ARI_CORE_C7)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700146 ERROR("%s: unknown cstate (%d)\n", __func__, state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800147 ret = EINVAL;
148 } else {
149 /* clean the previous response state */
150 ari_clobber_response(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700151
Anthony Zhou1ab31402017-03-06 16:06:45 +0800152 /* Enter the cstate, to be woken up after wake_time (TSC ticks) */
153 ret = ari_request_wait(ari_base, ARI_EVT_MASK_STANDBYWFI_BIT,
Anthony Zhou0e07e452017-07-26 17:16:54 +0800154 (uint32_t)TEGRA_ARI_ENTER_CSTATE, state, wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800155 }
156
157 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700158}
159
Anthony Zhou1ab31402017-03-06 16:06:45 +0800160int32_t ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700161 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
162 uint8_t update_wake_mask)
163{
Anthony Zhou3b804502017-06-26 20:33:34 +0800164 uint64_t val = 0U;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700165
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700166 /* clean the previous response state */
167 ari_clobber_response(ari_base);
168
Varun Wadekara0352ab2017-03-14 14:24:35 -0700169 /* update CLUSTER_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800170 if (cluster != 0U) {
Anthony Zhou3b804502017-06-26 20:33:34 +0800171 val |= (cluster & CLUSTER_CSTATE_MASK) |
172 CLUSTER_CSTATE_UPDATE_BIT;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800173 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700174
175 /* update CCPLEX_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800176 if (ccplex != 0U) {
Anthony Zhou3b804502017-06-26 20:33:34 +0800177 val |= ((ccplex & CCPLEX_CSTATE_MASK) << CCPLEX_CSTATE_SHIFT) |
178 CCPLEX_CSTATE_UPDATE_BIT;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800179 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700180
181 /* update SYSTEM_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800182 if (system != 0U) {
Anthony Zhou3b804502017-06-26 20:33:34 +0800183 val |= ((system & SYSTEM_CSTATE_MASK) << SYSTEM_CSTATE_SHIFT) |
184 (((uint64_t)sys_state_force << SYSTEM_CSTATE_FORCE_UPDATE_SHIFT) |
185 SYSTEM_CSTATE_UPDATE_BIT);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800186 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700187
188 /* update wake mask value? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800189 if (update_wake_mask != 0U) {
Anthony Zhou3b804502017-06-26 20:33:34 +0800190 val |= CSTATE_WAKE_MASK_UPDATE_BIT;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800191 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700192
193 /* set the updated cstate info */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800194 return ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_UPDATE_CSTATE_INFO,
Anthony Zhou3b804502017-06-26 20:33:34 +0800195 (uint32_t)val, wake_mask);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700196}
197
Anthony Zhou1ab31402017-03-06 16:06:45 +0800198int32_t ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700199{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800200 int32_t ret = 0;
201
Varun Wadekara0352ab2017-03-14 14:24:35 -0700202 /* sanity check crossover type */
203 if ((type == TEGRA_ARI_CROSSOVER_C1_C6) ||
Anthony Zhou1ab31402017-03-06 16:06:45 +0800204 (type > TEGRA_ARI_CROSSOVER_CCP3_SC1)) {
205 ret = EINVAL;
206 } else {
207 /* clean the previous response state */
208 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700209
Anthony Zhou1ab31402017-03-06 16:06:45 +0800210 /* update crossover threshold time */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800211 ret = ari_request_wait(ari_base, 0U,
212 (uint32_t)TEGRA_ARI_UPDATE_CROSSOVER, type, time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800213 }
214
215 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700216}
217
218uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state)
219{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800220 int32_t ret;
221 uint64_t result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700222
223 /* sanity check crossover type */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800224 if (state == 0U) {
225 result = EINVAL;
226 } else {
227 /* clean the previous response state */
228 ari_clobber_response(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700229
Anthony Zhou0e07e452017-07-26 17:16:54 +0800230 ret = ari_request_wait(ari_base, 0U,
231 (uint32_t)TEGRA_ARI_CSTATE_STATS, state, 0U);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800232 if (ret != 0) {
233 result = EINVAL;
234 } else {
235 result = (uint64_t)ari_get_response_low(ari_base);
236 }
237 }
238 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700239}
240
Anthony Zhou1ab31402017-03-06 16:06:45 +0800241int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700242{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700243 /* clean the previous response state */
244 ari_clobber_response(ari_base);
245
Varun Wadekara0352ab2017-03-14 14:24:35 -0700246 /* write the cstate stats */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800247 return ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_WRITE_CSTATE_STATS,
248 state, stats);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700249}
250
251uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data)
252{
253 uint64_t resp;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800254 int32_t ret;
255 uint32_t local_data = data;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700256
257 /* clean the previous response state */
258 ari_clobber_response(ari_base);
259
260 /* ARI_REQUEST_DATA_HI is reserved for commands other than 'ECHO' */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800261 if (cmd != TEGRA_ARI_MISC_ECHO) {
262 local_data = 0U;
263 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700264
Anthony Zhou0e07e452017-07-26 17:16:54 +0800265 ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_MISC, cmd, local_data);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800266 if (ret != 0) {
267 resp = (uint64_t)ret;
268 } else {
269 /* get the command response */
270 resp = ari_get_response_low(ari_base);
271 resp |= ((uint64_t)ari_get_response_high(ari_base) << 32);
272 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700273
274 return resp;
275}
276
Anthony Zhou1ab31402017-03-06 16:06:45 +0800277int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700278{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800279 int32_t ret;
280 uint32_t result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700281
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700282 /* clean the previous response state */
283 ari_clobber_response(ari_base);
284
Anthony Zhou0e07e452017-07-26 17:16:54 +0800285 ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_IS_CCX_ALLOWED,
286 state & 0x7U, wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800287 if (ret != 0) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700288 ERROR("%s: failed (%d)\n", __func__, ret);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800289 result = 0U;
290 } else {
291 result = ari_get_response_low(ari_base) & 0x1U;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700292 }
293
294 /* 1 = CCx allowed, 0 = CCx not allowed */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800295 return (int32_t)result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700296}
297
Anthony Zhou1ab31402017-03-06 16:06:45 +0800298int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700299{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800300 int32_t ret, result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700301
302 /* check for allowed power state */
Anthony Zhou3b804502017-06-26 20:33:34 +0800303 if ((state != TEGRA_ARI_CORE_C0) && (state != TEGRA_ARI_CORE_C1) &&
304 (state != TEGRA_ARI_CORE_C6) && (state != TEGRA_ARI_CORE_C7)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700305 ERROR("%s: unknown cstate (%d)\n", __func__, state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800306 result = EINVAL;
307 } else {
308 /* clean the previous response state */
309 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700310
Anthony Zhou0e07e452017-07-26 17:16:54 +0800311 ret = ari_request_wait(ari_base, 0U,
312 (uint32_t)TEGRA_ARI_IS_SC7_ALLOWED, state, wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800313 if (ret != 0) {
314 ERROR("%s: failed (%d)\n", __func__, ret);
315 result = 0;
316 } else {
317 /* 1 = SC7 allowed, 0 = SC7 not allowed */
318 result = (ari_get_response_low(ari_base) != 0U) ? 1 : 0;
319 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700320 }
321
Anthony Zhou1ab31402017-03-06 16:06:45 +0800322 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700323}
324
Anthony Zhou1ab31402017-03-06 16:06:45 +0800325int32_t ari_online_core(uint32_t ari_base, uint32_t core)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700326{
Anthony Zhou3b804502017-06-26 20:33:34 +0800327 uint64_t cpu = read_mpidr() & (MPIDR_CPU_MASK);
328 uint64_t cluster = (read_mpidr() & (MPIDR_CLUSTER_MASK)) >>
329 (MPIDR_AFFINITY_BITS);
330 uint64_t impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800331 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700332
333 /* construct the current CPU # */
334 cpu |= (cluster << 2);
335
336 /* sanity check target core id */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800337 if ((core >= MCE_CORE_ID_MAX) || (cpu == (uint64_t)core)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700338 ERROR("%s: unsupported core id (%d)\n", __func__, core);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800339 ret = EINVAL;
340 } else {
341 /*
342 * The Denver cluster has 2 CPUs only - 0, 1.
343 */
Anthony Zhou3b804502017-06-26 20:33:34 +0800344 if ((impl == DENVER_IMPL) && ((core == 2U) || (core == 3U))) {
Anthony Zhou1ab31402017-03-06 16:06:45 +0800345 ERROR("%s: unknown core id (%d)\n", __func__, core);
346 ret = EINVAL;
347 } else {
348 /* clean the previous response state */
349 ari_clobber_response(ari_base);
Anthony Zhou0e07e452017-07-26 17:16:54 +0800350 ret = ari_request_wait(ari_base, 0U,
351 (uint32_t)TEGRA_ARI_ONLINE_CORE, core, 0U);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800352 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700353 }
354
Anthony Zhou1ab31402017-03-06 16:06:45 +0800355 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700356}
357
Anthony Zhou1ab31402017-03-06 16:06:45 +0800358int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700359{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800360 uint32_t val;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700361
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700362 /* clean the previous response state */
363 ari_clobber_response(ari_base);
364
Varun Wadekara0352ab2017-03-14 14:24:35 -0700365 /*
366 * If the enable bit is cleared, Auto-CC3 will be disabled by setting
367 * the SW visible voltage/frequency request registers for all non
368 * floorswept cores valid independent of StandbyWFI and disabling
369 * the IDLE voltage/frequency request register. If set, Auto-CC3
370 * will be enabled by setting the ARM SW visible voltage/frequency
371 * request registers for all non floorswept cores to be enabled by
372 * StandbyWFI or the equivalent signal, and always keeping the IDLE
373 * voltage/frequency request register enabled.
374 */
375 val = (((freq & MCE_AUTO_CC3_FREQ_MASK) << MCE_AUTO_CC3_FREQ_SHIFT) |\
376 ((volt & MCE_AUTO_CC3_VTG_MASK) << MCE_AUTO_CC3_VTG_SHIFT) |\
Anthony Zhou1ab31402017-03-06 16:06:45 +0800377 ((enable != 0U) ? MCE_AUTO_CC3_ENABLE_BIT : 0U));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700378
Anthony Zhou0e07e452017-07-26 17:16:54 +0800379 return ari_request_wait(ari_base, 0U,
380 (uint32_t)TEGRA_ARI_CC3_CTRL, val, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700381}
382
Anthony Zhou1ab31402017-03-06 16:06:45 +0800383int32_t ari_reset_vector_update(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700384{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700385 /* clean the previous response state */
386 ari_clobber_response(ari_base);
387
Varun Wadekara0352ab2017-03-14 14:24:35 -0700388 /*
389 * Need to program the CPU reset vector one time during cold boot
390 * and SC7 exit
391 */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800392 (void)ari_request_wait(ari_base, 0U,
393 (uint32_t)TEGRA_ARI_COPY_MISCREG_AA64_RST, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700394
395 return 0;
396}
397
Anthony Zhou1ab31402017-03-06 16:06:45 +0800398int32_t ari_roc_flush_cache_trbits(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700399{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700400 /* clean the previous response state */
401 ari_clobber_response(ari_base);
402
Anthony Zhou0e07e452017-07-26 17:16:54 +0800403 return ari_request_wait(ari_base, 0U,
404 (uint32_t)TEGRA_ARI_ROC_FLUSH_CACHE_TRBITS, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700405}
406
Anthony Zhou1ab31402017-03-06 16:06:45 +0800407int32_t ari_roc_flush_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700408{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700409 /* clean the previous response state */
410 ari_clobber_response(ari_base);
411
Anthony Zhou0e07e452017-07-26 17:16:54 +0800412 return ari_request_wait(ari_base, 0U,
413 (uint32_t)TEGRA_ARI_ROC_FLUSH_CACHE_ONLY, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700414}
415
Anthony Zhou1ab31402017-03-06 16:06:45 +0800416int32_t ari_roc_clean_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700417{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700418 /* clean the previous response state */
419 ari_clobber_response(ari_base);
420
Anthony Zhou0e07e452017-07-26 17:16:54 +0800421 return ari_request_wait(ari_base, 0U,
422 (uint32_t)TEGRA_ARI_ROC_CLEAN_CACHE_ONLY, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700423}
424
Anthony Zhou1ab31402017-03-06 16:06:45 +0800425uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700426{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800427 uint64_t mca_arg_data, result = 0;
428 uint32_t resp_lo, resp_hi;
429 uint32_t mca_arg_err, mca_arg_finish;
430 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700431
432 /* Set data (write) */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800433 mca_arg_data = (data != NULL) ? *data : 0ULL;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700434
435 /* Set command */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800436 ari_write_32(ari_base, (uint32_t)cmd, ARI_RESPONSE_DATA_LO);
437 ari_write_32(ari_base, (uint32_t)(cmd >> 32U), ARI_RESPONSE_DATA_HI);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700438
Anthony Zhou0e07e452017-07-26 17:16:54 +0800439 ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_MCA,
Anthony Zhou1ab31402017-03-06 16:06:45 +0800440 (uint32_t)mca_arg_data,
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100441 (uint32_t)(mca_arg_data >> 32U));
Anthony Zhou1ab31402017-03-06 16:06:45 +0800442 if (ret == 0) {
443 resp_lo = ari_get_response_low(ari_base);
444 resp_hi = ari_get_response_high(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700445
Anthony Zhou1ab31402017-03-06 16:06:45 +0800446 mca_arg_err = resp_lo & MCA_ARG_ERROR_MASK;
447 mca_arg_finish = (resp_hi >> MCA_ARG_FINISH_SHIFT) &
448 MCA_ARG_FINISH_MASK;
449
450 if (mca_arg_finish == 0U) {
451 result = (uint64_t)mca_arg_err;
452 } else {
453 if (data != NULL) {
454 resp_lo = ari_get_request_low(ari_base);
455 resp_hi = ari_get_request_high(ari_base);
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100456 *data = ((uint64_t)resp_hi << 32U) |
Anthony Zhou1ab31402017-03-06 16:06:45 +0800457 (uint64_t)resp_lo;
458 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700459 }
460 }
461
Anthony Zhou1ab31402017-03-06 16:06:45 +0800462 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700463}
464
Anthony Zhou1ab31402017-03-06 16:06:45 +0800465int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700466{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800467 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700468 /* sanity check GSC ID */
Anthony Zhou3b804502017-06-26 20:33:34 +0800469 if (gsc_idx > TEGRA_ARI_GSC_VPR_IDX) {
Anthony Zhou1ab31402017-03-06 16:06:45 +0800470 ret = EINVAL;
471 } else {
472 /* clean the previous response state */
473 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700474
Anthony Zhou1ab31402017-03-06 16:06:45 +0800475 /*
476 * The MCE code will read the GSC carveout value, corrseponding to
477 * the ID, from the MC registers and update the internal GSC registers
478 * of the CCPLEX.
479 */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800480 (void)ari_request_wait(ari_base, 0U,
481 (uint32_t)TEGRA_ARI_UPDATE_CCPLEX_GSC, gsc_idx, 0U);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800482 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700483
Anthony Zhou1ab31402017-03-06 16:06:45 +0800484 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700485}
486
487void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx)
488{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700489 /* clean the previous response state */
490 ari_clobber_response(ari_base);
491
Varun Wadekara0352ab2017-03-14 14:24:35 -0700492 /*
493 * The MCE will shutdown or restart the entire system
494 */
Anthony Zhou0e07e452017-07-26 17:16:54 +0800495 (void)ari_request_wait(ari_base, 0U,
496 (uint32_t)TEGRA_ARI_MISC_CCPLEX, state_idx, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700497}
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700498
Anthony Zhou1ab31402017-03-06 16:06:45 +0800499int32_t ari_read_write_uncore_perfmon(uint32_t ari_base, uint64_t req,
500 uint64_t *data)
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700501{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800502 int32_t ret, result;
Anthony Zhou0a013212017-05-08 20:17:08 +0800503 uint32_t val, req_status;
504 uint8_t req_cmd;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800505
506 req_cmd = (uint8_t)(req >> UNCORE_PERFMON_CMD_SHIFT);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700507
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700508 /* clean the previous response state */
509 ari_clobber_response(ari_base);
510
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700511 /* sanity check input parameters */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800512 if ((req_cmd == UNCORE_PERFMON_CMD_READ) && (data == NULL)) {
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700513 ERROR("invalid parameters\n");
Anthony Zhou1ab31402017-03-06 16:06:45 +0800514 result = EINVAL;
515 } else {
516 /*
517 * For "write" commands get the value that has to be written
518 * to the uncore perfmon registers
519 */
520 val = (req_cmd == UNCORE_PERFMON_CMD_WRITE) ?
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100521 (uint32_t)*data : 0U;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700522
Anthony Zhou0e07e452017-07-26 17:16:54 +0800523 ret = ari_request_wait(ari_base, 0U,
524 (uint32_t)TEGRA_ARI_PERFMON, val, (uint32_t)req);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800525 if (ret != 0) {
526 result = ret;
527 } else {
528 /* read the command status value */
Anthony Zhou0a013212017-05-08 20:17:08 +0800529 req_status = ari_get_response_high(ari_base) &
Anthony Zhou1ab31402017-03-06 16:06:45 +0800530 UNCORE_PERFMON_RESP_STATUS_MASK;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700531
Anthony Zhou1ab31402017-03-06 16:06:45 +0800532 /*
533 * For "read" commands get the data from the uncore
534 * perfmon registers
535 */
536 req_status >>= UNCORE_PERFMON_RESP_STATUS_SHIFT;
537 if ((req_status == 0U) && (req_cmd == UNCORE_PERFMON_CMD_READ)) {
538 *data = ari_get_response_low(ari_base);
539 }
540 result = (int32_t)req_status;
541 }
542 }
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700543
Anthony Zhou1ab31402017-03-06 16:06:45 +0800544 return result;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700545}
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700546
547void ari_misc_ccplex(uint32_t ari_base, uint32_t index, uint32_t value)
548{
549 /*
550 * This invokes the ARI_MISC_CCPLEX commands. This can be
551 * used to enable/disable coresight clock gating.
552 */
553
Rich Wiley24e99392017-01-04 10:45:44 -0800554 if ((index > TEGRA_ARI_MISC_CCPLEX_EDBGREQ) ||
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700555 ((index == TEGRA_ARI_MISC_CCPLEX_CORESIGHT_CG_CTRL) &&
Anthony Zhou1ab31402017-03-06 16:06:45 +0800556 (value > 1U))) {
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700557 ERROR("%s: invalid parameters \n", __func__);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800558 } else {
559 /* clean the previous response state */
560 ari_clobber_response(ari_base);
Anthony Zhou0e07e452017-07-26 17:16:54 +0800561 (void)ari_request_wait(ari_base, 0U,
562 (uint32_t)TEGRA_ARI_MISC_CCPLEX, index, value);
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700563 }
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700564}