Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | #include <errno.h> |
| 9 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 10 | #include <arch.h> |
| 11 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <common/debug.h> |
| 13 | #include <drivers/delay_timer.h> |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 14 | #include <denver.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <lib/mmio.h> |
| 16 | #include <plat/common/platform.h> |
| 17 | |
Varun Wadekar | b556828 | 2016-12-13 18:04:35 -0800 | [diff] [blame] | 18 | #include <mce_private.h> |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 19 | #include <t18x_ari.h> |
| 20 | |
| 21 | /******************************************************************************* |
| 22 | * Register offsets for ARI request/results |
| 23 | ******************************************************************************/ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 24 | #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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 31 | |
| 32 | /* Status values for the current request */ |
Steven Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 33 | #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 | |
Varun Wadekar | 904a9be | 2017-08-31 17:14:22 -0700 | [diff] [blame] | 38 | /* default timeout (us) to wait for ARI completion */ |
| 39 | #define ARI_MAX_RETRY_COUNT U(2000000) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 40 | |
| 41 | /******************************************************************************* |
| 42 | * ARI helper functions |
| 43 | ******************************************************************************/ |
| 44 | static inline uint32_t ari_read_32(uint32_t ari_base, uint32_t reg) |
| 45 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 46 | return mmio_read_32((uint64_t)ari_base + (uint64_t)reg); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static inline void ari_write_32(uint32_t ari_base, uint32_t val, uint32_t reg) |
| 50 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 51 | mmio_write_32((uint64_t)ari_base + (uint64_t)reg, val); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static 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 | |
| 59 | static 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 | |
| 64 | static 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 | |
| 69 | static 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 | |
| 74 | static 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 80 | static int32_t ari_request_wait(uint32_t ari_base, uint32_t evt_mask, uint32_t req, |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 81 | uint32_t lo, uint32_t hi) |
| 82 | { |
Varun Wadekar | 904a9be | 2017-08-31 17:14:22 -0700 | [diff] [blame] | 83 | uint32_t retries = (uint32_t)ARI_MAX_RETRY_COUNT; |
Steven Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 84 | uint32_t status; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 85 | int32_t ret = 0; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 86 | |
| 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 98 | if (evt_mask != 0U) { |
| 99 | ret = 0; |
| 100 | } else { |
| 101 | /* For shutdown/reboot commands, we dont have to check for timeouts */ |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 102 | if ((req == TEGRA_ARI_MISC_CCPLEX) && |
| 103 | ((lo == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) || |
| 104 | (lo == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT))) { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 105 | ret = 0; |
| 106 | } else { |
| 107 | /* |
| 108 | * Wait for the command response for not more than the timeout |
| 109 | */ |
| 110 | while (retries != 0U) { |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 111 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 112 | /* 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 Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 117 | |
Varun Wadekar | 904a9be | 2017-08-31 17:14:22 -0700 | [diff] [blame] | 118 | /* delay 1 us */ |
| 119 | udelay(1); |
Steven Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 120 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 121 | /* decrement the retry count */ |
| 122 | retries--; |
| 123 | } |
Steven Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 124 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 125 | /* 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 Kao | d346dca | 2016-12-23 16:17:18 +0800 | [diff] [blame] | 132 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 133 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 134 | return ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 137 | int32_t ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 138 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 139 | int32_t ret = 0; |
| 140 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 141 | /* check for allowed power state */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 142 | 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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 146 | ERROR("%s: unknown cstate (%d)\n", __func__, state); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 147 | ret = EINVAL; |
| 148 | } else { |
| 149 | /* clean the previous response state */ |
| 150 | ari_clobber_response(ari_base); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 151 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 152 | /* 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 Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 154 | (uint32_t)TEGRA_ARI_ENTER_CSTATE, state, wake_time); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | return ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 160 | int32_t ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex, |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 161 | uint32_t system, uint8_t sys_state_force, uint32_t wake_mask, |
| 162 | uint8_t update_wake_mask) |
| 163 | { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 164 | uint64_t val = 0U; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 165 | |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 166 | /* clean the previous response state */ |
| 167 | ari_clobber_response(ari_base); |
| 168 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 169 | /* update CLUSTER_CSTATE? */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 170 | if (cluster != 0U) { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 171 | val |= (cluster & CLUSTER_CSTATE_MASK) | |
| 172 | CLUSTER_CSTATE_UPDATE_BIT; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 173 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 174 | |
| 175 | /* update CCPLEX_CSTATE? */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 176 | if (ccplex != 0U) { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 177 | val |= ((ccplex & CCPLEX_CSTATE_MASK) << CCPLEX_CSTATE_SHIFT) | |
| 178 | CCPLEX_CSTATE_UPDATE_BIT; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 179 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 180 | |
| 181 | /* update SYSTEM_CSTATE? */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 182 | if (system != 0U) { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 183 | 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 186 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 187 | |
| 188 | /* update wake mask value? */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 189 | if (update_wake_mask != 0U) { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 190 | val |= CSTATE_WAKE_MASK_UPDATE_BIT; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 191 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 192 | |
| 193 | /* set the updated cstate info */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 194 | return ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_UPDATE_CSTATE_INFO, |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 195 | (uint32_t)val, wake_mask); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 198 | int32_t ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 199 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 200 | int32_t ret = 0; |
| 201 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 202 | /* sanity check crossover type */ |
| 203 | if ((type == TEGRA_ARI_CROSSOVER_C1_C6) || |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 204 | (type > TEGRA_ARI_CROSSOVER_CCP3_SC1)) { |
| 205 | ret = EINVAL; |
| 206 | } else { |
| 207 | /* clean the previous response state */ |
| 208 | ari_clobber_response(ari_base); |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 209 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 210 | /* update crossover threshold time */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 211 | ret = ari_request_wait(ari_base, 0U, |
| 212 | (uint32_t)TEGRA_ARI_UPDATE_CROSSOVER, type, time); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | return ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state) |
| 219 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 220 | int32_t ret; |
| 221 | uint64_t result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 222 | |
| 223 | /* sanity check crossover type */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 224 | if (state == 0U) { |
| 225 | result = EINVAL; |
| 226 | } else { |
| 227 | /* clean the previous response state */ |
| 228 | ari_clobber_response(ari_base); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 229 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 230 | ret = ari_request_wait(ari_base, 0U, |
| 231 | (uint32_t)TEGRA_ARI_CSTATE_STATS, state, 0U); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 232 | if (ret != 0) { |
| 233 | result = EINVAL; |
| 234 | } else { |
| 235 | result = (uint64_t)ari_get_response_low(ari_base); |
| 236 | } |
| 237 | } |
| 238 | return result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 241 | int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 242 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 243 | /* clean the previous response state */ |
| 244 | ari_clobber_response(ari_base); |
| 245 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 246 | /* write the cstate stats */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 247 | return ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_WRITE_CSTATE_STATS, |
| 248 | state, stats); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data) |
| 252 | { |
| 253 | uint64_t resp; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 254 | int32_t ret; |
| 255 | uint32_t local_data = data; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 256 | |
| 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 261 | if (cmd != TEGRA_ARI_MISC_ECHO) { |
| 262 | local_data = 0U; |
| 263 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 264 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 265 | ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_MISC, cmd, local_data); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 266 | 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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 273 | |
| 274 | return resp; |
| 275 | } |
| 276 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 277 | int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 278 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 279 | int32_t ret; |
| 280 | uint32_t result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 281 | |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 282 | /* clean the previous response state */ |
| 283 | ari_clobber_response(ari_base); |
| 284 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 285 | ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_IS_CCX_ALLOWED, |
| 286 | state & 0x7U, wake_time); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 287 | if (ret != 0) { |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 288 | ERROR("%s: failed (%d)\n", __func__, ret); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 289 | result = 0U; |
| 290 | } else { |
| 291 | result = ari_get_response_low(ari_base) & 0x1U; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* 1 = CCx allowed, 0 = CCx not allowed */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 295 | return (int32_t)result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 298 | int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 299 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 300 | int32_t ret, result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 301 | |
| 302 | /* check for allowed power state */ |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 303 | if ((state != TEGRA_ARI_CORE_C0) && (state != TEGRA_ARI_CORE_C1) && |
| 304 | (state != TEGRA_ARI_CORE_C6) && (state != TEGRA_ARI_CORE_C7)) { |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 305 | ERROR("%s: unknown cstate (%d)\n", __func__, state); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 306 | result = EINVAL; |
| 307 | } else { |
| 308 | /* clean the previous response state */ |
| 309 | ari_clobber_response(ari_base); |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 310 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 311 | ret = ari_request_wait(ari_base, 0U, |
| 312 | (uint32_t)TEGRA_ARI_IS_SC7_ALLOWED, state, wake_time); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 313 | 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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 322 | return result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 325 | int32_t ari_online_core(uint32_t ari_base, uint32_t core) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 326 | { |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 327 | 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 331 | int32_t ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 332 | |
| 333 | /* construct the current CPU # */ |
| 334 | cpu |= (cluster << 2); |
| 335 | |
| 336 | /* sanity check target core id */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 337 | if ((core >= MCE_CORE_ID_MAX) || (cpu == (uint64_t)core)) { |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 338 | ERROR("%s: unsupported core id (%d)\n", __func__, core); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 339 | ret = EINVAL; |
| 340 | } else { |
| 341 | /* |
| 342 | * The Denver cluster has 2 CPUs only - 0, 1. |
| 343 | */ |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 344 | if ((impl == DENVER_IMPL) && ((core == 2U) || (core == 3U))) { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 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); |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 350 | ret = ari_request_wait(ari_base, 0U, |
| 351 | (uint32_t)TEGRA_ARI_ONLINE_CORE, core, 0U); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 352 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 355 | return ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 358 | int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 359 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 360 | uint32_t val; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 361 | |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 362 | /* clean the previous response state */ |
| 363 | ari_clobber_response(ari_base); |
| 364 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 365 | /* |
| 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 Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 377 | ((enable != 0U) ? MCE_AUTO_CC3_ENABLE_BIT : 0U)); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 378 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 379 | return ari_request_wait(ari_base, 0U, |
| 380 | (uint32_t)TEGRA_ARI_CC3_CTRL, val, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 383 | int32_t ari_reset_vector_update(uint32_t ari_base) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 384 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 385 | /* clean the previous response state */ |
| 386 | ari_clobber_response(ari_base); |
| 387 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 388 | /* |
| 389 | * Need to program the CPU reset vector one time during cold boot |
| 390 | * and SC7 exit |
| 391 | */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 392 | (void)ari_request_wait(ari_base, 0U, |
| 393 | (uint32_t)TEGRA_ARI_COPY_MISCREG_AA64_RST, 0U, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 398 | int32_t ari_roc_flush_cache_trbits(uint32_t ari_base) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 399 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 400 | /* clean the previous response state */ |
| 401 | ari_clobber_response(ari_base); |
| 402 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 403 | return ari_request_wait(ari_base, 0U, |
| 404 | (uint32_t)TEGRA_ARI_ROC_FLUSH_CACHE_TRBITS, 0U, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 407 | int32_t ari_roc_flush_cache(uint32_t ari_base) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 408 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 409 | /* clean the previous response state */ |
| 410 | ari_clobber_response(ari_base); |
| 411 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 412 | return ari_request_wait(ari_base, 0U, |
| 413 | (uint32_t)TEGRA_ARI_ROC_FLUSH_CACHE_ONLY, 0U, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 416 | int32_t ari_roc_clean_cache(uint32_t ari_base) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 417 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 418 | /* clean the previous response state */ |
| 419 | ari_clobber_response(ari_base); |
| 420 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 421 | return ari_request_wait(ari_base, 0U, |
| 422 | (uint32_t)TEGRA_ARI_ROC_CLEAN_CACHE_ONLY, 0U, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 425 | uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 426 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 427 | 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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 431 | |
| 432 | /* Set data (write) */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 433 | mca_arg_data = (data != NULL) ? *data : 0ULL; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 434 | |
| 435 | /* Set command */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 436 | 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 Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 438 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 439 | ret = ari_request_wait(ari_base, 0U, (uint32_t)TEGRA_ARI_MCA, |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 440 | (uint32_t)mca_arg_data, |
Antonio Nino Diaz | f94e40d | 2017-09-14 15:57:44 +0100 | [diff] [blame] | 441 | (uint32_t)(mca_arg_data >> 32U)); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 442 | if (ret == 0) { |
| 443 | resp_lo = ari_get_response_low(ari_base); |
| 444 | resp_hi = ari_get_response_high(ari_base); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 445 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 446 | 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 Diaz | f94e40d | 2017-09-14 15:57:44 +0100 | [diff] [blame] | 456 | *data = ((uint64_t)resp_hi << 32U) | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 457 | (uint64_t)resp_lo; |
| 458 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 462 | return result; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 465 | int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx) |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 466 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 467 | int32_t ret = 0; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 468 | /* sanity check GSC ID */ |
Anthony Zhou | 3b80450 | 2017-06-26 20:33:34 +0800 | [diff] [blame] | 469 | if (gsc_idx > TEGRA_ARI_GSC_VPR_IDX) { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 470 | ret = EINVAL; |
| 471 | } else { |
| 472 | /* clean the previous response state */ |
| 473 | ari_clobber_response(ari_base); |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 474 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 475 | /* |
| 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 Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 480 | (void)ari_request_wait(ari_base, 0U, |
| 481 | (uint32_t)TEGRA_ARI_UPDATE_CCPLEX_GSC, gsc_idx, 0U); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 482 | } |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 483 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 484 | return ret; |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx) |
| 488 | { |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 489 | /* clean the previous response state */ |
| 490 | ari_clobber_response(ari_base); |
| 491 | |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 492 | /* |
| 493 | * The MCE will shutdown or restart the entire system |
| 494 | */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 495 | (void)ari_request_wait(ari_base, 0U, |
| 496 | (uint32_t)TEGRA_ARI_MISC_CCPLEX, state_idx, 0U); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 497 | } |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 498 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 499 | int32_t ari_read_write_uncore_perfmon(uint32_t ari_base, uint64_t req, |
| 500 | uint64_t *data) |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 501 | { |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 502 | int32_t ret, result; |
Anthony Zhou | 0a01321 | 2017-05-08 20:17:08 +0800 | [diff] [blame] | 503 | uint32_t val, req_status; |
| 504 | uint8_t req_cmd; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 505 | |
Varun Wadekar | 61593cf | 2017-09-06 10:48:27 -0700 | [diff] [blame] | 506 | req_cmd = (uint8_t)(req & UNCORE_PERFMON_CMD_MASK); |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 507 | |
Krishna Sitaraman | 282e583 | 2016-07-28 13:54:29 -0700 | [diff] [blame] | 508 | /* clean the previous response state */ |
| 509 | ari_clobber_response(ari_base); |
| 510 | |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 511 | /* sanity check input parameters */ |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 512 | if ((req_cmd == UNCORE_PERFMON_CMD_READ) && (data == NULL)) { |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 513 | ERROR("invalid parameters\n"); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 514 | 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 Diaz | f94e40d | 2017-09-14 15:57:44 +0100 | [diff] [blame] | 521 | (uint32_t)*data : 0U; |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 522 | |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 523 | ret = ari_request_wait(ari_base, 0U, |
| 524 | (uint32_t)TEGRA_ARI_PERFMON, val, (uint32_t)req); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 525 | if (ret != 0) { |
| 526 | result = ret; |
| 527 | } else { |
| 528 | /* read the command status value */ |
Anthony Zhou | 0a01321 | 2017-05-08 20:17:08 +0800 | [diff] [blame] | 529 | req_status = ari_get_response_high(ari_base) & |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 530 | UNCORE_PERFMON_RESP_STATUS_MASK; |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 531 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 532 | /* |
| 533 | * For "read" commands get the data from the uncore |
| 534 | * perfmon registers |
| 535 | */ |
Varun Wadekar | 61593cf | 2017-09-06 10:48:27 -0700 | [diff] [blame] | 536 | req_status &= UNCORE_PERFMON_RESP_STATUS_MASK; |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 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 Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 543 | |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 544 | return result; |
Varun Wadekar | 4ff3e8d | 2016-04-29 10:40:02 -0700 | [diff] [blame] | 545 | } |
Krishna Sitaraman | b429d56 | 2016-07-19 16:36:13 -0700 | [diff] [blame] | 546 | |
| 547 | void 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 Wiley | 24e9939 | 2017-01-04 10:45:44 -0800 | [diff] [blame] | 554 | if ((index > TEGRA_ARI_MISC_CCPLEX_EDBGREQ) || |
Krishna Sitaraman | b429d56 | 2016-07-19 16:36:13 -0700 | [diff] [blame] | 555 | ((index == TEGRA_ARI_MISC_CCPLEX_CORESIGHT_CG_CTRL) && |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 556 | (value > 1U))) { |
Krishna Sitaraman | b429d56 | 2016-07-19 16:36:13 -0700 | [diff] [blame] | 557 | ERROR("%s: invalid parameters \n", __func__); |
Anthony Zhou | 1ab3140 | 2017-03-06 16:06:45 +0800 | [diff] [blame] | 558 | } else { |
| 559 | /* clean the previous response state */ |
| 560 | ari_clobber_response(ari_base); |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 561 | (void)ari_request_wait(ari_base, 0U, |
| 562 | (uint32_t)TEGRA_ARI_MISC_CCPLEX, index, value); |
Krishna Sitaraman | b429d56 | 2016-07-19 16:36:13 -0700 | [diff] [blame] | 563 | } |
Krishna Sitaraman | b429d56 | 2016-07-19 16:36:13 -0700 | [diff] [blame] | 564 | } |