johpow01 | d0bbe6e | 2021-11-11 16:13:32 -0600 | [diff] [blame] | 1 | /* |
Juan Pablo Conde | be3bb7e | 2023-02-22 10:18:14 -0600 | [diff] [blame] | 2 | * Copyright (c) 2021-2023, Arm Limited. All rights reserved. |
johpow01 | d0bbe6e | 2021-11-11 16:13:32 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <tftf_lib.h> |
| 8 | #include <tftf.h> |
| 9 | #include <arch_helpers.h> |
| 10 | #include <arch_features.h> |
| 11 | |
| 12 | /* This very simple test just ensures that HCRX_EL2 access does not trap. */ |
| 13 | test_result_t test_feat_hcx_enabled(void) |
| 14 | { |
| 15 | #ifdef __aarch64__ |
Juan Pablo Conde | be3bb7e | 2023-02-22 10:18:14 -0600 | [diff] [blame] | 16 | u_register_t hcrx_el2; |
| 17 | |
johpow01 | d0bbe6e | 2021-11-11 16:13:32 -0600 | [diff] [blame] | 18 | /* Make sure FEAT_HCX is supported. */ |
| 19 | if (!get_feat_hcx_support()) { |
| 20 | return TEST_RESULT_SKIPPED; |
| 21 | } |
| 22 | |
| 23 | /* Attempt to read HCRX_EL2, if not enabled this should trap to EL3. */ |
Juan Pablo Conde | be3bb7e | 2023-02-22 10:18:14 -0600 | [diff] [blame] | 24 | hcrx_el2 = read_hcrx_el2(); |
johpow01 | d0bbe6e | 2021-11-11 16:13:32 -0600 | [diff] [blame] | 25 | |
Juan Pablo Conde | be3bb7e | 2023-02-22 10:18:14 -0600 | [diff] [blame] | 26 | /* |
| 27 | * If we make it this far, access to HCRX_EL2 was not trapped, and |
| 28 | * therefore FEAT_HCX is supported. |
| 29 | */ |
| 30 | if (hcrx_el2 == HCRX_EL2_INIT_VAL) { |
| 31 | /* |
| 32 | * If the value of the register is the reset value, the test |
| 33 | * passed. |
| 34 | */ |
| 35 | return TEST_RESULT_SUCCESS; |
| 36 | } |
| 37 | /* |
| 38 | * Otherwise, the test fails, as the HCRX_EL2 register has |
| 39 | * not been initialized properly. |
| 40 | */ |
| 41 | return TEST_RESULT_FAIL; |
johpow01 | d0bbe6e | 2021-11-11 16:13:32 -0600 | [diff] [blame] | 42 | #else |
| 43 | /* Skip test if AArch32 */ |
| 44 | return TEST_RESULT_SKIPPED; |
| 45 | #endif |
| 46 | } |