xref: /rk3399_ARM-atf/include/arch/aarch64/arch_features.h (revision 873d4241e324cf619e68880aaa9f890296cdba8b)
12559b2c8SAntonio Nino Diaz /*
2*873d4241Sjohpow01  * Copyright (c) 2019-2021, 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 
202559b2c8SAntonio Nino Diaz static inline bool is_armv8_2_ttcnp_present(void)
212559b2c8SAntonio Nino Diaz {
222559b2c8SAntonio Nino Diaz 	return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) &
232559b2c8SAntonio Nino Diaz 		ID_AA64MMFR2_EL1_CNP_MASK) != 0U;
242559b2c8SAntonio Nino Diaz }
252559b2c8SAntonio Nino Diaz 
26b86048c4SAntonio Nino Diaz static inline bool is_armv8_3_pauth_present(void)
27b86048c4SAntonio Nino Diaz {
28b86048c4SAntonio Nino Diaz 	uint64_t mask = (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
29b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) |
30b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) |
31b86048c4SAntonio Nino Diaz 			(ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT);
32b86048c4SAntonio Nino Diaz 
33b86048c4SAntonio Nino Diaz 	/* If any of the fields is not zero, PAuth is present */
34b86048c4SAntonio Nino Diaz 	return (read_id_aa64isar1_el1() & mask) != 0U;
35b86048c4SAntonio Nino Diaz }
36b86048c4SAntonio Nino Diaz 
37cedfa04bSSathees Balya static inline bool is_armv8_4_ttst_present(void)
38cedfa04bSSathees Balya {
39cedfa04bSSathees Balya 	return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
40cedfa04bSSathees Balya 		ID_AA64MMFR2_EL1_ST_MASK) == 1U;
41cedfa04bSSathees Balya }
42cedfa04bSSathees Balya 
439fc59639SAlexei Fedorov static inline bool is_armv8_5_bti_present(void)
449fc59639SAlexei Fedorov {
459fc59639SAlexei Fedorov 	return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) &
469fc59639SAlexei Fedorov 		ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
479fc59639SAlexei Fedorov }
489fc59639SAlexei Fedorov 
49b7e398d6SSoby Mathew static inline unsigned int get_armv8_5_mte_support(void)
50b7e398d6SSoby Mathew {
51b7e398d6SSoby Mathew 	return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
52b7e398d6SSoby Mathew 		ID_AA64PFR1_EL1_MTE_MASK);
53b7e398d6SSoby Mathew }
54b7e398d6SSoby Mathew 
5552696946SOlivier Deprez static inline bool is_armv8_4_sel2_present(void)
5652696946SOlivier Deprez {
5752696946SOlivier Deprez 	return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) &
5852696946SOlivier Deprez 		ID_AA64PFR0_SEL2_MASK) == 1ULL;
5952696946SOlivier Deprez }
6052696946SOlivier Deprez 
616cac724dSjohpow01 static inline bool is_armv8_6_twed_present(void)
626cac724dSjohpow01 {
636cac724dSjohpow01 	return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) &
646cac724dSjohpow01 		ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED);
656cac724dSjohpow01 }
666cac724dSjohpow01 
67110ee433SJimmy Brisson static inline bool is_armv8_6_fgt_present(void)
68110ee433SJimmy Brisson {
69110ee433SJimmy Brisson 	return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) &
70110ee433SJimmy Brisson 		ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED;
71110ee433SJimmy Brisson }
72110ee433SJimmy Brisson 
7329d0ee54SJimmy Brisson static inline unsigned long int get_armv8_6_ecv_support(void)
7429d0ee54SJimmy Brisson {
7529d0ee54SJimmy Brisson 	return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) &
7629d0ee54SJimmy Brisson 		ID_AA64MMFR0_EL1_ECV_MASK);
7729d0ee54SJimmy Brisson }
7829d0ee54SJimmy Brisson 
797c802c71STomas Pilar static inline bool is_armv8_5_rng_present(void)
807c802c71STomas Pilar {
817c802c71STomas Pilar 	return ((read_id_aa64isar0_el1() >> ID_AA64ISAR0_RNDR_SHIFT) &
827c802c71STomas Pilar 		ID_AA64ISAR0_RNDR_MASK);
837c802c71STomas Pilar }
847c802c71STomas Pilar 
85*873d4241Sjohpow01 static inline bool is_armv8_6_feat_amuv1p1_present(void)
86*873d4241Sjohpow01 {
87*873d4241Sjohpow01 	return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) &
88*873d4241Sjohpow01 		ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1);
89*873d4241Sjohpow01 }
90*873d4241Sjohpow01 
91dbcc44a1SAlexei Fedorov /*
92dbcc44a1SAlexei Fedorov  * Return MPAM version:
93dbcc44a1SAlexei Fedorov  *
94dbcc44a1SAlexei Fedorov  * 0x00: None Armv8.0 or later
95dbcc44a1SAlexei Fedorov  * 0x01: v0.1 Armv8.4 or later
96dbcc44a1SAlexei Fedorov  * 0x10: v1.0 Armv8.2 or later
97dbcc44a1SAlexei Fedorov  * 0x11: v1.1 Armv8.4 or later
98dbcc44a1SAlexei Fedorov  *
99dbcc44a1SAlexei Fedorov  */
100dbcc44a1SAlexei Fedorov static inline unsigned int get_mpam_version(void)
101dbcc44a1SAlexei Fedorov {
102dbcc44a1SAlexei Fedorov 	return (unsigned int)((((read_id_aa64pfr0_el1() >>
103dbcc44a1SAlexei Fedorov 		ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
104dbcc44a1SAlexei Fedorov 				((read_id_aa64pfr1_el1() >>
105dbcc44a1SAlexei Fedorov 		ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK));
106dbcc44a1SAlexei Fedorov }
107dbcc44a1SAlexei Fedorov 
1082559b2c8SAntonio Nino Diaz #endif /* ARCH_FEATURES_H */
109