blob: 3621f212696e961350851ed63bd47dae6b058e89 [file] [log] [blame]
johpow01d0bbe6e2021-11-11 16:13:32 -06001/*
Juan Pablo Condebe3bb7e2023-02-22 10:18:14 -06002 * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
johpow01d0bbe6e2021-11-11 16:13:32 -06003 *
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. */
13test_result_t test_feat_hcx_enabled(void)
14{
15#ifdef __aarch64__
Juan Pablo Condebe3bb7e2023-02-22 10:18:14 -060016 u_register_t hcrx_el2;
17
johpow01d0bbe6e2021-11-11 16:13:32 -060018 /* 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 Condebe3bb7e2023-02-22 10:18:14 -060024 hcrx_el2 = read_hcrx_el2();
johpow01d0bbe6e2021-11-11 16:13:32 -060025
Juan Pablo Condebe3bb7e2023-02-22 10:18:14 -060026 /*
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;
johpow01d0bbe6e2021-11-11 16:13:32 -060042#else
43 /* Skip test if AArch32 */
44 return TEST_RESULT_SKIPPED;
45#endif
46}