Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 1 | /* |
Govindraj Raja | 24d3a4e | 2023-12-21 13:57:49 -0600 | [diff] [blame] | 2 | * Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef ARCH_FEATURES_H |
| 8 | #define ARCH_FEATURES_H |
| 9 | |
| 10 | #include <stdbool.h> |
| 11 | |
| 12 | #include <arch_helpers.h> |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 13 | #include <common/feat_detect.h> |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 14 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 15 | #define ISOLATE_FIELD(reg, feat, mask) \ |
| 16 | ((unsigned int)(((reg) >> (feat)) & mask)) |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 17 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 18 | #define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 19 | __attribute__((always_inline)) \ |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 20 | static inline bool is_ ## name ## _supported(void) \ |
| 21 | { \ |
| 22 | if ((guard) == FEAT_STATE_DISABLED) { \ |
| 23 | return false; \ |
| 24 | } \ |
| 25 | if ((guard) == FEAT_STATE_ALWAYS) { \ |
| 26 | return true; \ |
| 27 | } \ |
| 28 | return read_func(); \ |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 31 | #define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 32 | __attribute__((always_inline)) \ |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 33 | static inline bool is_ ## name ## _present(void) \ |
| 34 | { \ |
| 35 | return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) \ |
| 36 | ? true : false; \ |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 39 | #define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard) \ |
| 40 | CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \ |
| 41 | CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard) |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 42 | |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 43 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 44 | /* |
| 45 | * +----------------------------+ |
| 46 | * | Features supported | |
| 47 | * +----------------------------+ |
| 48 | * | GENTIMER | |
| 49 | * +----------------------------+ |
| 50 | * | FEAT_TTCNP | |
| 51 | * +----------------------------+ |
| 52 | * | FEAT_AMU | |
| 53 | * +----------------------------+ |
| 54 | * | FEAT_AMUV1P1 | |
| 55 | * +----------------------------+ |
| 56 | * | FEAT_TRF | |
| 57 | * +----------------------------+ |
| 58 | * | FEAT_SYS_REG_TRACE | |
| 59 | * +----------------------------+ |
| 60 | * | FEAT_DIT | |
| 61 | * +----------------------------+ |
| 62 | * | FEAT_PAN | |
| 63 | * +----------------------------+ |
| 64 | * | FEAT_SSBS | |
| 65 | * +----------------------------+ |
| 66 | * | FEAT_PMUV3 | |
| 67 | * +----------------------------+ |
| 68 | * | FEAT_MTPMU | |
| 69 | * +----------------------------+ |
| 70 | */ |
Andre Przywara | 44e33e0 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 71 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 72 | /* GENTIMER */ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 73 | __attribute__((always_inline)) |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 74 | static inline bool is_armv7_gentimer_present(void) |
Andre Przywara | 44e33e0 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 75 | { |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 76 | return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER_SHIFT, |
| 77 | ID_PFR1_GENTIMER_MASK) != 0U; |
Andre Przywara | 44e33e0 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 80 | /* FEAT_TTCNP: Translation table common not private */ |
| 81 | CREATE_FEATURE_PRESENT(feat_ttcnp, id_mmfr4, ID_MMFR4_CNP_SHIFT, |
| 82 | ID_MMFR4_CNP_MASK, 1U) |
Andre Przywara | 1f55c41 | 2023-01-26 16:47:52 +0000 | [diff] [blame] | 83 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 84 | /* FEAT_AMU: Activity Monitors Extension */ |
| 85 | CREATE_FEATURE_FUNCS(feat_amu, id_pfr0, ID_PFR0_AMU_SHIFT, |
| 86 | ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1, ENABLE_FEAT_AMU) |
Andre Przywara | 1f55c41 | 2023-01-26 16:47:52 +0000 | [diff] [blame] | 87 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 88 | /* FEAT_AMUV1P1: AMU Extension v1.1 */ |
| 89 | CREATE_FEATURE_FUNCS(feat_amuv1p1, id_pfr0, ID_PFR0_AMU_SHIFT, |
| 90 | ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1) |
Andre Przywara | 1f55c41 | 2023-01-26 16:47:52 +0000 | [diff] [blame] | 91 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 92 | /* FEAT_TRF: Tracefilter */ |
| 93 | CREATE_FEATURE_FUNCS(feat_trf, id_dfr0, ID_DFR0_TRACEFILT_SHIFT, |
| 94 | ID_DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS) |
Andre Przywara | 1f55c41 | 2023-01-26 16:47:52 +0000 | [diff] [blame] | 95 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 96 | /* FEAT_SYS_REG_TRACE */ |
| 97 | CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_dfr0, ID_DFR0_COPTRC_SHIFT, |
| 98 | ID_DFR0_COPTRC_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS) |
Andre Przywara | 54d5791 | 2023-05-23 13:56:55 +0100 | [diff] [blame] | 99 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 100 | /* FEAT_DIT: Data independent timing */ |
| 101 | CREATE_FEATURE_FUNCS(feat_dit, id_pfr0, ID_PFR0_DIT_SHIFT, |
| 102 | ID_PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT) |
Andre Przywara | 54d5791 | 2023-05-23 13:56:55 +0100 | [diff] [blame] | 103 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 104 | /* FEAT_PAN: Privileged access never */ |
| 105 | CREATE_FEATURE_FUNCS(feat_pan, id_mmfr3, ID_MMFR3_PAN_SHIFT, |
| 106 | ID_MMFR3_PAN_MASK, 1U, ENABLE_FEAT_PAN) |
Andre Przywara | 54d5791 | 2023-05-23 13:56:55 +0100 | [diff] [blame] | 107 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 108 | /* FEAT_SSBS: Speculative store bypass safe */ |
| 109 | CREATE_FEATURE_PRESENT(feat_ssbs, id_pfr2, ID_PFR2_SSBS_SHIFT, |
| 110 | ID_PFR2_SSBS_MASK, 1U) |
Andre Przywara | 54d5791 | 2023-05-23 13:56:55 +0100 | [diff] [blame] | 111 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 112 | /* FEAT_PMUV3 */ |
| 113 | CREATE_FEATURE_PRESENT(feat_pmuv3, id_dfr0, ID_DFR0_PERFMON_SHIFT, |
| 114 | ID_DFR0_PERFMON_MASK, 3U) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 115 | |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 116 | /* FEAT_MTPMU */ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 117 | __attribute__((always_inline)) |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 118 | static inline bool is_feat_mtpmu_present(void) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 119 | { |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 120 | unsigned int mtpmu = ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU_SHIFT, |
| 121 | ID_DFR1_MTPMU_MASK); |
| 122 | return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED); |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 123 | } |
Sona Mathew | 9e505f9 | 2024-03-13 11:33:54 -0500 | [diff] [blame] | 124 | CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 125 | |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 126 | /* |
| 127 | * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch |
| 128 | * code. In fact, EL2 context switching is only needed for AArch64 (since |
| 129 | * there is no secure AArch32 EL2), so just disable these features here. |
| 130 | */ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 131 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 132 | static inline bool is_feat_twed_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 133 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 134 | static inline bool is_feat_ecv_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 135 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 136 | static inline bool is_feat_ecv_v2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 137 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 138 | static inline bool is_feat_csv2_2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 139 | __attribute__((always_inline)) |
Sona Mathew | 3b84c96 | 2023-10-25 16:48:19 -0500 | [diff] [blame] | 140 | static inline bool is_feat_csv2_3_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 141 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 142 | static inline bool is_feat_ras_supported(void) { return false; } |
| 143 | |
| 144 | /* The following features are supported in AArch64 only. */ |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 145 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 146 | static inline bool is_feat_vhe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 147 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 148 | static inline bool is_feat_sel2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 149 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 150 | static inline bool is_feat_fgt_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 151 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 152 | static inline bool is_feat_tcr2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 153 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 154 | static inline bool is_feat_spe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 155 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 156 | static inline bool is_feat_rng_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 157 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 158 | static inline bool is_feat_gcs_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 159 | __attribute__((always_inline)) |
Govindraj Raja | d7b63ac | 2024-01-26 10:08:37 -0600 | [diff] [blame] | 160 | static inline bool is_feat_mte2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 161 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 162 | static inline bool is_feat_mpam_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 163 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 164 | static inline bool is_feat_hcx_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 165 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 166 | static inline bool is_feat_sve_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 167 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 168 | static inline bool is_feat_brbe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 169 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 170 | static inline bool is_feat_trbe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 171 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 172 | static inline bool is_feat_nv2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 173 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 174 | static inline bool is_feat_sme_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 175 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 176 | static inline bool is_feat_sme2_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 177 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 178 | static inline bool is_feat_s2poe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 179 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 180 | static inline bool is_feat_s1poe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 181 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 182 | static inline bool is_feat_sxpoe_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 183 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 184 | static inline bool is_feat_s2pie_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 185 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 186 | static inline bool is_feat_s1pie_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 187 | __attribute__((always_inline)) |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 188 | static inline bool is_feat_sxpie_supported(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 189 | __attribute__((always_inline)) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 190 | static inline bool is_feat_uao_present(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 191 | __attribute__((always_inline)) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 192 | static inline bool is_feat_nmi_present(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 193 | __attribute__((always_inline)) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 194 | static inline bool is_feat_ebep_present(void) { return false; } |
Olivier Deprez | 5d2a5f2 | 2024-06-07 10:57:28 +0200 | [diff] [blame] | 195 | __attribute__((always_inline)) |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 196 | static inline bool is_feat_sebep_present(void) { return false; } |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 197 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 198 | #endif /* ARCH_FEATURES_H */ |