12559b2c8SAntonio Nino Diaz /* 24d482156SDaniel Boulby * Copyright (c) 2019-2022, 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> 132559b2c8SAntonio Nino Diaz 1429a24134SAntonio Nino Diaz static inline bool is_armv7_gentimer_present(void) 1529a24134SAntonio Nino Diaz { 1629a24134SAntonio Nino Diaz /* The Generic Timer is always present in an ARMv8-A implementation */ 1729a24134SAntonio Nino Diaz return true; 1829a24134SAntonio Nino Diaz } 1929a24134SAntonio Nino Diaz 2037596fcbSDaniel Boulby static inline bool is_armv8_1_pan_present(void) 2137596fcbSDaniel Boulby { 2237596fcbSDaniel Boulby return ((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_PAN_SHIFT) & 2337596fcbSDaniel Boulby ID_AA64MMFR1_EL1_PAN_MASK) != 0U; 2437596fcbSDaniel Boulby } 2537596fcbSDaniel Boulby 2637596fcbSDaniel Boulby static inline bool is_armv8_1_vhe_present(void) 2737596fcbSDaniel Boulby { 2837596fcbSDaniel Boulby return ((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_VHE_SHIFT) & 2937596fcbSDaniel Boulby ID_AA64MMFR1_EL1_VHE_MASK) != 0U; 3037596fcbSDaniel Boulby } 3137596fcbSDaniel Boulby 322559b2c8SAntonio Nino Diaz static inline bool is_armv8_2_ttcnp_present(void) 332559b2c8SAntonio Nino Diaz { 342559b2c8SAntonio Nino Diaz return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) & 352559b2c8SAntonio Nino Diaz ID_AA64MMFR2_EL1_CNP_MASK) != 0U; 362559b2c8SAntonio Nino Diaz } 372559b2c8SAntonio Nino Diaz 38*9ff5f754SJuan Pablo Conde static inline bool is_feat_pacqarma3_present(void) 39*9ff5f754SJuan Pablo Conde { 40*9ff5f754SJuan Pablo Conde uint64_t mask_id_aa64isar2 = 41*9ff5f754SJuan Pablo Conde (ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) | 42*9ff5f754SJuan Pablo Conde (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT); 43*9ff5f754SJuan Pablo Conde 44*9ff5f754SJuan Pablo Conde /* If any of the fields is not zero, QARMA3 algorithm is present */ 45*9ff5f754SJuan Pablo Conde return (read_id_aa64isar2_el1() & mask_id_aa64isar2) != 0U; 46*9ff5f754SJuan Pablo Conde } 47*9ff5f754SJuan Pablo Conde 48b86048c4SAntonio Nino Diaz static inline bool is_armv8_3_pauth_present(void) 49b86048c4SAntonio Nino Diaz { 50*9ff5f754SJuan Pablo Conde uint64_t mask_id_aa64isar1 = 51*9ff5f754SJuan Pablo Conde (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | 52b86048c4SAntonio Nino Diaz (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | 53b86048c4SAntonio Nino Diaz (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | 54b86048c4SAntonio Nino Diaz (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); 55b86048c4SAntonio Nino Diaz 56*9ff5f754SJuan Pablo Conde /* 57*9ff5f754SJuan Pablo Conde * If any of the fields is not zero or QARMA3 is present, 58*9ff5f754SJuan Pablo Conde * PAuth is present 59*9ff5f754SJuan Pablo Conde */ 60*9ff5f754SJuan Pablo Conde return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U || 61*9ff5f754SJuan Pablo Conde is_feat_pacqarma3_present()); 62b86048c4SAntonio Nino Diaz } 63b86048c4SAntonio Nino Diaz 644d482156SDaniel Boulby static inline bool is_armv8_4_dit_present(void) 654d482156SDaniel Boulby { 664d482156SDaniel Boulby return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) & 674d482156SDaniel Boulby ID_AA64PFR0_DIT_MASK) == 1U; 684d482156SDaniel Boulby } 694d482156SDaniel Boulby 70cedfa04bSSathees Balya static inline bool is_armv8_4_ttst_present(void) 71cedfa04bSSathees Balya { 72cedfa04bSSathees Balya return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) & 73cedfa04bSSathees Balya ID_AA64MMFR2_EL1_ST_MASK) == 1U; 74cedfa04bSSathees Balya } 75cedfa04bSSathees Balya 769fc59639SAlexei Fedorov static inline bool is_armv8_5_bti_present(void) 779fc59639SAlexei Fedorov { 789fc59639SAlexei Fedorov return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) & 799fc59639SAlexei Fedorov ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED; 809fc59639SAlexei Fedorov } 819fc59639SAlexei Fedorov 82b7e398d6SSoby Mathew static inline unsigned int get_armv8_5_mte_support(void) 83b7e398d6SSoby Mathew { 84b7e398d6SSoby Mathew return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) & 85b7e398d6SSoby Mathew ID_AA64PFR1_EL1_MTE_MASK); 86b7e398d6SSoby Mathew } 87b7e398d6SSoby Mathew 8852696946SOlivier Deprez static inline bool is_armv8_4_sel2_present(void) 8952696946SOlivier Deprez { 9052696946SOlivier Deprez return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) & 9152696946SOlivier Deprez ID_AA64PFR0_SEL2_MASK) == 1ULL; 9252696946SOlivier Deprez } 9352696946SOlivier Deprez 946cac724dSjohpow01 static inline bool is_armv8_6_twed_present(void) 956cac724dSjohpow01 { 966cac724dSjohpow01 return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) & 976cac724dSjohpow01 ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED); 986cac724dSjohpow01 } 996cac724dSjohpow01 100110ee433SJimmy Brisson static inline bool is_armv8_6_fgt_present(void) 101110ee433SJimmy Brisson { 102110ee433SJimmy Brisson return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) & 103110ee433SJimmy Brisson ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED; 104110ee433SJimmy Brisson } 105110ee433SJimmy Brisson 10629d0ee54SJimmy Brisson static inline unsigned long int get_armv8_6_ecv_support(void) 10729d0ee54SJimmy Brisson { 10829d0ee54SJimmy Brisson return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) & 10929d0ee54SJimmy Brisson ID_AA64MMFR0_EL1_ECV_MASK); 11029d0ee54SJimmy Brisson } 11129d0ee54SJimmy Brisson 1127c802c71STomas Pilar static inline bool is_armv8_5_rng_present(void) 1137c802c71STomas Pilar { 1147c802c71STomas Pilar return ((read_id_aa64isar0_el1() >> ID_AA64ISAR0_RNDR_SHIFT) & 1157c802c71STomas Pilar ID_AA64ISAR0_RNDR_MASK); 1167c802c71STomas Pilar } 1177c802c71STomas Pilar 118873d4241Sjohpow01 static inline bool is_armv8_6_feat_amuv1p1_present(void) 119873d4241Sjohpow01 { 120873d4241Sjohpow01 return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & 121873d4241Sjohpow01 ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1); 122873d4241Sjohpow01 } 123873d4241Sjohpow01 124dbcc44a1SAlexei Fedorov /* 125dbcc44a1SAlexei Fedorov * Return MPAM version: 126dbcc44a1SAlexei Fedorov * 127dbcc44a1SAlexei Fedorov * 0x00: None Armv8.0 or later 128dbcc44a1SAlexei Fedorov * 0x01: v0.1 Armv8.4 or later 129dbcc44a1SAlexei Fedorov * 0x10: v1.0 Armv8.2 or later 130dbcc44a1SAlexei Fedorov * 0x11: v1.1 Armv8.4 or later 131dbcc44a1SAlexei Fedorov * 132dbcc44a1SAlexei Fedorov */ 133dbcc44a1SAlexei Fedorov static inline unsigned int get_mpam_version(void) 134dbcc44a1SAlexei Fedorov { 135dbcc44a1SAlexei Fedorov return (unsigned int)((((read_id_aa64pfr0_el1() >> 136dbcc44a1SAlexei Fedorov ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | 137dbcc44a1SAlexei Fedorov ((read_id_aa64pfr1_el1() >> 138dbcc44a1SAlexei Fedorov ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK)); 139dbcc44a1SAlexei Fedorov } 140dbcc44a1SAlexei Fedorov 141cb4ec47bSjohpow01 static inline bool is_feat_hcx_present(void) 142cb4ec47bSjohpow01 { 143cb4ec47bSjohpow01 return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) & 144cb4ec47bSjohpow01 ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED); 145cb4ec47bSjohpow01 } 146cb4ec47bSjohpow01 14781c272b3SZelalem Aweke static inline unsigned int get_armv9_2_feat_rme_support(void) 14881c272b3SZelalem Aweke { 14981c272b3SZelalem Aweke /* 15081c272b3SZelalem Aweke * Return the RME version, zero if not supported. This function can be 15181c272b3SZelalem Aweke * used as both an integer value for the RME version or compared to zero 15281c272b3SZelalem Aweke * to detect RME presence. 15381c272b3SZelalem Aweke */ 15481c272b3SZelalem Aweke return (unsigned int)(read_id_aa64pfr0_el1() >> 15581c272b3SZelalem Aweke ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK; 15681c272b3SZelalem Aweke } 15781c272b3SZelalem Aweke 1586a0da736SJayanth Dodderi Chidanand /********************************************************************************* 1596a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_SB (Speculation Barrier Instruction) 1606a0da736SJayanth Dodderi Chidanand ********************************************************************************/ 1616a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_0_feat_sb_present(void) 1626a0da736SJayanth Dodderi Chidanand { 1636a0da736SJayanth Dodderi Chidanand return (((read_id_aa64isar1_el1() >> ID_AA64ISAR1_SB_SHIFT) & 1646a0da736SJayanth Dodderi Chidanand ID_AA64ISAR1_SB_MASK) == ID_AA64ISAR1_SB_SUPPORTED); 1656a0da736SJayanth Dodderi Chidanand } 1666a0da736SJayanth Dodderi Chidanand 1676a0da736SJayanth Dodderi Chidanand /********************************************************************************* 1686a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_CSV2_2 (Cache Speculation Variant 2) 1696a0da736SJayanth Dodderi Chidanand ********************************************************************************/ 1706a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_0_feat_csv2_2_present(void) 1716a0da736SJayanth Dodderi Chidanand { 1726a0da736SJayanth Dodderi Chidanand return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_CSV2_SHIFT) & 1736a0da736SJayanth Dodderi Chidanand ID_AA64PFR0_CSV2_MASK) == ID_AA64PFR0_CSV2_2_SUPPORTED); 1746a0da736SJayanth Dodderi Chidanand } 1756a0da736SJayanth Dodderi Chidanand 1766a0da736SJayanth Dodderi Chidanand /********************************************************************************** 1776a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_SPE (Statistical Profiling Extension) 1786a0da736SJayanth Dodderi Chidanand *********************************************************************************/ 1796a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_2_feat_spe_present(void) 1806a0da736SJayanth Dodderi Chidanand { 1816a0da736SJayanth Dodderi Chidanand return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_PMS_SHIFT) & 1826a0da736SJayanth Dodderi Chidanand ID_AA64DFR0_PMS_MASK) != ID_AA64DFR0_SPE_NOT_SUPPORTED); 1836a0da736SJayanth Dodderi Chidanand } 1846a0da736SJayanth Dodderi Chidanand 1856a0da736SJayanth Dodderi Chidanand /******************************************************************************* 1866a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_SVE (Scalable Vector Extension) 1876a0da736SJayanth Dodderi Chidanand ******************************************************************************/ 1886a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_2_feat_sve_present(void) 1896a0da736SJayanth Dodderi Chidanand { 1906a0da736SJayanth Dodderi Chidanand return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SVE_SHIFT) & 1916a0da736SJayanth Dodderi Chidanand ID_AA64PFR0_SVE_MASK) == ID_AA64PFR0_SVE_SUPPORTED); 1926a0da736SJayanth Dodderi Chidanand } 1936a0da736SJayanth Dodderi Chidanand 1946a0da736SJayanth Dodderi Chidanand /******************************************************************************* 1956a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_RAS (Reliability,Availability, 1966a0da736SJayanth Dodderi Chidanand * and Serviceability Extension) 1976a0da736SJayanth Dodderi Chidanand ******************************************************************************/ 1986a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_2_feat_ras_present(void) 1996a0da736SJayanth Dodderi Chidanand { 2006a0da736SJayanth Dodderi Chidanand return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_RAS_SHIFT) & 2016a0da736SJayanth Dodderi Chidanand ID_AA64PFR0_RAS_MASK) != ID_AA64PFR0_RAS_NOT_SUPPORTED); 2026a0da736SJayanth Dodderi Chidanand } 2036a0da736SJayanth Dodderi Chidanand 2046a0da736SJayanth Dodderi Chidanand /************************************************************************** 2056a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_DIT (Data Independent Timing) 2066a0da736SJayanth Dodderi Chidanand *************************************************************************/ 2076a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_4_feat_dit_present(void) 2086a0da736SJayanth Dodderi Chidanand { 2096a0da736SJayanth Dodderi Chidanand return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) & 2106a0da736SJayanth Dodderi Chidanand ID_AA64PFR0_DIT_MASK) == ID_AA64PFR0_DIT_SUPPORTED); 2116a0da736SJayanth Dodderi Chidanand } 2126a0da736SJayanth Dodderi Chidanand 2136a0da736SJayanth Dodderi Chidanand /************************************************************************* 2146a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_TRF (TraceLift) 2156a0da736SJayanth Dodderi Chidanand ************************************************************************/ 2166a0da736SJayanth Dodderi Chidanand static inline bool is_arm8_4_feat_trf_present(void) 2176a0da736SJayanth Dodderi Chidanand { 2186a0da736SJayanth Dodderi Chidanand return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEFILT_SHIFT) & 2196a0da736SJayanth Dodderi Chidanand ID_AA64DFR0_TRACEFILT_MASK) == ID_AA64DFR0_TRACEFILT_SUPPORTED); 2206a0da736SJayanth Dodderi Chidanand } 2216a0da736SJayanth Dodderi Chidanand 2226a0da736SJayanth Dodderi Chidanand /******************************************************************************* 2236a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_AMUv1 (Activity Monitors- 2246a0da736SJayanth Dodderi Chidanand * Extension v1) 2256a0da736SJayanth Dodderi Chidanand ******************************************************************************/ 2266a0da736SJayanth Dodderi Chidanand static inline bool is_armv8_4_feat_amuv1_present(void) 2276a0da736SJayanth Dodderi Chidanand { 2286a0da736SJayanth Dodderi Chidanand return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) & 2296a0da736SJayanth Dodderi Chidanand ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1); 2306a0da736SJayanth Dodderi Chidanand } 2316a0da736SJayanth Dodderi Chidanand 2326a0da736SJayanth Dodderi Chidanand /******************************************************************************** 2336a0da736SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_NV2 (Enhanced Nested Virtualization 2346a0da736SJayanth Dodderi Chidanand * Support) 2356a0da736SJayanth Dodderi Chidanand *******************************************************************************/ 2366a0da736SJayanth Dodderi Chidanand static inline unsigned int get_armv8_4_feat_nv_support(void) 2376a0da736SJayanth Dodderi Chidanand { 2386a0da736SJayanth Dodderi Chidanand return (((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_NV_SHIFT) & 2396a0da736SJayanth Dodderi Chidanand ID_AA64MMFR2_EL1_NV_MASK)); 2406a0da736SJayanth Dodderi Chidanand } 2416a0da736SJayanth Dodderi Chidanand 2421298f2f1SJayanth Dodderi Chidanand /******************************************************************************* 2431298f2f1SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_BRBE (Branch Record Buffer 2441298f2f1SJayanth Dodderi Chidanand * Extension) 2451298f2f1SJayanth Dodderi Chidanand ******************************************************************************/ 2461298f2f1SJayanth Dodderi Chidanand static inline bool is_feat_brbe_present(void) 2471298f2f1SJayanth Dodderi Chidanand { 2481298f2f1SJayanth Dodderi Chidanand return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_BRBE_SHIFT) & 2491298f2f1SJayanth Dodderi Chidanand ID_AA64DFR0_BRBE_MASK) == ID_AA64DFR0_BRBE_SUPPORTED); 2501298f2f1SJayanth Dodderi Chidanand } 2511298f2f1SJayanth Dodderi Chidanand 25247c681b7SJayanth Dodderi Chidanand /******************************************************************************* 25347c681b7SJayanth Dodderi Chidanand * Function to identify the presence of FEAT_TRBE (Trace Buffer Extension) 25447c681b7SJayanth Dodderi Chidanand ******************************************************************************/ 25547c681b7SJayanth Dodderi Chidanand static inline bool is_feat_trbe_present(void) 25647c681b7SJayanth Dodderi Chidanand { 25747c681b7SJayanth Dodderi Chidanand return (((read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEBUFFER_SHIFT) & 25847c681b7SJayanth Dodderi Chidanand ID_AA64DFR0_TRACEBUFFER_MASK) == ID_AA64DFR0_TRACEBUFFER_SUPPORTED); 25947c681b7SJayanth Dodderi Chidanand } 2601298f2f1SJayanth Dodderi Chidanand 2612559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */ 262