feat(hcx): test that HCRX_EL2 is accessible

On systems with FEAT_HCX support this CPU extension test attempts
to access HCRX_EL2, if it can then the test passes, if not the
system traps to EL3 and crashes. This tells us whether or not TF-A
has properly enabled access to the register. To enable this test,
compile TFTF with TESTS=hcx, this is done to prevent this test from
running automatically on systems which may support FEAT_HCX but do
not have it enabled in TFA.

Signed-off-by: John Powell <john.powell@arm.com>
Change-Id: If5787c3e947872169af3c9c3e57587cbcd41fd9e
diff --git a/tftf/tests/extensions/hcx/test_hcx.c b/tftf/tests/extensions/hcx/test_hcx.c
new file mode 100644
index 0000000..ebc6e81
--- /dev/null
+++ b/tftf/tests/extensions/hcx/test_hcx.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <tftf_lib.h>
+#include <tftf.h>
+#include <arch_helpers.h>
+#include <arch_features.h>
+
+/* This very simple test just ensures that HCRX_EL2 access does not trap. */
+test_result_t test_feat_hcx_enabled(void)
+{
+#ifdef __aarch64__
+	/* Make sure FEAT_HCX is supported. */
+	if (!get_feat_hcx_support()) {
+		return TEST_RESULT_SKIPPED;
+	}
+
+	/* Attempt to read HCRX_EL2, if not enabled this should trap to EL3. */
+	read_hcrx_el2();
+
+	/* If we make it this far, the test was successful. */
+	return TEST_RESULT_SUCCESS;
+#else
+	/* Skip test if AArch32 */
+	return TEST_RESULT_SKIPPED;
+#endif
+}