blob: 16f4fb996e89c40975edfb1d7a8336ca9059565f [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
Daniel Boulby60786e72021-10-22 11:37:34 +010092static inline bool is_armv8_4_dit_present(void)
93{
94 return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) &
95 ID_AA64PFR0_DIT_MASK) == 1U;
96}
97
Sathees Balya74155972019-01-25 11:36:01 +000098static inline bool is_armv8_4_ttst_present(void)
99{
100 return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
101 ID_AA64MMFR2_EL1_ST_MASK) == 1U;
102}
103
Alexei Fedorov90f2e882019-05-24 12:17:09 +0100104static inline bool is_armv8_5_bti_present(void)
105{
106 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) &
107 ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
108}
109
Soby Mathew830f0ad2019-07-12 09:23:38 +0100110static inline unsigned int get_armv8_5_mte_support(void)
111{
112 return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
113 ID_AA64PFR1_EL1_MTE_MASK);
114}
115
Andre Przywara6dd2d062023-02-22 16:53:50 +0000116static inline unsigned int read_feat_sel2_id_field(void)
117{
118 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_SEL2);
119}
120
121static inline bool is_feat_sel2_supported(void)
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200122{
Andre Przywara6dd2d062023-02-22 16:53:50 +0000123 if (ENABLE_FEAT_SEL2 == FEAT_STATE_DISABLED) {
124 return false;
125 }
126
127 if (ENABLE_FEAT_SEL2 == FEAT_STATE_ALWAYS) {
128 return true;
129 }
130
131 return read_feat_sel2_id_field() != 0U;
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200132}
133
Andre Przywara0cf77402023-01-27 12:25:49 +0000134static inline unsigned int read_feat_twed_id_field(void)
135{
136 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_TWED);
137}
138
139static inline bool is_feat_twed_supported(void)
johpow013e24c162020-04-22 14:05:13 -0500140{
Andre Przywara0cf77402023-01-27 12:25:49 +0000141 if (ENABLE_FEAT_TWED == FEAT_STATE_DISABLED) {
142 return false;
143 }
144
145 if (ENABLE_FEAT_TWED == FEAT_STATE_ALWAYS) {
146 return true;
147 }
148
149 return read_feat_twed_id_field() != 0U;
johpow013e24c162020-04-22 14:05:13 -0500150}
151
Andre Przywarae8920f62022-11-10 14:28:01 +0000152static unsigned int read_feat_fgt_id_field(void)
Jimmy Brissonecc3c672020-04-16 10:47:56 -0500153{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000154 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(), ID_AA64MMFR0_EL1_FGT);
Andre Przywarae8920f62022-11-10 14:28:01 +0000155}
156
157static inline bool is_feat_fgt_supported(void)
158{
159 if (ENABLE_FEAT_FGT == FEAT_STATE_DISABLED) {
160 return false;
161 }
162
163 if (ENABLE_FEAT_FGT == FEAT_STATE_ALWAYS) {
164 return true;
165 }
166
167 return read_feat_fgt_id_field() != 0U;
Jimmy Brissonecc3c672020-04-16 10:47:56 -0500168}
169
Andre Przywarac3464182022-11-17 17:30:43 +0000170static unsigned int read_feat_ecv_id_field(void)
171{
172 return ISOLATE_FIELD(read_id_aa64mmfr0_el1(), ID_AA64MMFR0_EL1_ECV);
173}
174
175static inline bool is_feat_ecv_supported(void)
176{
177 if (ENABLE_FEAT_ECV == FEAT_STATE_DISABLED) {
178 return false;
179 }
180
181 if (ENABLE_FEAT_ECV == FEAT_STATE_ALWAYS) {
182 return true;
183 }
184
185 return read_feat_ecv_id_field() != 0U;
186}
187
188static inline bool is_feat_ecv_v2_supported(void)
Jimmy Brisson83573892020-04-16 10:48:02 -0500189{
Andre Przywarac3464182022-11-17 17:30:43 +0000190 if (ENABLE_FEAT_ECV == FEAT_STATE_DISABLED) {
191 return false;
192 }
193
194 if (ENABLE_FEAT_ECV == FEAT_STATE_ALWAYS) {
195 return true;
196 }
197
198 return read_feat_ecv_id_field() >= ID_AA64MMFR0_EL1_ECV_SELF_SYNCH;
Jimmy Brisson83573892020-04-16 10:48:02 -0500199}
200
Andre Przywara436b4bb2023-02-22 17:55:59 +0000201static unsigned int read_feat_rng_id_field(void)
202{
203 return ISOLATE_FIELD(read_id_aa64isar0_el1(), ID_AA64ISAR0_RNDR);
204}
205
206static inline bool is_feat_rng_supported(void)
Tomas Pilar6fd816e2020-10-28 15:34:12 +0000207{
Andre Przywara436b4bb2023-02-22 17:55:59 +0000208 if (ENABLE_FEAT_RNG == FEAT_STATE_DISABLED) {
209 return false;
210 }
211
212 if (ENABLE_FEAT_RNG == FEAT_STATE_ALWAYS) {
213 return true;
214 }
215
216 return read_feat_rng_id_field() != 0U;
Tomas Pilar6fd816e2020-10-28 15:34:12 +0000217}
218
Mark Brownc37eee72023-03-14 20:13:03 +0000219static unsigned int read_feat_tcrx_id_field(void)
220{
221 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_TCRX);
222}
223
224static inline bool is_feat_tcr2_supported(void)
225{
226 if (ENABLE_FEAT_TCR2 == FEAT_STATE_DISABLED) {
227 return false;
228 }
229
230 if (ENABLE_FEAT_TCR2 == FEAT_STATE_ALWAYS) {
231 return true;
232 }
233
234 return read_feat_tcrx_id_field() != 0U;
235}
236
Mark Brown293a6612023-03-14 20:48:43 +0000237static unsigned int read_feat_s2poe_id_field(void)
238{
239 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S2POE);
240}
241
242static inline bool is_feat_s2poe_supported(void)
243{
244 if (ENABLE_FEAT_S2POE == FEAT_STATE_DISABLED) {
245 return false;
246 }
247
248 if (ENABLE_FEAT_S2POE == FEAT_STATE_ALWAYS) {
249 return true;
250 }
251
252 return read_feat_s2poe_id_field() != 0U;
253}
254
255static unsigned int read_feat_s1poe_id_field(void)
256{
257 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S1POE);
258}
259
260static inline bool is_feat_s1poe_supported(void)
261{
262 if (ENABLE_FEAT_S1POE == FEAT_STATE_DISABLED) {
263 return false;
264 }
265
266 if (ENABLE_FEAT_S1POE == FEAT_STATE_ALWAYS) {
267 return true;
268 }
269
270 return read_feat_s1poe_id_field() != 0U;
271}
272
273static inline bool is_feat_sxpoe_supported(void)
274{
275 return is_feat_s1poe_supported() || is_feat_s2poe_supported();
276}
277
278static unsigned int read_feat_s2pie_id_field(void)
279{
280 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S2PIE);
281}
282
283static inline bool is_feat_s2pie_supported(void)
284{
285 if (ENABLE_FEAT_S2PIE == FEAT_STATE_DISABLED) {
286 return false;
287 }
288
289 if (ENABLE_FEAT_S2PIE == FEAT_STATE_ALWAYS) {
290 return true;
291 }
292
293 return read_feat_s2pie_id_field() != 0U;
294}
295
296static unsigned int read_feat_s1pie_id_field(void)
297{
298 return ISOLATE_FIELD(read_id_aa64mmfr3_el1(), ID_AA64MMFR3_EL1_S1PIE);
299}
300
301static inline bool is_feat_s1pie_supported(void)
302{
303 if (ENABLE_FEAT_S1PIE == FEAT_STATE_DISABLED) {
304 return false;
305 }
306
307 if (ENABLE_FEAT_S1PIE == FEAT_STATE_ALWAYS) {
308 return true;
309 }
310
311 return read_feat_s1pie_id_field() != 0U;
312}
313
314static inline bool is_feat_sxpie_supported(void)
315{
316 return is_feat_s1pie_supported() || is_feat_s2pie_supported();
317}
318
Mark Brown326f2952023-03-14 21:33:04 +0000319static unsigned int read_feat_gcs_id_field(void)
320{
321 return ISOLATE_FIELD(read_id_aa64pfr1_el1(), ID_AA64PFR1_EL1_GCS);
322}
323
324static inline bool is_feat_gcs_supported(void)
325{
326 if (ENABLE_FEAT_GCS == FEAT_STATE_DISABLED) {
327 return false;
328 }
329
330 if (ENABLE_FEAT_GCS == FEAT_STATE_ALWAYS) {
331 return true;
332 }
333
334 return read_feat_gcs_id_field() != 0U;
335}
336
Andre Przywara2c550e32022-11-10 14:41:07 +0000337/*******************************************************************************
338 * Functions to identify the presence of the Activity Monitors Extension
339 ******************************************************************************/
340static unsigned int read_feat_amu_id_field(void)
341{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000342 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_AMU);
Andre Przywara2c550e32022-11-10 14:41:07 +0000343}
344
345static inline bool is_feat_amu_supported(void)
346{
Andre Przywara0b7f1b02023-03-21 13:53:19 +0000347 if (ENABLE_FEAT_AMU == FEAT_STATE_DISABLED) {
Andre Przywara2c550e32022-11-10 14:41:07 +0000348 return false;
349 }
350
Andre Przywara0b7f1b02023-03-21 13:53:19 +0000351 if (ENABLE_FEAT_AMU == FEAT_STATE_ALWAYS) {
Andre Przywara2c550e32022-11-10 14:41:07 +0000352 return true;
353 }
354
355 return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1;
356}
357
Andre Przywara906776e2023-03-03 10:30:06 +0000358static inline bool is_feat_amuv1p1_supported(void)
johpow01fa59c6f2020-10-02 13:41:11 -0500359{
Andre Przywara906776e2023-03-03 10:30:06 +0000360 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_DISABLED) {
361 return false;
362 }
363
364 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_ALWAYS) {
365 return true;
366 }
367
Andre Przywara2c550e32022-11-10 14:41:07 +0000368 return read_feat_amu_id_field() >= ID_AA64PFR0_AMU_V1P1;
johpow01fa59c6f2020-10-02 13:41:11 -0500369}
370
Alexei Fedorov19933552020-05-26 13:16:41 +0100371/*
372 * Return MPAM version:
373 *
374 * 0x00: None Armv8.0 or later
375 * 0x01: v0.1 Armv8.4 or later
376 * 0x10: v1.0 Armv8.2 or later
377 * 0x11: v1.1 Armv8.4 or later
378 *
379 */
Andre Przywara84b86532022-11-17 16:42:09 +0000380static inline unsigned int read_feat_mpam_version(void)
Alexei Fedorov19933552020-05-26 13:16:41 +0100381{
382 return (unsigned int)((((read_id_aa64pfr0_el1() >>
383 ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) |
384 ((read_id_aa64pfr1_el1() >>
385 ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK));
386}
387
Andre Przywara84b86532022-11-17 16:42:09 +0000388static inline bool is_feat_mpam_supported(void)
389{
390 if (ENABLE_MPAM_FOR_LOWER_ELS == FEAT_STATE_DISABLED) {
391 return false;
392 }
393
394 if (ENABLE_MPAM_FOR_LOWER_ELS == FEAT_STATE_ALWAYS) {
395 return true;
396 }
397
398 return read_feat_mpam_version() != 0U;
399}
400
Andre Przywaraf20ad902022-11-15 11:45:19 +0000401static inline unsigned int read_feat_hcx_id_field(void)
402{
Andre Przywarabb0db3b2023-01-25 12:26:14 +0000403 return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_HCX);
Andre Przywaraf20ad902022-11-15 11:45:19 +0000404}
405
406static inline bool is_feat_hcx_supported(void)
johpow01f91e59f2021-08-04 19:38:18 -0500407{
Andre Przywaraf20ad902022-11-15 11:45:19 +0000408 if (ENABLE_FEAT_HCX == FEAT_STATE_DISABLED) {
409 return false;
410 }
411
412 if (ENABLE_FEAT_HCX == FEAT_STATE_ALWAYS) {
413 return true;
414 }
415
416 return read_feat_hcx_id_field() != 0U;
johpow01f91e59f2021-08-04 19:38:18 -0500417}
418
Juan Pablo Conde42305f22022-07-12 16:40:29 -0400419static inline bool is_feat_rng_trap_present(void)
420{
421 return (((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_RNDR_TRAP_SHIFT) &
422 ID_AA64PFR1_EL1_RNDR_TRAP_MASK)
423 == ID_AA64PFR1_EL1_RNG_TRAP_SUPPORTED);
424}
425
Zelalem Aweke79e3d292021-07-08 16:51:14 -0500426static inline unsigned int get_armv9_2_feat_rme_support(void)
427{
428 /*
429 * Return the RME version, zero if not supported. This function can be
430 * used as both an integer value for the RME version or compared to zero
431 * to detect RME presence.
432 */
433 return (unsigned int)(read_id_aa64pfr0_el1() >>
434 ID_AA64PFR0_FEAT_RME_SHIFT) & ID_AA64PFR0_FEAT_RME_MASK;
435}
436
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000437/*********************************************************************************
438 * Function to identify the presence of FEAT_SB (Speculation Barrier Instruction)
439 ********************************************************************************/
Andre Przywara46880dc2022-11-17 16:42:09 +0000440static inline unsigned int read_feat_sb_id_field(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000441{
Andre Przywara46880dc2022-11-17 16:42:09 +0000442 return ISOLATE_FIELD(read_id_aa64isar1_el1(), ID_AA64ISAR1_SB);
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000443}
444
445/*********************************************************************************
446 * Function to identify the presence of FEAT_CSV2_2 (Cache Speculation Variant 2)
447 ********************************************************************************/
Andre Przywara902c9022022-11-17 17:30:43 +0000448static inline unsigned int read_feat_csv2_id_field(void)
449{
450 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_CSV2);
451}
452
453static inline bool is_feat_csv2_2_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000454{
Andre Przywara902c9022022-11-17 17:30:43 +0000455 if (ENABLE_FEAT_CSV2_2 == FEAT_STATE_DISABLED) {
456 return false;
457 }
458
459 if (ENABLE_FEAT_CSV2_2 == FEAT_STATE_ALWAYS) {
460 return true;
461 }
462
463 return read_feat_csv2_id_field() >= ID_AA64PFR0_CSV2_2_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000464}
465
466/**********************************************************************************
467 * Function to identify the presence of FEAT_SPE (Statistical Profiling Extension)
468 *********************************************************************************/
Andre Przywaraf3e8cfc2022-11-17 16:42:09 +0000469static inline unsigned int read_feat_spe_id_field(void)
470{
471 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_PMS);
472}
473
474static inline bool is_feat_spe_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000475{
Andre Przywaraf3e8cfc2022-11-17 16:42:09 +0000476 if (ENABLE_SPE_FOR_NS == FEAT_STATE_DISABLED) {
477 return false;
478 }
479
480 if (ENABLE_SPE_FOR_NS == FEAT_STATE_ALWAYS) {
481 return true;
482 }
483
484 return read_feat_spe_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000485}
486
487/*******************************************************************************
488 * Function to identify the presence of FEAT_SVE (Scalable Vector Extension)
489 ******************************************************************************/
Jayanth Dodderi Chidanandd62c6812023-03-07 10:43:19 +0000490static inline unsigned int read_feat_sve_id_field(void)
491{
492 return ISOLATE_FIELD(read_id_aa64pfr0_el1(), ID_AA64PFR0_SVE);
493}
494
495static inline bool is_feat_sve_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000496{
Jayanth Dodderi Chidanandd62c6812023-03-07 10:43:19 +0000497 if (ENABLE_SVE_FOR_NS == FEAT_STATE_DISABLED) {
498 return false;
499 }
500
501 if (ENABLE_SVE_FOR_NS == FEAT_STATE_ALWAYS) {
502 return true;
503 }
504
505 return read_feat_sve_id_field() >= ID_AA64PFR0_SVE_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000506}
507
508/*******************************************************************************
509 * Function to identify the presence of FEAT_RAS (Reliability,Availability,
510 * and Serviceability Extension)
511 ******************************************************************************/
512static inline bool is_armv8_2_feat_ras_present(void)
513{
514 return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_RAS_SHIFT) &
515 ID_AA64PFR0_RAS_MASK) != ID_AA64PFR0_RAS_NOT_SUPPORTED);
516}
517
518/**************************************************************************
519 * Function to identify the presence of FEAT_DIT (Data Independent Timing)
520 *************************************************************************/
521static inline bool is_armv8_4_feat_dit_present(void)
522{
523 return (((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) &
524 ID_AA64PFR0_DIT_MASK) == ID_AA64PFR0_DIT_SUPPORTED);
525}
526
Andre Przywara44e33e02022-11-17 16:42:09 +0000527static inline unsigned int read_feat_tracever_id_field(void)
528{
529 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEVER);
530}
531
532static inline bool is_feat_sys_reg_trace_supported(void)
533{
534 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) {
535 return false;
536 }
537
538 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) {
539 return true;
540 }
541
542 return read_feat_tracever_id_field() != 0U;
543}
544
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000545/*************************************************************************
546 * Function to identify the presence of FEAT_TRF (TraceLift)
547 ************************************************************************/
Andre Przywara06ea44e2022-11-17 17:30:43 +0000548static inline unsigned int read_feat_trf_id_field(void)
549{
550 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEFILT);
551}
552
553static inline bool is_feat_trf_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000554{
Andre Przywara06ea44e2022-11-17 17:30:43 +0000555 if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) {
556 return false;
557 }
558
559 if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) {
560 return true;
561 }
562
563 return read_feat_trf_id_field() != 0U;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000564}
565
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000566/********************************************************************************
567 * Function to identify the presence of FEAT_NV2 (Enhanced Nested Virtualization
568 * Support)
569 *******************************************************************************/
Andre Przywaraedc449d2023-01-27 14:09:20 +0000570static inline unsigned int read_feat_nv_id_field(void)
571{
572 return ISOLATE_FIELD(read_id_aa64mmfr2_el1(), ID_AA64MMFR2_EL1_NV);
573}
574
575static inline bool is_feat_nv2_supported(void)
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000576{
Andre Przywaraedc449d2023-01-27 14:09:20 +0000577 if (CTX_INCLUDE_NEVE_REGS == FEAT_STATE_DISABLED) {
578 return false;
579 }
580
581 if (CTX_INCLUDE_NEVE_REGS == FEAT_STATE_ALWAYS) {
582 return true;
583 }
584
585 return read_feat_nv_id_field() >= ID_AA64MMFR2_EL1_NV2_SUPPORTED;
Jayanth Dodderi Chidanand9461a892022-01-17 18:57:17 +0000586}
587
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100588/*******************************************************************************
589 * Function to identify the presence of FEAT_BRBE (Branch Record Buffer
590 * Extension)
591 ******************************************************************************/
Andre Przywarac97c5512022-11-17 16:42:09 +0000592static inline unsigned int read_feat_brbe_id_field(void)
593{
594 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_BRBE);
595}
596
597static inline bool is_feat_brbe_supported(void)
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100598{
Andre Przywarac97c5512022-11-17 16:42:09 +0000599 if (ENABLE_BRBE_FOR_NS == FEAT_STATE_DISABLED) {
600 return false;
601 }
602
603 if (ENABLE_BRBE_FOR_NS == FEAT_STATE_ALWAYS) {
604 return true;
605 }
606
607 return read_feat_brbe_id_field() != 0U;
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100608}
609
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100610/*******************************************************************************
611 * Function to identify the presence of FEAT_TRBE (Trace Buffer Extension)
612 ******************************************************************************/
Andre Przywara191eff62022-11-17 16:42:09 +0000613static inline unsigned int read_feat_trbe_id_field(void)
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100614{
Andre Przywara191eff62022-11-17 16:42:09 +0000615 return ISOLATE_FIELD(read_id_aa64dfr0_el1(), ID_AA64DFR0_TRACEBUFFER);
Jayanth Dodderi Chidananda793ccc2022-05-19 14:08:28 +0100616}
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +0100617
Andre Przywara191eff62022-11-17 16:42:09 +0000618static inline bool is_feat_trbe_supported(void)
619{
620 if (ENABLE_TRBE_FOR_NS == FEAT_STATE_DISABLED) {
621 return false;
622 }
623
624 if (ENABLE_TRBE_FOR_NS == FEAT_STATE_ALWAYS) {
625 return true;
626 }
627
628 return read_feat_trbe_id_field() != 0U;
629
630}
Jayanth Dodderi Chidanand605419a2023-03-06 23:56:14 +0000631/*******************************************************************************
632 * Function to identify the presence of FEAT_SMEx (Scalar Matrix Extension)
633 ******************************************************************************/
634static inline unsigned int read_feat_sme_fa64_id_field(void)
635{
636 return ISOLATE_FIELD(read_id_aa64smfr0_el1(), ID_AA64SMFR0_EL1_SME_FA64);
637}
638
639static inline unsigned int read_feat_sme_id_field(void)
640{
641 return ISOLATE_FIELD(read_id_aa64pfr1_el1(), ID_AA64PFR1_EL1_SME);
642}
643
644static inline bool is_feat_sme_supported(void)
645{
646 if (ENABLE_SME_FOR_NS == FEAT_STATE_DISABLED) {
647 return false;
648 }
649
650 if (ENABLE_SME_FOR_NS == FEAT_STATE_ALWAYS) {
651 return true;
652 }
653
654 return read_feat_sme_id_field() >= ID_AA64PFR1_EL1_SME_SUPPORTED;
655}
656
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000657#endif /* ARCH_FEATURES_H */