Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 1 | /* |
Daniel Boulby | 60786e7 | 2021-10-22 11:37:34 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2022, 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> |
| 13 | |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 14 | static inline bool is_armv7_gentimer_present(void) |
| 15 | { |
| 16 | /* The Generic Timer is always present in an ARMv8-A implementation */ |
| 17 | return true; |
| 18 | } |
| 19 | |
Daniel Boulby | 44b4333 | 2020-11-25 16:36:46 +0000 | [diff] [blame] | 20 | static inline bool is_armv8_1_pan_present(void) |
| 21 | { |
| 22 | return ((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_PAN_SHIFT) & |
| 23 | ID_AA64MMFR1_EL1_PAN_MASK) != 0U; |
| 24 | } |
| 25 | |
| 26 | static inline bool is_armv8_1_vhe_present(void) |
| 27 | { |
| 28 | return ((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_VHE_SHIFT) & |
| 29 | ID_AA64MMFR1_EL1_VHE_MASK) != 0U; |
| 30 | } |
| 31 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 32 | static inline bool is_armv8_2_ttcnp_present(void) |
| 33 | { |
| 34 | return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) & |
| 35 | ID_AA64MMFR2_EL1_CNP_MASK) != 0U; |
| 36 | } |
| 37 | |
Antonio Nino Diaz | 25cda67 | 2019-02-19 11:53:51 +0000 | [diff] [blame] | 38 | static inline bool is_armv8_3_pauth_present(void) |
| 39 | { |
| 40 | uint64_t mask = (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | |
| 41 | (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | |
| 42 | (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | |
| 43 | (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); |
| 44 | |
| 45 | /* If any of the fields is not zero, PAuth is present */ |
| 46 | return (read_id_aa64isar1_el1() & mask) != 0U; |
| 47 | } |
| 48 | |
Daniel Boulby | 60786e7 | 2021-10-22 11:37:34 +0100 | [diff] [blame] | 49 | static inline bool is_armv8_4_dit_present(void) |
| 50 | { |
| 51 | return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) & |
| 52 | ID_AA64PFR0_DIT_MASK) == 1U; |
| 53 | } |
| 54 | |
Sathees Balya | 7415597 | 2019-01-25 11:36:01 +0000 | [diff] [blame] | 55 | static inline bool is_armv8_4_ttst_present(void) |
| 56 | { |
| 57 | return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) & |
| 58 | ID_AA64MMFR2_EL1_ST_MASK) == 1U; |
| 59 | } |
| 60 | |
Alexei Fedorov | 90f2e88 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 61 | static inline bool is_armv8_5_bti_present(void) |
| 62 | { |
| 63 | return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) & |
| 64 | ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED; |
| 65 | } |
| 66 | |
Soby Mathew | 830f0ad | 2019-07-12 09:23:38 +0100 | [diff] [blame] | 67 | static inline unsigned int get_armv8_5_mte_support(void) |
| 68 | { |
| 69 | return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) & |
| 70 | ID_AA64PFR1_EL1_MTE_MASK); |
| 71 | } |
| 72 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 73 | static inline bool is_armv8_4_sel2_present(void) |
| 74 | { |
| 75 | return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) & |
| 76 | ID_AA64PFR0_SEL2_MASK) == 1ULL; |
| 77 | } |
| 78 | |
johpow01 | 3e24c16 | 2020-04-22 14:05:13 -0500 | [diff] [blame] | 79 | static inline bool is_armv8_6_twed_present(void) |
| 80 | { |
| 81 | return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) & |
| 82 | ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED); |
| 83 | } |
| 84 | |
Jimmy Brisson | ecc3c67 | 2020-04-16 10:47:56 -0500 | [diff] [blame] | 85 | static inline bool is_armv8_6_fgt_present(void) |
| 86 | { |
| 87 | return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) & |
| 88 | ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED; |
| 89 | } |
| 90 | |
Jimmy Brisson | 8357389 | 2020-04-16 10:48:02 -0500 | [diff] [blame] | 91 | static inline unsigned long int get_armv8_6_ecv_support(void) |
| 92 | { |
| 93 | return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) & |
| 94 | ID_AA64MMFR0_EL1_ECV_MASK); |
| 95 | } |
| 96 | |
Tomas Pilar | 6fd816e | 2020-10-28 15:34:12 +0000 | [diff] [blame] | 97 | static inline bool is_armv8_5_rng_present(void) |
| 98 | { |
| 99 | return ((read_id_aa64isar0_el1() >> ID_AA64ISAR0_RNDR_SHIFT) & |
| 100 | ID_AA64ISAR0_RNDR_MASK); |
| 101 | } |
| 102 | |
johpow01 | fa59c6f | 2020-10-02 13:41:11 -0500 | [diff] [blame] | 103 | static inline bool is_armv8_6_feat_amuv1p1_present(void) |
| 104 | { |
| 105 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & |
| 106 | ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1); |
| 107 | } |
| 108 | |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 109 | /* |
| 110 | * Return MPAM version: |
| 111 | * |
| 112 | * 0x00: None Armv8.0 or later |
| 113 | * 0x01: v0.1 Armv8.4 or later |
| 114 | * 0x10: v1.0 Armv8.2 or later |
| 115 | * 0x11: v1.1 Armv8.4 or later |
| 116 | * |
| 117 | */ |
| 118 | static inline unsigned int get_mpam_version(void) |
| 119 | { |
| 120 | return (unsigned int)((((read_id_aa64pfr0_el1() >> |
| 121 | ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | |
| 122 | ((read_id_aa64pfr1_el1() >> |
| 123 | ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK)); |
| 124 | } |
| 125 | |
johpow01 | f91e59f | 2021-08-04 19:38:18 -0500 | [diff] [blame] | 126 | static inline bool is_feat_hcx_present(void) |
| 127 | { |
| 128 | return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) & |
| 129 | ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED); |
| 130 | } |
| 131 | |
Juan Pablo Conde | 42305f2 | 2022-07-12 16:40:29 -0400 | [diff] [blame] | 132 | static inline bool is_feat_rng_trap_present(void) |
| 133 | { |
| 134 | return (((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT) & |
| 135 | ID_AA64PFR1_EL1_RNDR_TRAP_MASK) |
| 136 | == ID_AA64PFR1_EL1_RNG_TRAP_SUPPORTED); |
| 137 | } |
| 138 | |
Zelalem Aweke | 79e3d29 | 2021-07-08 16:51:14 -0500 | [diff] [blame] | 139 | static inline unsigned int get_armv9_2_feat_rme_support(void) |
| 140 | { |
| 141 | /* |
| 142 | * Return the RME version, zero if not supported. This function can be |
| 143 | * used as both an integer value for the RME version or compared to zero |
| 144 | * to detect RME presence. |
| 145 | */ |
| 146 | return (unsigned int)(read_id_aa64pfr0_el1() >> |
| 147 | ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK; |
| 148 | } |
| 149 | |
Jayanth Dodderi Chidanand | 9461a89 | 2022-01-17 18:57:17 +0000 | [diff] [blame] | 150 | /********************************************************************************* |
| 151 | * Function to identify the presence of FEAT_SB (Speculation Barrier Instruction) |
| 152 | ********************************************************************************/ |
| 153 | static inline bool is_armv8_0_feat_sb_present(void) |
| 154 | { |
| 155 | return (((read_id_aa64isar1_el1() >> ID_AA64ISAR1_SB_SHIFT) & |
| 156 | ID_AA64ISAR1_SB_MASK) == ID_AA64ISAR1_SB_SUPPORTED); |
| 157 | } |
| 158 | |
| 159 | /********************************************************************************* |
| 160 | * Function to identify the presence of FEAT_CSV2_2 (Cache Speculation Variant 2) |
| 161 | ********************************************************************************/ |
| 162 | static inline bool is_armv8_0_feat_csv2_2_present(void) |
| 163 | { |
| 164 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_CSV2_SHIFT) & |
| 165 | ID_AA64PFR0_CSV2_MASK) == ID_AA64PFR0_CSV2_2_SUPPORTED); |
| 166 | } |
| 167 | |
| 168 | /********************************************************************************** |
| 169 | * Function to identify the presence of FEAT_SPE (Statistical Profiling Extension) |
| 170 | *********************************************************************************/ |
| 171 | static inline bool is_armv8_2_feat_spe_present(void) |
| 172 | { |
| 173 | return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_PMS_SHIFT) & |
| 174 | ID_AA64DFR0_PMS_MASK) != ID_AA64DFR0_SPE_NOT_SUPPORTED); |
| 175 | } |
| 176 | |
| 177 | /******************************************************************************* |
| 178 | * Function to identify the presence of FEAT_SVE (Scalable Vector Extension) |
| 179 | ******************************************************************************/ |
| 180 | static inline bool is_armv8_2_feat_sve_present(void) |
| 181 | { |
| 182 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SVE_SHIFT) & |
| 183 | ID_AA64PFR0_SVE_MASK) == ID_AA64PFR0_SVE_SUPPORTED); |
| 184 | } |
| 185 | |
| 186 | /******************************************************************************* |
| 187 | * Function to identify the presence of FEAT_RAS (Reliability,Availability, |
| 188 | * and Serviceability Extension) |
| 189 | ******************************************************************************/ |
| 190 | static inline bool is_armv8_2_feat_ras_present(void) |
| 191 | { |
| 192 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_RAS_SHIFT) & |
| 193 | ID_AA64PFR0_RAS_MASK) != ID_AA64PFR0_RAS_NOT_SUPPORTED); |
| 194 | } |
| 195 | |
| 196 | /************************************************************************** |
| 197 | * Function to identify the presence of FEAT_DIT (Data Independent Timing) |
| 198 | *************************************************************************/ |
| 199 | static inline bool is_armv8_4_feat_dit_present(void) |
| 200 | { |
| 201 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) & |
| 202 | ID_AA64PFR0_DIT_MASK) == ID_AA64PFR0_DIT_SUPPORTED); |
| 203 | } |
| 204 | |
| 205 | /************************************************************************* |
| 206 | * Function to identify the presence of FEAT_TRF (TraceLift) |
| 207 | ************************************************************************/ |
| 208 | static inline bool is_arm8_4_feat_trf_present(void) |
| 209 | { |
| 210 | return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEFILT_SHIFT) & |
| 211 | ID_AA64DFR0_TRACEFILT_MASK) == ID_AA64DFR0_TRACEFILT_SUPPORTED); |
| 212 | } |
| 213 | |
| 214 | /******************************************************************************* |
| 215 | * Function to identify the presence of FEAT_AMUv1 (Activity Monitors- |
| 216 | * Extension v1) |
| 217 | ******************************************************************************/ |
| 218 | static inline bool is_armv8_4_feat_amuv1_present(void) |
| 219 | { |
| 220 | return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & |
| 221 | ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1); |
| 222 | } |
| 223 | |
| 224 | /******************************************************************************** |
| 225 | * Function to identify the presence of FEAT_NV2 (Enhanced Nested Virtualization |
| 226 | * Support) |
| 227 | *******************************************************************************/ |
| 228 | static inline unsigned int get_armv8_4_feat_nv_support(void) |
| 229 | { |
| 230 | return (((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_NV_SHIFT) & |
| 231 | ID_AA64MMFR2_EL1_NV_MASK)); |
| 232 | } |
| 233 | |
Jayanth Dodderi Chidanand | 6931675 | 2022-05-09 12:33:03 +0100 | [diff] [blame] | 234 | /******************************************************************************* |
| 235 | * Function to identify the presence of FEAT_BRBE (Branch Record Buffer |
| 236 | * Extension) |
| 237 | ******************************************************************************/ |
| 238 | static inline bool is_feat_brbe_present(void) |
| 239 | { |
| 240 | return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_BRBE_SHIFT) & |
| 241 | ID_AA64DFR0_BRBE_MASK) == ID_AA64DFR0_BRBE_SUPPORTED); |
| 242 | } |
| 243 | |
Jayanth Dodderi Chidanand | a793ccc | 2022-05-19 14:08:28 +0100 | [diff] [blame] | 244 | /******************************************************************************* |
| 245 | * Function to identify the presence of FEAT_TRBE (Trace Buffer Extension) |
| 246 | ******************************************************************************/ |
| 247 | static inline bool is_feat_trbe_present(void) |
| 248 | { |
| 249 | return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEBUFFER_SHIFT) & |
| 250 | ID_AA64DFR0_TRACEBUFFER_MASK) == ID_AA64DFR0_TRACEBUFFER_SUPPORTED); |
| 251 | } |
Jayanth Dodderi Chidanand | 6931675 | 2022-05-09 12:33:03 +0100 | [diff] [blame] | 252 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 253 | #endif /* ARCH_FEATURES_H */ |