blob: d42441dd36ae9c1c00a9fe9c41d705f47cd533cc [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]
301:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020031 /* Choose Error record 0 on the PE */
32 msr ERRSELR_EL1, x0
33 isb
34
35 /* Enable error reporting */
36 orr x1, x1, #ERXCTLR_ED_BIT
37 msr ERXCTLR_EL1, x1
38
39 /* Program count down timer to 1 */
40 mov x0, #1
41 msr ERXPFGCDN_EL1, x0
42
43 /* Start count down to generate error */
44 orr x2, x2, #ERXPFGCTL_CDEN_BIT
45 msr ERXPFGCTL_EL1, x2
46 isb
47
David Horstmann85c39c52020-11-09 11:42:31 +000048 /* If no waiting is required, jump to end */
49 cbz x3, 3f
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020050
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020051 sevl
52
David Horstmann85c39c52020-11-09 11:42:31 +0000532:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020054 wfe
55 ldr x0, [x3, #0]
David Horstmann85c39c52020-11-09 11:42:31 +000056 cbz x0, 2b
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020057
David Horstmann85c39c52020-11-09 11:42:31 +0000583:
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020059 ret
60endfunc inject_serror_record
61
62/*
63 * Inject Unrecoverable error through fault record 0. Wait until serror_received
64 * is set by the SDEI handler in response to receving the event.
65 */
66func inject_serror
67 /* Inject fault into record 0 */
68 mov x0, #0
69
70 /* Enable error reporting */
71 mov x1, #ERXCTLR_UE_BIT
72 msr ERXCTLR_EL1, x1
73
74 /* Injected fault control */
75 mov x2, #ERXPFGCTL_UEU_BIT
76
77 /* Wait address */
78 adrp x3, serror_received
79 add x3, x3, :lo12:serror_received
80
81 b inject_serror_record
82endfunc inject_serror
83
84/*
85 * Inject Uncontainable error through fault record 0. This function doesn't wait
86 * as the handling is terminal in EL3.
87 */
88func inject_uncontainable
89 /* Inject fault into record 0 */
90 mov x0, #0
91
92 mov x1, xzr
93
94 /* Injected fault control */
95 mov x2, #ERXPFGCTL_UC_BIT
96
97 /* Nothing to wait for */
98 mov x3, xzr
99
100 b inject_serror_record
101endfunc inject_uncontainable
102
103/*
104 * SDEI event handler for SErrors.
105 */
106func serror_sdei_event_handler
107 stp x29, x30, [sp, #-16]!
108 bl serror_handler
109 ldp x29, x30, [sp], #16
110 mov_imm x0, SDEI_EVENT_COMPLETE
111 mov x1, xzr
112 smc #0
113 b .
114endfunc serror_sdei_event_handler
115#endif