blob: 75d7aa08e31a88963714653aefb26828847acde0 [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/*
31 * Check if RNDR is available
32 */
33static inline bool is_feat_rng_present(void)
34{
AlexeiFedorov537bee02023-02-02 13:38:23 +000035 return (EXTRACT(ID_AA64ISAR0_EL1_RNDR,
36 read_id_aa64isar0_el1()) != 0UL);
Soby Mathewb4c6df42022-11-09 11:13:29 +000037}
38
39/*
40 * Check if FEAT_VMID16 is implemented
41 * ID_AA64MMFR1_EL1.VMIDBits, bits [7:4]:
42 * 0b0000 8 bits.
43 * 0b0010 16 bits.
44 * All other values are reserved.
45 */
46static inline bool is_feat_vmid16_present(void)
47{
AlexeiFedorov537bee02023-02-02 13:38:23 +000048 return (EXTRACT(ID_AA64MMFR1_EL1_VMIDBits,
49 read_id_aa64mmfr1_el1()) == ID_AA64MMFR1_EL1_VMIDBits_16);
Soby Mathewb4c6df42022-11-09 11:13:29 +000050}
51
52/*
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +010053 * Check if FEAT_LPA2 is implemented for stage 1.
54 * 4KB granule at stage 1 supports 52-bit input and output addresses:
55 * ID_AA64MMFR0_EL1.TGran4 bits [31:28]: 0b0001
Soby Mathewb4c6df42022-11-09 11:13:29 +000056 */
57static inline bool is_feat_lpa2_4k_present(void)
58{
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +010059 return (EXTRACT(ID_AA64MMFR0_EL1_TGRAN4,
60 read_id_aa64mmfr0_el1()) == ID_AA64MMFR0_EL1_TGRAN4_LPA2);
61}
62
63/*
64 * Check if FEAT_LPA2 is implemented for stage 2.
65 * 4KB granule at stage 2 supports 52-bit input and output addresses:
66 * ID_AA64MMFR0_EL1.TGran4_2 bits [43:40]: 0b0011 ||
67 * (ID_AA64MMFR0_EL1.TGran4_2 bits [43:40]: 0b0000 &&
68 * ID_AA64MMFR0_EL1.TGran4 bits [31:28]: 0b0001 &&
69 */
70static inline bool is_feat_lpa2_4k_2_present(void)
71{
72 u_register_t id_aa64mmfr0_el1 = read_id_aa64mmfr0_el1();
73
74 return ((EXTRACT(ID_AA64MMFR0_EL1_TGRAN4_2, id_aa64mmfr0_el1) ==
75 ID_AA64MMFR0_EL1_TGRAN4_2_LPA2) ||
76 ((EXTRACT(ID_AA64MMFR0_EL1_TGRAN4_2, id_aa64mmfr0_el1) ==
77 ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4) && is_feat_lpa2_4k_present()));
Soby Mathewb4c6df42022-11-09 11:13:29 +000078}
79
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000080/*
81 * Returns Performance Monitors Extension version.
82 * ID_AA64DFR0_EL1.PMUVer, bits [11:8]:
83 * 0b0000: Performance Monitors Extension not implemented
84 */
85static inline unsigned int read_pmu_version(void)
86{
AlexeiFedorov3f24ea72023-08-29 13:59:55 +010087 return (unsigned int)EXTRACT(ID_AA64DFR0_EL1_PMUVer,
88 read_id_aa64dfr0_el1());
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000089}
90
Soby Mathewb4c6df42022-11-09 11:13:29 +000091unsigned int arch_feat_get_pa_width(void);
92
93#endif /* ARCH_FEATURES_H */