Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 1 | /* |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2023, 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> |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 13 | #include <common/feat_detect.h> |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 14 | |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 15 | #define ISOLATE_FIELD(reg, feat) \ |
| 16 | ((unsigned int)(((reg) >> (feat ## _SHIFT)) & (feat ## _MASK))) |
| 17 | |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 18 | static inline bool is_armv7_gentimer_present(void) |
| 19 | { |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 20 | return ISOLATE_FIELD(read_id_pfr1(), ID_PFR1_GENTIMER) != 0U; |
Antonio Nino Diaz | d29d21e | 2019-02-06 09:23:04 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 23 | static inline bool is_armv8_2_ttcnp_present(void) |
| 24 | { |
Andre Przywara | bb0db3b | 2023-01-25 12:26:14 +0000 | [diff] [blame] | 25 | return ISOLATE_FIELD(read_id_mmfr4(), ID_MMFR4_CNP) != 0U; |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Andre Przywara | 06ea44e | 2022-11-17 17:30:43 +0000 | [diff] [blame] | 28 | static inline unsigned int read_feat_trf_id_field(void) |
| 29 | { |
| 30 | return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_TRACEFILT); |
| 31 | } |
| 32 | |
| 33 | static inline bool is_feat_trf_supported(void) |
| 34 | { |
| 35 | if (ENABLE_TRF_FOR_NS == FEAT_STATE_DISABLED) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | if (ENABLE_TRF_FOR_NS == FEAT_STATE_ALWAYS) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | return read_feat_trf_id_field() != 0U; |
| 44 | } |
| 45 | |
Andre Przywara | 44e33e0 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 46 | static inline unsigned int read_feat_coptrc_id_field(void) |
| 47 | { |
| 48 | return ISOLATE_FIELD(read_id_dfr0(), ID_DFR0_COPTRC); |
| 49 | } |
| 50 | |
| 51 | static inline bool is_feat_sys_reg_trace_supported(void) |
| 52 | { |
| 53 | if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_DISABLED) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if (ENABLE_SYS_REG_TRACE_FOR_NS == FEAT_STATE_ALWAYS) { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | return read_feat_coptrc_id_field() != 0U; |
| 62 | } |
| 63 | |
Andre Przywara | f3e8cfc | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 64 | static inline bool is_feat_spe_supported(void) |
| 65 | { |
| 66 | /* FEAT_SPE is AArch64 only */ |
| 67 | return false; |
| 68 | } |
| 69 | |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 70 | #endif /* ARCH_FEATURES_H */ |