blob: 757ce06a59282c66ae6a6be62d4ef0685dbdb84d [file] [log] [blame]
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +00001/*
Boyan Karatotevb0b76092025-04-01 13:50:56 +01002 * Copyright (c) 2019-2025, Arm Limited. All rights reserved.
Antonio Nino Diaz2559b2c2019-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 Przywarace485952022-11-10 14:28:01 +000013#include <common/feat_detect.h>
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +000014
Sona Mathewaaaf2cc2024-03-13 11:33:54 -050015#define ISOLATE_FIELD(reg, feat, mask) \
16 ((unsigned int)(((reg) >> (feat)) & mask))
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +010017
Sona Mathewaaaf2cc2024-03-13 11:33:54 -050018#define CREATE_FEATURE_SUPPORTED(name, read_func, guard) \
Olivier Deprez0dfa07b2024-06-07 10:57:28 +020019__attribute__((always_inline)) \
Sona Mathewaaaf2cc2024-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(); \
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +010029}
30
Sona Mathewaaaf2cc2024-03-13 11:33:54 -050031#define CREATE_FEATURE_PRESENT(name, idreg, idfield, mask, idval) \
Olivier Deprez0dfa07b2024-06-07 10:57:28 +020032__attribute__((always_inline)) \
Sona Mathewaaaf2cc2024-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 Prakash33e6aaa2024-06-06 11:33:37 -0500135 * | FEAT_FGT2 |
136 * +----------------------------+
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100137 * | FEAT_THE |
138 * +----------------------------+
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100139 * | FEAT_SCTLR2 |
140 * +----------------------------+
Govindraj Raja30655132024-09-06 15:43:43 +0100141 * | FEAT_D128 |
142 * +----------------------------+
Andre Przywara19d52a82024-08-09 17:04:22 +0100143 * | FEAT_LS64_ACCDATA |
144 * +----------------------------+
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600145 * | FEAT_FPMR |
146 * +----------------------------+
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600147 * | FEAT_MOPS |
148 * +----------------------------+
John Powell025b1b82025-03-10 20:09:03 -0500149 * | FEAT_PAUTH_LR |
150 * +----------------------------+
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500151 */
Andre Przywarafd1dd4c2023-01-25 12:26:14 +0000152
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200153__attribute__((always_inline))
Antonio Nino Diaz29a24132019-02-06 09:23:04 +0000154static inline bool is_armv7_gentimer_present(void)
155{
156 /* The Generic Timer is always present in an ARMv8-A implementation */
157 return true;
158}
159
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500160/* FEAT_PAN: Privileged access never */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100161CREATE_FEATURE_FUNCS(feat_pan, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_PAN_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500162 ID_AA64MMFR1_EL1_PAN_MASK, 1U, ENABLE_FEAT_PAN)
Manish Pandey30f05b42024-01-09 15:55:20 +0000163
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500164/* FEAT_VHE: Virtualization Host Extensions */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100165CREATE_FEATURE_FUNCS(feat_vhe, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_VHE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500166 ID_AA64MMFR1_EL1_VHE_MASK, 1U, ENABLE_FEAT_VHE)
Daniel Boulby37596fc2020-11-25 16:36:46 +0000167
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500168/* FEAT_TTCNP: Translation table common not private */
169CREATE_FEATURE_PRESENT(feat_ttcnp, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_CNP_SHIFT,
170 ID_AA64MMFR2_EL1_CNP_MASK, 1U)
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +0000171
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500172/* FEAT_UAO: User access override */
173CREATE_FEATURE_PRESENT(feat_uao, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_UAO_SHIFT,
174 ID_AA64MMFR2_EL1_UAO_MASK, 1U)
Manish Pandey30f05b42024-01-09 15:55:20 +0000175
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500176/* If any of the fields is not zero, QARMA3 algorithm is present */
177CREATE_FEATURE_PRESENT(feat_pacqarma3, id_aa64isar2_el1, 0,
178 ((ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) |
179 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT)), 1U)
Juan Pablo Conde9ff5f752022-06-29 17:44:43 -0400180
Boyan Karatotevb0b76092025-04-01 13:50:56 +0100181/* FEAT_PAUTH: Pointer Authentication */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200182__attribute__((always_inline))
Boyan Karatotevb0b76092025-04-01 13:50:56 +0100183static inline bool is_feat_pauth_present(void)
Antonio Nino Diazb86048c2019-02-19 11:53:51 +0000184{
Juan Pablo Conde9ff5f752022-06-29 17:44:43 -0400185 uint64_t mask_id_aa64isar1 =
186 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
187 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) |
188 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) |
189 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT);
Antonio Nino Diazb86048c2019-02-19 11:53:51 +0000190
Juan Pablo Conde9ff5f752022-06-29 17:44:43 -0400191 /*
192 * If any of the fields is not zero or QARMA3 is present,
193 * PAuth is present
194 */
195 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U ||
196 is_feat_pacqarma3_present());
Antonio Nino Diazb86048c2019-02-19 11:53:51 +0000197}
Boyan Karatotevb0b76092025-04-01 13:50:56 +0100198CREATE_FEATURE_SUPPORTED(feat_pauth, is_feat_pauth_present, ENABLE_PAUTH)
199CREATE_FEATURE_SUPPORTED(ctx_pauth, is_feat_pauth_present, CTX_INCLUDE_PAUTH_REGS)
Antonio Nino Diazb86048c2019-02-19 11:53:51 +0000200
John Powell025b1b82025-03-10 20:09:03 -0500201/*
202 * FEAT_PAUTH_LR
203 * This feature has a non-standard discovery method so define this function
204 * manually then call use the CREATE_FEATURE_SUPPORTED macro with it. This
205 * feature is enabled with ENABLE_PAUTH when present.
206 */
207__attribute__((always_inline))
208static inline bool is_feat_pauth_lr_present(void)
209{
210 /*
211 * FEAT_PAUTH_LR support is indicated by up to 3 fields, if one or more
212 * of these is 0b0110 then the feature is present.
213 * 1) id_aa64isr1_el1.api
214 * 2) id_aa64isr1_el1.apa
215 * 3) id_aa64isr2_el1.apa3
216 */
217 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_API_SHIFT, ID_AA64ISAR1_API_MASK) == 0b0110) {
218 return true;
219 }
220 if (ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_APA_SHIFT, ID_AA64ISAR1_APA_MASK) == 0b0110) {
221 return true;
222 }
223 if (ISOLATE_FIELD(read_id_aa64isar2_el1(), ID_AA64ISAR2_APA3_SHIFT, ID_AA64ISAR2_APA3_MASK) == 0b0110) {
224 return true;
225 }
226 return false;
227}
228CREATE_FEATURE_SUPPORTED(feat_pauth_lr, is_feat_pauth_lr_present, ENABLE_FEAT_PAUTH_LR)
229
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500230/* FEAT_TTST: Small translation tables */
231CREATE_FEATURE_PRESENT(feat_ttst, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_ST_SHIFT,
232 ID_AA64MMFR2_EL1_ST_MASK, 1U)
Sathees Balyacedfa042019-01-25 11:36:01 +0000233
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500234/* FEAT_BTI: Branch target identification */
Boyan Karatotev10ecd582025-03-26 15:54:55 +0000235CREATE_FEATURE_FUNCS(feat_bti, id_aa64pfr1_el1, ID_AA64PFR1_EL1_BT_SHIFT,
236 ID_AA64PFR1_EL1_BT_MASK, BTI_IMPLEMENTED, ENABLE_BTI)
Alexei Fedorov9fc59632019-05-24 12:17:09 +0100237
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500238/* FEAT_MTE2: Memory tagging extension */
239CREATE_FEATURE_FUNCS(feat_mte2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_MTE_SHIFT,
240 ID_AA64PFR1_EL1_MTE_MASK, MTE_IMPLEMENTED_ELX, ENABLE_FEAT_MTE2)
Manish Pandey30f05b42024-01-09 15:55:20 +0000241
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500242/* FEAT_SSBS: Speculative store bypass safe */
243CREATE_FEATURE_PRESENT(feat_ssbs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SSBS_SHIFT,
244 ID_AA64PFR1_EL1_SSBS_MASK, 1U)
Manish Pandey30f05b42024-01-09 15:55:20 +0000245
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500246/* FEAT_NMI: Non-maskable interrupts */
247CREATE_FEATURE_PRESENT(feat_nmi, id_aa64pfr1_el1, ID_AA64PFR1_EL1_NMI_SHIFT,
248 ID_AA64PFR1_EL1_NMI_MASK, NMI_IMPLEMENTED)
Manish Pandey30f05b42024-01-09 15:55:20 +0000249
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500250/* FEAT_EBEP */
251CREATE_FEATURE_PRESENT(feat_ebep, id_aa64dfr1_el1, ID_AA64DFR1_EBEP_SHIFT,
252 ID_AA64DFR1_EBEP_MASK, EBEP_IMPLEMENTED)
Manish Pandey30f05b42024-01-09 15:55:20 +0000253
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500254/* FEAT_SEBEP */
255CREATE_FEATURE_PRESENT(feat_sebep, id_aa64dfr0_el1, ID_AA64DFR0_SEBEP_SHIFT,
256 ID_AA64DFR0_SEBEP_MASK, SEBEP_IMPLEMENTED)
Manish Pandey30f05b42024-01-09 15:55:20 +0000257
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500258/* FEAT_SEL2: Secure EL2 */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100259CREATE_FEATURE_FUNCS(feat_sel2, id_aa64pfr0_el1, ID_AA64PFR0_SEL2_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500260 ID_AA64PFR0_SEL2_MASK, 1U, ENABLE_FEAT_SEL2)
261
262/* FEAT_TWED: Delayed trapping of WFE */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100263CREATE_FEATURE_FUNCS(feat_twed, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_TWED_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500264 ID_AA64MMFR1_EL1_TWED_MASK, 1U, ENABLE_FEAT_TWED)
265
266/* FEAT_FGT: Fine-grained traps */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100267CREATE_FEATURE_FUNCS(feat_fgt, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500268 ID_AA64MMFR0_EL1_FGT_MASK, 1U, ENABLE_FEAT_FGT)
269
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500270/* FEAT_FGT2: Fine-grained traps extended */
271CREATE_FEATURE_FUNCS(feat_fgt2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_FGT_SHIFT,
272 ID_AA64MMFR0_EL1_FGT_MASK, FGT2_IMPLEMENTED, ENABLE_FEAT_FGT2)
273
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500274/* FEAT_ECV: Enhanced Counter Virtualization */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100275CREATE_FEATURE_FUNCS(feat_ecv, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500276 ID_AA64MMFR0_EL1_ECV_MASK, 1U, ENABLE_FEAT_ECV)
277CREATE_FEATURE_FUNCS(feat_ecv_v2, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_ECV_SHIFT,
278 ID_AA64MMFR0_EL1_ECV_MASK, ID_AA64MMFR0_EL1_ECV_SELF_SYNCH, ENABLE_FEAT_ECV)
Andre Przywara623f6142023-02-22 16:53:50 +0000279
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500280/* FEAT_RNG: Random number generator */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100281CREATE_FEATURE_FUNCS(feat_rng, id_aa64isar0_el1, ID_AA64ISAR0_RNDR_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500282 ID_AA64ISAR0_RNDR_MASK, 1U, ENABLE_FEAT_RNG)
Andre Przywara623f6142023-02-22 16:53:50 +0000283
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500284/* FEAT_TCR2: Support TCR2_ELx regs */
285CREATE_FEATURE_FUNCS(feat_tcr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_TCRX_SHIFT,
286 ID_AA64MMFR3_EL1_TCRX_MASK, 1U, ENABLE_FEAT_TCR2)
287
288/* FEAT_S2POE */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100289CREATE_FEATURE_FUNCS(feat_s2poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2POE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500290 ID_AA64MMFR3_EL1_S2POE_MASK, 1U, ENABLE_FEAT_S2POE)
291
292/* FEAT_S1POE */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100293CREATE_FEATURE_FUNCS(feat_s1poe, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1POE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500294 ID_AA64MMFR3_EL1_S1POE_MASK, 1U, ENABLE_FEAT_S1POE)
295
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200296__attribute__((always_inline))
Mark Brown062b6c62023-03-14 20:48:43 +0000297static inline bool is_feat_sxpoe_supported(void)
298{
299 return is_feat_s1poe_supported() || is_feat_s2poe_supported();
300}
301
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500302/* FEAT_S2PIE */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100303CREATE_FEATURE_FUNCS(feat_s2pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S2PIE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500304 ID_AA64MMFR3_EL1_S2PIE_MASK, 1U, ENABLE_FEAT_S2PIE)
305
306/* FEAT_S1PIE */
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100307CREATE_FEATURE_FUNCS(feat_s1pie, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_S1PIE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500308 ID_AA64MMFR3_EL1_S1PIE_MASK, 1U, ENABLE_FEAT_S1PIE)
309
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100310/* FEAT_THE: Translation Hardening Extension */
311CREATE_FEATURE_FUNCS(feat_the, id_aa64pfr1_el1, ID_AA64PFR1_EL1_THE_SHIFT,
312 ID_AA64PFR1_EL1_THE_MASK, THE_IMPLEMENTED, ENABLE_FEAT_THE)
313
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100314/* FEAT_SCTLR2 */
315CREATE_FEATURE_FUNCS(feat_sctlr2, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_SCTLR2_SHIFT,
316 ID_AA64MMFR3_EL1_SCTLR2_MASK, SCTLR2_IMPLEMENTED,
317 ENABLE_FEAT_SCTLR2)
318
Govindraj Raja30655132024-09-06 15:43:43 +0100319/* FEAT_D128 */
320CREATE_FEATURE_FUNCS(feat_d128, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_D128_SHIFT,
321 ID_AA64MMFR3_EL1_D128_MASK, D128_IMPLEMENTED,
322 ENABLE_FEAT_D128)
323
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600324/* FEAT_FPMR */
325CREATE_FEATURE_FUNCS(feat_fpmr, id_aa64pfr2_el1, ID_AA64PFR2_EL1_FPMR_SHIFT,
326 ID_AA64PFR2_EL1_FPMR_MASK, FPMR_IMPLEMENTED,
327 ENABLE_FEAT_FPMR)
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600328/* FEAT_MOPS */
329CREATE_FEATURE_FUNCS(feat_mops, id_aa64isar2_el1, ID_AA64ISAR2_EL1_MOPS_SHIFT,
330 ID_AA64ISAR2_EL1_MOPS_MASK, MOPS_IMPLEMENTED,
331 ENABLE_FEAT_MOPS)
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600332
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200333__attribute__((always_inline))
Mark Brown062b6c62023-03-14 20:48:43 +0000334static inline bool is_feat_sxpie_supported(void)
335{
336 return is_feat_s1pie_supported() || is_feat_s2pie_supported();
337}
338
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100339/* FEAT_GCS: Guarded Control Stack */
340CREATE_FEATURE_FUNCS(feat_gcs, id_aa64pfr1_el1, ID_AA64PFR1_EL1_GCS_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500341 ID_AA64PFR1_EL1_GCS_MASK, 1U, ENABLE_FEAT_GCS)
Mark Brown688ab572023-03-14 21:33:04 +0000342
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100343/* FEAT_AMU: Activity Monitors Extension */
344CREATE_FEATURE_FUNCS(feat_amu, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500345 ID_AA64PFR0_AMU_MASK, 1U, ENABLE_FEAT_AMU)
346
Boyan Karatotev83ec7e42024-11-06 14:55:35 +0000347/* Auxiliary counters for FEAT_AMU */
348CREATE_FEATURE_FUNCS(feat_amu_aux, amcfgr_el0, AMCFGR_EL0_NCG_SHIFT,
349 AMCFGR_EL0_NCG_MASK, 1U, ENABLE_AMU_AUXILIARY_COUNTERS)
350
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500351/* FEAT_AMUV1P1: AMU Extension v1.1 */
352CREATE_FEATURE_FUNCS(feat_amuv1p1, id_aa64pfr0_el1, ID_AA64PFR0_AMU_SHIFT,
353 ID_AA64PFR0_AMU_MASK, ID_AA64PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1)
johpow01873d4242020-10-02 13:41:11 -0500354
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +0100355/*
356 * Return MPAM version:
357 *
358 * 0x00: None Armv8.0 or later
359 * 0x01: v0.1 Armv8.4 or later
360 * 0x10: v1.0 Armv8.2 or later
361 * 0x11: v1.1 Armv8.4 or later
362 *
363 */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200364__attribute__((always_inline))
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500365static inline bool is_feat_mpam_present(void)
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +0100366{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500367 unsigned int ret = (unsigned int)((((read_id_aa64pfr0_el1() >>
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +0100368 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500369 ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_MPAM_FRAC_SHIFT)
370 & ID_AA64PFR1_MPAM_FRAC_MASK));
371 return ret;
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +0100372}
373
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500374CREATE_FEATURE_SUPPORTED(feat_mpam, is_feat_mpam_present, ENABLE_FEAT_MPAM)
Andre Przywara9448f2b2022-11-17 16:42:09 +0000375
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500376/*
377 * FEAT_DebugV8P9: Debug extension. This function checks the field 3:0 of
378 * ID_AA64DFR0 Aarch64 Debug Feature Register 0 for the version of
379 * Feat_Debug supported. The value of the field determines feature presence
380 *
381 * 0b0110 - Arm v8.0 debug
382 * 0b0111 - Arm v8.0 debug architecture with Virtualization host extensions
383 * 0x1000 - FEAT_Debugv8p2 is supported
384 * 0x1001 - FEAT_Debugv8p4 is supported
385 * 0x1010 - FEAT_Debugv8p8 is supported
386 * 0x1011 - FEAT_Debugv8p9 is supported
387 *
388 */
389CREATE_FEATURE_FUNCS(feat_debugv8p9, id_aa64dfr0_el1, ID_AA64DFR0_DEBUGVER_SHIFT,
390 ID_AA64DFR0_DEBUGVER_MASK, DEBUGVER_V8P9_IMPLEMENTED,
391 ENABLE_FEAT_DEBUGV8P9)
392
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100393/* FEAT_HCX: Extended Hypervisor Configuration Register */
394CREATE_FEATURE_FUNCS(feat_hcx, id_aa64mmfr1_el1, ID_AA64MMFR1_EL1_HCX_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500395 ID_AA64MMFR1_EL1_HCX_MASK, 1U, ENABLE_FEAT_HCX)
johpow01cb4ec472021-08-04 19:38:18 -0500396
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500397/* FEAT_RNG_TRAP: Trapping support */
Boyan Karatotev79c0c7f2024-12-10 17:13:51 +0000398CREATE_FEATURE_FUNCS(feat_rng_trap, id_aa64pfr1_el1, ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT,
399 ID_AA64PFR1_EL1_RNDR_TRAP_MASK, RNG_TRAP_IMPLEMENTED, ENABLE_FEAT_RNG_TRAP)
Juan Pablo Condeff86e0b2022-07-12 16:40:29 -0400400
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500401/* Return the RME version, zero if not supported. */
402CREATE_FEATURE_FUNCS(feat_rme, id_aa64pfr0_el1, ID_AA64PFR0_FEAT_RME_SHIFT,
403 ID_AA64PFR0_FEAT_RME_MASK, 1U, ENABLE_RME)
Zelalem Aweke81c272b2021-07-08 16:51:14 -0500404
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500405/* FEAT_SB: Speculation barrier instruction */
406CREATE_FEATURE_PRESENT(feat_sb, id_aa64isar1_el1, ID_AA64ISAR1_SB_SHIFT,
407 ID_AA64ISAR1_SB_MASK, 1U)
Jayanth Dodderi Chidanand6a0da732022-01-17 18:57:17 +0000408
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000409/* FEAT_MEC: Memory Encryption Contexts */
410CREATE_FEATURE_FUNCS(feat_mec, id_aa64mmfr3_el1, ID_AA64MMFR3_EL1_MEC_SHIFT,
411 ID_AA64MMFR3_EL1_MEC_MASK, 1U, ENABLE_FEAT_MEC)
412
Sona Mathew30019d82023-10-25 16:48:19 -0500413/*
414 * FEAT_CSV2: Cache Speculation Variant 2. This checks bit fields[56-59]
415 * of id_aa64pfr0_el1 register and can be used to check for below features:
416 * FEAT_CSV2_2: Cache Speculation Variant CSV2_2.
417 * FEAT_CSV2_3: Cache Speculation Variant CSV2_3.
418 * 0b0000 - Feature FEAT_CSV2 is not implemented.
419 * 0b0001 - Feature FEAT_CSV2 is implemented, but FEAT_CSV2_2 and FEAT_CSV2_3
420 * are not implemented.
421 * 0b0010 - Feature FEAT_CSV2_2 is implemented but FEAT_CSV2_3 is not
422 * implemented.
423 * 0b0011 - Feature FEAT_CSV2_3 is implemented.
424 */
Sona Mathew30019d82023-10-25 16:48:19 -0500425
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500426CREATE_FEATURE_FUNCS(feat_csv2_2, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT,
427 ID_AA64PFR0_CSV2_MASK, CSV2_2_IMPLEMENTED, ENABLE_FEAT_CSV2_2)
428CREATE_FEATURE_FUNCS(feat_csv2_3, id_aa64pfr0_el1, ID_AA64PFR0_CSV2_SHIFT,
429 ID_AA64PFR0_CSV2_MASK, CSV2_3_IMPLEMENTED, ENABLE_FEAT_CSV2_3)
Andre Przywara7db710f2022-11-17 17:30:43 +0000430
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100431/* FEAT_SPE: Statistical Profiling Extension */
432CREATE_FEATURE_FUNCS(feat_spe, id_aa64dfr0_el1, ID_AA64DFR0_PMS_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500433 ID_AA64DFR0_PMS_MASK, 1U, ENABLE_SPE_FOR_NS)
Andre Przywara7db710f2022-11-17 17:30:43 +0000434
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100435/* FEAT_SVE: Scalable Vector Extension */
436CREATE_FEATURE_FUNCS(feat_sve, id_aa64pfr0_el1, ID_AA64PFR0_SVE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500437 ID_AA64PFR0_SVE_MASK, 1U, ENABLE_SVE_FOR_NS)
Andre Przywara7db710f2022-11-17 17:30:43 +0000438
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100439/* FEAT_RAS: Reliability, Accessibility, Serviceability */
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500440CREATE_FEATURE_FUNCS(feat_ras, id_aa64pfr0_el1, ID_AA64PFR0_RAS_SHIFT,
441 ID_AA64PFR0_RAS_MASK, 1U, ENABLE_FEAT_RAS)
Jayanth Dodderi Chidanand6a0da732022-01-17 18:57:17 +0000442
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100443/* FEAT_DIT: Data Independent Timing instructions */
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500444CREATE_FEATURE_FUNCS(feat_dit, id_aa64pfr0_el1, ID_AA64PFR0_DIT_SHIFT,
445 ID_AA64PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT)
Andre Przywara6437a092022-11-17 16:42:09 +0000446
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500447/* FEAT_SYS_REG_TRACE */
448CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_aa64dfr0_el1, ID_AA64DFR0_TRACEVER_SHIFT,
449 ID_AA64DFR0_TRACEVER_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS)
Andre Przywara6437a092022-11-17 16:42:09 +0000450
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100451/* FEAT_TRF: TraceFilter */
452CREATE_FEATURE_FUNCS(feat_trf, id_aa64dfr0_el1, ID_AA64DFR0_TRACEFILT_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500453 ID_AA64DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS)
Andre Przywara6437a092022-11-17 16:42:09 +0000454
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100455/* FEAT_NV2: Enhanced Nested Virtualization */
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500456CREATE_FEATURE_FUNCS(feat_nv, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT,
457 ID_AA64MMFR2_EL1_NV_MASK, 1U, 0U)
458CREATE_FEATURE_FUNCS(feat_nv2, id_aa64mmfr2_el1, ID_AA64MMFR2_EL1_NV_SHIFT,
459 ID_AA64MMFR2_EL1_NV_MASK, NV2_IMPLEMENTED, CTX_INCLUDE_NEVE_REGS)
Jayanth Dodderi Chidanand6a0da732022-01-17 18:57:17 +0000460
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100461/* FEAT_BRBE: Branch Record Buffer Extension */
462CREATE_FEATURE_FUNCS(feat_brbe, id_aa64dfr0_el1, ID_AA64DFR0_BRBE_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500463 ID_AA64DFR0_BRBE_MASK, 1U, ENABLE_BRBE_FOR_NS)
Jayanth Dodderi Chidanand2b0bc4e2023-03-07 10:43:19 +0000464
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100465/* FEAT_TRBE: Trace Buffer Extension */
466CREATE_FEATURE_FUNCS(feat_trbe, id_aa64dfr0_el1, ID_AA64DFR0_TRACEBUFFER_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500467 ID_AA64DFR0_TRACEBUFFER_MASK, 1U, ENABLE_TRBE_FOR_NS)
Jayanth Dodderi Chidanand2b0bc4e2023-03-07 10:43:19 +0000468
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500469/* FEAT_SME_FA64: Full A64 Instruction support in streaming SVE mode */
470CREATE_FEATURE_PRESENT(feat_sme_fa64, id_aa64smfr0_el1, ID_AA64SMFR0_EL1_SME_FA64_SHIFT,
471 ID_AA64SMFR0_EL1_SME_FA64_MASK, 1U)
472
Andre Przywaraa8d5d3d2023-04-18 16:58:36 +0100473/* FEAT_SMEx: Scalar Matrix Extension */
474CREATE_FEATURE_FUNCS(feat_sme, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT,
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500475 ID_AA64PFR1_EL1_SME_MASK, 1U, ENABLE_SME_FOR_NS)
476
477CREATE_FEATURE_FUNCS(feat_sme2, id_aa64pfr1_el1, ID_AA64PFR1_EL1_SME_SHIFT,
478 ID_AA64PFR1_EL1_SME_MASK, SME2_IMPLEMENTED, ENABLE_SME2_FOR_NS)
Jayanth Dodderi Chidanand03d3c0d2022-11-08 10:31:07 +0000479
Andre Przywara19d52a82024-08-09 17:04:22 +0100480/* FEAT_LS64_ACCDATA: */
481CREATE_FEATURE_FUNCS(feat_ls64_accdata, id_aa64isar1_el1, ID_AA64ISAR1_LS64_SHIFT,
482 ID_AA64ISAR1_LS64_MASK, LS64_ACCDATA_IMPLEMENTED,
483 ENABLE_FEAT_LS64_ACCDATA)
484
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100485/*******************************************************************************
486 * Function to get hardware granularity support
487 ******************************************************************************/
488
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200489__attribute__((always_inline))
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500490static inline bool is_feat_tgran4K_present(void)
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100491{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500492 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
493 ID_AA64MMFR0_EL1_TGRAN4_SHIFT, ID_REG_FIELD_MASK);
494 return (tgranx < 8U);
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100495}
496
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500497CREATE_FEATURE_PRESENT(feat_tgran16K, id_aa64mmfr0_el1, ID_AA64MMFR0_EL1_TGRAN16_SHIFT,
498 ID_AA64MMFR0_EL1_TGRAN16_MASK, TGRAN16_IMPLEMENTED)
499
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200500__attribute__((always_inline))
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500501static inline bool is_feat_tgran64K_present(void)
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100502{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500503 unsigned int tgranx = ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
504 ID_AA64MMFR0_EL1_TGRAN64_SHIFT, ID_REG_FIELD_MASK);
505 return (tgranx < 8U);
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100506}
507
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500508/* FEAT_PMUV3 */
509CREATE_FEATURE_PRESENT(feat_pmuv3, id_aa64dfr0_el1, ID_AA64DFR0_PMUVER_SHIFT,
510 ID_AA64DFR0_PMUVER_MASK, 1U)
511
512/* FEAT_MTPMU */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200513__attribute__((always_inline))
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500514static inline bool is_feat_mtpmu_present(void)
Javier Almansa Sobrinobff074d2023-05-03 12:16:11 +0100515{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500516 unsigned int mtpmu = ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU_SHIFT,
517 ID_AA64DFR0_MTPMU_MASK);
Sona Mathew9e51f152024-03-11 15:58:15 -0500518 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED);
Boyan Karatotev83a4dae2023-02-16 09:45:29 +0000519}
520
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500521CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU)
522
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +0000523#endif /* ARCH_FEATURES_H */