Trusted Firmware-A Tests, version 2.0

This is the first public version of the tests for the Trusted
Firmware-A project. Please see the documentation provided in the
source tree for more details.

Change-Id: I6f3452046a1351ac94a71b3525c30a4ca8db7867
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Co-authored-by: amobal01 <amol.balasokamble@arm.com>
Co-authored-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Co-authored-by: Asha R <asha.r@arm.com>
Co-authored-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
Co-authored-by: David Cunado <david.cunado@arm.com>
Co-authored-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Co-authored-by: Douglas Raillard <douglas.raillard@arm.com>
Co-authored-by: dp-arm <dimitris.papastamos@arm.com>
Co-authored-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
Co-authored-by: Jonathan Wright <jonathan.wright@arm.com>
Co-authored-by: Kévin Petit <kevin.petit@arm.com>
Co-authored-by: Roberto Vargas <roberto.vargas@arm.com>
Co-authored-by: Sathees Balya <sathees.balya@arm.com>
Co-authored-by: Shawon Roy <Shawon.Roy@arm.com>
Co-authored-by: Soby Mathew <soby.mathew@arm.com>
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Co-authored-by: Vikram Kanigiri <vikram.kanigiri@arm.com>
Co-authored-by: Yatharth Kochar <yatharth.kochar@arm.com>
diff --git a/tftf/tests/misc_tests/inject_serror.S b/tftf/tests/misc_tests/inject_serror.S
new file mode 100644
index 0000000..0d7dbf2
--- /dev/null
+++ b/tftf/tests/misc_tests/inject_serror.S
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <asm_macros.S>
+#include <sdei.h>
+
+
+#ifdef AARCH64
+	.globl	inject_serror
+	.globl	inject_uncontainable
+	.globl	serror_sdei_event_handler
+
+/*
+ * Program fault injection register, and wait for ever for the fault to trigger.
+ * Note that Trusted Firmware must be compiled for ARMv8.4 along with
+ * FAULT_INJECTION_SUPPORT=1 for this to work. Besides, the model has to be
+ * launched with fault inject support.
+ *
+ * x0: Fault record number to program
+ * x1: Injected fault properties
+ * x2: Type of error to be generated
+ * x3: Memory location to wait for, or 0 if no waiting is required
+ */
+func inject_serror_record
+	/* Choose Error record 0 on the PE */
+	msr	ERRSELR_EL1, x0
+	isb
+
+	/* Enable error reporting */
+	orr	x1, x1, #ERXCTLR_ED_BIT
+	msr	ERXCTLR_EL1, x1
+
+	/* Program count down timer to 1 */
+	mov	x0, #1
+	msr	ERXPFGCDN_EL1, x0
+
+	/* Start count down to generate error */
+	orr	x2, x2, #ERXPFGCTL_CDEN_BIT
+	msr	ERXPFGCTL_EL1, x2
+	isb
+
+	cbz	x3, 2f
+
+	/* Clear SError received flag */
+	str	xzr, [x3, #0]
+	sevl
+
+1:
+	wfe
+	ldr	x0, [x3, #0]
+	cbz	x0, 1b
+
+2:
+	ret
+endfunc inject_serror_record
+
+/*
+ * Inject Unrecoverable error through fault record 0. Wait until serror_received
+ * is set by the SDEI handler in response to receving the event.
+ */
+func inject_serror
+	/* Inject fault into record 0 */
+	mov	x0, #0
+
+	/* Enable error reporting */
+	mov	x1, #ERXCTLR_UE_BIT
+	msr	ERXCTLR_EL1, x1
+
+	/* Injected fault control */
+	mov	x2, #ERXPFGCTL_UEU_BIT
+
+	/* Wait address */
+	adrp	x3, serror_received
+	add	x3, x3, :lo12:serror_received
+
+	b	inject_serror_record
+endfunc inject_serror
+
+/*
+ * Inject Uncontainable error through fault record 0. This function doesn't wait
+ * as the handling is terminal in EL3.
+ */
+func inject_uncontainable
+	/* Inject fault into record 0 */
+	mov	x0, #0
+
+	mov	x1, xzr
+
+	/* Injected fault control */
+	mov	x2, #ERXPFGCTL_UC_BIT
+
+	/* Nothing to wait for */
+	mov	x3, xzr
+
+	b	inject_serror_record
+endfunc inject_uncontainable
+
+/*
+ * SDEI event handler for SErrors.
+ */
+func serror_sdei_event_handler
+	stp	x29, x30, [sp, #-16]!
+	bl	serror_handler
+	ldp	x29, x30, [sp], #16
+	mov_imm	x0, SDEI_EVENT_COMPLETE
+	mov	x1, xzr
+	smc	#0
+	b	.
+endfunc serror_sdei_event_handler
+#endif