blob: 46cd1c9824cbd4e104179020d5cc7d593e649eac [file] [log] [blame]
Antonio Nino Diazc326c342019-01-11 11:20:10 +00001/*
johpow01fa59c6f2020-10-02 13:41:11 -05002 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
Antonio Nino Diazc326c342019-01-11 11:20:10 +00003 *
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 Diazd29d21e2019-02-06 09:23:04 +000014static 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 Boulby44b43332020-11-25 16:36:46 +000020static 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
26static 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 Diazc326c342019-01-11 11:20:10 +000032static 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 Diaz25cda672019-02-19 11:53:51 +000038static 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
Sathees Balya74155972019-01-25 11:36:01 +000049static inline bool is_armv8_4_ttst_present(void)
50{
51 return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
52 ID_AA64MMFR2_EL1_ST_MASK) == 1U;
53}
54
Alexei Fedorov90f2e882019-05-24 12:17:09 +010055static inline bool is_armv8_5_bti_present(void)
56{
57 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) &
58 ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
59}
60
Soby Mathew830f0ad2019-07-12 09:23:38 +010061static inline unsigned int get_armv8_5_mte_support(void)
62{
63 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
64 ID_AA64PFR1_EL1_MTE_MASK);
65}
66
Olivier Deprez2bae35f2020-04-16 13:39:06 +020067static inline bool is_armv8_4_sel2_present(void)
68{
69 return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) &
70 ID_AA64PFR0_SEL2_MASK) == 1ULL;
71}
72
johpow013e24c162020-04-22 14:05:13 -050073static inline bool is_armv8_6_twed_present(void)
74{
75 return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) &
76 ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED);
77}
78
Jimmy Brissonecc3c672020-04-16 10:47:56 -050079static inline bool is_armv8_6_fgt_present(void)
80{
81 return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) &
82 ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED;
83}
84
Jimmy Brisson83573892020-04-16 10:48:02 -050085static inline unsigned long int get_armv8_6_ecv_support(void)
86{
87 return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) &
88 ID_AA64MMFR0_EL1_ECV_MASK);
89}
90
Tomas Pilar6fd816e2020-10-28 15:34:12 +000091static inline bool is_armv8_5_rng_present(void)
92{
93 return ((read_id_aa64isar0_el1() >> ID_AA64ISAR0_RNDR_SHIFT) &
94 ID_AA64ISAR0_RNDR_MASK);
95}
96
johpow01fa59c6f2020-10-02 13:41:11 -050097static inline bool is_armv8_6_feat_amuv1p1_present(void)
98{
99 return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_AMU_SHIFT) &
100 ID_AA64PFR0_AMU_MASK) >= ID_AA64PFR0_AMU_V1P1);
101}
102
Alexei Fedorov19933552020-05-26 13:16:41 +0100103/*
104 * Return MPAM version:
105 *
106 * 0x00: None Armv8.0 or later
107 * 0x01: v0.1 Armv8.4 or later
108 * 0x10: v1.0 Armv8.2 or later
109 * 0x11: v1.1 Armv8.4 or later
110 *
111 */
112static inline unsigned int get_mpam_version(void)
113{
114 return (unsigned int)((((read_id_aa64pfr0_el1() >>
115 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
116 ((read_id_aa64pfr1_el1() >>
117 ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK));
118}
119
johpow01f91e59f2021-08-04 19:38:18 -0500120static inline bool is_feat_hcx_present(void)
121{
122 return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_HCX_SHIFT) &
123 ID_AA64MMFR1_EL1_HCX_MASK) == ID_AA64MMFR1_EL1_HCX_SUPPORTED);
124}
125
Zelalem Aweke79e3d292021-07-08 16:51:14 -0500126static inline unsigned int get_armv9_2_feat_rme_support(void)
127{
128 /*
129 * Return the RME version, zero if not supported. This function can be
130 * used as both an integer value for the RME version or compared to zero
131 * to detect RME presence.
132 */
133 return (unsigned int)(read_id_aa64pfr0_el1() >>
134 ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK;
135}
136
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000137#endif /* ARCH_FEATURES_H */