12559b2c8SAntonio Nino Diaz /* 2*0a33adc0SGovindraj 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 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 131733d112fSAndre Przywara /* 132733d112fSAndre Przywara * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch 133733d112fSAndre Przywara * code. In fact, EL2 context switching is only needed for AArch64 (since 134733d112fSAndre Przywara * there is no secure AArch32 EL2), so just disable these features here. 135733d112fSAndre Przywara */ 136733d112fSAndre Przywara static inline bool is_feat_twed_supported(void) { return false; } 137733d112fSAndre Przywara static inline bool is_feat_ecv_supported(void) { return false; } 138733d112fSAndre Przywara static inline bool is_feat_ecv_v2_supported(void) { return false; } 139733d112fSAndre Przywara static inline bool is_feat_csv2_2_supported(void) { return false; } 140733d112fSAndre Przywara static inline bool is_feat_ras_supported(void) { return false; } 141733d112fSAndre Przywara 142733d112fSAndre Przywara /* The following features are supported in AArch64 only. */ 143733d112fSAndre Przywara static inline bool is_feat_vhe_supported(void) { return false; } 144733d112fSAndre Przywara static inline bool is_feat_sel2_supported(void) { return false; } 145733d112fSAndre Przywara static inline bool is_feat_fgt_supported(void) { return false; } 146733d112fSAndre Przywara static inline bool is_feat_tcr2_supported(void) { return false; } 147733d112fSAndre Przywara static inline bool is_feat_spe_supported(void) { return false; } 148733d112fSAndre Przywara static inline bool is_feat_rng_supported(void) { return false; } 149733d112fSAndre Przywara static inline bool is_feat_gcs_supported(void) { return false; } 150*0a33adc0SGovindraj Raja static inline bool is_feat_mte_supported(void) { return false; } 151733d112fSAndre Przywara static inline bool is_feat_mpam_supported(void) { return false; } 152733d112fSAndre Przywara static inline bool is_feat_hcx_supported(void) { return false; } 153733d112fSAndre Przywara static inline bool is_feat_sve_supported(void) { return false; } 154733d112fSAndre Przywara static inline bool is_feat_brbe_supported(void) { return false; } 155733d112fSAndre Przywara static inline bool is_feat_trbe_supported(void) { return false; } 156733d112fSAndre Przywara static inline bool is_feat_nv2_supported(void) { return false; } 157733d112fSAndre Przywara static inline bool is_feat_sme_supported(void) { return false; } 158733d112fSAndre Przywara static inline bool is_feat_sme2_supported(void) { return false; } 159733d112fSAndre Przywara static inline bool is_feat_s2poe_supported(void) { return false; } 160733d112fSAndre Przywara static inline bool is_feat_s1poe_supported(void) { return false; } 161733d112fSAndre Przywara static inline bool is_feat_sxpoe_supported(void) { return false; } 162733d112fSAndre Przywara static inline bool is_feat_s2pie_supported(void) { return false; } 163733d112fSAndre Przywara static inline bool is_feat_s1pie_supported(void) { return false; } 164733d112fSAndre Przywara static inline bool is_feat_sxpie_supported(void) { return false; } 165733d112fSAndre Przywara 166c73686a1SBoyan Karatotev static inline unsigned int read_feat_pmuv3_id_field(void) 167c73686a1SBoyan Karatotev { 168c73686a1SBoyan Karatotev return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_PERFMON); 169c73686a1SBoyan Karatotev } 170c73686a1SBoyan Karatotev 17183a4dae1SBoyan Karatotev static inline unsigned int read_feat_mtpmu_id_field(void) 17283a4dae1SBoyan Karatotev { 17383a4dae1SBoyan Karatotev return ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU); 17483a4dae1SBoyan Karatotev } 17583a4dae1SBoyan Karatotev 17683a4dae1SBoyan Karatotev static inline bool is_feat_mtpmu_supported(void) 17783a4dae1SBoyan Karatotev { 17883a4dae1SBoyan Karatotev if (DISABLE_MTPMU == FEAT_STATE_DISABLED) { 17983a4dae1SBoyan Karatotev return false; 18083a4dae1SBoyan Karatotev } 18183a4dae1SBoyan Karatotev 18283a4dae1SBoyan Karatotev if (DISABLE_MTPMU == FEAT_STATE_ALWAYS) { 18383a4dae1SBoyan Karatotev return true; 18483a4dae1SBoyan Karatotev } 18583a4dae1SBoyan Karatotev 18683a4dae1SBoyan Karatotev unsigned int mtpmu = read_feat_mtpmu_id_field(); 18783a4dae1SBoyan Karatotev 18883a4dae1SBoyan Karatotev return mtpmu != 0U && mtpmu != ID_DFR1_MTPMU_DISABLED; 18983a4dae1SBoyan Karatotev } 19083a4dae1SBoyan Karatotev 1912559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */ 192