xref: /rk3399_ARM-atf/include/arch/aarch64/arch_features.h (revision 4d4821569d15c3411a6fe5dcfc791d6b28c6d6a9)
12559b2c8SAntonio Nino Diaz /*
2*4d482156SDaniel 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 
38b86048c4SAntonio Nino Diaz static inline bool is_armv8_3_pauth_present(void)
39b86048c4SAntonio Nino Diaz {
40b86048c4SAntonio Nino Diaz 	uint64_t mask = (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
41b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) |
42b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) |
43b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT);
44b86048c4SAntonio Nino Diaz 
45b86048c4SAntonio Nino Diaz 	/* If any of the fields is not zero, PAuth is present */
46b86048c4SAntonio Nino Diaz 	return (read_id_aa64isar1_el1() & mask) != 0U;
47b86048c4SAntonio Nino Diaz }
48b86048c4SAntonio Nino Diaz 
49*4d482156SDaniel Boulby static inline bool is_armv8_4_dit_present(void)
50*4d482156SDaniel Boulby {
51*4d482156SDaniel Boulby 	return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) &
52*4d482156SDaniel Boulby 		ID_AA64PFR0_DIT_MASK) == 1U;
53*4d482156SDaniel Boulby }
54*4d482156SDaniel Boulby 
55cedfa04bSSathees Balya static inline bool is_armv8_4_ttst_present(void)
56cedfa04bSSathees Balya {
57cedfa04bSSathees Balya 	return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
58cedfa04bSSathees Balya 		ID_AA64MMFR2_EL1_ST_MASK) == 1U;
59cedfa04bSSathees Balya }
60cedfa04bSSathees Balya 
619fc59639SAlexei Fedorov static inline bool is_armv8_5_bti_present(void)
629fc59639SAlexei Fedorov {
639fc59639SAlexei Fedorov 	return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) &
649fc59639SAlexei Fedorov 		ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
659fc59639SAlexei Fedorov }
669fc59639SAlexei Fedorov 
67b7e398d6SSoby Mathew static inline unsigned int get_armv8_5_mte_support(void)
68b7e398d6SSoby Mathew {
69b7e398d6SSoby Mathew 	return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
70b7e398d6SSoby Mathew 		ID_AA64PFR1_EL1_MTE_MASK);
71b7e398d6SSoby Mathew }
72b7e398d6SSoby Mathew 
7352696946SOlivier Deprez static inline bool is_armv8_4_sel2_present(void)
7452696946SOlivier Deprez {
7552696946SOlivier Deprez 	return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) &
7652696946SOlivier Deprez 		ID_AA64PFR0_SEL2_MASK) == 1ULL;
7752696946SOlivier Deprez }
7852696946SOlivier Deprez 
796cac724dSjohpow01 static inline bool is_armv8_6_twed_present(void)
806cac724dSjohpow01 {
816cac724dSjohpow01 	return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) &
826cac724dSjohpow01 		ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED);
836cac724dSjohpow01 }
846cac724dSjohpow01 
85110ee433SJimmy Brisson static inline bool is_armv8_6_fgt_present(void)
86110ee433SJimmy Brisson {
87110ee433SJimmy Brisson 	return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) &
88110ee433SJimmy Brisson 		ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED;
89110ee433SJimmy Brisson }
90110ee433SJimmy Brisson 
9129d0ee54SJimmy Brisson static inline unsigned long int get_armv8_6_ecv_support(void)
9229d0ee54SJimmy Brisson {
9329d0ee54SJimmy Brisson 	return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) &
9429d0ee54SJimmy Brisson 		ID_AA64MMFR0_EL1_ECV_MASK);
9529d0ee54SJimmy Brisson }
9629d0ee54SJimmy Brisson 
977c802c71STomas Pilar static inline bool is_armv8_5_rng_present(void)
987c802c71STomas Pilar {
997c802c71STomas Pilar 	return ((read_id_aa64isar0_el1() >> ID_AA64ISAR0_RNDR_SHIFT) &
1007c802c71STomas Pilar 		ID_AA64ISAR0_RNDR_MASK);
1017c802c71STomas Pilar }
1027c802c71STomas Pilar 
103873d4241Sjohpow01 static inline bool is_armv8_6_feat_amuv1p1_present(void)
104873d4241Sjohpow01 {
105873d4241Sjohpow01 	return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) &
106873d4241Sjohpow01 		ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1);
107873d4241Sjohpow01 }
108873d4241Sjohpow01 
109dbcc44a1SAlexei Fedorov /*
110dbcc44a1SAlexei Fedorov  * Return MPAM version:
111dbcc44a1SAlexei Fedorov  *
112dbcc44a1SAlexei Fedorov  * 0x00: None Armv8.0 or later
113dbcc44a1SAlexei Fedorov  * 0x01: v0.1 Armv8.4 or later
114dbcc44a1SAlexei Fedorov  * 0x10: v1.0 Armv8.2 or later
115dbcc44a1SAlexei Fedorov  * 0x11: v1.1 Armv8.4 or later
116dbcc44a1SAlexei Fedorov  *
117dbcc44a1SAlexei Fedorov  */
118dbcc44a1SAlexei Fedorov static inline unsigned int get_mpam_version(void)
119dbcc44a1SAlexei Fedorov {
120dbcc44a1SAlexei Fedorov 	return (unsigned int)((((read_id_aa64pfr0_el1() >>
121dbcc44a1SAlexei Fedorov 		ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
122dbcc44a1SAlexei Fedorov 				((read_id_aa64pfr1_el1() >>
123dbcc44a1SAlexei Fedorov 		ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK));
124dbcc44a1SAlexei Fedorov }
125dbcc44a1SAlexei Fedorov 
126cb4ec47bSjohpow01 static inline bool is_feat_hcx_present(void)
127cb4ec47bSjohpow01 {
128cb4ec47bSjohpow01 	return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) &
129cb4ec47bSjohpow01 		ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED);
130cb4ec47bSjohpow01 }
131cb4ec47bSjohpow01 
13281c272b3SZelalem Aweke static inline unsigned int get_armv9_2_feat_rme_support(void)
13381c272b3SZelalem Aweke {
13481c272b3SZelalem Aweke 	/*
13581c272b3SZelalem Aweke 	 * Return the RME version, zero if not supported.  This function can be
13681c272b3SZelalem Aweke 	 * used as both an integer value for the RME version or compared to zero
13781c272b3SZelalem Aweke 	 * to detect RME presence.
13881c272b3SZelalem Aweke 	 */
13981c272b3SZelalem Aweke 	return (unsigned int)(read_id_aa64pfr0_el1() >>
14081c272b3SZelalem Aweke 		ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK;
14181c272b3SZelalem Aweke }
14281c272b3SZelalem Aweke 
1432559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */
144