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 | |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 15 | #define ISOLATE_FIELD(reg, feat) \ |
| 16 | ((unsigned int)(((reg) >> (feat ## _SHIFT)) & (feat ## _MASK))) |
| 17 | |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 18 | static inline bool is_armv7_gentimer_present(void) |
| 19 | { |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 20 | return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER) != 0U; |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 23 | static inline bool is_armv8_2_ttcnp_present(void) |
| 24 | { |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 25 | return ISOLATE_FIELD(read_id_mmfr4(), ID_MMFR4_CNP) != 0U; |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Andre Przywara | 906776e | 2023-03-03 10:30:06 +0000 | [diff] [blame] | 28 | static unsigned int read_feat_amu_id_field(void) |
| 29 | { |
| 30 | return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_AMU); |
| 31 | } |
| 32 | |
| 33 | static inline bool is_feat_amu_supported(void) |
| 34 | { |
| 35 | if (ENABLE_FEAT_AMU == FEAT_STATE_DISABLED) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | if (ENABLE_FEAT_AMU == FEAT_STATE_ALWAYS) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | return read_feat_amu_id_field() >= ID_PFR0_AMU_V1; |
| 44 | } |
| 45 | |
| 46 | static inline bool is_feat_amuv1p1_supported(void) |
| 47 | { |
| 48 | if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_DISABLED) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_ALWAYS) { |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | return read_feat_amu_id_field() >= ID_PFR0_AMU_V1P1; |
| 57 | } |
| 58 | |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 59 | static inline unsigned int read_feat_trf_id_field(void) |
| 60 | { |
| 61 | return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_TRACEFILT); |
| 62 | } |
| 63 | |
| 64 | static inline bool is_feat_trf_supported(void) |
| 65 | { |
| 66 | if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | return read_feat_trf_id_field() != 0U; |
| 75 | } |
| 76 | |
Andre Przywara | 44e33e0 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 77 | static inline unsigned int read_feat_coptrc_id_field(void) |
| 78 | { |
| 79 | return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_COPTRC); |
| 80 | } |
| 81 | |
| 82 | static inline bool is_feat_sys_reg_trace_supported(void) |
| 83 | { |
| 84 | if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | return read_feat_coptrc_id_field() != 0U; |
| 93 | } |
| 94 | |
Andre Przywara | 1f55c41 | 2023-01-26 16:47:52 +0000 | [diff] [blame] | 95 | static inline unsigned int read_feat_dit_id_field(void) |
| 96 | { |
| 97 | return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_DIT); |
| 98 | } |
| 99 | |
| 100 | static inline bool is_feat_dit_supported(void) |
| 101 | { |
| 102 | if (ENABLE_FEAT_DIT == FEAT_STATE_DISABLED) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | if (ENABLE_FEAT_DIT == FEAT_STATE_ALWAYS) { |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | return read_feat_dit_id_field() != 0U; |
| 111 | } |
| 112 | |
Andre Przywara | 54d5791 | 2023-05-23 13:56:55 +0100 | [diff] [blame] | 113 | static inline unsigned int read_feat_pan_id_field(void) |
| 114 | { |
| 115 | return ISOLATE_FIELD(read_id_mmfr3(), ID_MMFR3_PAN); |
| 116 | } |
| 117 | |
| 118 | static inline bool is_feat_pan_supported(void) |
| 119 | { |
| 120 | if (ENABLE_FEAT_PAN == FEAT_STATE_DISABLED) { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | if (ENABLE_FEAT_PAN == FEAT_STATE_ALWAYS) { |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | return read_feat_pan_id_field() != 0U; |
| 129 | } |
| 130 | |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 131 | static inline bool is_feat_pan_present(void) |
| 132 | { |
| 133 | return read_feat_pan_id_field() != 0U; |
| 134 | } |
| 135 | |
| 136 | static inline unsigned int is_feat_ssbs_present(void) |
| 137 | { |
| 138 | return ((read_id_pfr2() >> ID_PFR2_SSBS_SHIFT) & |
| 139 | ID_PFR2_SSBS_MASK) != SSBS_UNAVAILABLE; |
| 140 | } |
| 141 | |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 142 | /* |
| 143 | * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch |
| 144 | * code. In fact, EL2 context switching is only needed for AArch64 (since |
| 145 | * there is no secure AArch32 EL2), so just disable these features here. |
| 146 | */ |
| 147 | static inline bool is_feat_twed_supported(void) { return false; } |
| 148 | static inline bool is_feat_ecv_supported(void) { return false; } |
| 149 | static inline bool is_feat_ecv_v2_supported(void) { return false; } |
| 150 | static inline bool is_feat_csv2_2_supported(void) { return false; } |
Sona Mathew | 3b84c96 | 2023-10-25 16:48:19 -0500 | [diff] [blame] | 151 | static inline bool is_feat_csv2_3_supported(void) { return false; } |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 152 | static inline bool is_feat_ras_supported(void) { return false; } |
| 153 | |
| 154 | /* The following features are supported in AArch64 only. */ |
| 155 | static inline bool is_feat_vhe_supported(void) { return false; } |
| 156 | static inline bool is_feat_sel2_supported(void) { return false; } |
| 157 | static inline bool is_feat_fgt_supported(void) { return false; } |
| 158 | static inline bool is_feat_tcr2_supported(void) { return false; } |
| 159 | static inline bool is_feat_spe_supported(void) { return false; } |
| 160 | static inline bool is_feat_rng_supported(void) { return false; } |
| 161 | static inline bool is_feat_gcs_supported(void) { return false; } |
Govindraj Raja | 24d3a4e | 2023-12-21 13:57:49 -0600 | [diff] [blame] | 162 | static inline bool is_feat_mte_supported(void) { return false; } |
Govindraj Raja | d7b63ac | 2024-01-26 10:08:37 -0600 | [diff] [blame] | 163 | static inline bool is_feat_mte2_supported(void) { return false; } |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 164 | static inline bool is_feat_mpam_supported(void) { return false; } |
| 165 | static inline bool is_feat_hcx_supported(void) { return false; } |
| 166 | static inline bool is_feat_sve_supported(void) { return false; } |
| 167 | static inline bool is_feat_brbe_supported(void) { return false; } |
| 168 | static inline bool is_feat_trbe_supported(void) { return false; } |
| 169 | static inline bool is_feat_nv2_supported(void) { return false; } |
| 170 | static inline bool is_feat_sme_supported(void) { return false; } |
| 171 | static inline bool is_feat_sme2_supported(void) { return false; } |
| 172 | static inline bool is_feat_s2poe_supported(void) { return false; } |
| 173 | static inline bool is_feat_s1poe_supported(void) { return false; } |
| 174 | static inline bool is_feat_sxpoe_supported(void) { return false; } |
| 175 | static inline bool is_feat_s2pie_supported(void) { return false; } |
| 176 | static inline bool is_feat_s1pie_supported(void) { return false; } |
| 177 | static inline bool is_feat_sxpie_supported(void) { return false; } |
Manish Pandey | 5cfe515 | 2024-01-09 15:55:20 +0000 | [diff] [blame] | 178 | static inline bool is_feat_uao_present(void) { return false; } |
| 179 | static inline bool is_feat_nmi_present(void) { return false; } |
| 180 | static inline bool is_feat_ebep_present(void) { return false; } |
| 181 | static inline bool is_feat_sebep_present(void) { return false; } |
Andre Przywara | dc3fcdf | 2023-05-23 10:34:38 +0100 | [diff] [blame] | 182 | |
Boyan Karatotev | 05504ba | 2023-02-15 13:21:50 +0000 | [diff] [blame] | 183 | static inline unsigned int read_feat_pmuv3_id_field(void) |
| 184 | { |
| 185 | return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_PERFMON); |
| 186 | } |
| 187 | |
Boyan Karatotev | 677ed8a | 2023-02-16 09:45:29 +0000 | [diff] [blame] | 188 | static inline unsigned int read_feat_mtpmu_id_field(void) |
| 189 | { |
| 190 | return ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU); |
| 191 | } |
| 192 | |
| 193 | static inline bool is_feat_mtpmu_supported(void) |
| 194 | { |
| 195 | if (DISABLE_MTPMU == FEAT_STATE_DISABLED) { |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | if (DISABLE_MTPMU == FEAT_STATE_ALWAYS) { |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | unsigned int mtpmu = read_feat_mtpmu_id_field(); |
| 204 | |
| 205 | return mtpmu != 0U && mtpmu != ID_DFR1_MTPMU_DISABLED; |
| 206 | } |
| 207 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 208 | #endif /* ARCH_FEATURES_H */ |