xref: /rk3399_ARM-atf/include/arch/aarch32/arch_features.h (revision aaaf2cc3135ca311ced63f49741c97897289ddcf)
12559b2c8SAntonio Nino Diaz /*
20a33adc0SGovindraj Raja  * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
32559b2c8SAntonio Nino Diaz  *
42559b2c8SAntonio Nino Diaz  * SPDX-License-Identifier: BSD-3-Clause
52559b2c8SAntonio Nino Diaz  */
62559b2c8SAntonio Nino Diaz 
72559b2c8SAntonio Nino Diaz #ifndef ARCH_FEATURES_H
82559b2c8SAntonio Nino Diaz #define ARCH_FEATURES_H
92559b2c8SAntonio Nino Diaz 
102559b2c8SAntonio Nino Diaz #include <stdbool.h>
112559b2c8SAntonio Nino Diaz 
122559b2c8SAntonio Nino Diaz #include <arch_helpers.h>
13fc8d2d39SAndre Przywara #include <common/feat_detect.h>
142559b2c8SAntonio Nino Diaz 
15*aaaf2cc3SSona Mathew #define ISOLATE_FIELD(reg, feat, mask)						\
16*aaaf2cc3SSona Mathew 	((unsigned int)(((reg) >> (feat)) & mask))
17fd1dd4cbSAndre Przywara 
18*aaaf2cc3SSona Mathew #define CREATE_FEATURE_SUPPORTED(name, read_func, guard)			\
19*aaaf2cc3SSona Mathew static inline bool is_ ## name ## _supported(void)				\
20*aaaf2cc3SSona Mathew {										\
21*aaaf2cc3SSona Mathew 	if ((guard) == FEAT_STATE_DISABLED) {					\
22*aaaf2cc3SSona Mathew 		return false;							\
23*aaaf2cc3SSona Mathew 	}									\
24*aaaf2cc3SSona Mathew 	if ((guard) == FEAT_STATE_ALWAYS) {					\
25*aaaf2cc3SSona Mathew 		return true;							\
26*aaaf2cc3SSona Mathew 	}									\
27*aaaf2cc3SSona Mathew 	return read_func();							\
28*aaaf2cc3SSona Mathew }
29*aaaf2cc3SSona Mathew 
30*aaaf2cc3SSona Mathew #define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval)		\
31*aaaf2cc3SSona Mathew static inline bool is_ ## name ## _present(void)				\
32*aaaf2cc3SSona Mathew {										\
33*aaaf2cc3SSona Mathew 	return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) 	\
34*aaaf2cc3SSona Mathew 		? true : false;							\
35*aaaf2cc3SSona Mathew }
36*aaaf2cc3SSona Mathew 
37*aaaf2cc3SSona Mathew #define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard)		\
38*aaaf2cc3SSona Mathew CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval)			\
39*aaaf2cc3SSona Mathew CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard)
40*aaaf2cc3SSona Mathew 
41*aaaf2cc3SSona Mathew 
42*aaaf2cc3SSona Mathew /*
43*aaaf2cc3SSona Mathew  * +----------------------------+
44*aaaf2cc3SSona Mathew  * |	Features supported	|
45*aaaf2cc3SSona Mathew  * +----------------------------+
46*aaaf2cc3SSona Mathew  * |	GENTIMER		|
47*aaaf2cc3SSona Mathew  * +----------------------------+
48*aaaf2cc3SSona Mathew  * |	FEAT_TTCNP		|
49*aaaf2cc3SSona Mathew  * +----------------------------+
50*aaaf2cc3SSona Mathew  * |	FEAT_AMU		|
51*aaaf2cc3SSona Mathew  * +----------------------------+
52*aaaf2cc3SSona Mathew  * |	FEAT_AMUV1P1		|
53*aaaf2cc3SSona Mathew  * +----------------------------+
54*aaaf2cc3SSona Mathew  * |	FEAT_TRF		|
55*aaaf2cc3SSona Mathew  * +----------------------------+
56*aaaf2cc3SSona Mathew  * |	FEAT_SYS_REG_TRACE 	|
57*aaaf2cc3SSona Mathew  * +----------------------------+
58*aaaf2cc3SSona Mathew  * |	FEAT_DIT		|
59*aaaf2cc3SSona Mathew  * +----------------------------+
60*aaaf2cc3SSona Mathew  * |	FEAT_PAN		|
61*aaaf2cc3SSona Mathew  * +----------------------------+
62*aaaf2cc3SSona Mathew  * |	FEAT_SSBS		|
63*aaaf2cc3SSona Mathew  * +----------------------------+
64*aaaf2cc3SSona Mathew  * |	FEAT_PMUV3		|
65*aaaf2cc3SSona Mathew  * +----------------------------+
66*aaaf2cc3SSona Mathew  * |	FEAT_MTPMU		|
67*aaaf2cc3SSona Mathew  * +----------------------------+
68*aaaf2cc3SSona Mathew  */
69*aaaf2cc3SSona Mathew 
70*aaaf2cc3SSona Mathew /* GENTIMER */
7129a24134SAntonio Nino Diaz static inline bool is_armv7_gentimer_present(void)
7229a24134SAntonio Nino Diaz {
73*aaaf2cc3SSona Mathew 	return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER_SHIFT,
74*aaaf2cc3SSona Mathew 			    ID_PFR1_GENTIMER_MASK) != 0U;
7529a24134SAntonio Nino Diaz }
7629a24134SAntonio Nino Diaz 
77*aaaf2cc3SSona Mathew /* FEAT_TTCNP: Translation table common not private */
78*aaaf2cc3SSona Mathew CREATE_FEATURE_PRESENT(feat_ttcnp, id_mmfr4, ID_MMFR4_CNP_SHIFT,
79*aaaf2cc3SSona Mathew 		      ID_MMFR4_CNP_MASK, 1U)
80*aaaf2cc3SSona Mathew 
81*aaaf2cc3SSona Mathew /* FEAT_AMU: Activity Monitors Extension */
82*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_amu, id_pfr0, ID_PFR0_AMU_SHIFT,
83*aaaf2cc3SSona Mathew 		    ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1, ENABLE_FEAT_AMU)
84*aaaf2cc3SSona Mathew 
85*aaaf2cc3SSona Mathew /* FEAT_AMUV1P1: AMU Extension v1.1 */
86*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_amuv1p1, id_pfr0, ID_PFR0_AMU_SHIFT,
87*aaaf2cc3SSona Mathew 		    ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1)
88*aaaf2cc3SSona Mathew 
89*aaaf2cc3SSona Mathew /* FEAT_TRF: Tracefilter */
90*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_trf, id_dfr0, ID_DFR0_TRACEFILT_SHIFT,
91*aaaf2cc3SSona Mathew 		    ID_DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS)
92*aaaf2cc3SSona Mathew 
93*aaaf2cc3SSona Mathew /* FEAT_SYS_REG_TRACE */
94*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_dfr0, ID_DFR0_COPTRC_SHIFT,
95*aaaf2cc3SSona Mathew 		    ID_DFR0_COPTRC_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS)
96*aaaf2cc3SSona Mathew 
97*aaaf2cc3SSona Mathew /* FEAT_DIT: Data independent timing */
98*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_dit, id_pfr0, ID_PFR0_DIT_SHIFT,
99*aaaf2cc3SSona Mathew 		    ID_PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT)
100*aaaf2cc3SSona Mathew 
101*aaaf2cc3SSona Mathew /* FEAT_PAN: Privileged access never */
102*aaaf2cc3SSona Mathew CREATE_FEATURE_FUNCS(feat_pan, id_mmfr3, ID_MMFR3_PAN_SHIFT,
103*aaaf2cc3SSona Mathew 		    ID_MMFR3_PAN_MASK, 1U, ENABLE_FEAT_PAN)
104*aaaf2cc3SSona Mathew 
105*aaaf2cc3SSona Mathew /* FEAT_SSBS: Speculative store bypass safe */
106*aaaf2cc3SSona Mathew CREATE_FEATURE_PRESENT(feat_ssbs, id_pfr2, ID_PFR2_SSBS_SHIFT,
107*aaaf2cc3SSona Mathew 		      ID_PFR2_SSBS_MASK, 1U)
108*aaaf2cc3SSona Mathew 
109*aaaf2cc3SSona Mathew /* FEAT_PMUV3 */
110*aaaf2cc3SSona Mathew CREATE_FEATURE_PRESENT(feat_pmuv3, id_dfr0, ID_DFR0_PERFMON_SHIFT,
111*aaaf2cc3SSona Mathew 		      ID_DFR0_PERFMON_MASK, 3U)
112*aaaf2cc3SSona Mathew 
113*aaaf2cc3SSona Mathew /* FEAT_MTPMU */
114*aaaf2cc3SSona Mathew static inline bool is_feat_mtpmu_present(void)
1152559b2c8SAntonio Nino Diaz {
116*aaaf2cc3SSona Mathew 	unsigned int mtpmu = ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU_SHIFT,
117*aaaf2cc3SSona Mathew 			    ID_DFR1_MTPMU_MASK);
118*aaaf2cc3SSona Mathew 	return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED);
1192559b2c8SAntonio Nino Diaz }
120*aaaf2cc3SSona Mathew CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU)
12130f05b4fSManish Pandey 
122733d112fSAndre Przywara /*
123733d112fSAndre Przywara  * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch
124733d112fSAndre Przywara  * code. In fact, EL2 context switching is only needed for AArch64 (since
125733d112fSAndre Przywara  * there is no secure AArch32 EL2), so just disable these features here.
126733d112fSAndre Przywara  */
127733d112fSAndre Przywara static inline bool is_feat_twed_supported(void) { return false; }
128733d112fSAndre Przywara static inline bool is_feat_ecv_supported(void) { return false; }
129733d112fSAndre Przywara static inline bool is_feat_ecv_v2_supported(void) { return false; }
130733d112fSAndre Przywara static inline bool is_feat_csv2_2_supported(void) { return false; }
13130019d86SSona Mathew static inline bool is_feat_csv2_3_supported(void) { return false; }
132733d112fSAndre Przywara static inline bool is_feat_ras_supported(void) { return false; }
133733d112fSAndre Przywara 
134733d112fSAndre Przywara /* The following features are supported in AArch64 only. */
135733d112fSAndre Przywara static inline bool is_feat_vhe_supported(void) { return false; }
136733d112fSAndre Przywara static inline bool is_feat_sel2_supported(void) { return false; }
137733d112fSAndre Przywara static inline bool is_feat_fgt_supported(void) { return false; }
138733d112fSAndre Przywara static inline bool is_feat_tcr2_supported(void) { return false; }
139733d112fSAndre Przywara static inline bool is_feat_spe_supported(void) { return false; }
140733d112fSAndre Przywara static inline bool is_feat_rng_supported(void) { return false; }
141733d112fSAndre Przywara static inline bool is_feat_gcs_supported(void) { return false; }
1428e397889SGovindraj Raja static inline bool is_feat_mte2_supported(void) { return false; }
143733d112fSAndre Przywara static inline bool is_feat_mpam_supported(void) { return false; }
144733d112fSAndre Przywara static inline bool is_feat_hcx_supported(void) { return false; }
145733d112fSAndre Przywara static inline bool is_feat_sve_supported(void) { return false; }
146733d112fSAndre Przywara static inline bool is_feat_brbe_supported(void) { return false; }
147733d112fSAndre Przywara static inline bool is_feat_trbe_supported(void) { return false; }
148733d112fSAndre Przywara static inline bool is_feat_nv2_supported(void) { return false; }
149733d112fSAndre Przywara static inline bool is_feat_sme_supported(void) { return false; }
150733d112fSAndre Przywara static inline bool is_feat_sme2_supported(void) { return false; }
151733d112fSAndre Przywara static inline bool is_feat_s2poe_supported(void) { return false; }
152733d112fSAndre Przywara static inline bool is_feat_s1poe_supported(void) { return false; }
153733d112fSAndre Przywara static inline bool is_feat_sxpoe_supported(void) { return false; }
154733d112fSAndre Przywara static inline bool is_feat_s2pie_supported(void) { return false; }
155733d112fSAndre Przywara static inline bool is_feat_s1pie_supported(void) { return false; }
156733d112fSAndre Przywara static inline bool is_feat_sxpie_supported(void) { return false; }
15730f05b4fSManish Pandey static inline bool is_feat_uao_present(void) { return false; }
15830f05b4fSManish Pandey static inline bool is_feat_nmi_present(void) { return false; }
15930f05b4fSManish Pandey static inline bool is_feat_ebep_present(void) { return false; }
16030f05b4fSManish Pandey static inline bool is_feat_sebep_present(void) { return false; }
161733d112fSAndre Przywara 
1622559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */
163