xref: /rk3399_ARM-atf/plat/nvidia/tegra/soc/t186/drivers/include/mce_private.h (revision bc5e79cd738c4be40647819795f70d970b536c9b)
106060028SVarun Wadekar /*
250e91633SAnthony Zhou  * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
306060028SVarun Wadekar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
506060028SVarun Wadekar  */
606060028SVarun Wadekar 
7c3cf06f1SAntonio Nino Diaz #ifndef MCE_PRIVATE_H
8c3cf06f1SAntonio Nino Diaz #define MCE_PRIVATE_H
906060028SVarun Wadekar 
1009d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1109d40e0eSAntonio Nino Diaz 
1206060028SVarun Wadekar #include <tegra_def.h>
1306060028SVarun Wadekar 
1406060028SVarun Wadekar /*******************************************************************************
1506060028SVarun Wadekar  * Macros to prepare CSTATE info request
1606060028SVarun Wadekar  ******************************************************************************/
1706060028SVarun Wadekar /* Description of the parameters for UPDATE_CSTATE_INFO request */
18ab712fd8SAnthony Zhou #define CLUSTER_CSTATE_MASK			ULL(0x7)
19ab712fd8SAnthony Zhou #define CLUSTER_CSTATE_SHIFT			U(0)
20ab712fd8SAnthony Zhou #define CLUSTER_CSTATE_UPDATE_BIT		(ULL(1) << 7)
21ab712fd8SAnthony Zhou #define CCPLEX_CSTATE_MASK			ULL(0x3)
22ab712fd8SAnthony Zhou #define CCPLEX_CSTATE_SHIFT			ULL(8)
23ab712fd8SAnthony Zhou #define CCPLEX_CSTATE_UPDATE_BIT		(ULL(1) << 15)
24ab712fd8SAnthony Zhou #define SYSTEM_CSTATE_MASK			ULL(0xF)
25ab712fd8SAnthony Zhou #define SYSTEM_CSTATE_SHIFT			ULL(16)
26ab712fd8SAnthony Zhou #define SYSTEM_CSTATE_FORCE_UPDATE_SHIFT	ULL(22)
27ab712fd8SAnthony Zhou #define SYSTEM_CSTATE_FORCE_UPDATE_BIT		(ULL(1) << 22)
28ab712fd8SAnthony Zhou #define SYSTEM_CSTATE_UPDATE_BIT		(ULL(1) << 23)
29ab712fd8SAnthony Zhou #define CSTATE_WAKE_MASK_UPDATE_BIT		(ULL(1) << 31)
30ab712fd8SAnthony Zhou #define CSTATE_WAKE_MASK_SHIFT			ULL(32)
31ab712fd8SAnthony Zhou #define CSTATE_WAKE_MASK_CLEAR			U(0xFFFFFFFF)
3206060028SVarun Wadekar 
3306060028SVarun Wadekar /*******************************************************************************
3406060028SVarun Wadekar  * Auto-CC3 control macros
3506060028SVarun Wadekar  ******************************************************************************/
36ab712fd8SAnthony Zhou #define MCE_AUTO_CC3_FREQ_MASK			U(0x1FF)
37ab712fd8SAnthony Zhou #define MCE_AUTO_CC3_FREQ_SHIFT			U(0)
38ab712fd8SAnthony Zhou #define MCE_AUTO_CC3_VTG_MASK			U(0x7F)
39ab712fd8SAnthony Zhou #define MCE_AUTO_CC3_VTG_SHIFT			U(16)
40ab712fd8SAnthony Zhou #define MCE_AUTO_CC3_ENABLE_BIT			(U(1) << 31)
4106060028SVarun Wadekar 
4206060028SVarun Wadekar /*******************************************************************************
4306060028SVarun Wadekar  * Macros for the 'IS_SC7_ALLOWED' command
4406060028SVarun Wadekar  ******************************************************************************/
45ab712fd8SAnthony Zhou #define MCE_SC7_ALLOWED_MASK			U(0x7)
46ab712fd8SAnthony Zhou #define MCE_SC7_WAKE_TIME_SHIFT			U(32)
4706060028SVarun Wadekar 
4806060028SVarun Wadekar /*******************************************************************************
4906060028SVarun Wadekar  * Macros for 'read/write ctats' commands
5006060028SVarun Wadekar  ******************************************************************************/
51ab712fd8SAnthony Zhou #define MCE_CSTATE_STATS_TYPE_SHIFT		ULL(32)
52ab712fd8SAnthony Zhou #define MCE_CSTATE_WRITE_DATA_LO_MASK		U(0xF)
5306060028SVarun Wadekar 
5406060028SVarun Wadekar /*******************************************************************************
5506060028SVarun Wadekar  * Macros for 'update crossover threshold' command
5606060028SVarun Wadekar  ******************************************************************************/
57ab712fd8SAnthony Zhou #define MCE_CROSSOVER_THRESHOLD_TIME_SHIFT	U(32)
5806060028SVarun Wadekar 
5906060028SVarun Wadekar /*******************************************************************************
60ab712fd8SAnthony Zhou  * MCA argument macros
6106060028SVarun Wadekar  ******************************************************************************/
62ab712fd8SAnthony Zhou #define MCA_ARG_ERROR_MASK			U(0xFF)
63ab712fd8SAnthony Zhou #define MCA_ARG_FINISH_SHIFT			U(24)
64ab712fd8SAnthony Zhou #define MCA_ARG_FINISH_MASK			U(0xFF)
6506060028SVarun Wadekar 
6606060028SVarun Wadekar /*******************************************************************************
67*f8f400d2SVarun Wadekar  * Uncore PERFMON ARI macros
6806060028SVarun Wadekar  ******************************************************************************/
69ab712fd8SAnthony Zhou #define UNCORE_PERFMON_CMD_READ			U(0)
70ab712fd8SAnthony Zhou #define UNCORE_PERFMON_CMD_WRITE		U(1)
7106060028SVarun Wadekar 
72ab712fd8SAnthony Zhou #define UNCORE_PERFMON_CMD_MASK			U(0xFF)
73ab712fd8SAnthony Zhou #define UNCORE_PERFMON_UNIT_GRP_MASK		U(0xF)
74ab712fd8SAnthony Zhou #define UNCORE_PERFMON_SELECTOR_MASK		U(0xF)
75ab712fd8SAnthony Zhou #define UNCORE_PERFMON_REG_MASK			U(0xFF)
76ab712fd8SAnthony Zhou #define UNCORE_PERFMON_CTR_MASK			U(0xFF)
77ab712fd8SAnthony Zhou #define UNCORE_PERFMON_RESP_STATUS_MASK		U(0xFF)
7806060028SVarun Wadekar 
7906060028SVarun Wadekar /*******************************************************************************
8006060028SVarun Wadekar  * Structure populated by arch specific code to export routines which perform
8106060028SVarun Wadekar  * common low level MCE functions
8206060028SVarun Wadekar  ******************************************************************************/
8306060028SVarun Wadekar typedef struct arch_mce_ops {
8406060028SVarun Wadekar 	/*
8506060028SVarun Wadekar 	 * This ARI request sets up the MCE to start execution on assertion
8606060028SVarun Wadekar 	 * of STANDBYWFI, update the core power state and expected wake time,
8706060028SVarun Wadekar 	 * then determine the proper power state to enter.
8806060028SVarun Wadekar 	 */
89ab712fd8SAnthony Zhou 	int32_t (*enter_cstate)(uint32_t ari_base, uint32_t state,
9006060028SVarun Wadekar 			    uint32_t wake_time);
9106060028SVarun Wadekar 	/*
9206060028SVarun Wadekar 	 * This ARI request allows updating of the CLUSTER_CSTATE,
9306060028SVarun Wadekar 	 * CCPLEX_CSTATE, and SYSTEM_CSTATE register values.
9406060028SVarun Wadekar 	 */
95ab712fd8SAnthony Zhou 	int32_t (*update_cstate_info)(uint32_t ari_base,
9606060028SVarun Wadekar 				  uint32_t cluster,
9706060028SVarun Wadekar 				  uint32_t ccplex,
9806060028SVarun Wadekar 				  uint32_t system,
9906060028SVarun Wadekar 				  uint8_t sys_state_force,
10006060028SVarun Wadekar 				  uint32_t wake_mask,
10106060028SVarun Wadekar 				  uint8_t update_wake_mask);
10206060028SVarun Wadekar 	/*
10306060028SVarun Wadekar 	 * This ARI request allows updating of power state crossover
10406060028SVarun Wadekar 	 * threshold times. An index value specifies which crossover
10506060028SVarun Wadekar 	 * state is being updated.
10606060028SVarun Wadekar 	 */
107ab712fd8SAnthony Zhou 	int32_t (*update_crossover_time)(uint32_t ari_base,
10806060028SVarun Wadekar 				     uint32_t type,
10906060028SVarun Wadekar 				     uint32_t time);
11006060028SVarun Wadekar 	/*
11106060028SVarun Wadekar 	 * This ARI request allows read access to statistical information
11206060028SVarun Wadekar 	 * related to power states.
11306060028SVarun Wadekar 	 */
11406060028SVarun Wadekar 	uint64_t (*read_cstate_stats)(uint32_t ari_base,
11506060028SVarun Wadekar 				     uint32_t state);
11606060028SVarun Wadekar 	/*
11706060028SVarun Wadekar 	 * This ARI request allows write access to statistical information
11806060028SVarun Wadekar 	 * related to power states.
11906060028SVarun Wadekar 	 */
120ab712fd8SAnthony Zhou 	int32_t (*write_cstate_stats)(uint32_t ari_base,
12106060028SVarun Wadekar 				  uint32_t state,
12206060028SVarun Wadekar 				  uint32_t stats);
12306060028SVarun Wadekar 	/*
12406060028SVarun Wadekar 	 * This ARI request allows the CPU to understand the features
12506060028SVarun Wadekar 	 * supported by the MCE firmware.
12606060028SVarun Wadekar 	 */
12706060028SVarun Wadekar 	uint64_t (*call_enum_misc)(uint32_t ari_base, uint32_t cmd,
12806060028SVarun Wadekar 				   uint32_t data);
12906060028SVarun Wadekar 	/*
13006060028SVarun Wadekar 	 * This ARI request allows querying the CCPLEX to determine if
13106060028SVarun Wadekar 	 * the CCx state is allowed given a target core C-state and wake
13206060028SVarun Wadekar 	 * time. If the CCx state is allowed, the response indicates CCx
13306060028SVarun Wadekar 	 * must be entered. If the CCx state is not allowed, the response
13406060028SVarun Wadekar 	 * indicates CC6/CC7 can't be entered
13506060028SVarun Wadekar 	 */
136ab712fd8SAnthony Zhou 	int32_t (*is_ccx_allowed)(uint32_t ari_base, uint32_t state,
13706060028SVarun Wadekar 			      uint32_t wake_time);
13806060028SVarun Wadekar 	/*
13906060028SVarun Wadekar 	 * This ARI request allows querying the CCPLEX to determine if
14006060028SVarun Wadekar 	 * the SC7 state is allowed given a target core C-state and wake
14106060028SVarun Wadekar 	 * time. If the SC7 state is allowed, all cores but the associated
14206060028SVarun Wadekar 	 * core are offlined (WAKE_EVENTS are set to 0) and the response
14306060028SVarun Wadekar 	 * indicates SC7 must be entered. If the SC7 state is not allowed,
14406060028SVarun Wadekar 	 * the response indicates SC7 can't be entered
14506060028SVarun Wadekar 	 */
146ab712fd8SAnthony Zhou 	int32_t (*is_sc7_allowed)(uint32_t ari_base, uint32_t state,
14706060028SVarun Wadekar 			      uint32_t wake_time);
14806060028SVarun Wadekar 	/*
14906060028SVarun Wadekar 	 * This ARI request allows a core to bring another offlined core
15006060028SVarun Wadekar 	 * back online to the C0 state. Note that a core is offlined by
15106060028SVarun Wadekar 	 * entering a C-state where the WAKE_MASK is all 0.
15206060028SVarun Wadekar 	 */
153ab712fd8SAnthony Zhou 	int32_t (*online_core)(uint32_t ari_base, uint32_t cpuid);
15406060028SVarun Wadekar 	/*
15506060028SVarun Wadekar 	 * This ARI request allows the CPU to enable/disable Auto-CC3 idle
15606060028SVarun Wadekar 	 * state.
15706060028SVarun Wadekar 	 */
158ab712fd8SAnthony Zhou 	int32_t (*cc3_ctrl)(uint32_t ari_base,
15906060028SVarun Wadekar 			uint32_t freq,
16006060028SVarun Wadekar 			uint32_t volt,
16106060028SVarun Wadekar 			uint8_t enable);
16206060028SVarun Wadekar 	/*
16306060028SVarun Wadekar 	 * This ARI request allows updating the reset vector register for
16406060028SVarun Wadekar 	 * D15 and A57 CPUs.
16506060028SVarun Wadekar 	 */
166ab712fd8SAnthony Zhou 	int32_t (*update_reset_vector)(uint32_t ari_base);
16706060028SVarun Wadekar 	/*
16806060028SVarun Wadekar 	 * This ARI request instructs the ROC to flush A57 data caches in
16906060028SVarun Wadekar 	 * order to maintain coherency with the Denver cluster.
17006060028SVarun Wadekar 	 */
171ab712fd8SAnthony Zhou 	int32_t (*roc_flush_cache)(uint32_t ari_base);
17206060028SVarun Wadekar 	/*
17306060028SVarun Wadekar 	 * This ARI request instructs the ROC to flush A57 data caches along
17406060028SVarun Wadekar 	 * with the caches covering ARM code in order to maintain coherency
17506060028SVarun Wadekar 	 * with the Denver cluster.
17606060028SVarun Wadekar 	 */
177ab712fd8SAnthony Zhou 	int32_t (*roc_flush_cache_trbits)(uint32_t ari_base);
17806060028SVarun Wadekar 	/*
17906060028SVarun Wadekar 	 * This ARI request instructs the ROC to clean A57 data caches along
18006060028SVarun Wadekar 	 * with the caches covering ARM code in order to maintain coherency
18106060028SVarun Wadekar 	 * with the Denver cluster.
18206060028SVarun Wadekar 	 */
183ab712fd8SAnthony Zhou 	int32_t (*roc_clean_cache)(uint32_t ari_base);
18406060028SVarun Wadekar 	/*
18506060028SVarun Wadekar 	 * This ARI request reads/writes the Machine Check Arch. (MCA)
18606060028SVarun Wadekar 	 * registers.
18706060028SVarun Wadekar 	 */
18806060028SVarun Wadekar 	uint64_t (*read_write_mca)(uint32_t ari_base,
189ab712fd8SAnthony Zhou 			      uint64_t cmd,
19006060028SVarun Wadekar 			      uint64_t *data);
19106060028SVarun Wadekar 	/*
19206060028SVarun Wadekar 	 * Some MC GSC (General Security Carveout) register values are
19306060028SVarun Wadekar 	 * expected to be changed by TrustZone secure ARM code after boot.
19406060028SVarun Wadekar 	 * Since there is no hardware mechanism for the CCPLEX to know
19506060028SVarun Wadekar 	 * that an MC GSC register has changed to allow it to update its
19606060028SVarun Wadekar 	 * own internal GSC register, there needs to be a mechanism that
19706060028SVarun Wadekar 	 * can be used by ARM code to cause the CCPLEX to update its GSC
19806060028SVarun Wadekar 	 * register value. This ARI request allows updating the GSC register
19906060028SVarun Wadekar 	 * value for a certain carveout in the CCPLEX.
20006060028SVarun Wadekar 	 */
201ab712fd8SAnthony Zhou 	int32_t (*update_ccplex_gsc)(uint32_t ari_base, uint32_t gsc_idx);
20206060028SVarun Wadekar 	/*
20306060028SVarun Wadekar 	 * This ARI request instructs the CCPLEX to either shutdown or
20406060028SVarun Wadekar 	 * reset the entire system
20506060028SVarun Wadekar 	 */
20606060028SVarun Wadekar 	void (*enter_ccplex_state)(uint32_t ari_base, uint32_t state_idx);
20706060028SVarun Wadekar 	/*
20806060028SVarun Wadekar 	 * This ARI request reads/writes data from/to Uncore PERFMON
20906060028SVarun Wadekar 	 * registers
21006060028SVarun Wadekar 	 */
211ab712fd8SAnthony Zhou 	int32_t (*read_write_uncore_perfmon)(uint32_t ari_base,
212ab712fd8SAnthony Zhou 			uint64_t req, uint64_t *data);
21306060028SVarun Wadekar 	/*
21406060028SVarun Wadekar 	 * This ARI implements ARI_MISC_CCPLEX commands. This can be
21506060028SVarun Wadekar 	 * used to enable/disable coresight clock gating.
21606060028SVarun Wadekar 	 */
21706060028SVarun Wadekar 	void (*misc_ccplex)(uint32_t ari_base, uint32_t index,
21806060028SVarun Wadekar 			uint32_t value);
21906060028SVarun Wadekar } arch_mce_ops_t;
22006060028SVarun Wadekar 
22106060028SVarun Wadekar /* declarations for ARI/NVG handler functions */
222ab712fd8SAnthony Zhou int32_t ari_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
223ab712fd8SAnthony Zhou int32_t ari_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
22406060028SVarun Wadekar 	uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
22506060028SVarun Wadekar 	uint8_t update_wake_mask);
226ab712fd8SAnthony Zhou int32_t ari_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
22706060028SVarun Wadekar uint64_t ari_read_cstate_stats(uint32_t ari_base, uint32_t state);
228ab712fd8SAnthony Zhou int32_t ari_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats);
22906060028SVarun Wadekar uint64_t ari_enumeration_misc(uint32_t ari_base, uint32_t cmd, uint32_t data);
230ab712fd8SAnthony Zhou int32_t ari_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
231ab712fd8SAnthony Zhou int32_t ari_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
232ab712fd8SAnthony Zhou int32_t ari_online_core(uint32_t ari_base, uint32_t core);
233ab712fd8SAnthony Zhou int32_t ari_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
234ab712fd8SAnthony Zhou int32_t ari_reset_vector_update(uint32_t ari_base);
235ab712fd8SAnthony Zhou int32_t ari_roc_flush_cache_trbits(uint32_t ari_base);
236ab712fd8SAnthony Zhou int32_t ari_roc_flush_cache(uint32_t ari_base);
237ab712fd8SAnthony Zhou int32_t ari_roc_clean_cache(uint32_t ari_base);
238ab712fd8SAnthony Zhou uint64_t ari_read_write_mca(uint32_t ari_base, uint64_t cmd, uint64_t *data);
239ab712fd8SAnthony Zhou int32_t ari_update_ccplex_gsc(uint32_t ari_base, uint32_t gsc_idx);
24006060028SVarun Wadekar void ari_enter_ccplex_state(uint32_t ari_base, uint32_t state_idx);
241ab712fd8SAnthony Zhou int32_t ari_read_write_uncore_perfmon(uint32_t ari_base,
242ab712fd8SAnthony Zhou 		uint64_t req, uint64_t *data);
24306060028SVarun Wadekar void ari_misc_ccplex(uint32_t ari_base, uint32_t index, uint32_t value);
24406060028SVarun Wadekar 
245ab712fd8SAnthony Zhou int32_t nvg_enter_cstate(uint32_t ari_base, uint32_t state, uint32_t wake_time);
246ab712fd8SAnthony Zhou int32_t nvg_update_cstate_info(uint32_t ari_base, uint32_t cluster, uint32_t ccplex,
24706060028SVarun Wadekar 		uint32_t system, uint8_t sys_state_force, uint32_t wake_mask,
24806060028SVarun Wadekar 		uint8_t update_wake_mask);
249ab712fd8SAnthony Zhou int32_t nvg_update_crossover_time(uint32_t ari_base, uint32_t type, uint32_t time);
25006060028SVarun Wadekar uint64_t nvg_read_cstate_stats(uint32_t ari_base, uint32_t state);
251ab712fd8SAnthony Zhou int32_t nvg_write_cstate_stats(uint32_t ari_base, uint32_t state, uint32_t stats);
252ab712fd8SAnthony Zhou int32_t nvg_is_ccx_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
253ab712fd8SAnthony Zhou int32_t nvg_is_sc7_allowed(uint32_t ari_base, uint32_t state, uint32_t wake_time);
254ab712fd8SAnthony Zhou int32_t nvg_online_core(uint32_t ari_base, uint32_t core);
255ab712fd8SAnthony Zhou int32_t nvg_cc3_ctrl(uint32_t ari_base, uint32_t freq, uint32_t volt, uint8_t enable);
25606060028SVarun Wadekar 
257ab712fd8SAnthony Zhou extern void nvg_set_request_data(uint64_t req, uint64_t data);
258ab712fd8SAnthony Zhou extern void nvg_set_request(uint64_t req);
259ab712fd8SAnthony Zhou extern uint64_t nvg_get_result(void);
260c3cf06f1SAntonio Nino Diaz #endif /* MCE_PRIVATE_H */
261