aboutsummaryrefslogtreecommitdiff
path: root/tftf/tests/misc_tests/inject_serror.S
diff options
context:
space:
mode:
Diffstat (limited to 'tftf/tests/misc_tests/inject_serror.S')
-rw-r--r--tftf/tests/misc_tests/inject_serror.S114
1 files changed, 114 insertions, 0 deletions
diff --git a/tftf/tests/misc_tests/inject_serror.S b/tftf/tests/misc_tests/inject_serror.S
new file mode 100644
index 000000000..0d7dbf2d7
--- /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