Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __MCE_H__ |
| 32 | #define __MCE_H__ |
| 33 | |
| 34 | #include <mmio.h> |
| 35 | #include <tegra_def.h> |
| 36 | |
| 37 | /******************************************************************************* |
| 38 | * MCE apertures used by the ARI interface |
| 39 | * |
| 40 | * Aperture 0 - Cpu0 (ARM Cortex A-57) |
| 41 | * Aperture 1 - Cpu1 (ARM Cortex A-57) |
| 42 | * Aperture 2 - Cpu2 (ARM Cortex A-57) |
| 43 | * Aperture 3 - Cpu3 (ARM Cortex A-57) |
| 44 | * Aperture 4 - Cpu4 (Denver15) |
| 45 | * Aperture 5 - Cpu5 (Denver15) |
| 46 | ******************************************************************************/ |
| 47 | #define MCE_ARI_APERTURE_0_OFFSET 0x0 |
| 48 | #define MCE_ARI_APERTURE_1_OFFSET 0x10000 |
| 49 | #define MCE_ARI_APERTURE_2_OFFSET 0x20000 |
| 50 | #define MCE_ARI_APERTURE_3_OFFSET 0x30000 |
| 51 | #define MCE_ARI_APERTURE_4_OFFSET 0x40000 |
| 52 | #define MCE_ARI_APERTURE_5_OFFSET 0x50000 |
| 53 | #define MCE_ARI_APERTURE_OFFSET_MAX MCE_APERTURE_5_OFFSET |
| 54 | |
| 55 | /* number of apertures */ |
| 56 | #define MCE_ARI_APERTURES_MAX 6 |
| 57 | |
| 58 | /* each ARI aperture is 64KB */ |
| 59 | #define MCE_ARI_APERTURE_SIZE 0x10000 |
| 60 | |
| 61 | /******************************************************************************* |
| 62 | * CPU core ids - used by the MCE_ONLINE_CORE ARI |
| 63 | ******************************************************************************/ |
| 64 | typedef enum mce_core_id { |
| 65 | MCE_CORE_ID_DENVER_15_0, |
| 66 | MCE_CORE_ID_DENVER_15_1, |
| 67 | /* 2 and 3 are reserved */ |
| 68 | MCE_CORE_ID_A57_0 = 4, |
| 69 | MCE_CORE_ID_A57_1, |
| 70 | MCE_CORE_ID_A57_2, |
| 71 | MCE_CORE_ID_A57_3, |
| 72 | MCE_CORE_ID_MAX |
| 73 | } mce_core_id_t; |
| 74 | |
| 75 | #define MCE_CORE_ID_MASK 0x7 |
| 76 | |
| 77 | /******************************************************************************* |
| 78 | * MCE commands |
| 79 | ******************************************************************************/ |
| 80 | typedef enum mce_cmd { |
| 81 | MCE_CMD_ENTER_CSTATE = 0, |
| 82 | MCE_CMD_UPDATE_CSTATE_INFO, |
| 83 | MCE_CMD_UPDATE_CROSSOVER_TIME, |
| 84 | MCE_CMD_READ_CSTATE_STATS, |
| 85 | MCE_CMD_WRITE_CSTATE_STATS, |
| 86 | MCE_CMD_IS_SC7_ALLOWED, |
| 87 | MCE_CMD_ONLINE_CORE, |
| 88 | MCE_CMD_CC3_CTRL, |
| 89 | MCE_CMD_ECHO_DATA, |
| 90 | MCE_CMD_READ_VERSIONS, |
| 91 | MCE_CMD_ENUM_FEATURES, |
| 92 | MCE_CMD_ROC_FLUSH_CACHE_TRBITS, |
| 93 | MCE_CMD_ENUM_READ_MCA, |
| 94 | MCE_CMD_ENUM_WRITE_MCA, |
| 95 | MCE_CMD_ROC_FLUSH_CACHE, |
| 96 | MCE_CMD_ROC_CLEAN_CACHE, |
Varun Wadekar | ad2824f | 2016-03-28 13:44:35 -0700 | [diff] [blame] | 97 | MCE_CMD_ENABLE_LATIC, |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 98 | MCE_CMD_IS_CCX_ALLOWED = 0xFE, |
| 99 | MCE_CMD_MAX = 0xFF, |
| 100 | } mce_cmd_t; |
| 101 | |
| 102 | #define MCE_CMD_MASK 0xFF |
| 103 | |
| 104 | /******************************************************************************* |
| 105 | * Macros to prepare CSTATE info request |
| 106 | ******************************************************************************/ |
| 107 | /* Description of the parameters for UPDATE_CSTATE_INFO request */ |
| 108 | #define CLUSTER_CSTATE_MASK 0x7 |
| 109 | #define CLUSTER_CSTATE_SHIFT 0 |
| 110 | #define CLUSTER_CSTATE_UPDATE_BIT (1 << 7) |
| 111 | #define CCPLEX_CSTATE_MASK 0x3 |
| 112 | #define CCPLEX_CSTATE_SHIFT 8 |
| 113 | #define CCPLEX_CSTATE_UPDATE_BIT (1 << 15) |
| 114 | #define SYSTEM_CSTATE_MASK 0xF |
| 115 | #define SYSTEM_CSTATE_SHIFT 16 |
| 116 | #define SYSTEM_CSTATE_FORCE_UPDATE_SHIFT 22 |
| 117 | #define SYSTEM_CSTATE_FORCE_UPDATE_BIT (1 << 22) |
| 118 | #define SYSTEM_CSTATE_UPDATE_BIT (1 << 23) |
| 119 | #define CSTATE_WAKE_MASK_UPDATE_BIT (1 << 31) |
| 120 | #define CSTATE_WAKE_MASK_SHIFT 32 |
| 121 | #define CSTATE_WAKE_MASK_CLEAR 0xFFFFFFFF |
| 122 | |
| 123 | /******************************************************************************* |
| 124 | * Auto-CC3 control macros |
| 125 | ******************************************************************************/ |
| 126 | #define MCE_AUTO_CC3_FREQ_MASK 0x1FF |
| 127 | #define MCE_AUTO_CC3_FREQ_SHIFT 0 |
| 128 | #define MCE_AUTO_CC3_VTG_MASK 0x7F |
| 129 | #define MCE_AUTO_CC3_VTG_SHIFT 16 |
| 130 | #define MCE_AUTO_CC3_ENABLE_BIT (1 << 31) |
| 131 | |
| 132 | /******************************************************************************* |
| 133 | * Macros for the 'IS_SC7_ALLOWED' command |
| 134 | ******************************************************************************/ |
| 135 | #define MCE_SC7_ALLOWED_MASK 0x7 |
| 136 | #define MCE_SC7_WAKE_TIME_SHIFT 32 |
| 137 | |
| 138 | /******************************************************************************* |
| 139 | * Macros for 'read/write ctats' commands |
| 140 | ******************************************************************************/ |
| 141 | #define MCE_CSTATE_STATS_TYPE_SHIFT 32 |
| 142 | #define MCE_CSTATE_WRITE_DATA_LO_MASK 0xF |
| 143 | |
| 144 | /******************************************************************************* |
| 145 | * Macros for 'update crossover threshold' command |
| 146 | ******************************************************************************/ |
| 147 | #define MCE_CROSSOVER_THRESHOLD_TIME_SHIFT 32 |
| 148 | |
| 149 | /******************************************************************************* |
| 150 | * Timeout value used to powerdown a core |
| 151 | ******************************************************************************/ |
| 152 | #define MCE_CORE_SLEEP_TIME_INFINITE 0xFFFFFFFF |
| 153 | |
| 154 | /******************************************************************************* |
| 155 | * MCA command struct |
| 156 | ******************************************************************************/ |
| 157 | typedef union mca_cmd { |
| 158 | struct command { |
| 159 | uint8_t cmd; |
| 160 | uint8_t idx; |
| 161 | uint8_t subidx; |
| 162 | } command; |
| 163 | struct input { |
| 164 | uint32_t low; |
| 165 | uint32_t high; |
| 166 | } input; |
| 167 | uint64_t data; |
| 168 | } mca_cmd_t; |
| 169 | |
| 170 | /******************************************************************************* |
| 171 | * MCA argument struct |
| 172 | ******************************************************************************/ |
| 173 | typedef union mca_arg { |
| 174 | struct err { |
| 175 | uint64_t error:8; |
| 176 | uint64_t unused:48; |
| 177 | uint64_t finish:8; |
| 178 | } err; |
| 179 | struct arg { |
| 180 | uint32_t low; |
| 181 | uint32_t high; |
| 182 | } arg; |
| 183 | uint64_t data; |
| 184 | } mca_arg_t; |
| 185 | |
| 186 | /******************************************************************************* |
| 187 | * Structure populated by arch specific code to export routines which perform |
| 188 | * common low level MCE functions |
| 189 | ******************************************************************************/ |
| 190 | typedef struct arch_mce_ops { |
| 191 | /* |
| 192 | * This ARI request sets up the MCE to start execution on assertion |
| 193 | * of STANDBYWFI, update the core power state and expected wake time, |
| 194 | * then determine the proper power state to enter. |
| 195 | */ |
| 196 | int (*enter_cstate)(uint32_t ari_base, uint32_t state, |
| 197 | uint32_t wake_time); |
| 198 | /* |
| 199 | * This ARI request allows updating of the CLUSTER_CSTATE, |
| 200 | * CCPLEX_CSTATE, and SYSTEM_CSTATE register values. |
| 201 | */ |
| 202 | int (*update_cstate_info)(uint32_t ari_base, |
| 203 | uint32_t cluster, |
| 204 | uint32_t ccplex, |
| 205 | uint32_t system, |
| 206 | uint8_t sys_state_force, |
| 207 | uint32_t wake_mask, |
| 208 | uint8_t update_wake_mask); |
| 209 | /* |
| 210 | * This ARI request allows updating of power state crossover |
| 211 | * threshold times. An index value specifies which crossover |
| 212 | * state is being updated. |
| 213 | */ |
| 214 | int (*update_crossover_time)(uint32_t ari_base, |
| 215 | uint32_t type, |
| 216 | uint32_t time); |
| 217 | /* |
| 218 | * This ARI request allows read access to statistical information |
| 219 | * related to power states. |
| 220 | */ |
| 221 | uint64_t (*read_cstate_stats)(uint32_t ari_base, |
| 222 | uint32_t state); |
| 223 | /* |
| 224 | * This ARI request allows write access to statistical information |
| 225 | * related to power states. |
| 226 | */ |
| 227 | int (*write_cstate_stats)(uint32_t ari_base, |
| 228 | uint32_t state, |
| 229 | uint32_t stats); |
| 230 | /* |
| 231 | * This ARI request allows the CPU to understand the features |
| 232 | * supported by the MCE firmware. |
| 233 | */ |
| 234 | uint64_t (*call_enum_misc)(uint32_t ari_base, uint32_t cmd, |
| 235 | uint32_t data); |
| 236 | /* |
| 237 | * This ARI request allows querying the CCPLEX to determine if |
| 238 | * the CCx state is allowed given a target core C-state and wake |
| 239 | * time. If the CCx state is allowed, the response indicates CCx |
| 240 | * must be entered. If the CCx state is not allowed, the response |
| 241 | * indicates CC6/CC7 can't be entered |
| 242 | */ |
| 243 | int (*is_ccx_allowed)(uint32_t ari_base, uint32_t state, |
| 244 | uint32_t wake_time); |
| 245 | /* |
| 246 | * This ARI request allows querying the CCPLEX to determine if |
| 247 | * the SC7 state is allowed given a target core C-state and wake |
| 248 | * time. If the SC7 state is allowed, all cores but the associated |
| 249 | * core are offlined (WAKE_EVENTS are set to 0) and the response |
| 250 | * indicates SC7 must be entered. If the SC7 state is not allowed, |
| 251 | * the response indicates SC7 can't be entered |
| 252 | */ |
| 253 | int (*is_sc7_allowed)(uint32_t ari_base, uint32_t state, |
| 254 | uint32_t wake_time); |
| 255 | /* |
| 256 | * This ARI request allows a core to bring another offlined core |
| 257 | * back online to the C0 state. Note that a core is offlined by |
| 258 | * entering a C-state where the WAKE_MASK is all 0. |
| 259 | */ |
| 260 | int (*online_core)(uint32_t ari_base, uint32_t cpuid); |
| 261 | /* |
| 262 | * This ARI request allows the CPU to enable/disable Auto-CC3 idle |
| 263 | * state. |
| 264 | */ |
| 265 | int (*cc3_ctrl)(uint32_t ari_base, |
| 266 | uint32_t freq, |
| 267 | uint32_t volt, |
| 268 | uint8_t enable); |
| 269 | /* |
| 270 | * This ARI request allows updating the reset vector register for |
| 271 | * D15 and A57 CPUs. |
| 272 | */ |
| 273 | int (*update_reset_vector)(uint32_t ari_base, |
| 274 | uint32_t addr_low, |
| 275 | uint32_t addr_high); |
| 276 | /* |
| 277 | * This ARI request instructs the ROC to flush A57 data caches in |
| 278 | * order to maintain coherency with the Denver cluster. |
| 279 | */ |
| 280 | int (*roc_flush_cache)(uint32_t ari_base); |
| 281 | /* |
| 282 | * This ARI request instructs the ROC to flush A57 data caches along |
| 283 | * with the caches covering ARM code in order to maintain coherency |
| 284 | * with the Denver cluster. |
| 285 | */ |
| 286 | int (*roc_flush_cache_trbits)(uint32_t ari_base); |
| 287 | /* |
| 288 | * This ARI request instructs the ROC to clean A57 data caches along |
| 289 | * with the caches covering ARM code in order to maintain coherency |
| 290 | * with the Denver cluster. |
| 291 | */ |
| 292 | int (*roc_clean_cache)(uint32_t ari_base); |
| 293 | /* |
| 294 | * This ARI request reads/writes the Machine Check Arch. (MCA) |
| 295 | * registers. |
| 296 | */ |
| 297 | uint64_t (*read_write_mca)(uint32_t ari_base, |
| 298 | mca_cmd_t cmd, |
| 299 | uint64_t *data); |
| 300 | /* |
| 301 | * Some MC GSC (General Security Carveout) register values are |
| 302 | * expected to be changed by TrustZone secure ARM code after boot. |
| 303 | * Since there is no hardware mechanism for the CCPLEX to know |
| 304 | * that an MC GSC register has changed to allow it to update its |
| 305 | * own internal GSC register, there needs to be a mechanism that |
| 306 | * can be used by ARM code to cause the CCPLEX to update its GSC |
| 307 | * register value. This ARI request allows updating the GSC register |
| 308 | * value for a certain carveout in the CCPLEX. |
| 309 | */ |
| 310 | int (*update_ccplex_gsc)(uint32_t ari_base, uint32_t gsc_idx); |
| 311 | /* |
| 312 | * This ARI request instructs the CCPLEX to either shutdown or |
| 313 | * reset the entire system |
| 314 | */ |
| 315 | void (*enter_ccplex_state)(uint32_t ari_base, uint32_t state_idx); |
| 316 | } arch_mce_ops_t; |
| 317 | |
| 318 | int mce_command_handler(mce_cmd_t cmd, uint64_t arg0, uint64_t arg1, |
| 319 | uint64_t arg2); |
| 320 | int mce_update_reset_vector(uint32_t addr_lo, uint32_t addr_hi); |
| 321 | int mce_update_gsc_videomem(void); |
| 322 | int mce_update_gsc_tzdram(void); |
| 323 | int mce_update_gsc_tzram(void); |
| 324 | __dead2 void mce_enter_ccplex_state(uint32_t state_idx); |
Varun Wadekar | 47ddd00 | 2016-03-28 16:00:02 -0700 | [diff] [blame] | 325 | void mce_verify_firmware_version(void); |
Varun Wadekar | a0352ab | 2017-03-14 14:24:35 -0700 | [diff] [blame] | 326 | |
| 327 | /* declarations for ARI/NVG handler functions */ |
| 328 | int ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 329 | int ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex, |
| 330 | uint32_t system, uint8_t sys_state_force, uint32_t wake_mask, |
| 331 | uint8_t update_wake_mask); |
| 332 | int ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time); |
| 333 | uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state); |
| 334 | int ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats); |
| 335 | uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data); |
| 336 | int ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 337 | int ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 338 | int ari_online_core(uint32_t ari_base, uint32_t core); |
| 339 | int ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable); |
| 340 | int ari_reset_vector_update(uint32_t ari_base, uint32_t lo, uint32_t hi); |
| 341 | int ari_roc_flush_cache_trbits(uint32_t ari_base); |
| 342 | int ari_roc_flush_cache(uint32_t ari_base); |
| 343 | int ari_roc_clean_cache(uint32_t ari_base); |
| 344 | uint64_t ari_read_write_mca(uint32_t ari_base, mca_cmd_t cmd, uint64_t *data); |
| 345 | int ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx); |
| 346 | void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx); |
| 347 | |
| 348 | int nvg_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 349 | int nvg_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex, |
| 350 | uint32_t system, uint8_t sys_state_force, uint32_t wake_mask, |
| 351 | uint8_t update_wake_mask); |
| 352 | int nvg_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time); |
| 353 | uint64_t nvg_read_cstate_stats(uint32_t ari_base, uint32_t state); |
| 354 | int nvg_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t val); |
| 355 | int nvg_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 356 | int nvg_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time); |
| 357 | int nvg_online_core(uint32_t ari_base, uint32_t core); |
| 358 | int nvg_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable); |
| 359 | |
| 360 | #endif /* __MCE_H__ */ |