Manish V Badarkhe | 589a112 | 2021-12-31 15:20:08 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <test_helpers.h> |
| 8 | |
| 9 | #ifdef __aarch64__ |
| 10 | /* |
| 11 | * Get SPE version value from id_aa64dfr0_el1. |
| 12 | * Return values |
| 13 | * ID_AA64DFR0_SPE_NOT_SUPPORTED: not supported |
| 14 | * ID_AA64DFR0_SPE: FEAT_SPE supported (introduced in ARM v8.2) |
| 15 | * ID_AA64DFR0_SPE_V1P1: FEAT_SPEv1p1 supported (introduced in ARM v8.5) |
| 16 | * ID_AA64DFR0_SPE_V1P2: FEAT_SPEv1p2 supported (introduced in ARM v8.7) |
| 17 | */ |
| 18 | |
| 19 | typedef enum { |
| 20 | ID_AA64DFR0_SPE_NOT_SUPPORTED = 0, |
| 21 | ID_AA64DFR0_SPE, |
| 22 | ID_AA64DFR0_SPE_V1P1, |
| 23 | ID_AA64DFR0_SPE_V1P2 |
| 24 | } spe_ver_t; |
| 25 | |
| 26 | static spe_ver_t spe_get_version(void) |
| 27 | { |
| 28 | return (spe_ver_t)((read_id_aa64dfr0_el1() >> ID_AA64DFR0_PMS_SHIFT) & |
| 29 | ID_AA64DFR0_PMS_MASK); |
| 30 | } |
| 31 | #endif /* __aarch64__ */ |
| 32 | |
| 33 | test_result_t test_spe_support(void) |
| 34 | { |
| 35 | /* SPE is an AArch64-only feature.*/ |
| 36 | SKIP_TEST_IF_AARCH32(); |
| 37 | |
| 38 | #ifdef __aarch64__ |
| 39 | spe_ver_t spe_ver = spe_get_version(); |
| 40 | |
| 41 | assert(spe_ver <= ID_AA64DFR0_SPE_V1P2); |
| 42 | |
| 43 | if (spe_ver == ID_AA64DFR0_SPE_NOT_SUPPORTED) { |
| 44 | return TEST_RESULT_SKIPPED; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * If runtime-EL3 does not enable access to SPE system |
| 49 | * registers from NS-EL2/NS-EL1 then read of these |
| 50 | * registers traps in EL3 |
| 51 | */ |
| 52 | read_pmscr_el1(); |
| 53 | read_pmsfcr_el1(); |
| 54 | read_pmsicr_el1(); |
| 55 | read_pmsidr_el1(); |
| 56 | read_pmsirr_el1(); |
| 57 | read_pmslatfr_el1(); |
| 58 | read_pmblimitr_el1(); |
| 59 | read_pmbptr_el1(); |
| 60 | read_pmbsr_el1(); |
| 61 | read_pmsevfr_el1(); |
| 62 | if (IS_IN_EL2()) { |
| 63 | read_pmscr_el2(); |
| 64 | } |
| 65 | if (spe_ver == ID_AA64DFR0_SPE_V1P2) { |
| 66 | read_pmsnevfr_el1(); |
| 67 | } |
| 68 | |
| 69 | return TEST_RESULT_SUCCESS; |
| 70 | #endif /* __aarch64__ */ |
| 71 | } |