Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 1 | /* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 3 | * |
| 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> |
| 13 | |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 14 | static inline bool is_armv7_gentimer_present(void) |
| 15 | { |
| 16 | /* The Generic Timer is always present in an ARMv8-A implementation */ |
| 17 | return true; |
| 18 | } |
| 19 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 20 | static inline bool is_armv8_2_ttcnp_present(void) |
| 21 | { |
| 22 | return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_CNP_SHIFT) & |
| 23 | ID_AA64MMFR2_EL1_CNP_MASK) != 0U; |
| 24 | } |
| 25 | |
Antonio Nino Diaz | 25cda67 | 2019-02-19 11:53:51 +0000 | [diff] [blame] | 26 | static inline bool is_armv8_3_pauth_present(void) |
| 27 | { |
| 28 | uint64_t mask = (ID_AA64ISAR1_GPI_MASK << ID_AA64ISAR1_GPI_SHIFT) | |
| 29 | (ID_AA64ISAR1_GPA_MASK << ID_AA64ISAR1_GPA_SHIFT) | |
| 30 | (ID_AA64ISAR1_API_MASK << ID_AA64ISAR1_API_SHIFT) | |
| 31 | (ID_AA64ISAR1_APA_MASK << ID_AA64ISAR1_APA_SHIFT); |
| 32 | |
| 33 | /* If any of the fields is not zero, PAuth is present */ |
| 34 | return (read_id_aa64isar1_el1() & mask) != 0U; |
| 35 | } |
| 36 | |
Sathees Balya | 7415597 | 2019-01-25 11:36:01 +0000 | [diff] [blame] | 37 | static inline bool is_armv8_4_ttst_present(void) |
| 38 | { |
| 39 | return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) & |
| 40 | ID_AA64MMFR2_EL1_ST_MASK) == 1U; |
| 41 | } |
| 42 | |
Alexei Fedorov | 90f2e88 | 2019-05-24 12:17:09 +0100 | [diff] [blame] | 43 | static inline bool is_armv8_5_bti_present(void) |
| 44 | { |
| 45 | return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_BT_SHIFT) & |
| 46 | ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED; |
| 47 | } |
| 48 | |
Soby Mathew | 830f0ad | 2019-07-12 09:23:38 +0100 | [diff] [blame] | 49 | static inline unsigned int get_armv8_5_mte_support(void) |
| 50 | { |
| 51 | return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) & |
| 52 | ID_AA64PFR1_EL1_MTE_MASK); |
| 53 | } |
| 54 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 55 | static inline bool is_armv8_4_sel2_present(void) |
| 56 | { |
| 57 | return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_SEL2_SHIFT) & |
| 58 | ID_AA64PFR0_SEL2_MASK) == 1ULL; |
| 59 | } |
| 60 | |
johpow01 | 3e24c16 | 2020-04-22 14:05:13 -0500 | [diff] [blame] | 61 | static inline bool is_armv8_6_twed_present(void) |
| 62 | { |
| 63 | return (((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_TWED_SHIFT) & |
| 64 | ID_AA64MMFR1_EL1_TWED_MASK) == ID_AA64MMFR1_EL1_TWED_SUPPORTED); |
| 65 | } |
| 66 | |
Jimmy Brisson | ecc3c67 | 2020-04-16 10:47:56 -0500 | [diff] [blame] | 67 | static inline bool is_armv8_6_fgt_present(void) |
| 68 | { |
| 69 | return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_FGT_SHIFT) & |
| 70 | ID_AA64MMFR0_EL1_FGT_MASK) == ID_AA64MMFR0_EL1_FGT_SUPPORTED; |
| 71 | } |
| 72 | |
Jimmy Brisson | 8357389 | 2020-04-16 10:48:02 -0500 | [diff] [blame] | 73 | static inline unsigned long int get_armv8_6_ecv_support(void) |
| 74 | { |
| 75 | return ((read_id_aa64mmfr0_el1() >> ID_AA64MMFR0_EL1_ECV_SHIFT) & |
| 76 | ID_AA64MMFR0_EL1_ECV_MASK); |
| 77 | } |
| 78 | |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 79 | /* |
| 80 | * Return MPAM version: |
| 81 | * |
| 82 | * 0x00: None Armv8.0 or later |
| 83 | * 0x01: v0.1 Armv8.4 or later |
| 84 | * 0x10: v1.0 Armv8.2 or later |
| 85 | * 0x11: v1.1 Armv8.4 or later |
| 86 | * |
| 87 | */ |
| 88 | static inline unsigned int get_mpam_version(void) |
| 89 | { |
| 90 | return (unsigned int)((((read_id_aa64pfr0_el1() >> |
| 91 | ID_AA64PFR0_MPAM_SHIFT) & ID_AA64PFR0_MPAM_MASK) << 4) | |
| 92 | ((read_id_aa64pfr1_el1() >> |
| 93 | ID_AA64PFR1_MPAM_FRAC_SHIFT) & ID_AA64PFR1_MPAM_FRAC_MASK)); |
| 94 | } |
| 95 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 96 | #endif /* ARCH_FEATURES_H */ |