blob: fd51f8556a0f4a78086562141a389e139cd8ebee [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -06002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <sdei.h>
10
11
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060012#ifdef __aarch64__
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020013 .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.
David Horstmann85c39c52020-11-09 11:42:31 +000019 * Note that the model must be launched with fault inject support.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020020 *
21 * x0: Fault record number to program
22 * x1: Injected fault properties
23 * x2: Type of error to be generated
24 * x3: Memory location to wait for, or 0 if no waiting is required
25 */
26func inject_serror_record
David Horstmann85c39c52020-11-09 11:42:31 +000027 /* Clear SError received flag if necessary */
28 cbz x3, 1f
29 str xzr, [x3, #0]
David Horstmannaeda12b2021-04-23 15:24:46 +010030 dsb st
David Horstmann85c39c52020-11-09 11:42:31 +0000311:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020032 /* Choose Error record 0 on the PE */
33 msr ERRSELR_EL1, x0
34 isb
35
36 /* Enable error reporting */
37 orr x1, x1, #ERXCTLR_ED_BIT
38 msr ERXCTLR_EL1, x1
39
40 /* Program count down timer to 1 */
41 mov x0, #1
42 msr ERXPFGCDN_EL1, x0
43
44 /* Start count down to generate error */
45 orr x2, x2, #ERXPFGCTL_CDEN_BIT
46 msr ERXPFGCTL_EL1, x2
47 isb
48
David Horstmann85c39c52020-11-09 11:42:31 +000049 /* If no waiting is required, jump to end */
50 cbz x3, 3f
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020051
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020052 sevl
53
David Horstmann85c39c52020-11-09 11:42:31 +0000542:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020055 wfe
David Horstmannaeda12b2021-04-23 15:24:46 +010056 dsb st
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020057 ldr x0, [x3, #0]
David Horstmann85c39c52020-11-09 11:42:31 +000058 cbz x0, 2b
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020059
David Horstmann85c39c52020-11-09 11:42:31 +0000603:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020061 ret
62endfunc inject_serror_record
63
64/*
65 * Inject Unrecoverable error through fault record 0. Wait until serror_received
66 * is set by the SDEI handler in response to receving the event.
67 */
68func inject_serror
69 /* Inject fault into record 0 */
70 mov x0, #0
71
72 /* Enable error reporting */
73 mov x1, #ERXCTLR_UE_BIT
74 msr ERXCTLR_EL1, x1
75
76 /* Injected fault control */
77 mov x2, #ERXPFGCTL_UEU_BIT
78
79 /* Wait address */
80 adrp x3, serror_received
81 add x3, x3, :lo12:serror_received
82
83 b inject_serror_record
84endfunc inject_serror
85
86/*
87 * Inject Uncontainable error through fault record 0. This function doesn't wait
88 * as the handling is terminal in EL3.
89 */
90func inject_uncontainable
91 /* Inject fault into record 0 */
92 mov x0, #0
93
94 mov x1, xzr
95
96 /* Injected fault control */
97 mov x2, #ERXPFGCTL_UC_BIT
98
99 /* Nothing to wait for */
100 mov x3, xzr
101
102 b inject_serror_record
103endfunc inject_uncontainable
104
105/*
106 * SDEI event handler for SErrors.
107 */
108func serror_sdei_event_handler
109 stp x29, x30, [sp, #-16]!
110 bl serror_handler
111 ldp x29, x30, [sp], #16
112 mov_imm x0, SDEI_EVENT_COMPLETE
113 mov x1, xzr
114 smc #0
115 b .
116endfunc serror_sdei_event_handler
117#endif