blob: 7c25b99ac001027f10e6ada66e35b23873070e2b [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 Przywara06ea44e2022-11-17 17:30:43 +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{
Andre Przywarabb0db3b2023-01-25 12:26:14 +000020 return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER) != 0U;
Antonio Nino Diazd29d21e2019-02-06 09:23:04 +000021}
22
Antonio Nino Diazc326c342019-01-11 11:20:10 +000023static inline bool is_armv8_2_ttcnp_present(void)
24{
Andre Przywarabb0db3b2023-01-25 12:26:14 +000025 return ISOLATE_FIELD(read_id_mmfr4(), ID_MMFR4_CNP) != 0U;
Antonio Nino Diazc326c342019-01-11 11:20:10 +000026}
27
Andre Przywara906776e2023-03-03 10:30:06 +000028static unsigned int read_feat_amu_id_field(void)
29{
30 return ISOLATE_FIELD(read_id_pfr0(), ID_PFR0_AMU);
31}
32
33static inline bool is_feat_amu_supported(void)
34{
35 if (ENABLE_FEAT_AMU == FEAT_STATE_DISABLED) {
36 return false;
37 }
38
39 if (ENABLE_FEAT_AMU == FEAT_STATE_ALWAYS) {
40 return true;
41 }
42
43 return read_feat_amu_id_field() >= ID_PFR0_AMU_V1;
44}
45
46static inline bool is_feat_amuv1p1_supported(void)
47{
48 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_DISABLED) {
49 return false;
50 }
51
52 if (ENABLE_FEAT_AMUv1p1 == FEAT_STATE_ALWAYS) {
53 return true;
54 }
55
56 return read_feat_amu_id_field() >= ID_PFR0_AMU_V1P1;
57}
58
Andre Przywara06ea44e2022-11-17 17:30:43 +000059static inline unsigned int read_feat_trf_id_field(void)
60{
61 return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_TRACEFILT);
62}
63
64static inline bool is_feat_trf_supported(void)
65{
66 if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) {
67 return false;
68 }
69
70 if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) {
71 return true;
72 }
73
74 return read_feat_trf_id_field() != 0U;
75}
76
Andre Przywara44e33e02022-11-17 16:42:09 +000077static inline unsigned int read_feat_coptrc_id_field(void)
78{
79 return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_COPTRC);
80}
81
82static inline bool is_feat_sys_reg_trace_supported(void)
83{
84 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) {
85 return false;
86 }
87
88 if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) {
89 return true;
90 }
91
92 return read_feat_coptrc_id_field() != 0U;
93}
94
Andre Przywaraf3e8cfc2022-11-17 16:42:09 +000095static inline bool is_feat_spe_supported(void)
96{
97 /* FEAT_SPE is AArch64 only */
98 return false;
99}
100
Antonio Nino Diazc326c342019-01-11 11:20:10 +0000101#endif /* ARCH_FEATURES_H */