blob: 38ca32c37d352001807bd2bf0faf9dd84ddfd3a2 [file] [log] [blame]
Varun Wadekara0352ab2017-03-14 14:24:35 -07001/*
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 ******************************************************************************/
64typedef 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 ******************************************************************************/
80typedef 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 Wadekarad2824f2016-03-28 13:44:35 -070097 MCE_CMD_ENABLE_LATIC,
Varun Wadekara0352ab2017-03-14 14:24:35 -070098 MCE_CMD_IS_CCX_ALLOWED = 0xFE,
99 MCE_CMD_MAX = 0xFF,
100} mce_cmd_t;
101
102#define MCE_CMD_MASK 0xFF
103
104/*******************************************************************************
Varun Wadekarc47504f2017-03-23 17:32:20 -0700105 * Struct to prepare UPDATE_CSTATE_INFO request
106 ******************************************************************************/
107typedef struct mce_cstate_info {
108 /* cluster cstate value */
109 uint32_t cluster;
110 /* ccplex cstate value */
111 uint32_t ccplex;
112 /* system cstate value */
113 uint32_t system;
114 /* force system state? */
115 uint8_t system_state_force;
116 /* wake mask value */
117 uint32_t wake_mask;
118 /* update the wake mask? */
119 uint8_t update_wake_mask;
120} mce_cstate_info_t;
121
122/*******************************************************************************
Varun Wadekara0352ab2017-03-14 14:24:35 -0700123 * Macros to prepare CSTATE info request
124 ******************************************************************************/
125/* Description of the parameters for UPDATE_CSTATE_INFO request */
126#define CLUSTER_CSTATE_MASK 0x7
127#define CLUSTER_CSTATE_SHIFT 0
128#define CLUSTER_CSTATE_UPDATE_BIT (1 << 7)
129#define CCPLEX_CSTATE_MASK 0x3
130#define CCPLEX_CSTATE_SHIFT 8
131#define CCPLEX_CSTATE_UPDATE_BIT (1 << 15)
132#define SYSTEM_CSTATE_MASK 0xF
133#define SYSTEM_CSTATE_SHIFT 16
134#define SYSTEM_CSTATE_FORCE_UPDATE_SHIFT 22
135#define SYSTEM_CSTATE_FORCE_UPDATE_BIT (1 << 22)
136#define SYSTEM_CSTATE_UPDATE_BIT (1 << 23)
137#define CSTATE_WAKE_MASK_UPDATE_BIT (1 << 31)
138#define CSTATE_WAKE_MASK_SHIFT 32
139#define CSTATE_WAKE_MASK_CLEAR 0xFFFFFFFF
140
141/*******************************************************************************
142 * Auto-CC3 control macros
143 ******************************************************************************/
144#define MCE_AUTO_CC3_FREQ_MASK 0x1FF
145#define MCE_AUTO_CC3_FREQ_SHIFT 0
146#define MCE_AUTO_CC3_VTG_MASK 0x7F
147#define MCE_AUTO_CC3_VTG_SHIFT 16
148#define MCE_AUTO_CC3_ENABLE_BIT (1 << 31)
149
150/*******************************************************************************
151 * Macros for the 'IS_SC7_ALLOWED' command
152 ******************************************************************************/
153#define MCE_SC7_ALLOWED_MASK 0x7
154#define MCE_SC7_WAKE_TIME_SHIFT 32
155
156/*******************************************************************************
157 * Macros for 'read/write ctats' commands
158 ******************************************************************************/
159#define MCE_CSTATE_STATS_TYPE_SHIFT 32
160#define MCE_CSTATE_WRITE_DATA_LO_MASK 0xF
161
162/*******************************************************************************
163 * Macros for 'update crossover threshold' command
164 ******************************************************************************/
165#define MCE_CROSSOVER_THRESHOLD_TIME_SHIFT 32
166
167/*******************************************************************************
168 * Timeout value used to powerdown a core
169 ******************************************************************************/
170#define MCE_CORE_SLEEP_TIME_INFINITE 0xFFFFFFFF
171
172/*******************************************************************************
173 * MCA command struct
174 ******************************************************************************/
175typedef union mca_cmd {
176 struct command {
177 uint8_t cmd;
178 uint8_t idx;
179 uint8_t subidx;
180 } command;
181 struct input {
182 uint32_t low;
183 uint32_t high;
184 } input;
185 uint64_t data;
186} mca_cmd_t;
187
188/*******************************************************************************
189 * MCA argument struct
190 ******************************************************************************/
191typedef union mca_arg {
192 struct err {
193 uint64_t error:8;
194 uint64_t unused:48;
195 uint64_t finish:8;
196 } err;
197 struct arg {
198 uint32_t low;
199 uint32_t high;
200 } arg;
201 uint64_t data;
202} mca_arg_t;
203
204/*******************************************************************************
205 * Structure populated by arch specific code to export routines which perform
206 * common low level MCE functions
207 ******************************************************************************/
208typedef struct arch_mce_ops {
209 /*
210 * This ARI request sets up the MCE to start execution on assertion
211 * of STANDBYWFI, update the core power state and expected wake time,
212 * then determine the proper power state to enter.
213 */
214 int (*enter_cstate)(uint32_t ari_base, uint32_t state,
215 uint32_t wake_time);
216 /*
217 * This ARI request allows updating of the CLUSTER_CSTATE,
218 * CCPLEX_CSTATE, and SYSTEM_CSTATE register values.
219 */
220 int (*update_cstate_info)(uint32_t ari_base,
221 uint32_t cluster,
222 uint32_t ccplex,
223 uint32_t system,
224 uint8_t sys_state_force,
225 uint32_t wake_mask,
226 uint8_t update_wake_mask);
227 /*
228 * This ARI request allows updating of power state crossover
229 * threshold times. An index value specifies which crossover
230 * state is being updated.
231 */
232 int (*update_crossover_time)(uint32_t ari_base,
233 uint32_t type,
234 uint32_t time);
235 /*
236 * This ARI request allows read access to statistical information
237 * related to power states.
238 */
239 uint64_t (*read_cstate_stats)(uint32_t ari_base,
240 uint32_t state);
241 /*
242 * This ARI request allows write access to statistical information
243 * related to power states.
244 */
245 int (*write_cstate_stats)(uint32_t ari_base,
246 uint32_t state,
247 uint32_t stats);
248 /*
249 * This ARI request allows the CPU to understand the features
250 * supported by the MCE firmware.
251 */
252 uint64_t (*call_enum_misc)(uint32_t ari_base, uint32_t cmd,
253 uint32_t data);
254 /*
255 * This ARI request allows querying the CCPLEX to determine if
256 * the CCx state is allowed given a target core C-state and wake
257 * time. If the CCx state is allowed, the response indicates CCx
258 * must be entered. If the CCx state is not allowed, the response
259 * indicates CC6/CC7 can't be entered
260 */
261 int (*is_ccx_allowed)(uint32_t ari_base, uint32_t state,
262 uint32_t wake_time);
263 /*
264 * This ARI request allows querying the CCPLEX to determine if
265 * the SC7 state is allowed given a target core C-state and wake
266 * time. If the SC7 state is allowed, all cores but the associated
267 * core are offlined (WAKE_EVENTS are set to 0) and the response
268 * indicates SC7 must be entered. If the SC7 state is not allowed,
269 * the response indicates SC7 can't be entered
270 */
271 int (*is_sc7_allowed)(uint32_t ari_base, uint32_t state,
272 uint32_t wake_time);
273 /*
274 * This ARI request allows a core to bring another offlined core
275 * back online to the C0 state. Note that a core is offlined by
276 * entering a C-state where the WAKE_MASK is all 0.
277 */
278 int (*online_core)(uint32_t ari_base, uint32_t cpuid);
279 /*
280 * This ARI request allows the CPU to enable/disable Auto-CC3 idle
281 * state.
282 */
283 int (*cc3_ctrl)(uint32_t ari_base,
284 uint32_t freq,
285 uint32_t volt,
286 uint8_t enable);
287 /*
288 * This ARI request allows updating the reset vector register for
289 * D15 and A57 CPUs.
290 */
291 int (*update_reset_vector)(uint32_t ari_base,
292 uint32_t addr_low,
293 uint32_t addr_high);
294 /*
295 * This ARI request instructs the ROC to flush A57 data caches in
296 * order to maintain coherency with the Denver cluster.
297 */
298 int (*roc_flush_cache)(uint32_t ari_base);
299 /*
300 * This ARI request instructs the ROC to flush A57 data caches along
301 * with the caches covering ARM code in order to maintain coherency
302 * with the Denver cluster.
303 */
304 int (*roc_flush_cache_trbits)(uint32_t ari_base);
305 /*
306 * This ARI request instructs the ROC to clean A57 data caches along
307 * with the caches covering ARM code in order to maintain coherency
308 * with the Denver cluster.
309 */
310 int (*roc_clean_cache)(uint32_t ari_base);
311 /*
312 * This ARI request reads/writes the Machine Check Arch. (MCA)
313 * registers.
314 */
315 uint64_t (*read_write_mca)(uint32_t ari_base,
316 mca_cmd_t cmd,
317 uint64_t *data);
318 /*
319 * Some MC GSC (General Security Carveout) register values are
320 * expected to be changed by TrustZone secure ARM code after boot.
321 * Since there is no hardware mechanism for the CCPLEX to know
322 * that an MC GSC register has changed to allow it to update its
323 * own internal GSC register, there needs to be a mechanism that
324 * can be used by ARM code to cause the CCPLEX to update its GSC
325 * register value. This ARI request allows updating the GSC register
326 * value for a certain carveout in the CCPLEX.
327 */
328 int (*update_ccplex_gsc)(uint32_t ari_base, uint32_t gsc_idx);
329 /*
330 * This ARI request instructs the CCPLEX to either shutdown or
331 * reset the entire system
332 */
333 void (*enter_ccplex_state)(uint32_t ari_base, uint32_t state_idx);
334} arch_mce_ops_t;
335
336int mce_command_handler(mce_cmd_t cmd, uint64_t arg0, uint64_t arg1,
337 uint64_t arg2);
338int mce_update_reset_vector(uint32_t addr_lo, uint32_t addr_hi);
339int mce_update_gsc_videomem(void);
340int mce_update_gsc_tzdram(void);
341int mce_update_gsc_tzram(void);
342__dead2 void mce_enter_ccplex_state(uint32_t state_idx);
Varun Wadekarc47504f2017-03-23 17:32:20 -0700343void mce_update_cstate_info(mce_cstate_info_t *cstate);
Varun Wadekar47ddd002016-03-28 16:00:02 -0700344void mce_verify_firmware_version(void);
Varun Wadekara0352ab2017-03-14 14:24:35 -0700345
346/* declarations for ARI/NVG handler functions */
347int ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
348int ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
349 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
350 uint8_t update_wake_mask);
351int ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
352uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state);
353int ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats);
354uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data);
355int ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
356int ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
357int ari_online_core(uint32_t ari_base, uint32_t core);
358int ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
359int ari_reset_vector_update(uint32_t ari_base, uint32_t lo, uint32_t hi);
360int ari_roc_flush_cache_trbits(uint32_t ari_base);
361int ari_roc_flush_cache(uint32_t ari_base);
362int ari_roc_clean_cache(uint32_t ari_base);
363uint64_t ari_read_write_mca(uint32_t ari_base, mca_cmd_t cmd, uint64_t *data);
364int ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx);
365void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx);
366
367int nvg_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
368int nvg_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
369 uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
370 uint8_t update_wake_mask);
371int nvg_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
372uint64_t nvg_read_cstate_stats(uint32_t ari_base, uint32_t state);
373int nvg_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t val);
374int nvg_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
375int nvg_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
376int nvg_online_core(uint32_t ari_base, uint32_t core);
377int nvg_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
378
379#endif /* __MCE_H__ */