arch_features.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef ARCH_FEATURES_H
  7. #define ARCH_FEATURES_H
  8. #include <stdbool.h>
  9. #include <arch_helpers.h>
  10. #include <common/feat_detect.h>
  11. #define ISOLATE_FIELD(reg, feat, mask) \
  12. ((unsigned int)(((reg) >> (feat)) & mask))
  13. #define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \
  14. static inline bool is_ ## name ## _supported(void) \
  15. { \
  16. if ((guard) == FEAT_STATE_DISABLED) { \
  17. return false; \
  18. } \
  19. if ((guard) == FEAT_STATE_ALWAYS) { \
  20. return true; \
  21. } \
  22. return read_func(); \
  23. }
  24. #define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \
  25. static inline bool is_ ## name ## _present(void) \
  26. { \
  27. return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) \
  28. ? true : false; \
  29. }
  30. #define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard) \
  31. CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \
  32. CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard)
  33. /*
  34. * +----------------------------+
  35. * | Features supported |
  36. * +----------------------------+
  37. * | GENTIMER |
  38. * +----------------------------+
  39. * | FEAT_TTCNP |
  40. * +----------------------------+
  41. * | FEAT_AMU |
  42. * +----------------------------+
  43. * | FEAT_AMUV1P1 |
  44. * +----------------------------+
  45. * | FEAT_TRF |
  46. * +----------------------------+
  47. * | FEAT_SYS_REG_TRACE |
  48. * +----------------------------+
  49. * | FEAT_DIT |
  50. * +----------------------------+
  51. * | FEAT_PAN |
  52. * +----------------------------+
  53. * | FEAT_SSBS |
  54. * +----------------------------+
  55. * | FEAT_PMUV3 |
  56. * +----------------------------+
  57. * | FEAT_MTPMU |
  58. * +----------------------------+
  59. */
  60. /* GENTIMER */
  61. static inline bool is_armv7_gentimer_present(void)
  62. {
  63. return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER_SHIFT,
  64. ID_PFR1_GENTIMER_MASK) != 0U;
  65. }
  66. /* FEAT_TTCNP: Translation table common not private */
  67. CREATE_FEATURE_PRESENT(feat_ttcnp, id_mmfr4, ID_MMFR4_CNP_SHIFT,
  68. ID_MMFR4_CNP_MASK, 1U)
  69. /* FEAT_AMU: Activity Monitors Extension */
  70. CREATE_FEATURE_FUNCS(feat_amu, id_pfr0, ID_PFR0_AMU_SHIFT,
  71. ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1, ENABLE_FEAT_AMU)
  72. /* FEAT_AMUV1P1: AMU Extension v1.1 */
  73. CREATE_FEATURE_FUNCS(feat_amuv1p1, id_pfr0, ID_PFR0_AMU_SHIFT,
  74. ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1)
  75. /* FEAT_TRF: Tracefilter */
  76. CREATE_FEATURE_FUNCS(feat_trf, id_dfr0, ID_DFR0_TRACEFILT_SHIFT,
  77. ID_DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS)
  78. /* FEAT_SYS_REG_TRACE */
  79. CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_dfr0, ID_DFR0_COPTRC_SHIFT,
  80. ID_DFR0_COPTRC_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS)
  81. /* FEAT_DIT: Data independent timing */
  82. CREATE_FEATURE_FUNCS(feat_dit, id_pfr0, ID_PFR0_DIT_SHIFT,
  83. ID_PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT)
  84. /* FEAT_PAN: Privileged access never */
  85. CREATE_FEATURE_FUNCS(feat_pan, id_mmfr3, ID_MMFR3_PAN_SHIFT,
  86. ID_MMFR3_PAN_MASK, 1U, ENABLE_FEAT_PAN)
  87. /* FEAT_SSBS: Speculative store bypass safe */
  88. CREATE_FEATURE_PRESENT(feat_ssbs, id_pfr2, ID_PFR2_SSBS_SHIFT,
  89. ID_PFR2_SSBS_MASK, 1U)
  90. /* FEAT_PMUV3 */
  91. CREATE_FEATURE_PRESENT(feat_pmuv3, id_dfr0, ID_DFR0_PERFMON_SHIFT,
  92. ID_DFR0_PERFMON_MASK, 3U)
  93. /* FEAT_MTPMU */
  94. static inline bool is_feat_mtpmu_present(void)
  95. {
  96. unsigned int mtpmu = ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU_SHIFT,
  97. ID_DFR1_MTPMU_MASK);
  98. return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED);
  99. }
  100. CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU)
  101. /*
  102. * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch
  103. * code. In fact, EL2 context switching is only needed for AArch64 (since
  104. * there is no secure AArch32 EL2), so just disable these features here.
  105. */
  106. static inline bool is_feat_twed_supported(void) { return false; }
  107. static inline bool is_feat_ecv_supported(void) { return false; }
  108. static inline bool is_feat_ecv_v2_supported(void) { return false; }
  109. static inline bool is_feat_csv2_2_supported(void) { return false; }
  110. static inline bool is_feat_csv2_3_supported(void) { return false; }
  111. static inline bool is_feat_ras_supported(void) { return false; }
  112. /* The following features are supported in AArch64 only. */
  113. static inline bool is_feat_vhe_supported(void) { return false; }
  114. static inline bool is_feat_sel2_supported(void) { return false; }
  115. static inline bool is_feat_fgt_supported(void) { return false; }
  116. static inline bool is_feat_tcr2_supported(void) { return false; }
  117. static inline bool is_feat_spe_supported(void) { return false; }
  118. static inline bool is_feat_rng_supported(void) { return false; }
  119. static inline bool is_feat_gcs_supported(void) { return false; }
  120. static inline bool is_feat_mte2_supported(void) { return false; }
  121. static inline bool is_feat_mpam_supported(void) { return false; }
  122. static inline bool is_feat_hcx_supported(void) { return false; }
  123. static inline bool is_feat_sve_supported(void) { return false; }
  124. static inline bool is_feat_brbe_supported(void) { return false; }
  125. static inline bool is_feat_trbe_supported(void) { return false; }
  126. static inline bool is_feat_nv2_supported(void) { return false; }
  127. static inline bool is_feat_sme_supported(void) { return false; }
  128. static inline bool is_feat_sme2_supported(void) { return false; }
  129. static inline bool is_feat_s2poe_supported(void) { return false; }
  130. static inline bool is_feat_s1poe_supported(void) { return false; }
  131. static inline bool is_feat_sxpoe_supported(void) { return false; }
  132. static inline bool is_feat_s2pie_supported(void) { return false; }
  133. static inline bool is_feat_s1pie_supported(void) { return false; }
  134. static inline bool is_feat_sxpie_supported(void) { return false; }
  135. static inline bool is_feat_uao_present(void) { return false; }
  136. static inline bool is_feat_nmi_present(void) { return false; }
  137. static inline bool is_feat_ebep_present(void) { return false; }
  138. static inline bool is_feat_sebep_present(void) { return false; }
  139. #endif /* ARCH_FEATURES_H */