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