blob: 0d7dbf2d7519ad80a6a8c1a85e40196bafdf943e [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <sdei.h>
10
11
12#ifdef AARCH64
13 .globl inject_serror
14 .globl inject_uncontainable
15 .globl serror_sdei_event_handler
16
17/*
18 * Program fault injection register, and wait for ever for the fault to trigger.
19 * Note that Trusted Firmware must be compiled for ARMv8.4 along with
20 * FAULT_INJECTION_SUPPORT=1 for this to work. Besides, the model has to be
21 * launched with fault inject support.
22 *
23 * x0: Fault record number to program
24 * x1: Injected fault properties
25 * x2: Type of error to be generated
26 * x3: Memory location to wait for, or 0 if no waiting is required
27 */
28func inject_serror_record
29 /* Choose Error record 0 on the PE */
30 msr ERRSELR_EL1, x0
31 isb
32
33 /* Enable error reporting */
34 orr x1, x1, #ERXCTLR_ED_BIT
35 msr ERXCTLR_EL1, x1
36
37 /* Program count down timer to 1 */
38 mov x0, #1
39 msr ERXPFGCDN_EL1, x0
40
41 /* Start count down to generate error */
42 orr x2, x2, #ERXPFGCTL_CDEN_BIT
43 msr ERXPFGCTL_EL1, x2
44 isb
45
46 cbz x3, 2f
47
48 /* Clear SError received flag */
49 str xzr, [x3, #0]
50 sevl
51
521:
53 wfe
54 ldr x0, [x3, #0]
55 cbz x0, 1b
56
572:
58 ret
59endfunc inject_serror_record
60
61/*
62 * Inject Unrecoverable error through fault record 0. Wait until serror_received
63 * is set by the SDEI handler in response to receving the event.
64 */
65func inject_serror
66 /* Inject fault into record 0 */
67 mov x0, #0
68
69 /* Enable error reporting */
70 mov x1, #ERXCTLR_UE_BIT
71 msr ERXCTLR_EL1, x1
72
73 /* Injected fault control */
74 mov x2, #ERXPFGCTL_UEU_BIT
75
76 /* Wait address */
77 adrp x3, serror_received
78 add x3, x3, :lo12:serror_received
79
80 b inject_serror_record
81endfunc inject_serror
82
83/*
84 * Inject Uncontainable error through fault record 0. This function doesn't wait
85 * as the handling is terminal in EL3.
86 */
87func inject_uncontainable
88 /* Inject fault into record 0 */
89 mov x0, #0
90
91 mov x1, xzr
92
93 /* Injected fault control */
94 mov x2, #ERXPFGCTL_UC_BIT
95
96 /* Nothing to wait for */
97 mov x3, xzr
98
99 b inject_serror_record
100endfunc inject_uncontainable
101
102/*
103 * SDEI event handler for SErrors.
104 */
105func serror_sdei_event_handler
106 stp x29, x30, [sp, #-16]!
107 bl serror_handler
108 ldp x29, x30, [sp], #16
109 mov_imm x0, SDEI_EVENT_COMPLETE
110 mov x1, xzr
111 smc #0
112 b .
113endfunc serror_sdei_event_handler
114#endif