xref: /rk3399_ARM-atf/include/arch/aarch32/arch_features.h (revision 733d112f05ecb29f7d8fce12c66a9721031970df)
12559b2c8SAntonio Nino Diaz /*
2fd1dd4cbSAndre Przywara  * Copyright (c) 2019-2023, 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 
15fd1dd4cbSAndre Przywara #define ISOLATE_FIELD(reg, feat)					\
16fd1dd4cbSAndre Przywara 	((unsigned int)(((reg) >> (feat ## _SHIFT)) & (feat ## _MASK)))
17fd1dd4cbSAndre Przywara 
1829a24134SAntonio Nino Diaz static inline bool is_armv7_gentimer_present(void)
1929a24134SAntonio Nino Diaz {
20fd1dd4cbSAndre Przywara 	return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER) != 0U;
2129a24134SAntonio Nino Diaz }
2229a24134SAntonio Nino Diaz 
232559b2c8SAntonio Nino Diaz static inline bool is_armv8_2_ttcnp_present(void)
242559b2c8SAntonio Nino Diaz {
25fd1dd4cbSAndre Przywara 	return ISOLATE_FIELD(read_id_mmfr4(), ID_MMFR4_CNP) != 0U;
262559b2c8SAntonio Nino Diaz }
272559b2c8SAntonio Nino Diaz 
28b57e16a4SAndre Przywara static unsigned int read_feat_amu_id_field(void)
29b57e16a4SAndre Przywara {
30b57e16a4SAndre Przywara 	return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_AMU);
31b57e16a4SAndre Przywara }
32b57e16a4SAndre Przywara 
33b57e16a4SAndre Przywara static inline bool is_feat_amu_supported(void)
34b57e16a4SAndre Przywara {
35b57e16a4SAndre Przywara 	if (ENABLE_FEAT_AMU == FEAT_STATE_DISABLED) {
36b57e16a4SAndre Przywara 		return false;
37b57e16a4SAndre Przywara 	}
38b57e16a4SAndre Przywara 
39b57e16a4SAndre Przywara 	if (ENABLE_FEAT_AMU == FEAT_STATE_ALWAYS) {
40b57e16a4SAndre Przywara 		return true;
41b57e16a4SAndre Przywara 	}
42b57e16a4SAndre Przywara 
43b57e16a4SAndre Przywara 	return read_feat_amu_id_field() >= ID_PFR0_AMU_V1;
44b57e16a4SAndre Przywara }
45b57e16a4SAndre Przywara 
46b57e16a4SAndre Przywara static inline bool is_feat_amuv1p1_supported(void)
47b57e16a4SAndre Przywara {
48b57e16a4SAndre Przywara 	if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_DISABLED) {
49b57e16a4SAndre Przywara 		return false;
50b57e16a4SAndre Przywara 	}
51b57e16a4SAndre Przywara 
52b57e16a4SAndre Przywara 	if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_ALWAYS) {
53b57e16a4SAndre Przywara 		return true;
54b57e16a4SAndre Przywara 	}
55b57e16a4SAndre Przywara 
56b57e16a4SAndre Przywara 	return read_feat_amu_id_field() >= ID_PFR0_AMU_V1P1;
57b57e16a4SAndre Przywara }
58b57e16a4SAndre Przywara 
59fc8d2d39SAndre Przywara static inline unsigned int read_feat_trf_id_field(void)
60fc8d2d39SAndre Przywara {
61fc8d2d39SAndre Przywara 	return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_TRACEFILT);
62fc8d2d39SAndre Przywara }
63fc8d2d39SAndre Przywara 
64fc8d2d39SAndre Przywara static inline bool is_feat_trf_supported(void)
65fc8d2d39SAndre Przywara {
66fc8d2d39SAndre Przywara 	if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) {
67fc8d2d39SAndre Przywara 		return false;
68fc8d2d39SAndre Przywara 	}
69fc8d2d39SAndre Przywara 
70fc8d2d39SAndre Przywara 	if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) {
71fc8d2d39SAndre Przywara 		return true;
72fc8d2d39SAndre Przywara 	}
73fc8d2d39SAndre Przywara 
74fc8d2d39SAndre Przywara 	return read_feat_trf_id_field() != 0U;
75fc8d2d39SAndre Przywara }
76fc8d2d39SAndre Przywara 
77603a0c6fSAndre Przywara static inline unsigned int read_feat_coptrc_id_field(void)
78603a0c6fSAndre Przywara {
79603a0c6fSAndre Przywara 	return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_COPTRC);
80603a0c6fSAndre Przywara }
81603a0c6fSAndre Przywara 
82603a0c6fSAndre Przywara static inline bool is_feat_sys_reg_trace_supported(void)
83603a0c6fSAndre Przywara {
84603a0c6fSAndre Przywara 	if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) {
85603a0c6fSAndre Przywara 		return false;
86603a0c6fSAndre Przywara 	}
87603a0c6fSAndre Przywara 
88603a0c6fSAndre Przywara 	if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) {
89603a0c6fSAndre Przywara 		return true;
90603a0c6fSAndre Przywara 	}
91603a0c6fSAndre Przywara 
92603a0c6fSAndre Przywara 	return read_feat_coptrc_id_field() != 0U;
93603a0c6fSAndre Przywara }
94603a0c6fSAndre Przywara 
9588727fc3SAndre Przywara static inline unsigned int read_feat_dit_id_field(void)
9688727fc3SAndre Przywara {
9788727fc3SAndre Przywara 	return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_DIT);
9888727fc3SAndre Przywara }
9988727fc3SAndre Przywara 
10088727fc3SAndre Przywara static inline bool is_feat_dit_supported(void)
10188727fc3SAndre Przywara {
10288727fc3SAndre Przywara 	if (ENABLE_FEAT_DIT == FEAT_STATE_DISABLED) {
10388727fc3SAndre Przywara 		return false;
10488727fc3SAndre Przywara 	}
10588727fc3SAndre Przywara 
10688727fc3SAndre Przywara 	if (ENABLE_FEAT_DIT == FEAT_STATE_ALWAYS) {
10788727fc3SAndre Przywara 		return true;
10888727fc3SAndre Przywara 	}
10988727fc3SAndre Przywara 
11088727fc3SAndre Przywara 	return read_feat_dit_id_field() != 0U;
11188727fc3SAndre Przywara }
11288727fc3SAndre Przywara 
113d156c522SAndre Przywara static inline unsigned int read_feat_pan_id_field(void)
114d156c522SAndre Przywara {
115d156c522SAndre Przywara 	return ISOLATE_FIELD(read_id_mmfr3(), ID_MMFR3_PAN);
116d156c522SAndre Przywara }
117d156c522SAndre Przywara 
118d156c522SAndre Przywara static inline bool is_feat_pan_supported(void)
119d156c522SAndre Przywara {
120d156c522SAndre Przywara 	if (ENABLE_FEAT_PAN == FEAT_STATE_DISABLED) {
121d156c522SAndre Przywara 		return false;
122d156c522SAndre Przywara 	}
123d156c522SAndre Przywara 
124d156c522SAndre Przywara 	if (ENABLE_FEAT_PAN == FEAT_STATE_ALWAYS) {
125d156c522SAndre Przywara 		return true;
126d156c522SAndre Przywara 	}
127d156c522SAndre Przywara 
128d156c522SAndre Przywara 	return read_feat_pan_id_field() != 0U;
129d156c522SAndre Przywara }
130d156c522SAndre Przywara 
131*733d112fSAndre Przywara /*
132*733d112fSAndre Przywara  * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch
133*733d112fSAndre Przywara  * code. In fact, EL2 context switching is only needed for AArch64 (since
134*733d112fSAndre Przywara  * there is no secure AArch32 EL2), so just disable these features here.
135*733d112fSAndre Przywara  */
136*733d112fSAndre Przywara static inline bool is_feat_twed_supported(void) { return false; }
137*733d112fSAndre Przywara static inline bool is_feat_ecv_supported(void) { return false; }
138*733d112fSAndre Przywara static inline bool is_feat_ecv_v2_supported(void) { return false; }
139*733d112fSAndre Przywara static inline bool is_feat_csv2_2_supported(void) { return false; }
140*733d112fSAndre Przywara static inline bool is_feat_ras_supported(void) { return false; }
141*733d112fSAndre Przywara 
142*733d112fSAndre Przywara /* The following features are supported in AArch64 only. */
143*733d112fSAndre Przywara static inline bool is_feat_vhe_supported(void) { return false; }
144*733d112fSAndre Przywara static inline bool is_feat_sel2_supported(void) { return false; }
145*733d112fSAndre Przywara static inline bool is_feat_fgt_supported(void) { return false; }
146*733d112fSAndre Przywara static inline bool is_feat_tcr2_supported(void) { return false; }
147*733d112fSAndre Przywara static inline bool is_feat_spe_supported(void) { return false; }
148*733d112fSAndre Przywara static inline bool is_feat_rng_supported(void) { return false; }
149*733d112fSAndre Przywara static inline bool is_feat_gcs_supported(void) { return false; }
150*733d112fSAndre Przywara static inline bool is_feat_mpam_supported(void) { return false; }
151*733d112fSAndre Przywara static inline bool is_feat_hcx_supported(void) { return false; }
152*733d112fSAndre Przywara static inline bool is_feat_sve_supported(void) { return false; }
153*733d112fSAndre Przywara static inline bool is_feat_brbe_supported(void) { return false; }
154*733d112fSAndre Przywara static inline bool is_feat_trbe_supported(void) { return false; }
155*733d112fSAndre Przywara static inline bool is_feat_nv2_supported(void) { return false; }
156*733d112fSAndre Przywara static inline bool is_feat_sme_supported(void) { return false; }
157*733d112fSAndre Przywara static inline bool is_feat_sme2_supported(void) { return false; }
158*733d112fSAndre Przywara static inline bool is_feat_s2poe_supported(void) { return false; }
159*733d112fSAndre Przywara static inline bool is_feat_s1poe_supported(void) { return false; }
160*733d112fSAndre Przywara static inline bool is_feat_sxpoe_supported(void) { return false; }
161*733d112fSAndre Przywara static inline bool is_feat_s2pie_supported(void) { return false; }
162*733d112fSAndre Przywara static inline bool is_feat_s1pie_supported(void) { return false; }
163*733d112fSAndre Przywara static inline bool is_feat_sxpie_supported(void) { return false; }
164*733d112fSAndre Przywara 
1652559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */
166