Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | static inline bool is_armv8_4_ttst_present(void) |
| 13 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 14 | return (EXTRACT(ID_AA64MMFR2_EL1_ST, |
| 15 | read_id_aa64mmfr2_el1()) == 1U); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 16 | } |
| 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 | */ |
| 24 | static inline bool is_feat_sve_present(void) |
| 25 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 26 | return (EXTRACT(ID_AA64PFR0_EL1_SVE, |
| 27 | read_id_aa64pfr0_el1()) != 0UL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Check if RNDR is available |
| 32 | */ |
| 33 | static inline bool is_feat_rng_present(void) |
| 34 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 35 | return (EXTRACT(ID_AA64ISAR0_EL1_RNDR, |
| 36 | read_id_aa64isar0_el1()) != 0UL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 37 | } |
| 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 | */ |
| 46 | static inline bool is_feat_vmid16_present(void) |
| 47 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 48 | return (EXTRACT(ID_AA64MMFR1_EL1_VMIDBits, |
| 49 | read_id_aa64mmfr1_el1()) == ID_AA64MMFR1_EL1_VMIDBits_16); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Check if FEAT_LPA2 is implemented. |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 54 | * 4KB granule at stage 2 supports 52-bit input and output addresses: |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 55 | * ID_AA64MMFR0_EL1.TGran4_2 bits [43:40]: 0b0011 |
| 56 | */ |
| 57 | static inline bool is_feat_lpa2_4k_present(void) |
| 58 | { |
AlexeiFedorov | 537bee0 | 2023-02-02 13:38:23 +0000 | [diff] [blame] | 59 | return (EXTRACT(ID_AA64MMFR0_EL1_TGRAN4_2, |
| 60 | read_id_aa64mmfr0_el1()) == ID_AA64MMFR0_EL1_TGRAN4_2_LPA2); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 61 | } |
| 62 | |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 63 | /* |
| 64 | * Returns Performance Monitors Extension version. |
| 65 | * ID_AA64DFR0_EL1.PMUVer, bits [11:8]: |
| 66 | * 0b0000: Performance Monitors Extension not implemented |
| 67 | */ |
| 68 | static inline unsigned int read_pmu_version(void) |
| 69 | { |
| 70 | return EXTRACT(ID_AA64DFR0_EL1_PMUVer, read_id_aa64dfr0_el1()); |
| 71 | } |
| 72 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 73 | unsigned int arch_feat_get_pa_width(void); |
| 74 | |
| 75 | #endif /* ARCH_FEATURES_H */ |