blob: 59188da38dd80f4d8c89dd29957a3bd3170d9084 [file] [log] [blame]
Antonio Nino Diazc326c342019-01-11 11:20:10 +00001/*
Govindraj Raja24d3a4e2023-12-21 13:57:49 -06002 * Copyright (c) 2019-2024, 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>
Andre Przywarae8920f62022-11-10 14:28:01 +000013#include <common/feat_detect.h>
Antonio Nino Diazc326c342019-01-11 11:20:10 +000014
Sona Mathew9e505f92024-03-13 11:33:54 -050015#define ISOLATE_FIELD(reg, feat, mask) \
16 ((unsigned int)(((reg) >> (feat)) & mask))
Andre Przywarabb0db3b2023-01-25 12:26:14 +000017
Sona Mathew9e505f92024-03-13 11:33:54 -050018#define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \
Olivier Deprez5d2a5f22024-06-07 10:57:28 +020019__attribute__((always_inline)) \
Sona Mathew9e505f92024-03-13 11:33:54 -050020static inline bool is_ ## name ## _supported(void) \
21{ \
22 if ((guard) == FEAT_STATE_DISABLED) { \
23 return false; \
24 } \
25 if ((guard) == FEAT_STATE_ALWAYS) { \
26 return true; \
27 } \
28 return read_func(); \
Antonio Nino Diazd29d21e2019-02-06 09:23:04 +000029}
30
Sona Mathew9e505f92024-03-13 11:33:54 -050031#define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \
Olivier Deprez5d2a5f22024-06-07 10:57:28 +020032__attribute__((always_inline)) \
Sona Mathew9e505f92024-03-13 11:33:54 -050033static inline bool is_ ## name ## _present(void) \
34{ \
35 return (ISOLATE_FIELD(read_ ## idreg(), idfield, mask) >= idval) \
36 ? true : false; \
37}
38
39#define CREATE_FEATURE_FUNCS(name, idreg, idfield, mask, idval, guard) \
40CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \
41CREATE_FEATURE_SUPPORTED(name, is_ ## name ## _present, guard)
42
43
44/* +----------------------------+
45 * | Features supported |
46 * +----------------------------+
47 * | GENTIMER |
48 * +----------------------------+
49 * | FEAT_PAN |
50 * +----------------------------+
51 * | FEAT_VHE |
52 * +----------------------------+
53 * | FEAT_TTCNP |
54 * +----------------------------+
55 * | FEAT_UAO |
56 * +----------------------------+
57 * | FEAT_PACQARMA3 |
58 * +----------------------------+
59 * | FEAT_PAUTH |
60 * +----------------------------+
61 * | FEAT_TTST |
62 * +----------------------------+
63 * | FEAT_BTI |
64 * +----------------------------+
65 * | FEAT_MTE2 |
66 * +----------------------------+
67 * | FEAT_SSBS |
68 * +----------------------------+
69 * | FEAT_NMI |
70 * +----------------------------+
71 * | FEAT_GCS |
72 * +----------------------------+
73 * | FEAT_EBEP |
74 * +----------------------------+
75 * | FEAT_SEBEP |
76 * +----------------------------+
77 * | FEAT_SEL2 |
78 * +----------------------------+
79 * | FEAT_TWED |
80 * +----------------------------+
81 * | FEAT_FGT |
82 * +----------------------------+
83 * | FEAT_EC/ECV2 |
84 * +----------------------------+
85 * | FEAT_RNG |
86 * +----------------------------+
87 * | FEAT_TCR2 |
88 * +----------------------------+
89 * | FEAT_S2POE |
90 * +----------------------------+
91 * | FEAT_S1POE |
92 * +----------------------------+
93 * | FEAT_S2PIE |
94 * +----------------------------+
95 * | FEAT_S1PIE |
96 * +----------------------------+
97 * | FEAT_AMU/AMUV1P1 |
98 * +----------------------------+
99 * | FEAT_MPAM |
100 * +----------------------------+
101 * | FEAT_HCX |
102 * +----------------------------+
103 * | FEAT_RNG_TRAP |
104 * +----------------------------+
105 * | FEAT_RME |
106 * +----------------------------+
107 * | FEAT_SB |
108 * +----------------------------+
109 * | FEAT_CSV2/CSV3 |
110 * +----------------------------+
111 * | FEAT_SPE |
112 * +----------------------------+
113 * | FEAT_SVE |
114 * +----------------------------+
115 * | FEAT_RAS |
116 * +----------------------------+
117 * | FEAT_DIT |
118 * +----------------------------+
119 * | FEAT_SYS_REG_TRACE |
120 * +----------------------------+
121 * | FEAT_TRF |
122 * +----------------------------+
123 * | FEAT_NV/NV2 |
124 * +----------------------------+
125 * | FEAT_BRBE |
126 * +----------------------------+
127 * | FEAT_TRBE |
128 * +----------------------------+
129 * | FEAT_SME/SME2 |
130 * +----------------------------+
131 * | FEAT_PMUV3 |
132 * +----------------------------+
133 * | FEAT_MTPMU |
134 * +----------------------------+
Arvind Ram Prakash62d87e72024-06-06 11:33:37 -0500135 * | FEAT_FGT2 |
136 * +----------------------------+
Jayanth Dodderi Chidanand6b706862024-09-05 22:24:04 +0100137 * | FEAT_THE |
138 * +----------------------------+
Jayanth Dodderi Chidanand70cc1752024-09-06 13:49:31 +0100139 * | FEAT_SCTLR2 |
140 * +----------------------------+
Govindraj Rajae63794e2024-09-06 15:43:43 +0100141 * | FEAT_D128 |
142 * +----------------------------+
Andre Przywara8fc8e182024-08-09 17:04:22 +0100143 * | FEAT_LS64_ACCDATA |
144 * +----------------------------+
Sona Mathew9e505f92024-03-13 11:33:54 -0500145 */
Andre Przywara97272942023-01-26 15:27:38 +0000146
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200147__attribute__((always_inline))
Andre Przywara0dda4242023-04-18 16:58:36 +0100148static inline bool is_armv7_gentimer_present(void)
Andre Przywara98908b32022-11-17 16:42:09 +0000149{
Andre Przywara0dda4242023-04-18 16:58:36 +0100150 /* The Generic Timer is always present in an ARMv8-A implementation */
151 return true;
Andre Przywara98908b32022-11-17 16:42:09 +0000152}
153
Sona Mathew9e505f92024-03-13 11:33:54 -0500154/* FEAT_PAN: Privileged access never */
Andre Przywara0dda4242023-04-18 16:58:36 +0100155CREATE_FEATURE_FUNCS(feat_pan, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_PAN_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500156 ID_AA64MMFR1_EL1_PAN_MASK, 1U, ENABLE_FEAT_PAN)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000157
Sona Mathew9e505f92024-03-13 11:33:54 -0500158/* FEAT_VHE: Virtualization Host Extensions */
Andre Przywara0dda4242023-04-18 16:58:36 +0100159CREATE_FEATURE_FUNCS(feat_vhe, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_VHE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500160 ID_AA64MMFR1_EL1_VHE_MASK, 1U, ENABLE_FEAT_VHE)
Daniel Boulby44b43332020-11-25 16:36:46 +0000161
Sona Mathew9e505f92024-03-13 11:33:54 -0500162/* FEAT_TTCNP: Translation table common not private */
163CREATE_FEATURE_PRESENT(feat_ttcnp, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_CNP_SHIFT,
164 ID_AA64MMFR2_EL1_CNP_MASK, 1U)
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000165
Sona Mathew9e505f92024-03-13 11:33:54 -0500166/* FEAT_UAO: User access override */
167CREATE_FEATURE_PRESENT(feat_uao, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_UAO_SHIFT,
168 ID_AA64MMFR2_EL1_UAO_MASK, 1U)
Juan Pablo Condee089a172022-06-29 17:44:43 -0400169
Sona Mathew9e505f92024-03-13 11:33:54 -0500170/* If any of the fields is not zero, QARMA3 algorithm is present */
171CREATE_FEATURE_PRESENT(feat_pacqarma3, id_aa64isar2_el1, 0,
172 ((ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) |
173 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT)), 1U)
Juan Pablo Condee089a172022-06-29 17:44:43 -0400174
Sona Mathew9e505f92024-03-13 11:33:54 -0500175/* PAUTH */
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200176__attribute__((always_inline))
Antonio Nino Diaz25cda672019-02-19 11:53:51 +0000177static inline bool is_armv8_3_pauth_present(void)
178{
Juan Pablo Condee089a172022-06-29 17:44:43 -0400179 uint64_t mask_id_aa64isar1 =
180 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
181 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) |
182 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) |
183 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT);
Antonio Nino Diaz25cda672019-02-19 11:53:51 +0000184
Juan Pablo Condee089a172022-06-29 17:44:43 -0400185 /*
186 * If any of the fields is not zero or QARMA3 is present,
187 * PAuth is present
188 */
189 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U ||
190 is_feat_pacqarma3_present());
Antonio Nino Diaz25cda672019-02-19 11:53:51 +0000191}
192
Sona Mathew9e505f92024-03-13 11:33:54 -0500193/* FEAT_TTST: Small translation tables */
194CREATE_FEATURE_PRESENT(feat_ttst, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_ST_SHIFT,
195 ID_AA64MMFR2_EL1_ST_MASK, 1U)
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100196
Sona Mathew9e505f92024-03-13 11:33:54 -0500197/* FEAT_BTI: Branch target identification */
198CREATE_FEATURE_PRESENT(feat_bti, id_aa64pfr1_el1, ID_AA64PFR1_EL1_BT_SHIFT,
199 ID_AA64PFR1_EL1_BT_MASK, BTI_IMPLEMENTED)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000200
Sona Mathew9e505f92024-03-13 11:33:54 -0500201/* FEAT_MTE2: Memory tagging extension */
202CREATE_FEATURE_FUNCS(feat_mte2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_MTE_SHIFT,
203 ID_AA64PFR1_EL1_MTE_MASK, MTE_IMPLEMENTED_ELX, ENABLE_FEAT_MTE2)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000204
Sona Mathew9e505f92024-03-13 11:33:54 -0500205/* FEAT_SSBS: Speculative store bypass safe */
206CREATE_FEATURE_PRESENT(feat_ssbs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SSBS_SHIFT,
207 ID_AA64PFR1_EL1_SSBS_MASK, 1U)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000208
Sona Mathew9e505f92024-03-13 11:33:54 -0500209/* FEAT_NMI: Non-maskable interrupts */
210CREATE_FEATURE_PRESENT(feat_nmi, id_aa64pfr1_el1, ID_AA64PFR1_EL1_NMI_SHIFT,
211 ID_AA64PFR1_EL1_NMI_MASK, NMI_IMPLEMENTED)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000212
Sona Mathew9e505f92024-03-13 11:33:54 -0500213/* FEAT_EBEP */
214CREATE_FEATURE_PRESENT(feat_ebep, id_aa64dfr1_el1, ID_AA64DFR1_EBEP_SHIFT,
215 ID_AA64DFR1_EBEP_MASK, EBEP_IMPLEMENTED)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000216
Sona Mathew9e505f92024-03-13 11:33:54 -0500217/* FEAT_SEBEP */
218CREATE_FEATURE_PRESENT(feat_sebep, id_aa64dfr0_el1, ID_AA64DFR0_SEBEP_SHIFT,
219 ID_AA64DFR0_SEBEP_MASK, SEBEP_IMPLEMENTED)
Manish Pandey5cfe5152024-01-09 15:55:20 +0000220
Sona Mathew9e505f92024-03-13 11:33:54 -0500221/* FEAT_SEL2: Secure EL2 */
Andre Przywara0dda4242023-04-18 16:58:36 +0100222CREATE_FEATURE_FUNCS(feat_sel2, id_aa64pfr0_el1, ID_AA64PFR0_SEL2_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500223 ID_AA64PFR0_SEL2_MASK, 1U, ENABLE_FEAT_SEL2)
224
225/* FEAT_TWED: Delayed trapping of WFE */
Andre Przywara0dda4242023-04-18 16:58:36 +0100226CREATE_FEATURE_FUNCS(feat_twed, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_TWED_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500227 ID_AA64MMFR1_EL1_TWED_MASK, 1U, ENABLE_FEAT_TWED)
228
229/* FEAT_FGT: Fine-grained traps */
Andre Przywara0dda4242023-04-18 16:58:36 +0100230CREATE_FEATURE_FUNCS(feat_fgt, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500231 ID_AA64MMFR0_EL1_FGT_MASK, 1U, ENABLE_FEAT_FGT)
232
Arvind Ram Prakash62d87e72024-06-06 11:33:37 -0500233/* FEAT_FGT2: Fine-grained traps extended */
234CREATE_FEATURE_FUNCS(feat_fgt2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT,
235 ID_AA64MMFR0_EL1_FGT_MASK, FGT2_IMPLEMENTED, ENABLE_FEAT_FGT2)
236
Sona Mathew9e505f92024-03-13 11:33:54 -0500237/* FEAT_ECV: Enhanced Counter Virtualization */
Andre Przywara0dda4242023-04-18 16:58:36 +0100238CREATE_FEATURE_FUNCS(feat_ecv, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500239 ID_AA64MMFR0_EL1_ECV_MASK, 1U, ENABLE_FEAT_ECV)
240CREATE_FEATURE_FUNCS(feat_ecv_v2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT,
241 ID_AA64MMFR0_EL1_ECV_MASK, ID_AA64MMFR0_EL1_ECV_SELF_SYNCH, ENABLE_FEAT_ECV)
Mark Brownc37eee72023-03-14 20:13:03 +0000242
Sona Mathew9e505f92024-03-13 11:33:54 -0500243/* FEAT_RNG: Random number generator */
Andre Przywara0dda4242023-04-18 16:58:36 +0100244CREATE_FEATURE_FUNCS(feat_rng, id_aa64isar0_el1, ID_AA64ISAR0_RNDR_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500245 ID_AA64ISAR0_RNDR_MASK, 1U, ENABLE_FEAT_RNG)
246
247/* FEAT_TCR2: Support TCR2_ELx regs */
Andre Przywara0dda4242023-04-18 16:58:36 +0100248CREATE_FEATURE_FUNCS(feat_tcr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_TCRX_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500249 ID_AA64MMFR3_EL1_TCRX_MASK, 1U, ENABLE_FEAT_TCR2)
Mark Brown293a6612023-03-14 20:48:43 +0000250
Sona Mathew9e505f92024-03-13 11:33:54 -0500251/* FEAT_S2POE */
Andre Przywara0dda4242023-04-18 16:58:36 +0100252CREATE_FEATURE_FUNCS(feat_s2poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2POE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500253 ID_AA64MMFR3_EL1_S2POE_MASK, 1U, ENABLE_FEAT_S2POE)
254
255/* FEAT_S1POE */
Andre Przywara0dda4242023-04-18 16:58:36 +0100256CREATE_FEATURE_FUNCS(feat_s1poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1POE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500257 ID_AA64MMFR3_EL1_S1POE_MASK, 1U, ENABLE_FEAT_S1POE)
258
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200259__attribute__((always_inline))
Mark Brown293a6612023-03-14 20:48:43 +0000260static inline bool is_feat_sxpoe_supported(void)
261{
262 return is_feat_s1poe_supported() || is_feat_s2poe_supported();
263}
264
Sona Mathew9e505f92024-03-13 11:33:54 -0500265/* FEAT_S2PIE */
Andre Przywara0dda4242023-04-18 16:58:36 +0100266CREATE_FEATURE_FUNCS(feat_s2pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2PIE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500267 ID_AA64MMFR3_EL1_S2PIE_MASK, 1U, ENABLE_FEAT_S2PIE)
268
269/* FEAT_S1PIE */
Andre Przywara0dda4242023-04-18 16:58:36 +0100270CREATE_FEATURE_FUNCS(feat_s1pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1PIE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500271 ID_AA64MMFR3_EL1_S1PIE_MASK, 1U, ENABLE_FEAT_S1PIE)
272
Jayanth Dodderi Chidanand6b706862024-09-05 22:24:04 +0100273/* FEAT_THE: Translation Hardening Extension */
274CREATE_FEATURE_FUNCS(feat_the, id_aa64pfr1_el1, ID_AA64PFR1_EL1_THE_SHIFT,
275 ID_AA64PFR1_EL1_THE_MASK, THE_IMPLEMENTED, ENABLE_FEAT_THE)
276
Jayanth Dodderi Chidanand70cc1752024-09-06 13:49:31 +0100277/* FEAT_SCTLR2 */
278CREATE_FEATURE_FUNCS(feat_sctlr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_SCTLR2_SHIFT,
279 ID_AA64MMFR3_EL1_SCTLR2_MASK, SCTLR2_IMPLEMENTED,
280 ENABLE_FEAT_SCTLR2)
281
Govindraj Rajae63794e2024-09-06 15:43:43 +0100282/* FEAT_D128 */
283CREATE_FEATURE_FUNCS(feat_d128, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_D128_SHIFT,
284 ID_AA64MMFR3_EL1_D128_MASK, D128_IMPLEMENTED,
285 ENABLE_FEAT_D128)
286
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200287__attribute__((always_inline))
Mark Brown293a6612023-03-14 20:48:43 +0000288static inline bool is_feat_sxpie_supported(void)
289{
290 return is_feat_s1pie_supported() || is_feat_s2pie_supported();
291}
292
Andre Przywara0dda4242023-04-18 16:58:36 +0100293/* FEAT_GCS: Guarded Control Stack */
294CREATE_FEATURE_FUNCS(feat_gcs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_GCS_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500295 ID_AA64PFR1_EL1_GCS_MASK, 1U, ENABLE_FEAT_GCS)
Andre Przywara2c550e32022-11-10 14:41:07 +0000296
Andre Przywara0dda4242023-04-18 16:58:36 +0100297/* FEAT_AMU: Activity Monitors Extension */
298CREATE_FEATURE_FUNCS(feat_amu, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500299 ID_AA64PFR0_AMU_MASK, 1U, ENABLE_FEAT_AMU)
300
301/* FEAT_AMUV1P1: AMU Extension v1.1 */
302CREATE_FEATURE_FUNCS(feat_amuv1p1, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT,
303 ID_AA64PFR0_AMU_MASK, ID_AA64PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1)
johpow01fa59c6f2020-10-02 13:41:11 -0500304
Alexei Fedorov19933552020-05-26 13:16:41 +0100305/*
306 * Return MPAM version:
307 *
308 * 0x00: None Armv8.0 or later
309 * 0x01: v0.1 Armv8.4 or later
310 * 0x10: v1.0 Armv8.2 or later
311 * 0x11: v1.1 Armv8.4 or later
312 *
313 */
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200314__attribute__((always_inline))
Sona Mathew9e505f92024-03-13 11:33:54 -0500315static inline bool is_feat_mpam_present(void)
Alexei Fedorov19933552020-05-26 13:16:41 +0100316{
Sona Mathew9e505f92024-03-13 11:33:54 -0500317 unsigned int ret = (unsigned int)((((read_id_aa64pfr0_el1() >>
Alexei Fedorov19933552020-05-26 13:16:41 +0100318 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
Sona Mathew9e505f92024-03-13 11:33:54 -0500319 ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_MPAM_FRAC_SHIFT)
320 & ID_AA64PFR1_MPAM_FRAC_MASK));
321 return ret;
Alexei Fedorov19933552020-05-26 13:16:41 +0100322}
323
Sona Mathew9e505f92024-03-13 11:33:54 -0500324CREATE_FEATURE_SUPPORTED(feat_mpam, is_feat_mpam_present, ENABLE_FEAT_MPAM)
Andre Przywaraf20ad902022-11-15 11:45:19 +0000325
Arvind Ram Prakash05b47632024-05-22 15:24:00 -0500326/*
327 * FEAT_DebugV8P9: Debug extension. This function checks the field 3:0 of
328 * ID_AA64DFR0 Aarch64 Debug Feature Register 0 for the version of
329 * Feat_Debug supported. The value of the field determines feature presence
330 *
331 * 0b0110 - Arm v8.0 debug
332 * 0b0111 - Arm v8.0 debug architecture with Virtualization host extensions
333 * 0x1000 - FEAT_Debugv8p2 is supported
334 * 0x1001 - FEAT_Debugv8p4 is supported
335 * 0x1010 - FEAT_Debugv8p8 is supported
336 * 0x1011 - FEAT_Debugv8p9 is supported
337 *
338 */
339CREATE_FEATURE_FUNCS(feat_debugv8p9, id_aa64dfr0_el1, ID_AA64DFR0_DEBUGVER_SHIFT,
340 ID_AA64DFR0_DEBUGVER_MASK, DEBUGVER_V8P9_IMPLEMENTED,
341 ENABLE_FEAT_DEBUGV8P9)
342
Andre Przywara0dda4242023-04-18 16:58:36 +0100343/* FEAT_HCX: Extended Hypervisor Configuration Register */
344CREATE_FEATURE_FUNCS(feat_hcx, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_HCX_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500345 ID_AA64MMFR1_EL1_HCX_MASK, 1U, ENABLE_FEAT_HCX)
johpow01f91e59f2021-08-04 19:38:18 -0500346
Sona Mathew9e505f92024-03-13 11:33:54 -0500347/* FEAT_RNG_TRAP: Trapping support */
348CREATE_FEATURE_PRESENT(feat_rng_trap, id_aa64pfr1_el1, ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT,
349 ID_AA64PFR1_EL1_RNDR_TRAP_MASK, RNG_TRAP_IMPLEMENTED)
Juan Pablo Conde42305f22022-07-12 16:40:29 -0400350
Sona Mathew9e505f92024-03-13 11:33:54 -0500351/* Return the RME version, zero if not supported. */
352CREATE_FEATURE_FUNCS(feat_rme, id_aa64pfr0_el1, ID_AA64PFR0_FEAT_RME_SHIFT,
353 ID_AA64PFR0_FEAT_RME_MASK, 1U, ENABLE_RME)
Zelalem Aweke79e3d292021-07-08 16:51:14 -0500354
Sona Mathew9e505f92024-03-13 11:33:54 -0500355/* FEAT_SB: Speculation barrier instruction */
356CREATE_FEATURE_PRESENT(feat_sb, id_aa64isar1_el1, ID_AA64ISAR1_SB_SHIFT,
357 ID_AA64ISAR1_SB_MASK, 1U)
Andre Przywara06ea44e2022-11-17 17:30:43 +0000358
Sona Mathew3b84c962023-10-25 16:48:19 -0500359/*
360 * FEAT_CSV2: Cache Speculation Variant 2. This checks bit fields[56-59]
361 * of id_aa64pfr0_el1 register and can be used to check for below features:
362 * FEAT_CSV2_2: Cache Speculation Variant CSV2_2.
363 * FEAT_CSV2_3: Cache Speculation Variant CSV2_3.
364 * 0b0000 - Feature FEAT_CSV2 is not implemented.
365 * 0b0001 - Feature FEAT_CSV2 is implemented, but FEAT_CSV2_2 and FEAT_CSV2_3
366 * are not implemented.
367 * 0b0010 - Feature FEAT_CSV2_2 is implemented but FEAT_CSV2_3 is not
368 * implemented.
369 * 0b0011 - Feature FEAT_CSV2_3 is implemented.
370 */
Sona Mathew3b84c962023-10-25 16:48:19 -0500371
Sona Mathew9e505f92024-03-13 11:33:54 -0500372CREATE_FEATURE_FUNCS(feat_csv2_2, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT,
373 ID_AA64PFR0_CSV2_MASK, CSV2_2_IMPLEMENTED, ENABLE_FEAT_CSV2_2)
374CREATE_FEATURE_FUNCS(feat_csv2_3, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT,
375 ID_AA64PFR0_CSV2_MASK, CSV2_3_IMPLEMENTED, ENABLE_FEAT_CSV2_3)
Andre Przywara06ea44e2022-11-17 17:30:43 +0000376
Andre Przywara0dda4242023-04-18 16:58:36 +0100377/* FEAT_SPE: Statistical Profiling Extension */
378CREATE_FEATURE_FUNCS(feat_spe, id_aa64dfr0_el1, ID_AA64DFR0_PMS_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500379 ID_AA64DFR0_PMS_MASK, 1U, ENABLE_SPE_FOR_NS)
Andre Przywara06ea44e2022-11-17 17:30:43 +0000380
Andre Przywara0dda4242023-04-18 16:58:36 +0100381/* FEAT_SVE: Scalable Vector Extension */
382CREATE_FEATURE_FUNCS(feat_sve, id_aa64pfr0_el1, ID_AA64PFR0_SVE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500383 ID_AA64PFR0_SVE_MASK, 1U, ENABLE_SVE_FOR_NS)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000384
Andre Przywara0dda4242023-04-18 16:58:36 +0100385/* FEAT_RAS: Reliability, Accessibility, Serviceability */
Sona Mathew9e505f92024-03-13 11:33:54 -0500386CREATE_FEATURE_FUNCS(feat_ras, id_aa64pfr0_el1, ID_AA64PFR0_RAS_SHIFT,
387 ID_AA64PFR0_RAS_MASK, 1U, ENABLE_FEAT_RAS)
Andre Przywaraedc449d2023-01-27 14:09:20 +0000388
Andre Przywara0dda4242023-04-18 16:58:36 +0100389/* FEAT_DIT: Data Independent Timing instructions */
Sona Mathew9e505f92024-03-13 11:33:54 -0500390CREATE_FEATURE_FUNCS(feat_dit, id_aa64pfr0_el1, ID_AA64PFR0_DIT_SHIFT,
391 ID_AA64PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT)
Andre Przywaraedc449d2023-01-27 14:09:20 +0000392
Sona Mathew9e505f92024-03-13 11:33:54 -0500393/* FEAT_SYS_REG_TRACE */
394CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_aa64dfr0_el1, ID_AA64DFR0_TRACEVER_SHIFT,
395 ID_AA64DFR0_TRACEVER_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS)
Andre Przywaraedc449d2023-01-27 14:09:20 +0000396
Andre Przywara0dda4242023-04-18 16:58:36 +0100397/* FEAT_TRF: TraceFilter */
398CREATE_FEATURE_FUNCS(feat_trf, id_aa64dfr0_el1, ID_AA64DFR0_TRACEFILT_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500399 ID_AA64DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000400
Andre Przywara0dda4242023-04-18 16:58:36 +0100401/* FEAT_NV2: Enhanced Nested Virtualization */
Sona Mathew9e505f92024-03-13 11:33:54 -0500402CREATE_FEATURE_FUNCS(feat_nv, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT,
403 ID_AA64MMFR2_EL1_NV_MASK, 1U, 0U)
404CREATE_FEATURE_FUNCS(feat_nv2, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT,
405 ID_AA64MMFR2_EL1_NV_MASK, NV2_IMPLEMENTED, CTX_INCLUDE_NEVE_REGS)
Andre Przywarac97c5512022-11-17 16:42:09 +0000406
Andre Przywara0dda4242023-04-18 16:58:36 +0100407/* FEAT_BRBE: Branch Record Buffer Extension */
408CREATE_FEATURE_FUNCS(feat_brbe, id_aa64dfr0_el1, ID_AA64DFR0_BRBE_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500409 ID_AA64DFR0_BRBE_MASK, 1U, ENABLE_BRBE_FOR_NS)
Andre Przywarac97c5512022-11-17 16:42:09 +0000410
Andre Przywara0dda4242023-04-18 16:58:36 +0100411/* FEAT_TRBE: Trace Buffer Extension */
412CREATE_FEATURE_FUNCS(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500413 ID_AA64DFR0_TRACEBUFFER_MASK, 1U, ENABLE_TRBE_FOR_NS)
Andre Przywarac97c5512022-11-17 16:42:09 +0000414
Sona Mathew9e505f92024-03-13 11:33:54 -0500415/* FEAT_SME_FA64: Full A64 Instruction support in streaming SVE mode */
416CREATE_FEATURE_PRESENT(feat_sme_fa64, id_aa64smfr0_el1, ID_AA64SMFR0_EL1_SME_FA64_SHIFT,
417 ID_AA64SMFR0_EL1_SME_FA64_MASK, 1U)
418
Andre Przywara0dda4242023-04-18 16:58:36 +0100419/* FEAT_SMEx: Scalar Matrix Extension */
420CREATE_FEATURE_FUNCS(feat_sme, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT,
Sona Mathew9e505f92024-03-13 11:33:54 -0500421 ID_AA64PFR1_EL1_SME_MASK, 1U, ENABLE_SME_FOR_NS)
422
423CREATE_FEATURE_FUNCS(feat_sme2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT,
424 ID_AA64PFR1_EL1_SME_MASK, SME2_IMPLEMENTED, ENABLE_SME2_FOR_NS)
Jayanth Dodderi Chidanandcfe053a2022-11-08 10:31:07 +0000425
Andre Przywara8fc8e182024-08-09 17:04:22 +0100426/* FEAT_LS64_ACCDATA: */
427CREATE_FEATURE_FUNCS(feat_ls64_accdata, id_aa64isar1_el1, ID_AA64ISAR1_LS64_SHIFT,
428 ID_AA64ISAR1_LS64_MASK, LS64_ACCDATA_IMPLEMENTED,
429 ENABLE_FEAT_LS64_ACCDATA)
430
Javier Almansa Sobrino8c8107e2023-05-03 12:16:11 +0100431/*******************************************************************************
432 * Function to get hardware granularity support
433 ******************************************************************************/
434
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200435__attribute__((always_inline))
Sona Mathew9e505f92024-03-13 11:33:54 -0500436static inline bool is_feat_tgran4K_present(void)
Javier Almansa Sobrino8c8107e2023-05-03 12:16:11 +0100437{
Sona Mathew9e505f92024-03-13 11:33:54 -0500438 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
439 ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_REG_FIELD_MASK);
440 return (tgranx < 8U);
Javier Almansa Sobrino8c8107e2023-05-03 12:16:11 +0100441}
442
Sona Mathew9e505f92024-03-13 11:33:54 -0500443CREATE_FEATURE_PRESENT(feat_tgran16K, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_TGRAN16_SHIFT,
444 ID_AA64MMFR0_EL1_TGRAN16_MASK, TGRAN16_IMPLEMENTED)
Javier Almansa Sobrino8c8107e2023-05-03 12:16:11 +0100445
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200446__attribute__((always_inline))
Sona Mathew9e505f92024-03-13 11:33:54 -0500447static inline bool is_feat_tgran64K_present(void)
Boyan Karatotev05504ba2023-02-15 13:21:50 +0000448{
Sona Mathew9e505f92024-03-13 11:33:54 -0500449 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
450 ID_AA64MMFR0_EL1_TGRAN64_SHIFT, ID_REG_FIELD_MASK);
451 return (tgranx < 8U);
Boyan Karatotev05504ba2023-02-15 13:21:50 +0000452}
453
Sona Mathew9e505f92024-03-13 11:33:54 -0500454/* FEAT_PMUV3 */
455CREATE_FEATURE_PRESENT(feat_pmuv3, id_aa64dfr0_el1, ID_AA64DFR0_PMUVER_SHIFT,
456 ID_AA64DFR0_PMUVER_MASK, 1U)
Boyan Karatotev677ed8a2023-02-16 09:45:29 +0000457
Sona Mathew9e505f92024-03-13 11:33:54 -0500458/* FEAT_MTPMU */
Olivier Deprez5d2a5f22024-06-07 10:57:28 +0200459__attribute__((always_inline))
Sona Mathew9e505f92024-03-13 11:33:54 -0500460static inline bool is_feat_mtpmu_present(void)
Boyan Karatotev677ed8a2023-02-16 09:45:29 +0000461{
Sona Mathew9e505f92024-03-13 11:33:54 -0500462 unsigned int mtpmu = ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU_SHIFT,
463 ID_AA64DFR0_MTPMU_MASK);
Sona Mathewe480ec22024-03-11 15:58:15 -0500464 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED);
Boyan Karatotev677ed8a2023-02-16 09:45:29 +0000465}
466
Sona Mathew9e505f92024-03-13 11:33:54 -0500467CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU)
468
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000469#endif /* ARCH_FEATURES_H */