blob: 386b2ac89b9d99ec113509a94f1b39ac70792db1 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#ifndef ARCH_FEATURES_H
7#define ARCH_FEATURES_H
8
9#include <arch_helpers.h>
10#include <stdbool.h>
11
12static inline bool is_armv8_4_ttst_present(void)
13{
AlexeiFedorov537bee02023-02-02 13:38:23 +000014 return (EXTRACT(ID_AA64MMFR2_EL1_ST,
15 read_id_aa64mmfr2_el1()) == 1U);
Soby Mathewb4c6df42022-11-09 11:13:29 +000016}
17
18/*
19 * Check if SVE is enabled
20 * ID_AA64PFR0_EL1.SVE, bits [35:32]:
21 * 0b0000 SVE architectural state and programmers' model are not implemented.
22 * 0b0001 SVE architectural state and programmers' model are implemented.
23 */
24static inline bool is_feat_sve_present(void)
25{
AlexeiFedorov537bee02023-02-02 13:38:23 +000026 return (EXTRACT(ID_AA64PFR0_EL1_SVE,
27 read_id_aa64pfr0_el1()) != 0UL);
Soby Mathewb4c6df42022-11-09 11:13:29 +000028}
29
30/*
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +010031 * Check if SME is enabled
32 * ID_AA64PFR1_EL1.SME, bits [27:24]:
33 * 0b0000 SME architectural state and programmers' model are not implemented.
34 * 0b0001 SME architectural state and programmers' model are implemented.
35 * 0b0010 SME2 implemented. As 0b0001, plus the SME2 ZT0 register.
36 */
37static inline bool is_feat_sme_present(void)
38{
39 return (EXTRACT(ID_AA64PFR1_EL1_SME, read_id_aa64pfr1_el1()) != 0UL);
40}
41
42/*
Soby Mathewb4c6df42022-11-09 11:13:29 +000043 * Check if RNDR is available
44 */
45static inline bool is_feat_rng_present(void)
46{
AlexeiFedorov537bee02023-02-02 13:38:23 +000047 return (EXTRACT(ID_AA64ISAR0_EL1_RNDR,
48 read_id_aa64isar0_el1()) != 0UL);
Soby Mathewb4c6df42022-11-09 11:13:29 +000049}
50
51/*
52 * Check if FEAT_VMID16 is implemented
53 * ID_AA64MMFR1_EL1.VMIDBits, bits [7:4]:
54 * 0b0000 8 bits.
55 * 0b0010 16 bits.
56 * All other values are reserved.
57 */
58static inline bool is_feat_vmid16_present(void)
59{
AlexeiFedorov537bee02023-02-02 13:38:23 +000060 return (EXTRACT(ID_AA64MMFR1_EL1_VMIDBits,
61 read_id_aa64mmfr1_el1()) == ID_AA64MMFR1_EL1_VMIDBits_16);
Soby Mathewb4c6df42022-11-09 11:13:29 +000062}
63
64/*
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +010065 * Check if FEAT_LPA2 is implemented for stage 1.
66 * 4KB granule at stage 1 supports 52-bit input and output addresses:
67 * ID_AA64MMFR0_EL1.TGran4 bits [31:28]: 0b0001
Soby Mathewb4c6df42022-11-09 11:13:29 +000068 */
69static inline bool is_feat_lpa2_4k_present(void)
70{
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +010071 return (EXTRACT(ID_AA64MMFR0_EL1_TGRAN4,
72 read_id_aa64mmfr0_el1()) == ID_AA64MMFR0_EL1_TGRAN4_LPA2);
73}
74
75/*
76 * Check if FEAT_LPA2 is implemented for stage 2.
77 * 4KB granule at stage 2 supports 52-bit input and output addresses:
78 * ID_AA64MMFR0_EL1.TGran4_2 bits [43:40]: 0b0011 ||
79 * (ID_AA64MMFR0_EL1.TGran4_2 bits [43:40]: 0b0000 &&
80 * ID_AA64MMFR0_EL1.TGran4 bits [31:28]: 0b0001 &&
81 */
82static inline bool is_feat_lpa2_4k_2_present(void)
83{
84 u_register_t id_aa64mmfr0_el1 = read_id_aa64mmfr0_el1();
85
86 return ((EXTRACT(ID_AA64MMFR0_EL1_TGRAN4_2, id_aa64mmfr0_el1) ==
87 ID_AA64MMFR0_EL1_TGRAN4_2_LPA2) ||
88 ((EXTRACT(ID_AA64MMFR0_EL1_TGRAN4_2, id_aa64mmfr0_el1) ==
89 ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4) && is_feat_lpa2_4k_present()));
Soby Mathewb4c6df42022-11-09 11:13:29 +000090}
91
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000092/*
93 * Returns Performance Monitors Extension version.
94 * ID_AA64DFR0_EL1.PMUVer, bits [11:8]:
95 * 0b0000: Performance Monitors Extension not implemented
96 */
97static inline unsigned int read_pmu_version(void)
98{
AlexeiFedorov3f24ea72023-08-29 13:59:55 +010099 return (unsigned int)EXTRACT(ID_AA64DFR0_EL1_PMUVer,
100 read_id_aa64dfr0_el1());
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000101}
102
Soby Mathewb4c6df42022-11-09 11:13:29 +0000103unsigned int arch_feat_get_pa_width(void);
104
105#endif /* ARCH_FEATURES_H */