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