blob: abe34a436aefd2db0c92224fad81bba72cf7cb60 [file] [log] [blame]
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +00001/*
Govindraj Raja0a33adc2023-12-21 13:57:49 -06002 * Copyright (c) 2019-2024, 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 Przywarafc8d2d32022-11-17 17:30:43 +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 Przywarafd1dd4c2023-01-25 12:26:14 +000017
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(); \
29}
30
31#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 * +----------------------------+
46 * | Features supported |
47 * +----------------------------+
48 * | GENTIMER |
49 * +----------------------------+
50 * | FEAT_TTCNP |
51 * +----------------------------+
52 * | FEAT_AMU |
53 * +----------------------------+
54 * | FEAT_AMUV1P1 |
55 * +----------------------------+
56 * | FEAT_TRF |
57 * +----------------------------+
58 * | FEAT_SYS_REG_TRACE |
59 * +----------------------------+
60 * | FEAT_DIT |
61 * +----------------------------+
62 * | FEAT_PAN |
63 * +----------------------------+
64 * | FEAT_SSBS |
65 * +----------------------------+
66 * | FEAT_PMUV3 |
67 * +----------------------------+
68 * | FEAT_MTPMU |
69 * +----------------------------+
70 */
71
72/* GENTIMER */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +020073__attribute__((always_inline))
Antonio Nino Diaz29a24132019-02-06 09:23:04 +000074static inline bool is_armv7_gentimer_present(void)
75{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -050076 return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER_SHIFT,
77 ID_PFR1_GENTIMER_MASK) != 0U;
Antonio Nino Diaz29a24132019-02-06 09:23:04 +000078}
79
Sona Mathewaaaf2cc2024-03-13 11:33:54 -050080/* FEAT_TTCNP: Translation table common not private */
81CREATE_FEATURE_PRESENT(feat_ttcnp, id_mmfr4, ID_MMFR4_CNP_SHIFT,
82 ID_MMFR4_CNP_MASK, 1U)
83
84/* FEAT_AMU: Activity Monitors Extension */
85CREATE_FEATURE_FUNCS(feat_amu, id_pfr0, ID_PFR0_AMU_SHIFT,
86 ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1, ENABLE_FEAT_AMU)
87
88/* FEAT_AMUV1P1: AMU Extension v1.1 */
89CREATE_FEATURE_FUNCS(feat_amuv1p1, id_pfr0, ID_PFR0_AMU_SHIFT,
90 ID_PFR0_AMU_MASK, ID_PFR0_AMU_V1P1, ENABLE_FEAT_AMUv1p1)
91
92/* FEAT_TRF: Tracefilter */
93CREATE_FEATURE_FUNCS(feat_trf, id_dfr0, ID_DFR0_TRACEFILT_SHIFT,
94 ID_DFR0_TRACEFILT_MASK, 1U, ENABLE_TRF_FOR_NS)
95
96/* FEAT_SYS_REG_TRACE */
97CREATE_FEATURE_FUNCS(feat_sys_reg_trace, id_dfr0, ID_DFR0_COPTRC_SHIFT,
98 ID_DFR0_COPTRC_MASK, 1U, ENABLE_SYS_REG_TRACE_FOR_NS)
99
100/* FEAT_DIT: Data independent timing */
101CREATE_FEATURE_FUNCS(feat_dit, id_pfr0, ID_PFR0_DIT_SHIFT,
102 ID_PFR0_DIT_MASK, 1U, ENABLE_FEAT_DIT)
103
104/* FEAT_PAN: Privileged access never */
105CREATE_FEATURE_FUNCS(feat_pan, id_mmfr3, ID_MMFR3_PAN_SHIFT,
106 ID_MMFR3_PAN_MASK, 1U, ENABLE_FEAT_PAN)
107
108/* FEAT_SSBS: Speculative store bypass safe */
109CREATE_FEATURE_PRESENT(feat_ssbs, id_pfr2, ID_PFR2_SSBS_SHIFT,
110 ID_PFR2_SSBS_MASK, 1U)
111
112/* FEAT_PMUV3 */
113CREATE_FEATURE_PRESENT(feat_pmuv3, id_dfr0, ID_DFR0_PERFMON_SHIFT,
114 ID_DFR0_PERFMON_MASK, 3U)
115
116/* FEAT_MTPMU */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200117__attribute__((always_inline))
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500118static inline bool is_feat_mtpmu_present(void)
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +0000119{
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500120 unsigned int mtpmu = ISOLATE_FIELD(read_id_dfr1(), ID_DFR1_MTPMU_SHIFT,
121 ID_DFR1_MTPMU_MASK);
122 return (mtpmu != 0U) && (mtpmu != MTPMU_NOT_IMPLEMENTED);
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +0000123}
Sona Mathewaaaf2cc2024-03-13 11:33:54 -0500124CREATE_FEATURE_SUPPORTED(feat_mtpmu, is_feat_mtpmu_present, DISABLE_MTPMU)
Manish Pandey30f05b42024-01-09 15:55:20 +0000125
Andre Przywara733d1122023-05-23 10:34:38 +0100126/*
127 * TWED, ECV, CSV2, RAS are only used by the AArch64 EL2 context switch
128 * code. In fact, EL2 context switching is only needed for AArch64 (since
129 * there is no secure AArch32 EL2), so just disable these features here.
130 */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200131__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100132static inline bool is_feat_twed_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200133__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100134static inline bool is_feat_ecv_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200135__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100136static inline bool is_feat_ecv_v2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200137__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100138static inline bool is_feat_csv2_2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200139__attribute__((always_inline))
Sona Mathew30019d82023-10-25 16:48:19 -0500140static inline bool is_feat_csv2_3_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200141__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100142static inline bool is_feat_ras_supported(void) { return false; }
143
144/* The following features are supported in AArch64 only. */
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200145__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100146static inline bool is_feat_vhe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200147__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100148static inline bool is_feat_sel2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200149__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100150static inline bool is_feat_fgt_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200151__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100152static inline bool is_feat_tcr2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200153__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100154static inline bool is_feat_spe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200155__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100156static inline bool is_feat_rng_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200157__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100158static inline bool is_feat_gcs_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200159__attribute__((always_inline))
Govindraj Raja8e397882024-01-26 10:08:37 -0600160static inline bool is_feat_mte2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200161__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100162static inline bool is_feat_mpam_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200163__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100164static inline bool is_feat_hcx_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200165__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100166static inline bool is_feat_sve_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200167__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100168static inline bool is_feat_brbe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200169__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100170static inline bool is_feat_trbe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200171__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100172static inline bool is_feat_nv2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200173__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100174static inline bool is_feat_sme_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200175__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100176static inline bool is_feat_sme2_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200177__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100178static inline bool is_feat_s2poe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200179__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100180static inline bool is_feat_s1poe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200181__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100182static inline bool is_feat_sxpoe_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200183__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100184static inline bool is_feat_s2pie_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200185__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100186static inline bool is_feat_s1pie_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200187__attribute__((always_inline))
Andre Przywara733d1122023-05-23 10:34:38 +0100188static inline bool is_feat_sxpie_supported(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200189__attribute__((always_inline))
Manish Pandey30f05b42024-01-09 15:55:20 +0000190static inline bool is_feat_uao_present(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200191__attribute__((always_inline))
Manish Pandey30f05b42024-01-09 15:55:20 +0000192static inline bool is_feat_nmi_present(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200193__attribute__((always_inline))
Manish Pandey30f05b42024-01-09 15:55:20 +0000194static inline bool is_feat_ebep_present(void) { return false; }
Olivier Deprez0dfa07b2024-06-07 10:57:28 +0200195__attribute__((always_inline))
Manish Pandey30f05b42024-01-09 15:55:20 +0000196static inline bool is_feat_sebep_present(void) { return false; }
Andre Przywara733d1122023-05-23 10:34:38 +0100197
Antonio Nino Diaz2559b2c2019-01-11 11:20:10 +0000198#endif /* ARCH_FEATURES_H */