feat: introduce test to generate sync EA

Introduce capability to generate Sync External Abort in TFTF.
One of the usecases of this capability is to test EL3 feature of
trapping lower ELs sync EA.

Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: I503c6776463efdd71cb8f05f6e19fc82b8dd7fdd
diff --git a/tftf/tests/misc_tests/test_inject_syncEA.c b/tftf/tests/misc_tests/test_inject_syncEA.c
new file mode 100644
index 0000000..1ff847b
--- /dev/null
+++ b/tftf/tests/misc_tests/test_inject_syncEA.c
@@ -0,0 +1,46 @@
+/*
+ * 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-syncEA.mk b/tftf/tests/tests-inject-syncEA.mk
new file mode 100644
index 0000000..0130b7e
--- /dev/null
+++ b/tftf/tests/tests-inject-syncEA.mk
@@ -0,0 +1,7 @@
+#
+# 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
new file mode 100644
index 0000000..993c4e4
--- /dev/null
+++ b/tftf/tests/tests-inject-syncEA.xml
@@ -0,0 +1,14 @@
+<?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>