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 95*88727fc3SAndre Przywara static inline unsigned int read_feat_dit_id_field(void) 96*88727fc3SAndre Przywara { 97*88727fc3SAndre Przywara return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_DIT); 98*88727fc3SAndre Przywara } 99*88727fc3SAndre Przywara 100*88727fc3SAndre Przywara static inline bool is_feat_dit_supported(void) 101*88727fc3SAndre Przywara { 102*88727fc3SAndre Przywara if (ENABLE_FEAT_DIT == FEAT_STATE_DISABLED) { 103*88727fc3SAndre Przywara return false; 104*88727fc3SAndre Przywara } 105*88727fc3SAndre Przywara 106*88727fc3SAndre Przywara if (ENABLE_FEAT_DIT == FEAT_STATE_ALWAYS) { 107*88727fc3SAndre Przywara return true; 108*88727fc3SAndre Przywara } 109*88727fc3SAndre Przywara 110*88727fc3SAndre Przywara return read_feat_dit_id_field() != 0U; 111*88727fc3SAndre Przywara } 112*88727fc3SAndre Przywara 1136437a09aSAndre Przywara static inline bool is_feat_spe_supported(void) 1146437a09aSAndre Przywara { 1156437a09aSAndre Przywara /* FEAT_SPE is AArch64 only */ 1166437a09aSAndre Przywara return false; 1176437a09aSAndre Przywara } 1186437a09aSAndre Przywara 1192559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */ 120