blob: 203f61a5d98278d512f82f8d70ae75b4a285e803 [file] [log] [blame]
Varun Wadekara0352ab2017-03-14 14:24:35 -07001/*
Anthony Zhou59fd6152017-03-13 15:34:08 +08002 * Copyright (c) 2016-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
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef MCE_PRIVATE_H
8#define MCE_PRIVATE_H
Varun Wadekara0352ab2017-03-14 14:24:35 -07009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/mmio.h>
11
Varun Wadekara0352ab2017-03-14 14:24:35 -070012#include <tegra_def.h>
13
14/*******************************************************************************
Varun Wadekara0352ab2017-03-14 14:24:35 -070015 * Macros to prepare CSTATE info request
16 ******************************************************************************/
17/* Description of the parameters for UPDATE_CSTATE_INFO request */
Anthony Zhou1ab31402017-03-06 16:06:45 +080018#define CLUSTER_CSTATE_MASK ULL(0x7)
19#define CLUSTER_CSTATE_SHIFT U(0)
20#define CLUSTER_CSTATE_UPDATE_BIT (ULL(1) << 7)
21#define CCPLEX_CSTATE_MASK ULL(0x3)
22#define CCPLEX_CSTATE_SHIFT ULL(8)
23#define CCPLEX_CSTATE_UPDATE_BIT (ULL(1) << 15)
24#define SYSTEM_CSTATE_MASK ULL(0xF)
25#define SYSTEM_CSTATE_SHIFT ULL(16)
26#define SYSTEM_CSTATE_FORCE_UPDATE_SHIFT ULL(22)
27#define SYSTEM_CSTATE_FORCE_UPDATE_BIT (ULL(1) << 22)
28#define SYSTEM_CSTATE_UPDATE_BIT (ULL(1) << 23)
29#define CSTATE_WAKE_MASK_UPDATE_BIT (ULL(1) << 31)
30#define CSTATE_WAKE_MASK_SHIFT ULL(32)
31#define CSTATE_WAKE_MASK_CLEAR U(0xFFFFFFFF)
Varun Wadekara0352ab2017-03-14 14:24:35 -070032
33/*******************************************************************************
34 * Auto-CC3 control macros
35 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080036#define MCE_AUTO_CC3_FREQ_MASK U(0x1FF)
37#define MCE_AUTO_CC3_FREQ_SHIFT U(0)
38#define MCE_AUTO_CC3_VTG_MASK U(0x7F)
39#define MCE_AUTO_CC3_VTG_SHIFT U(16)
40#define MCE_AUTO_CC3_ENABLE_BIT (U(1) << 31)
Varun Wadekara0352ab2017-03-14 14:24:35 -070041
42/*******************************************************************************
43 * Macros for the 'IS_SC7_ALLOWED' command
44 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080045#define MCE_SC7_ALLOWED_MASK U(0x7)
46#define MCE_SC7_WAKE_TIME_SHIFT U(32)
Varun Wadekara0352ab2017-03-14 14:24:35 -070047
48/*******************************************************************************
49 * Macros for 'read/write ctats' commands
50 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080051#define MCE_CSTATE_STATS_TYPE_SHIFT ULL(32)
52#define MCE_CSTATE_WRITE_DATA_LO_MASK U(0xF)
Varun Wadekara0352ab2017-03-14 14:24:35 -070053
54/*******************************************************************************
55 * Macros for 'update crossover threshold' command
56 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080057#define MCE_CROSSOVER_THRESHOLD_TIME_SHIFT U(32)
Varun Wadekara0352ab2017-03-14 14:24:35 -070058
59/*******************************************************************************
Anthony Zhou1ab31402017-03-06 16:06:45 +080060 * MCA argument macros
Varun Wadekara0352ab2017-03-14 14:24:35 -070061 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080062#define MCA_ARG_ERROR_MASK U(0xFF)
63#define MCA_ARG_FINISH_SHIFT U(24)
64#define MCA_ARG_FINISH_MASK U(0xFF)
Varun Wadekara0352ab2017-03-14 14:24:35 -070065
66/*******************************************************************************
Varun Wadekar61593cf2017-09-06 10:48:27 -070067 * Uncore PERFMON ARI macros
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070068 ******************************************************************************/
Anthony Zhou1ab31402017-03-06 16:06:45 +080069#define UNCORE_PERFMON_CMD_READ U(0)
70#define UNCORE_PERFMON_CMD_WRITE U(1)
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070071
Anthony Zhou1ab31402017-03-06 16:06:45 +080072#define UNCORE_PERFMON_CMD_MASK U(0xFF)
Anthony Zhou1ab31402017-03-06 16:06:45 +080073#define UNCORE_PERFMON_UNIT_GRP_MASK U(0xF)
74#define UNCORE_PERFMON_SELECTOR_MASK U(0xF)
75#define UNCORE_PERFMON_REG_MASK U(0xFF)
76#define UNCORE_PERFMON_CTR_MASK U(0xFF)
77#define UNCORE_PERFMON_RESP_STATUS_MASK U(0xFF)
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -070078
79/*******************************************************************************
Varun Wadekara0352ab2017-03-14 14:24:35 -070080 * Structure populated by arch specific code to export routines which perform
81 * common low level MCE functions
82 ******************************************************************************/
83typedef struct arch_mce_ops {
84 /*
85 * This ARI request sets up the MCE to start execution on assertion
86 * of STANDBYWFI, update the core power state and expected wake time,
87 * then determine the proper power state to enter.
88 */
Anthony Zhou1ab31402017-03-06 16:06:45 +080089 int32_t (*enter_cstate)(uint32_t ari_base, uint32_t state,
Varun Wadekara0352ab2017-03-14 14:24:35 -070090 uint32_t wake_time);
91 /*
92 * This ARI request allows updating of the CLUSTER_CSTATE,
93 * CCPLEX_CSTATE, and SYSTEM_CSTATE register values.
94 */
Anthony Zhou1ab31402017-03-06 16:06:45 +080095 int32_t (*update_cstate_info)(uint32_t ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -070096 uint32_t cluster,
97 uint32_t ccplex,
98 uint32_t system,
99 uint8_t sys_state_force,
100 uint32_t wake_mask,
101 uint8_t update_wake_mask);
102 /*
103 * This ARI request allows updating of power state crossover
104 * threshold times. An index value specifies which crossover
105 * state is being updated.
106 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800107 int32_t (*update_crossover_time)(uint32_t ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700108 uint32_t type,
109 uint32_t time);
110 /*
111 * This ARI request allows read access to statistical information
112 * related to power states.
113 */
114 uint64_t (*read_cstate_stats)(uint32_t ari_base,
115 uint32_t state);
116 /*
117 * This ARI request allows write access to statistical information
118 * related to power states.
119 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800120 int32_t (*write_cstate_stats)(uint32_t ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700121 uint32_t state,
122 uint32_t stats);
123 /*
124 * This ARI request allows the CPU to understand the features
125 * supported by the MCE firmware.
126 */
127 uint64_t (*call_enum_misc)(uint32_t ari_base, uint32_t cmd,
128 uint32_t data);
129 /*
130 * This ARI request allows querying the CCPLEX to determine if
131 * the CCx state is allowed given a target core C-state and wake
132 * time. If the CCx state is allowed, the response indicates CCx
133 * must be entered. If the CCx state is not allowed, the response
134 * indicates CC6/CC7 can't be entered
135 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800136 int32_t (*is_ccx_allowed)(uint32_t ari_base, uint32_t state,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700137 uint32_t wake_time);
138 /*
139 * This ARI request allows querying the CCPLEX to determine if
140 * the SC7 state is allowed given a target core C-state and wake
141 * time. If the SC7 state is allowed, all cores but the associated
142 * core are offlined (WAKE_EVENTS are set to 0) and the response
143 * indicates SC7 must be entered. If the SC7 state is not allowed,
144 * the response indicates SC7 can't be entered
145 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800146 int32_t (*is_sc7_allowed)(uint32_t ari_base, uint32_t state,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700147 uint32_t wake_time);
148 /*
149 * This ARI request allows a core to bring another offlined core
150 * back online to the C0 state. Note that a core is offlined by
151 * entering a C-state where the WAKE_MASK is all 0.
152 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800153 int32_t (*online_core)(uint32_t ari_base, uint32_t cpuid);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700154 /*
155 * This ARI request allows the CPU to enable/disable Auto-CC3 idle
156 * state.
157 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800158 int32_t (*cc3_ctrl)(uint32_t ari_base,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700159 uint32_t freq,
160 uint32_t volt,
161 uint8_t enable);
162 /*
163 * This ARI request allows updating the reset vector register for
164 * D15 and A57 CPUs.
165 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800166 int32_t (*update_reset_vector)(uint32_t ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700167 /*
168 * This ARI request instructs the ROC to flush A57 data caches in
169 * order to maintain coherency with the Denver cluster.
170 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800171 int32_t (*roc_flush_cache)(uint32_t ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700172 /*
173 * This ARI request instructs the ROC to flush A57 data caches along
174 * with the caches covering ARM code in order to maintain coherency
175 * with the Denver cluster.
176 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800177 int32_t (*roc_flush_cache_trbits)(uint32_t ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700178 /*
179 * This ARI request instructs the ROC to clean A57 data caches along
180 * with the caches covering ARM code in order to maintain coherency
181 * with the Denver cluster.
182 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800183 int32_t (*roc_clean_cache)(uint32_t ari_base);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700184 /*
185 * This ARI request reads/writes the Machine Check Arch. (MCA)
186 * registers.
187 */
188 uint64_t (*read_write_mca)(uint32_t ari_base,
Anthony Zhou1ab31402017-03-06 16:06:45 +0800189 uint64_t cmd,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700190 uint64_t *data);
191 /*
192 * Some MC GSC (General Security Carveout) register values are
193 * expected to be changed by TrustZone secure ARM code after boot.
194 * Since there is no hardware mechanism for the CCPLEX to know
195 * that an MC GSC register has changed to allow it to update its
196 * own internal GSC register, there needs to be a mechanism that
197 * can be used by ARM code to cause the CCPLEX to update its GSC
198 * register value. This ARI request allows updating the GSC register
199 * value for a certain carveout in the CCPLEX.
200 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800201 int32_t (*update_ccplex_gsc)(uint32_t ari_base, uint32_t gsc_idx);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700202 /*
203 * This ARI request instructs the CCPLEX to either shutdown or
204 * reset the entire system
205 */
206 void (*enter_ccplex_state)(uint32_t ari_base, uint32_t state_idx);
Varun Wadekar4ff3e8d2016-04-29 10:40:02 -0700207 /*
208 * This ARI request reads/writes data from/to Uncore PERFMON
209 * registers
210 */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800211 int32_t (*read_write_uncore_perfmon)(uint32_t ari_base,
212 uint64_t req, uint64_t *data);
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700213 /*
214 * This ARI implements ARI_MISC_CCPLEX commands. This can be
215 * used to enable/disable coresight clock gating.
216 */
217 void (*misc_ccplex)(uint32_t ari_base, uint32_t index,
218 uint32_t value);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700219} arch_mce_ops_t;
220
Varun Wadekara0352ab2017-03-14 14:24:35 -0700221/* declarations for ARI/NVG handler functions */
Anthony Zhou1ab31402017-03-06 16:06:45 +0800222int32_t ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
223int32_t ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700224 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
225 uint8_t update_wake_mask);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800226int32_t ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700227uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800228int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700229uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800230int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
231int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
232int32_t ari_online_core(uint32_t ari_base, uint32_t core);
233int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
234int32_t ari_reset_vector_update(uint32_t ari_base);
235int32_t ari_roc_flush_cache_trbits(uint32_t ari_base);
236int32_t ari_roc_flush_cache(uint32_t ari_base);
237int32_t ari_roc_clean_cache(uint32_t ari_base);
238uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data);
239int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700240void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800241int32_t ari_read_write_uncore_perfmon(uint32_t ari_base,
242 uint64_t req, uint64_t *data);
Krishna Sitaramanb429d562016-07-19 16:36:13 -0700243void ari_misc_ccplex(uint32_t ari_base, uint32_t index, uint32_t value);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700244
Anthony Zhou1ab31402017-03-06 16:06:45 +0800245int32_t nvg_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
246int32_t nvg_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
Varun Wadekara0352ab2017-03-14 14:24:35 -0700247 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
248 uint8_t update_wake_mask);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800249int32_t nvg_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700250uint64_t nvg_read_cstate_stats(uint32_t ari_base, uint32_t state);
Anthony Zhou1ab31402017-03-06 16:06:45 +0800251int32_t nvg_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats);
252int32_t nvg_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
253int32_t nvg_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
254int32_t nvg_online_core(uint32_t ari_base, uint32_t core);
255int32_t nvg_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700256
Anthony Zhou1ab31402017-03-06 16:06:45 +0800257extern void nvg_set_request_data(uint64_t req, uint64_t data);
258extern void nvg_set_request(uint64_t req);
259extern uint64_t nvg_get_result(void);
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000260#endif /* MCE_PRIVATE_H */