blob: 9d719877b752418f80fc72833456262edced4ca0 [file] [log] [blame]
Antonio Nino Diazc326c342019-01-11 11:20:10 +00001/*
Andre Przywarabb0db3b2023-01-25 12:26:14 +00002 * Copyright (c) 2019-2023, 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
Andre Przywarabb0db3b2023-01-25 12:26:14 +000015#define ISOLATE_FIELD(reg, feat) \
16 ((unsigned int)(((reg) >> (feat ## _SHIFT)) & (feat ## _MASK)))
17
Antonio Nino Diazd29d21e2019-02-06 09:23:04 +000018static inline bool is_armv7_gentimer_present(void)
19{
20 /* The Generic Timer is always present in an ARMv8-A implementation */
21 return true;
22}
23
Andre Przywara97272942023-01-26 15:27:38 +000024static inline unsigned int read_feat_pan_id_field(void)
25{
26 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_PAN);
27}
28
29static inline bool is_feat_pan_supported(void)
Daniel Boulby44b43332020-11-25 16:36:46 +000030{
Andre Przywara97272942023-01-26 15:27:38 +000031 if (ENABLE_FEAT_PAN == FEAT_STATE_DISABLED) {
32 return false;
33 }
34
35 if (ENABLE_FEAT_PAN == FEAT_STATE_ALWAYS) {
36 return true;
37 }
38
39 return read_feat_pan_id_field() != 0U;
Daniel Boulby44b43332020-11-25 16:36:46 +000040}
41
Andre Przywara98908b32022-11-17 16:42:09 +000042static inline unsigned int read_feat_vhe_id_field(void)
43{
44 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_VHE);
45}
46
47static inline bool is_feat_vhe_supported(void)
Daniel Boulby44b43332020-11-25 16:36:46 +000048{
Andre Przywara98908b32022-11-17 16:42:09 +000049 if (ENABLE_FEAT_VHE == FEAT_STATE_DISABLED) {
50 return false;
51 }
52
53 if (ENABLE_FEAT_VHE == FEAT_STATE_ALWAYS) {
54 return true;
55 }
56
57 return read_feat_vhe_id_field() != 0U;
Daniel Boulby44b43332020-11-25 16:36:46 +000058}
59
Antonio Nino Diazc326c342019-01-11 11:20:10 +000060static inline bool is_armv8_2_ttcnp_present(void)
61{
62 return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) &
63 ID_AA64MMFR2_EL1_CNP_MASK) != 0U;
64}
65
Juan Pablo Condee089a172022-06-29 17:44:43 -040066static inline bool is_feat_pacqarma3_present(void)
67{
68 uint64_t mask_id_aa64isar2 =
69 (ID_AA64ISAR2_GPA3_MASK << ID_AA64ISAR2_GPA3_SHIFT) |
70 (ID_AA64ISAR2_APA3_MASK << ID_AA64ISAR2_APA3_SHIFT);
71
72 /* If any of the fields is not zero, QARMA3 algorithm is present */
73 return (read_id_aa64isar2_el1() & mask_id_aa64isar2) != 0U;
74}
75
Antonio Nino Diaz25cda672019-02-19 11:53:51 +000076static inline bool is_armv8_3_pauth_present(void)
77{
Juan Pablo Condee089a172022-06-29 17:44:43 -040078 uint64_t mask_id_aa64isar1 =
79 (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) |
80 (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) |
81 (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) |
82 (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT);
Antonio Nino Diaz25cda672019-02-19 11:53:51 +000083
Juan Pablo Condee089a172022-06-29 17:44:43 -040084 /*
85 * If any of the fields is not zero or QARMA3 is present,
86 * PAuth is present
87 */
88 return ((read_id_aa64isar1_el1() & mask_id_aa64isar1) != 0U ||
89 is_feat_pacqarma3_present());
Antonio Nino Diaz25cda672019-02-19 11:53:51 +000090}
91
Sathees Balya74155972019-01-25 11:36:01 +000092static inline bool is_armv8_4_ttst_present(void)
93{
94 return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
95 ID_AA64MMFR2_EL1_ST_MASK) == 1U;
96}
97
Alexei Fedorov90f2e882019-05-24 12:17:09 +010098static inline bool is_armv8_5_bti_present(void)
99{
100 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) &
101 ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
102}
103
Soby Mathew830f0ad2019-07-12 09:23:38 +0100104static inline unsigned int get_armv8_5_mte_support(void)
105{
106 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
107 ID_AA64PFR1_EL1_MTE_MASK);
108}
109
Andre Przywara6dd2d062023-02-22 16:53:50 +0000110static inline unsigned int read_feat_sel2_id_field(void)
111{
112 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_SEL2);
113}
114
115static inline bool is_feat_sel2_supported(void)
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200116{
Andre Przywara6dd2d062023-02-22 16:53:50 +0000117 if (ENABLE_FEAT_SEL2 == FEAT_STATE_DISABLED) {
118 return false;
119 }
120
121 if (ENABLE_FEAT_SEL2 == FEAT_STATE_ALWAYS) {
122 return true;
123 }
124
125 return read_feat_sel2_id_field() != 0U;
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200126}
127
Andre Przywara0cf77402023-01-27 12:25:49 +0000128static inline unsigned int read_feat_twed_id_field(void)
129{
130 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_TWED);
131}
132
133static inline bool is_feat_twed_supported(void)
johpow013e24c162020-04-22 14:05:13 -0500134{
Andre Przywara0cf77402023-01-27 12:25:49 +0000135 if (ENABLE_FEAT_TWED == FEAT_STATE_DISABLED) {
136 return false;
137 }
138
139 if (ENABLE_FEAT_TWED == FEAT_STATE_ALWAYS) {
140 return true;
141 }
142
143 return read_feat_twed_id_field() != 0U;
johpow013e24c162020-04-22 14:05:13 -0500144}
145
Andre Przywarae8920f62022-11-10 14:28:01 +0000146static unsigned int read_feat_fgt_id_field(void)
Jimmy Brissonecc3c672020-04-16 10:47:56 -0500147{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000148 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(), ID_AA64MMFR0_EL1_FGT);
Andre Przywarae8920f62022-11-10 14:28:01 +0000149}
150
151static inline bool is_feat_fgt_supported(void)
152{
153 if (ENABLE_FEAT_FGT == FEAT_STATE_DISABLED) {
154 return false;
155 }
156
157 if (ENABLE_FEAT_FGT == FEAT_STATE_ALWAYS) {
158 return true;
159 }
160
161 return read_feat_fgt_id_field() != 0U;
Jimmy Brissonecc3c672020-04-16 10:47:56 -0500162}
163
Andre Przywarac3464182022-11-17 17:30:43 +0000164static unsigned int read_feat_ecv_id_field(void)
165{
166 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(), ID_AA64MMFR0_EL1_ECV);
167}
168
169static inline bool is_feat_ecv_supported(void)
170{
171 if (ENABLE_FEAT_ECV == FEAT_STATE_DISABLED) {
172 return false;
173 }
174
175 if (ENABLE_FEAT_ECV == FEAT_STATE_ALWAYS) {
176 return true;
177 }
178
179 return read_feat_ecv_id_field() != 0U;
180}
181
182static inline bool is_feat_ecv_v2_supported(void)
Jimmy Brisson83573892020-04-16 10:48:02 -0500183{
Andre Przywarac3464182022-11-17 17:30:43 +0000184 if (ENABLE_FEAT_ECV == FEAT_STATE_DISABLED) {
185 return false;
186 }
187
188 if (ENABLE_FEAT_ECV == FEAT_STATE_ALWAYS) {
189 return true;
190 }
191
192 return read_feat_ecv_id_field() >= ID_AA64MMFR0_EL1_ECV_SELF_SYNCH;
Jimmy Brisson83573892020-04-16 10:48:02 -0500193}
194
Andre Przywara436b4bb2023-02-22 17:55:59 +0000195static unsigned int read_feat_rng_id_field(void)
196{
197 return ISOLATE_FIELD(read_id_aa64isar0_el1(), ID_AA64ISAR0_RNDR);
198}
199
200static inline bool is_feat_rng_supported(void)
Tomas Pilar6fd816e2020-10-28 15:34:12 +0000201{
Andre Przywara436b4bb2023-02-22 17:55:59 +0000202 if (ENABLE_FEAT_RNG == FEAT_STATE_DISABLED) {
203 return false;
204 }
205
206 if (ENABLE_FEAT_RNG == FEAT_STATE_ALWAYS) {
207 return true;
208 }
209
210 return read_feat_rng_id_field() != 0U;
Tomas Pilar6fd816e2020-10-28 15:34:12 +0000211}
212
Mark Brownc37eee72023-03-14 20:13:03 +0000213static unsigned int read_feat_tcrx_id_field(void)
214{
215 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_TCRX);
216}
217
218static inline bool is_feat_tcr2_supported(void)
219{
220 if (ENABLE_FEAT_TCR2 == FEAT_STATE_DISABLED) {
221 return false;
222 }
223
224 if (ENABLE_FEAT_TCR2 == FEAT_STATE_ALWAYS) {
225 return true;
226 }
227
228 return read_feat_tcrx_id_field() != 0U;
229}
230
Mark Brown293a6612023-03-14 20:48:43 +0000231static unsigned int read_feat_s2poe_id_field(void)
232{
233 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S2POE);
234}
235
236static inline bool is_feat_s2poe_supported(void)
237{
238 if (ENABLE_FEAT_S2POE == FEAT_STATE_DISABLED) {
239 return false;
240 }
241
242 if (ENABLE_FEAT_S2POE == FEAT_STATE_ALWAYS) {
243 return true;
244 }
245
246 return read_feat_s2poe_id_field() != 0U;
247}
248
249static unsigned int read_feat_s1poe_id_field(void)
250{
251 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S1POE);
252}
253
254static inline bool is_feat_s1poe_supported(void)
255{
256 if (ENABLE_FEAT_S1POE == FEAT_STATE_DISABLED) {
257 return false;
258 }
259
260 if (ENABLE_FEAT_S1POE == FEAT_STATE_ALWAYS) {
261 return true;
262 }
263
264 return read_feat_s1poe_id_field() != 0U;
265}
266
267static inline bool is_feat_sxpoe_supported(void)
268{
269 return is_feat_s1poe_supported() || is_feat_s2poe_supported();
270}
271
272static unsigned int read_feat_s2pie_id_field(void)
273{
274 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S2PIE);
275}
276
277static inline bool is_feat_s2pie_supported(void)
278{
279 if (ENABLE_FEAT_S2PIE == FEAT_STATE_DISABLED) {
280 return false;
281 }
282
283 if (ENABLE_FEAT_S2PIE == FEAT_STATE_ALWAYS) {
284 return true;
285 }
286
287 return read_feat_s2pie_id_field() != 0U;
288}
289
290static unsigned int read_feat_s1pie_id_field(void)
291{
292 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S1PIE);
293}
294
295static inline bool is_feat_s1pie_supported(void)
296{
297 if (ENABLE_FEAT_S1PIE == FEAT_STATE_DISABLED) {
298 return false;
299 }
300
301 if (ENABLE_FEAT_S1PIE == FEAT_STATE_ALWAYS) {
302 return true;
303 }
304
305 return read_feat_s1pie_id_field() != 0U;
306}
307
308static inline bool is_feat_sxpie_supported(void)
309{
310 return is_feat_s1pie_supported() || is_feat_s2pie_supported();
311}
312
Mark Brown326f2952023-03-14 21:33:04 +0000313static unsigned int read_feat_gcs_id_field(void)
314{
315 return ISOLATE_FIELD(read_id_aa64pfr1_el1(), ID_AA64PFR1_EL1_GCS);
316}
317
318static inline bool is_feat_gcs_supported(void)
319{
320 if (ENABLE_FEAT_GCS == FEAT_STATE_DISABLED) {
321 return false;
322 }
323
324 if (ENABLE_FEAT_GCS == FEAT_STATE_ALWAYS) {
325 return true;
326 }
327
328 return read_feat_gcs_id_field() != 0U;
329}
330
Andre Przywara2c550e32022-11-10 14:41:07 +0000331/*******************************************************************************
332 * Functions to identify the presence of the Activity Monitors Extension
333 ******************************************************************************/
334static unsigned int read_feat_amu_id_field(void)
335{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000336 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_AMU);
Andre Przywara2c550e32022-11-10 14:41:07 +0000337}
338
339static inline bool is_feat_amu_supported(void)
340{
Andre Przywara0b7f1b02023-03-21 13:53:19 +0000341 if (ENABLE_FEAT_AMU == FEAT_STATE_DISABLED) {
Andre Przywara2c550e32022-11-10 14:41:07 +0000342 return false;
343 }
344
Andre Przywara0b7f1b02023-03-21 13:53:19 +0000345 if (ENABLE_FEAT_AMU == FEAT_STATE_ALWAYS) {
Andre Przywara2c550e32022-11-10 14:41:07 +0000346 return true;
347 }
348
349 return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1;
350}
351
Andre Przywara906776e2023-03-03 10:30:06 +0000352static inline bool is_feat_amuv1p1_supported(void)
johpow01fa59c6f2020-10-02 13:41:11 -0500353{
Andre Przywara906776e2023-03-03 10:30:06 +0000354 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_DISABLED) {
355 return false;
356 }
357
358 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_ALWAYS) {
359 return true;
360 }
361
Andre Przywara2c550e32022-11-10 14:41:07 +0000362 return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1P1;
johpow01fa59c6f2020-10-02 13:41:11 -0500363}
364
Alexei Fedorov19933552020-05-26 13:16:41 +0100365/*
366 * Return MPAM version:
367 *
368 * 0x00: None Armv8.0 or later
369 * 0x01: v0.1 Armv8.4 or later
370 * 0x10: v1.0 Armv8.2 or later
371 * 0x11: v1.1 Armv8.4 or later
372 *
373 */
Andre Przywara84b86532022-11-17 16:42:09 +0000374static inline unsigned int read_feat_mpam_version(void)
Alexei Fedorov19933552020-05-26 13:16:41 +0100375{
376 return (unsigned int)((((read_id_aa64pfr0_el1() >>
377 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
378 ((read_id_aa64pfr1_el1() >>
379 ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK));
380}
381
Andre Przywara84b86532022-11-17 16:42:09 +0000382static inline bool is_feat_mpam_supported(void)
383{
384 if (ENABLE_MPAM_FOR_LOWER_ELS == FEAT_STATE_DISABLED) {
385 return false;
386 }
387
388 if (ENABLE_MPAM_FOR_LOWER_ELS == FEAT_STATE_ALWAYS) {
389 return true;
390 }
391
392 return read_feat_mpam_version() != 0U;
393}
394
Andre Przywaraf20ad902022-11-15 11:45:19 +0000395static inline unsigned int read_feat_hcx_id_field(void)
396{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000397 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_HCX);
Andre Przywaraf20ad902022-11-15 11:45:19 +0000398}
399
400static inline bool is_feat_hcx_supported(void)
johpow01f91e59f2021-08-04 19:38:18 -0500401{
Andre Przywaraf20ad902022-11-15 11:45:19 +0000402 if (ENABLE_FEAT_HCX == FEAT_STATE_DISABLED) {
403 return false;
404 }
405
406 if (ENABLE_FEAT_HCX == FEAT_STATE_ALWAYS) {
407 return true;
408 }
409
410 return read_feat_hcx_id_field() != 0U;
johpow01f91e59f2021-08-04 19:38:18 -0500411}
412
Juan Pablo Conde42305f22022-07-12 16:40:29 -0400413static inline bool is_feat_rng_trap_present(void)
414{
415 return (((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT) &
416 ID_AA64PFR1_EL1_RNDR_TRAP_MASK)
417 == ID_AA64PFR1_EL1_RNG_TRAP_SUPPORTED);
418}
419
Zelalem Aweke79e3d292021-07-08 16:51:14 -0500420static inline unsigned int get_armv9_2_feat_rme_support(void)
421{
422 /*
423 * Return the RME version, zero if not supported. This function can be
424 * used as both an integer value for the RME version or compared to zero
425 * to detect RME presence.
426 */
427 return (unsigned int)(read_id_aa64pfr0_el1() >>
428 ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK;
429}
430
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000431/*********************************************************************************
432 * Function to identify the presence of FEAT_SB (Speculation Barrier Instruction)
433 ********************************************************************************/
Andre Przywara46880dc2022-11-17 16:42:09 +0000434static inline unsigned int read_feat_sb_id_field(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000435{
Andre Przywara46880dc2022-11-17 16:42:09 +0000436 return ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_SB);
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000437}
438
439/*********************************************************************************
440 * Function to identify the presence of FEAT_CSV2_2 (Cache Speculation Variant 2)
441 ********************************************************************************/
Andre Przywara902c9022022-11-17 17:30:43 +0000442static inline unsigned int read_feat_csv2_id_field(void)
443{
444 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_CSV2);
445}
446
447static inline bool is_feat_csv2_2_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000448{
Andre Przywara902c9022022-11-17 17:30:43 +0000449 if (ENABLE_FEAT_CSV2_2 == FEAT_STATE_DISABLED) {
450 return false;
451 }
452
453 if (ENABLE_FEAT_CSV2_2 == FEAT_STATE_ALWAYS) {
454 return true;
455 }
456
457 return read_feat_csv2_id_field() >= ID_AA64PFR0_CSV2_2_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000458}
459
460/**********************************************************************************
461 * Function to identify the presence of FEAT_SPE (Statistical Profiling Extension)
462 *********************************************************************************/
Andre Przywaraf3e8cfc2022-11-17 16:42:09 +0000463static inline unsigned int read_feat_spe_id_field(void)
464{
465 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_PMS);
466}
467
468static inline bool is_feat_spe_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000469{
Andre Przywaraf3e8cfc2022-11-17 16:42:09 +0000470 if (ENABLE_SPE_FOR_NS == FEAT_STATE_DISABLED) {
471 return false;
472 }
473
474 if (ENABLE_SPE_FOR_NS == FEAT_STATE_ALWAYS) {
475 return true;
476 }
477
478 return read_feat_spe_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000479}
480
481/*******************************************************************************
482 * Function to identify the presence of FEAT_SVE (Scalable Vector Extension)
483 ******************************************************************************/
Jayanth Dodderi Chidanandd62c6812023-03-07 10:43:19 +0000484static inline unsigned int read_feat_sve_id_field(void)
485{
486 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_SVE);
487}
488
489static inline bool is_feat_sve_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000490{
Jayanth Dodderi Chidanandd62c6812023-03-07 10:43:19 +0000491 if (ENABLE_SVE_FOR_NS == FEAT_STATE_DISABLED) {
492 return false;
493 }
494
495 if (ENABLE_SVE_FOR_NS == FEAT_STATE_ALWAYS) {
496 return true;
497 }
498
499 return read_feat_sve_id_field() >= ID_AA64PFR0_SVE_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000500}
501
Andre Przywara870627e2023-01-27 12:25:49 +0000502static unsigned int read_feat_ras_id_field(void)
503{
504 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_RAS);
505}
506
507static inline bool is_feat_ras_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000508{
Andre Przywara870627e2023-01-27 12:25:49 +0000509 if (ENABLE_FEAT_RAS == FEAT_STATE_DISABLED) {
510 return false;
511 }
512
513 if (ENABLE_FEAT_RAS == FEAT_STATE_ALWAYS) {
514 return true;
515 }
516
517 return read_feat_ras_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000518}
519
Andre Przywara1f55c412023-01-26 16:47:52 +0000520static unsigned int read_feat_dit_id_field(void)
521{
522 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_DIT);
523}
524
525static inline bool is_feat_dit_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000526{
Andre Przywara1f55c412023-01-26 16:47:52 +0000527 if (ENABLE_FEAT_DIT == FEAT_STATE_DISABLED) {
528 return false;
529 }
530
531 if (ENABLE_FEAT_DIT == FEAT_STATE_ALWAYS) {
532 return true;
533 }
534
535 return read_feat_dit_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000536}
537
Andre Przywara44e33e02022-11-17 16:42:09 +0000538static inline unsigned int read_feat_tracever_id_field(void)
539{
540 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEVER);
541}
542
543static inline bool is_feat_sys_reg_trace_supported(void)
544{
545 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) {
546 return false;
547 }
548
549 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) {
550 return true;
551 }
552
553 return read_feat_tracever_id_field() != 0U;
554}
555
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000556/*************************************************************************
557 * Function to identify the presence of FEAT_TRF (TraceLift)
558 ************************************************************************/
Andre Przywara06ea44e2022-11-17 17:30:43 +0000559static inline unsigned int read_feat_trf_id_field(void)
560{
561 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEFILT);
562}
563
564static inline bool is_feat_trf_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000565{
Andre Przywara06ea44e2022-11-17 17:30:43 +0000566 if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) {
567 return false;
568 }
569
570 if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) {
571 return true;
572 }
573
574 return read_feat_trf_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000575}
576
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000577/********************************************************************************
578 * Function to identify the presence of FEAT_NV2 (Enhanced Nested Virtualization
579 * Support)
580 *******************************************************************************/
Andre Przywaraedc449d2023-01-27 14:09:20 +0000581static inline unsigned int read_feat_nv_id_field(void)
582{
583 return ISOLATE_FIELD(read_id_aa64mmfr2_el1(), ID_AA64MMFR2_EL1_NV);
584}
585
586static inline bool is_feat_nv2_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000587{
Andre Przywaraedc449d2023-01-27 14:09:20 +0000588 if (CTX_INCLUDE_NEVE_REGS == FEAT_STATE_DISABLED) {
589 return false;
590 }
591
592 if (CTX_INCLUDE_NEVE_REGS == FEAT_STATE_ALWAYS) {
593 return true;
594 }
595
596 return read_feat_nv_id_field() >= ID_AA64MMFR2_EL1_NV2_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000597}
598
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100599/*******************************************************************************
600 * Function to identify the presence of FEAT_BRBE (Branch Record Buffer
601 * Extension)
602 ******************************************************************************/
Andre Przywarac97c5512022-11-17 16:42:09 +0000603static inline unsigned int read_feat_brbe_id_field(void)
604{
605 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_BRBE);
606}
607
608static inline bool is_feat_brbe_supported(void)
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100609{
Andre Przywarac97c5512022-11-17 16:42:09 +0000610 if (ENABLE_BRBE_FOR_NS == FEAT_STATE_DISABLED) {
611 return false;
612 }
613
614 if (ENABLE_BRBE_FOR_NS == FEAT_STATE_ALWAYS) {
615 return true;
616 }
617
618 return read_feat_brbe_id_field() != 0U;
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100619}
620
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100621/*******************************************************************************
622 * Function to identify the presence of FEAT_TRBE (Trace Buffer Extension)
623 ******************************************************************************/
Andre Przywara191eff62022-11-17 16:42:09 +0000624static inline unsigned int read_feat_trbe_id_field(void)
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100625{
Andre Przywara191eff62022-11-17 16:42:09 +0000626 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEBUFFER);
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100627}
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100628
Andre Przywara191eff62022-11-17 16:42:09 +0000629static inline bool is_feat_trbe_supported(void)
630{
631 if (ENABLE_TRBE_FOR_NS == FEAT_STATE_DISABLED) {
632 return false;
633 }
634
635 if (ENABLE_TRBE_FOR_NS == FEAT_STATE_ALWAYS) {
636 return true;
637 }
638
639 return read_feat_trbe_id_field() != 0U;
640
641}
Boyan Karatotev05504ba2023-02-15 13:21:50 +0000642
Jayanth Dodderi Chidanand605419a2023-03-06 23:56:14 +0000643/*******************************************************************************
644 * Function to identify the presence of FEAT_SMEx (Scalar Matrix Extension)
645 ******************************************************************************/
646static inline unsigned int read_feat_sme_fa64_id_field(void)
647{
648 return ISOLATE_FIELD(read_id_aa64smfr0_el1(), ID_AA64SMFR0_EL1_SME_FA64);
649}
650
651static inline unsigned int read_feat_sme_id_field(void)
652{
653 return ISOLATE_FIELD(read_id_aa64pfr1_el1(), ID_AA64PFR1_EL1_SME);
654}
655
656static inline bool is_feat_sme_supported(void)
657{
658 if (ENABLE_SME_FOR_NS == FEAT_STATE_DISABLED) {
659 return false;
660 }
661
662 if (ENABLE_SME_FOR_NS == FEAT_STATE_ALWAYS) {
663 return true;
664 }
665
666 return read_feat_sme_id_field() >= ID_AA64PFR1_EL1_SME_SUPPORTED;
667}
668
Jayanth Dodderi Chidanandcfe053a2022-11-08 10:31:07 +0000669static inline bool is_feat_sme2_supported(void)
670{
671 if (ENABLE_SME2_FOR_NS == FEAT_STATE_DISABLED) {
672 return false;
673 }
674
675 if (ENABLE_SME2_FOR_NS == FEAT_STATE_ALWAYS) {
676 return true;
677 }
678
679 return read_feat_sme_id_field() >= ID_AA64PFR1_EL1_SME2_SUPPORTED;
680}
681
Javier Almansa Sobrino8c8107e2023-05-03 12:16:11 +0100682/*******************************************************************************
683 * Function to get hardware granularity support
684 ******************************************************************************/
685
686static inline unsigned int read_id_aa64mmfr0_el0_tgran4_field(void)
687{
688 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(), ID_AA64MMFR0_EL1_TGRAN4);
689}
690
691static inline unsigned int read_id_aa64mmfr0_el0_tgran16_field(void)
692{
693 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
694 ID_AA64MMFR0_EL1_TGRAN16);
695}
696
697static inline unsigned int read_id_aa64mmfr0_el0_tgran64_field(void)
698{
699 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(),
700 ID_AA64MMFR0_EL1_TGRAN64);
701}
702
Boyan Karatotev05504ba2023-02-15 13:21:50 +0000703static inline unsigned int read_feat_pmuv3_id_field(void)
704{
705 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_PMUVER);
706}
707
Boyan Karatotev677ed8a2023-02-16 09:45:29 +0000708static inline unsigned int read_feat_mtpmu_id_field(void)
709{
710 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_MTPMU);
711}
712
713static inline bool is_feat_mtpmu_supported(void)
714{
715 if (DISABLE_MTPMU == FEAT_STATE_DISABLED) {
716 return false;
717 }
718
719 if (DISABLE_MTPMU == FEAT_STATE_ALWAYS) {
720 return true;
721 }
722
723 unsigned int mtpmu = read_feat_mtpmu_id_field();
724
725 return (mtpmu != 0U) && (mtpmu != ID_AA64DFR0_MTPMU_DISABLED);
726}
727
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000728#endif /* ARCH_FEATURES_H */