blob: 1429a6158dfb82a49e04e6803007a8805ba492e6 [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 */
102 if ((req == (uint32_t)TEGRA_ARI_MISC_CCPLEX) &&
103 ((lo == (uint32_t)TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) ||
104 (lo == (uint32_t)TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT))) {
105 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,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700154 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 Zhou1ab31402017-03-06 16:06:45 +0800164 uint32_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) {
171 val |= (cluster & (uint32_t)CLUSTER_CSTATE_MASK) |
172 (uint32_t)CLUSTER_CSTATE_UPDATE_BIT;
173 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700174
175 /* update CCPLEX_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800176 if (ccplex != 0U) {
177 val |= ((ccplex & (uint32_t)CCPLEX_CSTATE_MASK) << (uint32_t)CCPLEX_CSTATE_SHIFT) |
178 (uint32_t)CCPLEX_CSTATE_UPDATE_BIT;
179 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700180
181 /* update SYSTEM_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800182 if (system != 0U) {
183 val |= ((system & (uint32_t)SYSTEM_CSTATE_MASK) << (uint32_t)SYSTEM_CSTATE_SHIFT) |
184 (((uint32_t)sys_state_force << SYSTEM_CSTATE_FORCE_UPDATE_SHIFT) |
185 (uint32_t)SYSTEM_CSTATE_UPDATE_BIT);
186 }
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) {
190 val |= (uint32_t)CSTATE_WAKE_MASK_UPDATE_BIT;
191 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700192
193 /* set the updated cstate info */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800194 return ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CSTATE_INFO, val,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700195 wake_mask);
196}
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 */
211 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CROSSOVER,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700212 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 Zhou1ab31402017-03-06 16:06:45 +0800230 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_CSTATE_STATS, state, 0U);
231 if (ret != 0) {
232 result = EINVAL;
233 } else {
234 result = (uint64_t)ari_get_response_low(ari_base);
235 }
236 }
237 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700238}
239
Anthony Zhou1ab31402017-03-06 16:06:45 +0800240int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700241{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700242 /* clean the previous response state */
243 ari_clobber_response(ari_base);
244
Varun Wadekara0352ab2017-03-14 14:24:35 -0700245 /* write the cstate stats */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800246 return ari_request_wait(ari_base, 0U, TEGRA_ARI_WRITE_CSTATE_STATS, state,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700247 stats);
248}
249
250uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data)
251{
252 uint64_t resp;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800253 int32_t ret;
254 uint32_t local_data = data;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700255
256 /* clean the previous response state */
257 ari_clobber_response(ari_base);
258
259 /* ARI_REQUEST_DATA_HI is reserved for commands other than 'ECHO' */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800260 if (cmd != TEGRA_ARI_MISC_ECHO) {
261 local_data = 0U;
262 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700263
Anthony Zhou1ab31402017-03-06 16:06:45 +0800264 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC, cmd, local_data);
265 if (ret != 0) {
266 resp = (uint64_t)ret;
267 } else {
268 /* get the command response */
269 resp = ari_get_response_low(ari_base);
270 resp |= ((uint64_t)ari_get_response_high(ari_base) << 32);
271 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700272
273 return resp;
274}
275
Anthony Zhou1ab31402017-03-06 16:06:45 +0800276int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700277{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800278 int32_t ret;
279 uint32_t result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700280
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700281 /* clean the previous response state */
282 ari_clobber_response(ari_base);
283
Anthony Zhou1ab31402017-03-06 16:06:45 +0800284 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_IS_CCX_ALLOWED, state & 0x7U,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700285 wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800286 if (ret != 0) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700287 ERROR("%s: failed (%d)\n", __func__, ret);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800288 result = 0U;
289 } else {
290 result = ari_get_response_low(ari_base) & 0x1U;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700291 }
292
293 /* 1 = CCx allowed, 0 = CCx not allowed */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800294 return (int32_t)result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700295}
296
Anthony Zhou1ab31402017-03-06 16:06:45 +0800297int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700298{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800299 int32_t ret, result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700300
301 /* check for allowed power state */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800302 if ((state != TEGRA_ARI_CORE_C0) &&
303 (state != TEGRA_ARI_CORE_C1) &&
304 (state != TEGRA_ARI_CORE_C6) &&
305 (state != TEGRA_ARI_CORE_C7)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700306 ERROR("%s: unknown cstate (%d)\n", __func__, state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800307 result = EINVAL;
308 } else {
309 /* clean the previous response state */
310 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700311
Anthony Zhou1ab31402017-03-06 16:06:45 +0800312 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_IS_SC7_ALLOWED, state,
313 wake_time);
314 if (ret != 0) {
315 ERROR("%s: failed (%d)\n", __func__, ret);
316 result = 0;
317 } else {
318 /* 1 = SC7 allowed, 0 = SC7 not allowed */
319 result = (ari_get_response_low(ari_base) != 0U) ? 1 : 0;
320 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700321 }
322
Anthony Zhou1ab31402017-03-06 16:06:45 +0800323 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700324}
325
Anthony Zhou1ab31402017-03-06 16:06:45 +0800326int32_t ari_online_core(uint32_t ari_base, uint32_t core)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700327{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800328 uint64_t cpu = read_mpidr() & (uint64_t)(MPIDR_CPU_MASK);
329 uint64_t cluster = (read_mpidr() & (uint64_t)(MPIDR_CLUSTER_MASK)) >>
330 (uint64_t)(MPIDR_AFFINITY_BITS);
331 uint64_t impl = (read_midr() >> (uint64_t)MIDR_IMPL_SHIFT) & (uint64_t)MIDR_IMPL_MASK;
332 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700333
334 /* construct the current CPU # */
335 cpu |= (cluster << 2);
336
337 /* sanity check target core id */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800338 if ((core >= MCE_CORE_ID_MAX) || (cpu == (uint64_t)core)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700339 ERROR("%s: unsupported core id (%d)\n", __func__, core);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800340 ret = EINVAL;
341 } else {
342 /*
343 * The Denver cluster has 2 CPUs only - 0, 1.
344 */
345 if ((impl == (uint32_t)DENVER_IMPL) &&
346 ((core == 2U) || (core == 3U))) {
347 ERROR("%s: unknown core id (%d)\n", __func__, core);
348 ret = EINVAL;
349 } else {
350 /* clean the previous response state */
351 ari_clobber_response(ari_base);
352 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_ONLINE_CORE, core, 0U);
353 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700354 }
355
Anthony Zhou1ab31402017-03-06 16:06:45 +0800356 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700357}
358
Anthony Zhou1ab31402017-03-06 16:06:45 +0800359int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700360{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800361 uint32_t val;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700362
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700363 /* clean the previous response state */
364 ari_clobber_response(ari_base);
365
Varun Wadekara0352ab2017-03-14 14:24:35 -0700366 /*
367 * If the enable bit is cleared, Auto-CC3 will be disabled by setting
368 * the SW visible voltage/frequency request registers for all non
369 * floorswept cores valid independent of StandbyWFI and disabling
370 * the IDLE voltage/frequency request register. If set, Auto-CC3
371 * will be enabled by setting the ARM SW visible voltage/frequency
372 * request registers for all non floorswept cores to be enabled by
373 * StandbyWFI or the equivalent signal, and always keeping the IDLE
374 * voltage/frequency request register enabled.
375 */
376 val = (((freq & MCE_AUTO_CC3_FREQ_MASK) << MCE_AUTO_CC3_FREQ_SHIFT) |\
377 ((volt & MCE_AUTO_CC3_VTG_MASK) << MCE_AUTO_CC3_VTG_SHIFT) |\
Anthony Zhou1ab31402017-03-06 16:06:45 +0800378 ((enable != 0U) ? MCE_AUTO_CC3_ENABLE_BIT : 0U));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700379
Anthony Zhou1ab31402017-03-06 16:06:45 +0800380 return ari_request_wait(ari_base, 0U, 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 Zhou1ab31402017-03-06 16:06:45 +0800392 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_COPY_MISCREG_AA64_RST, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700393
394 return 0;
395}
396
Anthony Zhou1ab31402017-03-06 16:06:45 +0800397int32_t ari_roc_flush_cache_trbits(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700398{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700399 /* clean the previous response state */
400 ari_clobber_response(ari_base);
401
Anthony Zhou1ab31402017-03-06 16:06:45 +0800402 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_FLUSH_CACHE_TRBITS,
403 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700404}
405
Anthony Zhou1ab31402017-03-06 16:06:45 +0800406int32_t ari_roc_flush_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700407{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700408 /* clean the previous response state */
409 ari_clobber_response(ari_base);
410
Anthony Zhou1ab31402017-03-06 16:06:45 +0800411 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_FLUSH_CACHE_ONLY,
412 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700413}
414
Anthony Zhou1ab31402017-03-06 16:06:45 +0800415int32_t ari_roc_clean_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700416{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700417 /* clean the previous response state */
418 ari_clobber_response(ari_base);
419
Anthony Zhou1ab31402017-03-06 16:06:45 +0800420 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_CLEAN_CACHE_ONLY,
421 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700422}
423
Anthony Zhou1ab31402017-03-06 16:06:45 +0800424uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700425{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800426 uint64_t mca_arg_data, result = 0;
427 uint32_t resp_lo, resp_hi;
428 uint32_t mca_arg_err, mca_arg_finish;
429 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700430
431 /* Set data (write) */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800432 mca_arg_data = (data != NULL) ? *data : 0ULL;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700433
434 /* Set command */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800435 ari_write_32(ari_base, (uint32_t)cmd, ARI_RESPONSE_DATA_LO);
436 ari_write_32(ari_base, (uint32_t)(cmd >> 32U), ARI_RESPONSE_DATA_HI);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700437
Anthony Zhou1ab31402017-03-06 16:06:45 +0800438 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_MCA,
439 (uint32_t)mca_arg_data,
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100440 (uint32_t)(mca_arg_data >> 32U));
Anthony Zhou1ab31402017-03-06 16:06:45 +0800441 if (ret == 0) {
442 resp_lo = ari_get_response_low(ari_base);
443 resp_hi = ari_get_response_high(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700444
Anthony Zhou1ab31402017-03-06 16:06:45 +0800445 mca_arg_err = resp_lo & MCA_ARG_ERROR_MASK;
446 mca_arg_finish = (resp_hi >> MCA_ARG_FINISH_SHIFT) &
447 MCA_ARG_FINISH_MASK;
448
449 if (mca_arg_finish == 0U) {
450 result = (uint64_t)mca_arg_err;
451 } else {
452 if (data != NULL) {
453 resp_lo = ari_get_request_low(ari_base);
454 resp_hi = ari_get_request_high(ari_base);
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100455 *data = ((uint64_t)resp_hi << 32U) |
Anthony Zhou1ab31402017-03-06 16:06:45 +0800456 (uint64_t)resp_lo;
457 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700458 }
459 }
460
Anthony Zhou1ab31402017-03-06 16:06:45 +0800461 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700462}
463
Anthony Zhou1ab31402017-03-06 16:06:45 +0800464int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700465{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800466 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700467 /* sanity check GSC ID */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800468 if (gsc_idx > (uint32_t)TEGRA_ARI_GSC_VPR_IDX) {
469 ret = EINVAL;
470 } else {
471 /* clean the previous response state */
472 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700473
Anthony Zhou1ab31402017-03-06 16:06:45 +0800474 /*
475 * The MCE code will read the GSC carveout value, corrseponding to
476 * the ID, from the MC registers and update the internal GSC registers
477 * of the CCPLEX.
478 */
479 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CCPLEX_GSC, gsc_idx, 0U);
480 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700481
Anthony Zhou1ab31402017-03-06 16:06:45 +0800482 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700483}
484
485void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx)
486{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700487 /* clean the previous response state */
488 ari_clobber_response(ari_base);
489
Varun Wadekara0352ab2017-03-14 14:24:35 -0700490 /*
491 * The MCE will shutdown or restart the entire system
492 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800493 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC_CCPLEX, state_idx, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700494}
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700495
Anthony Zhou1ab31402017-03-06 16:06:45 +0800496int32_t ari_read_write_uncore_perfmon(uint32_t ari_base, uint64_t req,
497 uint64_t *data)
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700498{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800499 int32_t ret, result;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700500 uint32_t val;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800501 uint8_t req_cmd, req_status;
502
503 req_cmd = (uint8_t)(req >> UNCORE_PERFMON_CMD_SHIFT);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700504
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700505 /* clean the previous response state */
506 ari_clobber_response(ari_base);
507
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700508 /* sanity check input parameters */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800509 if ((req_cmd == UNCORE_PERFMON_CMD_READ) && (data == NULL)) {
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700510 ERROR("invalid parameters\n");
Anthony Zhou1ab31402017-03-06 16:06:45 +0800511 result = EINVAL;
512 } else {
513 /*
514 * For "write" commands get the value that has to be written
515 * to the uncore perfmon registers
516 */
517 val = (req_cmd == UNCORE_PERFMON_CMD_WRITE) ?
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100518 (uint32_t)*data : 0U;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700519
Anthony Zhou1ab31402017-03-06 16:06:45 +0800520 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_PERFMON, val,
521 (uint32_t)req);
522 if (ret != 0) {
523 result = ret;
524 } else {
525 /* read the command status value */
526 req_status = (uint8_t)ari_get_response_high(ari_base) &
527 UNCORE_PERFMON_RESP_STATUS_MASK;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700528
Anthony Zhou1ab31402017-03-06 16:06:45 +0800529 /*
530 * For "read" commands get the data from the uncore
531 * perfmon registers
532 */
533 req_status >>= UNCORE_PERFMON_RESP_STATUS_SHIFT;
534 if ((req_status == 0U) && (req_cmd == UNCORE_PERFMON_CMD_READ)) {
535 *data = ari_get_response_low(ari_base);
536 }
537 result = (int32_t)req_status;
538 }
539 }
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700540
Anthony Zhou1ab31402017-03-06 16:06:45 +0800541 return result;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700542}
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700543
544void ari_misc_ccplex(uint32_t ari_base, uint32_t index, uint32_t value)
545{
546 /*
547 * This invokes the ARI_MISC_CCPLEX commands. This can be
548 * used to enable/disable coresight clock gating.
549 */
550
Rich Wiley24e99392017-01-04 10:45:44 -0800551 if ((index > TEGRA_ARI_MISC_CCPLEX_EDBGREQ) ||
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700552 ((index == TEGRA_ARI_MISC_CCPLEX_CORESIGHT_CG_CTRL) &&
Anthony Zhou1ab31402017-03-06 16:06:45 +0800553 (value > 1U))) {
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700554 ERROR("%s: invalid parameters \n", __func__);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800555 } else {
556 /* clean the previous response state */
557 ari_clobber_response(ari_base);
558 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC_CCPLEX, index, value);
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700559 }
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700560}