blob: 7eb6c6c818e7e2228afe15b08b8031fa9c635f6d [file] [log] [blame]
Varun Wadekara0352ab2017-03-14 14:24:35 -07001/*
Steven Kaod346dca2016-12-23 16:17:18 +08002 * Copyright (c) 2015-2017, 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
7#include <arch.h>
8#include <arch_helpers.h>
Steven Kaod346dca2016-12-23 16:17:18 +08009#include <assert.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070010#include <debug.h>
Steven Kaod346dca2016-12-23 16:17:18 +080011#include <delay_timer.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070012#include <denver.h>
Varun Wadekarb5568282016-12-13 18:04:35 -080013#include <mce_private.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010014#include <mmio.h>
Steven Kaod346dca2016-12-23 16:17:18 +080015#include <platform.h>
Varun Wadekara0352ab2017-03-14 14:24:35 -070016#include <sys/errno.h>
17#include <t18x_ari.h>
18
19/*******************************************************************************
20 * Register offsets for ARI request/results
21 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080022#define ARI_REQUEST 0x0U
23#define ARI_REQUEST_EVENT_MASK 0x4U
24#define ARI_STATUS 0x8U
25#define ARI_REQUEST_DATA_LO 0xCU
26#define ARI_REQUEST_DATA_HI 0x10U
27#define ARI_RESPONSE_DATA_LO 0x14U
28#define ARI_RESPONSE_DATA_HI 0x18U
Varun Wadekara0352ab2017-03-14 14:24:35 -070029
30/* Status values for the current request */
Steven Kaod346dca2016-12-23 16:17:18 +080031#define ARI_REQ_PENDING 1U
32#define ARI_REQ_ONGOING 3U
33#define ARI_REQUEST_VALID_BIT (1U << 8)
34#define ARI_EVT_MASK_STANDBYWFI_BIT (1U << 7)
35
36/* default timeout (ms) to wait for ARI completion */
37#define ARI_MAX_RETRY_COUNT 2000
Varun Wadekara0352ab2017-03-14 14:24:35 -070038
39/*******************************************************************************
40 * ARI helper functions
41 ******************************************************************************/
42static inline uint32_t ari_read_32(uint32_t ari_base, uint32_t reg)
43{
Anthony Zhou1ab31402017-03-06 16:06:45 +080044 return mmio_read_32((uint64_t)ari_base + (uint64_t)reg);
Varun Wadekara0352ab2017-03-14 14:24:35 -070045}
46
47static inline void ari_write_32(uint32_t ari_base, uint32_t val, uint32_t reg)
48{
Anthony Zhou1ab31402017-03-06 16:06:45 +080049 mmio_write_32((uint64_t)ari_base + (uint64_t)reg, val);
Varun Wadekara0352ab2017-03-14 14:24:35 -070050}
51
52static inline uint32_t ari_get_request_low(uint32_t ari_base)
53{
54 return ari_read_32(ari_base, ARI_REQUEST_DATA_LO);
55}
56
57static inline uint32_t ari_get_request_high(uint32_t ari_base)
58{
59 return ari_read_32(ari_base, ARI_REQUEST_DATA_HI);
60}
61
62static inline uint32_t ari_get_response_low(uint32_t ari_base)
63{
64 return ari_read_32(ari_base, ARI_RESPONSE_DATA_LO);
65}
66
67static inline uint32_t ari_get_response_high(uint32_t ari_base)
68{
69 return ari_read_32(ari_base, ARI_RESPONSE_DATA_HI);
70}
71
72static inline void ari_clobber_response(uint32_t ari_base)
73{
74 ari_write_32(ari_base, 0, ARI_RESPONSE_DATA_LO);
75 ari_write_32(ari_base, 0, ARI_RESPONSE_DATA_HI);
76}
77
Anthony Zhou1ab31402017-03-06 16:06:45 +080078static int32_t ari_request_wait(uint32_t ari_base, uint32_t evt_mask, uint32_t req,
Varun Wadekara0352ab2017-03-14 14:24:35 -070079 uint32_t lo, uint32_t hi)
80{
Steven Kaod346dca2016-12-23 16:17:18 +080081 uint32_t retries = ARI_MAX_RETRY_COUNT;
82 uint32_t status;
Anthony Zhou1ab31402017-03-06 16:06:45 +080083 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -070084
85 /* program the request, event_mask, hi and lo registers */
86 ari_write_32(ari_base, lo, ARI_REQUEST_DATA_LO);
87 ari_write_32(ari_base, hi, ARI_REQUEST_DATA_HI);
88 ari_write_32(ari_base, evt_mask, ARI_REQUEST_EVENT_MASK);
89 ari_write_32(ari_base, req | ARI_REQUEST_VALID_BIT, ARI_REQUEST);
90
91 /*
92 * For commands that have an event trigger, we should bypass
93 * ARI_STATUS polling, since MCE is waiting for SW to trigger
94 * the event.
95 */
Anthony Zhou1ab31402017-03-06 16:06:45 +080096 if (evt_mask != 0U) {
97 ret = 0;
98 } else {
99 /* For shutdown/reboot commands, we dont have to check for timeouts */
100 if ((req == (uint32_t)TEGRA_ARI_MISC_CCPLEX) &&
101 ((lo == (uint32_t)TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) ||
102 (lo == (uint32_t)TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT))) {
103 ret = 0;
104 } else {
105 /*
106 * Wait for the command response for not more than the timeout
107 */
108 while (retries != 0U) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700109
Anthony Zhou1ab31402017-03-06 16:06:45 +0800110 /* read the command status */
111 status = ari_read_32(ari_base, ARI_STATUS);
112 if ((status & (ARI_REQ_ONGOING | ARI_REQ_PENDING)) == 0U) {
113 break;
114 }
Steven Kaod346dca2016-12-23 16:17:18 +0800115
Anthony Zhou1ab31402017-03-06 16:06:45 +0800116 /* delay 1 ms */
117 mdelay(1);
Steven Kaod346dca2016-12-23 16:17:18 +0800118
Anthony Zhou1ab31402017-03-06 16:06:45 +0800119 /* decrement the retry count */
120 retries--;
121 }
Steven Kaod346dca2016-12-23 16:17:18 +0800122
Anthony Zhou1ab31402017-03-06 16:06:45 +0800123 /* assert if the command timed out */
124 if (retries == 0U) {
125 ERROR("ARI request timed out: req %d on CPU %d\n",
126 req, plat_my_core_pos());
127 assert(retries != 0U);
128 }
129 }
Steven Kaod346dca2016-12-23 16:17:18 +0800130 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700131
Anthony Zhou1ab31402017-03-06 16:06:45 +0800132 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700133}
134
Anthony Zhou1ab31402017-03-06 16:06:45 +0800135int32_t ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700136{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800137 int32_t ret = 0;
138
Varun Wadekara0352ab2017-03-14 14:24:35 -0700139 /* check for allowed power state */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800140 if ((state != TEGRA_ARI_CORE_C0) &&
141 (state != TEGRA_ARI_CORE_C1) &&
142 (state != TEGRA_ARI_CORE_C6) &&
143 (state != TEGRA_ARI_CORE_C7)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700144 ERROR("%s: unknown cstate (%d)\n", __func__, state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800145 ret = EINVAL;
146 } else {
147 /* clean the previous response state */
148 ari_clobber_response(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700149
Anthony Zhou1ab31402017-03-06 16:06:45 +0800150 /* Enter the cstate, to be woken up after wake_time (TSC ticks) */
151 ret = ari_request_wait(ari_base, ARI_EVT_MASK_STANDBYWFI_BIT,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700152 TEGRA_ARI_ENTER_CSTATE, state, wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800153 }
154
155 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700156}
157
Anthony Zhou1ab31402017-03-06 16:06:45 +0800158int32_t ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700159 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
160 uint8_t update_wake_mask)
161{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800162 uint32_t val = 0U;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700163
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700164 /* clean the previous response state */
165 ari_clobber_response(ari_base);
166
Varun Wadekara0352ab2017-03-14 14:24:35 -0700167 /* update CLUSTER_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800168 if (cluster != 0U) {
169 val |= (cluster & (uint32_t)CLUSTER_CSTATE_MASK) |
170 (uint32_t)CLUSTER_CSTATE_UPDATE_BIT;
171 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700172
173 /* update CCPLEX_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800174 if (ccplex != 0U) {
175 val |= ((ccplex & (uint32_t)CCPLEX_CSTATE_MASK) << (uint32_t)CCPLEX_CSTATE_SHIFT) |
176 (uint32_t)CCPLEX_CSTATE_UPDATE_BIT;
177 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700178
179 /* update SYSTEM_CSTATE? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800180 if (system != 0U) {
181 val |= ((system & (uint32_t)SYSTEM_CSTATE_MASK) << (uint32_t)SYSTEM_CSTATE_SHIFT) |
182 (((uint32_t)sys_state_force << SYSTEM_CSTATE_FORCE_UPDATE_SHIFT) |
183 (uint32_t)SYSTEM_CSTATE_UPDATE_BIT);
184 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700185
186 /* update wake mask value? */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800187 if (update_wake_mask != 0U) {
188 val |= (uint32_t)CSTATE_WAKE_MASK_UPDATE_BIT;
189 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700190
191 /* set the updated cstate info */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800192 return ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CSTATE_INFO, val,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700193 wake_mask);
194}
195
Anthony Zhou1ab31402017-03-06 16:06:45 +0800196int32_t ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700197{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800198 int32_t ret = 0;
199
Varun Wadekara0352ab2017-03-14 14:24:35 -0700200 /* sanity check crossover type */
201 if ((type == TEGRA_ARI_CROSSOVER_C1_C6) ||
Anthony Zhou1ab31402017-03-06 16:06:45 +0800202 (type > TEGRA_ARI_CROSSOVER_CCP3_SC1)) {
203 ret = EINVAL;
204 } else {
205 /* clean the previous response state */
206 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700207
Anthony Zhou1ab31402017-03-06 16:06:45 +0800208 /* update crossover threshold time */
209 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CROSSOVER,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700210 type, time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800211 }
212
213 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700214}
215
216uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state)
217{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800218 int32_t ret;
219 uint64_t result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700220
221 /* sanity check crossover type */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800222 if (state == 0U) {
223 result = EINVAL;
224 } else {
225 /* clean the previous response state */
226 ari_clobber_response(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700227
Anthony Zhou1ab31402017-03-06 16:06:45 +0800228 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_CSTATE_STATS, state, 0U);
229 if (ret != 0) {
230 result = EINVAL;
231 } else {
232 result = (uint64_t)ari_get_response_low(ari_base);
233 }
234 }
235 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700236}
237
Anthony Zhou1ab31402017-03-06 16:06:45 +0800238int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700239{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700240 /* clean the previous response state */
241 ari_clobber_response(ari_base);
242
Varun Wadekara0352ab2017-03-14 14:24:35 -0700243 /* write the cstate stats */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800244 return ari_request_wait(ari_base, 0U, TEGRA_ARI_WRITE_CSTATE_STATS, state,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700245 stats);
246}
247
248uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data)
249{
250 uint64_t resp;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800251 int32_t ret;
252 uint32_t local_data = data;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700253
254 /* clean the previous response state */
255 ari_clobber_response(ari_base);
256
257 /* ARI_REQUEST_DATA_HI is reserved for commands other than 'ECHO' */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800258 if (cmd != TEGRA_ARI_MISC_ECHO) {
259 local_data = 0U;
260 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700261
Anthony Zhou1ab31402017-03-06 16:06:45 +0800262 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC, cmd, local_data);
263 if (ret != 0) {
264 resp = (uint64_t)ret;
265 } else {
266 /* get the command response */
267 resp = ari_get_response_low(ari_base);
268 resp |= ((uint64_t)ari_get_response_high(ari_base) << 32);
269 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700270
271 return resp;
272}
273
Anthony Zhou1ab31402017-03-06 16:06:45 +0800274int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700275{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800276 int32_t ret;
277 uint32_t result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700278
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700279 /* clean the previous response state */
280 ari_clobber_response(ari_base);
281
Anthony Zhou1ab31402017-03-06 16:06:45 +0800282 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_IS_CCX_ALLOWED, state & 0x7U,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700283 wake_time);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800284 if (ret != 0) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700285 ERROR("%s: failed (%d)\n", __func__, ret);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800286 result = 0U;
287 } else {
288 result = ari_get_response_low(ari_base) & 0x1U;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700289 }
290
291 /* 1 = CCx allowed, 0 = CCx not allowed */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800292 return (int32_t)result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700293}
294
Anthony Zhou1ab31402017-03-06 16:06:45 +0800295int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700296{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800297 int32_t ret, result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700298
299 /* check for allowed power state */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800300 if ((state != TEGRA_ARI_CORE_C0) &&
301 (state != TEGRA_ARI_CORE_C1) &&
302 (state != TEGRA_ARI_CORE_C6) &&
303 (state != TEGRA_ARI_CORE_C7)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700304 ERROR("%s: unknown cstate (%d)\n", __func__, state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800305 result = EINVAL;
306 } else {
307 /* clean the previous response state */
308 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700309
Anthony Zhou1ab31402017-03-06 16:06:45 +0800310 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_IS_SC7_ALLOWED, state,
311 wake_time);
312 if (ret != 0) {
313 ERROR("%s: failed (%d)\n", __func__, ret);
314 result = 0;
315 } else {
316 /* 1 = SC7 allowed, 0 = SC7 not allowed */
317 result = (ari_get_response_low(ari_base) != 0U) ? 1 : 0;
318 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700319 }
320
Anthony Zhou1ab31402017-03-06 16:06:45 +0800321 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700322}
323
Anthony Zhou1ab31402017-03-06 16:06:45 +0800324int32_t ari_online_core(uint32_t ari_base, uint32_t core)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700325{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800326 uint64_t cpu = read_mpidr() & (uint64_t)(MPIDR_CPU_MASK);
327 uint64_t cluster = (read_mpidr() & (uint64_t)(MPIDR_CLUSTER_MASK)) >>
328 (uint64_t)(MPIDR_AFFINITY_BITS);
329 uint64_t impl = (read_midr() >> (uint64_t)MIDR_IMPL_SHIFT) & (uint64_t)MIDR_IMPL_MASK;
330 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700331
332 /* construct the current CPU # */
333 cpu |= (cluster << 2);
334
335 /* sanity check target core id */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800336 if ((core >= MCE_CORE_ID_MAX) || (cpu == (uint64_t)core)) {
Varun Wadekara0352ab2017-03-14 14:24:35 -0700337 ERROR("%s: unsupported core id (%d)\n", __func__, core);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800338 ret = EINVAL;
339 } else {
340 /*
341 * The Denver cluster has 2 CPUs only - 0, 1.
342 */
343 if ((impl == (uint32_t)DENVER_IMPL) &&
344 ((core == 2U) || (core == 3U))) {
345 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);
350 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_ONLINE_CORE, core, 0U);
351 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700352 }
353
Anthony Zhou1ab31402017-03-06 16:06:45 +0800354 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700355}
356
Anthony Zhou1ab31402017-03-06 16:06:45 +0800357int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700358{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800359 uint32_t val;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700360
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700361 /* clean the previous response state */
362 ari_clobber_response(ari_base);
363
Varun Wadekara0352ab2017-03-14 14:24:35 -0700364 /*
365 * If the enable bit is cleared, Auto-CC3 will be disabled by setting
366 * the SW visible voltage/frequency request registers for all non
367 * floorswept cores valid independent of StandbyWFI and disabling
368 * the IDLE voltage/frequency request register. If set, Auto-CC3
369 * will be enabled by setting the ARM SW visible voltage/frequency
370 * request registers for all non floorswept cores to be enabled by
371 * StandbyWFI or the equivalent signal, and always keeping the IDLE
372 * voltage/frequency request register enabled.
373 */
374 val = (((freq & MCE_AUTO_CC3_FREQ_MASK) << MCE_AUTO_CC3_FREQ_SHIFT) |\
375 ((volt & MCE_AUTO_CC3_VTG_MASK) << MCE_AUTO_CC3_VTG_SHIFT) |\
Anthony Zhou1ab31402017-03-06 16:06:45 +0800376 ((enable != 0U) ? MCE_AUTO_CC3_ENABLE_BIT : 0U));
Varun Wadekara0352ab2017-03-14 14:24:35 -0700377
Anthony Zhou1ab31402017-03-06 16:06:45 +0800378 return ari_request_wait(ari_base, 0U, TEGRA_ARI_CC3_CTRL, val, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700379}
380
Anthony Zhou1ab31402017-03-06 16:06:45 +0800381int32_t ari_reset_vector_update(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700382{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700383 /* clean the previous response state */
384 ari_clobber_response(ari_base);
385
Varun Wadekara0352ab2017-03-14 14:24:35 -0700386 /*
387 * Need to program the CPU reset vector one time during cold boot
388 * and SC7 exit
389 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800390 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_COPY_MISCREG_AA64_RST, 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700391
392 return 0;
393}
394
Anthony Zhou1ab31402017-03-06 16:06:45 +0800395int32_t ari_roc_flush_cache_trbits(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700396{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700397 /* clean the previous response state */
398 ari_clobber_response(ari_base);
399
Anthony Zhou1ab31402017-03-06 16:06:45 +0800400 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_FLUSH_CACHE_TRBITS,
401 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700402}
403
Anthony Zhou1ab31402017-03-06 16:06:45 +0800404int32_t ari_roc_flush_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700405{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700406 /* clean the previous response state */
407 ari_clobber_response(ari_base);
408
Anthony Zhou1ab31402017-03-06 16:06:45 +0800409 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_FLUSH_CACHE_ONLY,
410 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700411}
412
Anthony Zhou1ab31402017-03-06 16:06:45 +0800413int32_t ari_roc_clean_cache(uint32_t ari_base)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700414{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700415 /* clean the previous response state */
416 ari_clobber_response(ari_base);
417
Anthony Zhou1ab31402017-03-06 16:06:45 +0800418 return ari_request_wait(ari_base, 0U, TEGRA_ARI_ROC_CLEAN_CACHE_ONLY,
419 0U, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700420}
421
Anthony Zhou1ab31402017-03-06 16:06:45 +0800422uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700423{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800424 uint64_t mca_arg_data, result = 0;
425 uint32_t resp_lo, resp_hi;
426 uint32_t mca_arg_err, mca_arg_finish;
427 int32_t ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700428
429 /* Set data (write) */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800430 mca_arg_data = (data != NULL) ? *data : 0ULL;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700431
432 /* Set command */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800433 ari_write_32(ari_base, (uint32_t)cmd, ARI_RESPONSE_DATA_LO);
434 ari_write_32(ari_base, (uint32_t)(cmd >> 32U), ARI_RESPONSE_DATA_HI);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700435
Anthony Zhou1ab31402017-03-06 16:06:45 +0800436 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_MCA,
437 (uint32_t)mca_arg_data,
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100438 (uint32_t)(mca_arg_data >> 32U));
Anthony Zhou1ab31402017-03-06 16:06:45 +0800439 if (ret == 0) {
440 resp_lo = ari_get_response_low(ari_base);
441 resp_hi = ari_get_response_high(ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700442
Anthony Zhou1ab31402017-03-06 16:06:45 +0800443 mca_arg_err = resp_lo & MCA_ARG_ERROR_MASK;
444 mca_arg_finish = (resp_hi >> MCA_ARG_FINISH_SHIFT) &
445 MCA_ARG_FINISH_MASK;
446
447 if (mca_arg_finish == 0U) {
448 result = (uint64_t)mca_arg_err;
449 } else {
450 if (data != NULL) {
451 resp_lo = ari_get_request_low(ari_base);
452 resp_hi = ari_get_request_high(ari_base);
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100453 *data = ((uint64_t)resp_hi << 32U) |
Anthony Zhou1ab31402017-03-06 16:06:45 +0800454 (uint64_t)resp_lo;
455 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700456 }
457 }
458
Anthony Zhou1ab31402017-03-06 16:06:45 +0800459 return result;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700460}
461
Anthony Zhou1ab31402017-03-06 16:06:45 +0800462int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx)
Varun Wadekara0352ab2017-03-14 14:24:35 -0700463{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800464 int32_t ret = 0;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700465 /* sanity check GSC ID */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800466 if (gsc_idx > (uint32_t)TEGRA_ARI_GSC_VPR_IDX) {
467 ret = EINVAL;
468 } else {
469 /* clean the previous response state */
470 ari_clobber_response(ari_base);
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700471
Anthony Zhou1ab31402017-03-06 16:06:45 +0800472 /*
473 * The MCE code will read the GSC carveout value, corrseponding to
474 * the ID, from the MC registers and update the internal GSC registers
475 * of the CCPLEX.
476 */
477 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_UPDATE_CCPLEX_GSC, gsc_idx, 0U);
478 }
Varun Wadekara0352ab2017-03-14 14:24:35 -0700479
Anthony Zhou1ab31402017-03-06 16:06:45 +0800480 return ret;
Varun Wadekara0352ab2017-03-14 14:24:35 -0700481}
482
483void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx)
484{
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700485 /* clean the previous response state */
486 ari_clobber_response(ari_base);
487
Varun Wadekara0352ab2017-03-14 14:24:35 -0700488 /*
489 * The MCE will shutdown or restart the entire system
490 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800491 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC_CCPLEX, state_idx, 0U);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700492}
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700493
Anthony Zhou1ab31402017-03-06 16:06:45 +0800494int32_t ari_read_write_uncore_perfmon(uint32_t ari_base, uint64_t req,
495 uint64_t *data)
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700496{
Anthony Zhou1ab31402017-03-06 16:06:45 +0800497 int32_t ret, result;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700498 uint32_t val;
Anthony Zhou1ab31402017-03-06 16:06:45 +0800499 uint8_t req_cmd, req_status;
500
501 req_cmd = (uint8_t)(req >> UNCORE_PERFMON_CMD_SHIFT);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700502
Krishna Sitaraman282e5832016-07-28 13:54:29 -0700503 /* clean the previous response state */
504 ari_clobber_response(ari_base);
505
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700506 /* sanity check input parameters */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800507 if ((req_cmd == UNCORE_PERFMON_CMD_READ) && (data == NULL)) {
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700508 ERROR("invalid parameters\n");
Anthony Zhou1ab31402017-03-06 16:06:45 +0800509 result = EINVAL;
510 } else {
511 /*
512 * For "write" commands get the value that has to be written
513 * to the uncore perfmon registers
514 */
515 val = (req_cmd == UNCORE_PERFMON_CMD_WRITE) ?
Antonio Nino Diazf94e40d2017-09-14 15:57:44 +0100516 (uint32_t)*data : 0U;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700517
Anthony Zhou1ab31402017-03-06 16:06:45 +0800518 ret = ari_request_wait(ari_base, 0U, TEGRA_ARI_PERFMON, val,
519 (uint32_t)req);
520 if (ret != 0) {
521 result = ret;
522 } else {
523 /* read the command status value */
524 req_status = (uint8_t)ari_get_response_high(ari_base) &
525 UNCORE_PERFMON_RESP_STATUS_MASK;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700526
Anthony Zhou1ab31402017-03-06 16:06:45 +0800527 /*
528 * For "read" commands get the data from the uncore
529 * perfmon registers
530 */
531 req_status >>= UNCORE_PERFMON_RESP_STATUS_SHIFT;
532 if ((req_status == 0U) && (req_cmd == UNCORE_PERFMON_CMD_READ)) {
533 *data = ari_get_response_low(ari_base);
534 }
535 result = (int32_t)req_status;
536 }
537 }
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700538
Anthony Zhou1ab31402017-03-06 16:06:45 +0800539 return result;
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700540}
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700541
542void ari_misc_ccplex(uint32_t ari_base, uint32_t index, uint32_t value)
543{
544 /*
545 * This invokes the ARI_MISC_CCPLEX commands. This can be
546 * used to enable/disable coresight clock gating.
547 */
548
Rich Wiley24e99392017-01-04 10:45:44 -0800549 if ((index > TEGRA_ARI_MISC_CCPLEX_EDBGREQ) ||
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700550 ((index == TEGRA_ARI_MISC_CCPLEX_CORESIGHT_CG_CTRL) &&
Anthony Zhou1ab31402017-03-06 16:06:45 +0800551 (value > 1U))) {
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700552 ERROR("%s: invalid parameters \n", __func__);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800553 } else {
554 /* clean the previous response state */
555 ari_clobber_response(ari_base);
556 (void)ari_request_wait(ari_base, 0U, TEGRA_ARI_MISC_CCPLEX, index, value);
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700557 }
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700558}