feat: unify Firmware First handling of lower el EA

Lower EL External Abort tests were implemented in such a way that after
triggering EA in tftf it gets trapped in EL3 and causing a crash in EL3
Because of the tests ending up in crash there are few problems:
 - Need to have to seperate tests one each for sync EA and Serror.
 - Unable to test the behaviour of system had the lower EL EA's been
   properly handled in EL3.

This patch merges both lower EL injection tests in single test suite and
expects a proper handling of lower EL EA's in TF-A. TF-A build macro
PLATFORM_TEST_EA_FFH allows fvp to have a proper handling.

This change will prepare ground for testing EA's which are caused by
syncronization barriers at exception boundry, which needs proper
handling of EA and then continue handling the original exception.

Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: I27d6a3d63ec4fc873ce07a55452185b6b6b4281a
diff --git a/tftf/tests/misc_tests/test_ea_ffh.c b/tftf/tests/misc_tests/test_ea_ffh.c
new file mode 100644
index 0000000..911962e
--- /dev/null
+++ b/tftf/tests/misc_tests/test_ea_ffh.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+
+#include <arch_helpers.h>
+#include <arm_arch_svc.h>
+#include <debug.h>
+#include <mmio.h>
+#include <tftf_lib.h>
+#include <smccc.h>
+#include <xlat_tables_v2.h>
+
+#define TEST_ADDRESS	UL(0x7FFFF000)
+
+/*
+ * Purpose of these tests is to ensure EA from lower EL trap/handled in EL3.
+ *
+ * Tests HANDLE_EA_EL3_FIRST_NS feature(SCR_EL3.EA = 1) of TF-A
+ *
+ * Works in conjunction with PLATFORM_TEST_EA_FFH macro in TF-A.
+ */
+
+/*
+ * This test maps a non-existent memory as Device memory and reads it.
+ * Memory is mapped as device and cause an error on bus and trap as an Sync EA.
+ */
+test_result_t test_inject_syncEA(void)
+{
+	int rc;
+
+	rc = mmap_add_dynamic_region(TEST_ADDRESS, TEST_ADDRESS, PAGE_SIZE,
+						MT_DEVICE | MT_RO | MT_NS);
+	if (rc != 0) {
+		tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
+				      __LINE__, TEST_ADDRESS, rc);
+		return TEST_RESULT_FAIL;
+	}
+
+	/*
+	 * Try reading invalid address, which will cause an exception to be handled in EL3.
+	 * EL3 after handling the exception returns to the next instruction to avoid
+	 * continous exceptions.
+	 */
+	rc = mmio_read_32(TEST_ADDRESS);
+
+	rc = mmap_remove_dynamic_region(TEST_ADDRESS, PAGE_SIZE);
+	if (rc != 0) {
+		tftf_testcase_printf("%d: mmap_remove_dynamic_region() = %d\n", __LINE__, rc);
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
+
+/*
+ * This test maps a non-existent memory as Device memory and write to it.
+ * Memory is mapped as device and cause an error on bus and trap as an SError.
+ */
+test_result_t test_inject_serror(void)
+{
+	int rc;
+
+	rc = mmap_add_dynamic_region(TEST_ADDRESS, TEST_ADDRESS, PAGE_SIZE,
+						MT_DEVICE | MT_RW | MT_NS);
+	if (rc != 0) {
+		tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
+				      __LINE__, TEST_ADDRESS, rc);
+		return TEST_RESULT_FAIL;
+	}
+
+	/* Try writing to invalid address */
+	mmio_write_32(TEST_ADDRESS, 1);
+
+	rc = mmap_remove_dynamic_region(TEST_ADDRESS, PAGE_SIZE);
+	if (rc != 0) {
+		tftf_testcase_printf("%d: mmap_remove_dynamic_region() = %d\n", __LINE__, rc);
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/misc_tests/test_inject_serror.c b/tftf/tests/misc_tests/test_inject_serror.c
deleted file mode 100644
index d02cd4e..0000000
--- a/tftf/tests/misc_tests/test_inject_serror.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2023, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-
-#include <arch_helpers.h>
-#include <debug.h>
-#include <mmio.h>
-#include <tftf_lib.h>
-#include <xlat_tables_v2.h>
-
-/*
- * Purpose of this test to ensure the crash dump for lower ELs in EL3 works fine.
- *
- * This test never returns, it ends up with a crash in EL3.
- *
- * This test maps a non-existent memory as Device memory and write to it.
- * Memory is mapped as device and cause an error on bus and trap as an SError.
- * This test is used in conjunction with HANDLE_EA_EL3_FIRST_NS feature
- * (trapping EA in lower ELs to EL3) in TF-A.
- * SError caused by this error will be trapped in EL3 and eventually cause a
- * panic along with printing Crash Dump for lower EL.
- */
-test_result_t test_inject_serror(void)
-{
-	int rc;
-	const uintptr_t test_address = 0x7FFFF000;
-
-	rc = mmap_add_dynamic_region(test_address, test_address, PAGE_SIZE,
-						MT_DEVICE | MT_RW | MT_NS);
-	if (rc != 0) {
-		tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
-				      __LINE__, test_address, rc);
-		return TEST_RESULT_FAIL;
-	}
-
-	/* Try writing to invalid address */
-	mmio_write_32(test_address, 1);
-
-	/* Should not come this far */
-	return TEST_RESULT_FAIL;
-}
diff --git a/tftf/tests/misc_tests/test_inject_syncEA.c b/tftf/tests/misc_tests/test_inject_syncEA.c
deleted file mode 100644
index 1ff847b..0000000
--- a/tftf/tests/misc_tests/test_inject_syncEA.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2023, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-
-#include <arch_helpers.h>
-#include <debug.h>
-#include <mmio.h>
-#include <tftf_lib.h>
-#include <xlat_tables_v2.h>
-
-/*
- * Purpose of this test to ensure the crash dump for lower ELs in EL3 works fine.
- *
- * This test never returns, it ends up with a crash in EL3.
- *
- * This test maps a non-existent memory as Device memory and reads it.
- * Memory is mapped as device and cause an error on bus and trap as an Sync EA.
- * This test is used in conjunction with HANDLE_EA_EL3_FIRST_NS feature
- * (trapping EA in lower ELs to EL3) in TF-A.
- * Sync EA caused by this error will be trapped in EL3 and eventually cause a
- * panic along with printing Crash Dump for lower EL.
- */
-test_result_t test_inject_syncEA(void)
-{
-	int rc;
-	const uintptr_t test_address = 0x7FFFF000;
-
-	rc = mmap_add_dynamic_region(test_address, test_address, PAGE_SIZE,
-						MT_DEVICE | MT_RO | MT_NS);
-	if (rc != 0) {
-		tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
-				      __LINE__, test_address, rc);
-		return TEST_RESULT_FAIL;
-	}
-
-	/* Try reading invalid address */
-	rc = mmio_read_32(test_address);
-
-	/* Should not come this far, print rc to avoid compiler optimization */
-	ERROR("Reading invalid address did not cause syncEA, rc = %d\n", rc);
-
-	return TEST_RESULT_FAIL;
-}
diff --git a/tftf/tests/tests-inject-serror.mk b/tftf/tests/tests-ea-ffh.mk
similarity index 63%
rename from tftf/tests/tests-inject-serror.mk
rename to tftf/tests/tests-ea-ffh.mk
index 6be9ebc..be0eb65 100644
--- a/tftf/tests/tests-inject-serror.mk
+++ b/tftf/tests/tests-ea-ffh.mk
@@ -4,4 +4,4 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-TESTS_SOURCES	+=	tftf/tests/misc_tests/test_inject_serror.c
+TESTS_SOURCES	+=	tftf/tests/misc_tests/test_ea_ffh.c
diff --git a/tftf/tests/tests-ea-ffh.xml b/tftf/tests/tests-ea-ffh.xml
new file mode 100644
index 0000000..1d31b8c
--- /dev/null
+++ b/tftf/tests/tests-ea-ffh.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright (c) 2023, Arm Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-3-Clause
+-->
+
+<testsuites>
+  <testsuite name="Inject External aborts" description="Injected EA's gets handled in EL3">
+     <testcase name="Inject syncEA which gets handled in EL3" function="test_inject_syncEA" />
+     <testcase name="Inject Serror which gets handled in EL3" function="test_inject_serror" />
+  </testsuite>
+
+</testsuites>
diff --git a/tftf/tests/tests-inject-serror.xml b/tftf/tests/tests-inject-serror.xml
deleted file mode 100644
index 6553640..0000000
--- a/tftf/tests/tests-inject-serror.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  Copyright (c) 2023, Arm Limited. All rights reserved.
-
-  SPDX-License-Identifier: BSD-3-Clause
--->
-
-<testsuites>
-  <testsuite name="Inject Serror" description="Inject SError">
-     <testcase name="Inject SError which will cause EL3 panic and produce crash dump" function="test_inject_serror" />
-  </testsuite>
-
-</testsuites>
diff --git a/tftf/tests/tests-inject-syncEA.mk b/tftf/tests/tests-inject-syncEA.mk
deleted file mode 100644
index 0130b7e..0000000
--- a/tftf/tests/tests-inject-syncEA.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-#
-# Copyright (c) 2023, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-TESTS_SOURCES	+=	tftf/tests/misc_tests/test_inject_syncEA.c
diff --git a/tftf/tests/tests-inject-syncEA.xml b/tftf/tests/tests-inject-syncEA.xml
deleted file mode 100644
index 993c4e4..0000000
--- a/tftf/tests/tests-inject-syncEA.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  Copyright (c) 2023, Arm Limited. All rights reserved.
-
-  SPDX-License-Identifier: BSD-3-Clause
--->
-
-<testsuites>
-  <testsuite name="Inject Sync EA" description="Inject Synchronous external abort">
-     <testcase name="Inject sync EA which will cause EL3 panic and produce crash dump" function="test_inject_syncEA" />
-  </testsuite>
-
-</testsuites>