blob: 6e71a063a2550ee98c3c9f2668ff6676e97da043 [file] [log] [blame]
Jeenu Viswambharane86a2472018-07-05 15:24:45 +01001/*
Antonio Nino Diaz594811b2019-01-31 11:58:00 +00002 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharane86a2472018-07-05 15:24:45 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +01008#include <assert_macros.S>
Jeenu Viswambharane86a2472018-07-05 15:24:45 +01009#include <asm_macros.S>
Jeenu Viswambharan476c29f2018-02-19 12:25:53 +000010#include <assert_macros.S>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <bl31/ea_handle.h>
Jeenu Viswambharane86a2472018-07-05 15:24:45 +010012#include <context.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/extensions/ras_arch.h>
Jeenu Viswambharane86a2472018-07-05 15:24:45 +010014
15
16 .globl handle_lower_el_ea_esb
17 .globl enter_lower_el_sync_ea
18 .globl enter_lower_el_async_ea
19
20
21/*
22 * Function to delegate External Aborts synchronized by ESB instruction at EL3
23 * vector entry. This function assumes GP registers x0-x29 have been saved, and
24 * are available for use. It delegates the handling of the EA to platform
25 * handler, and returns only upon successfully handling the EA; otherwise
26 * panics. On return from this function, the original exception handler is
27 * expected to resume.
28 */
29func handle_lower_el_ea_esb
30 mov x0, #ERROR_EA_ESB
31 mrs x1, DISR_EL1
32 b ea_proceed
33endfunc handle_lower_el_ea_esb
34
35
36/*
37 * This function forms the tail end of Synchronous Exception entry from lower
38 * EL, and expects to handle only Synchronous External Aborts from lower EL. If
39 * any other kind of exception is detected, then this function reports unhandled
40 * exception.
41 *
42 * Since it's part of exception vector, this function doesn't expect any GP
43 * registers to have been saved. It delegates the handling of the EA to platform
44 * handler, and upon successfully handling the EA, exits EL3; otherwise panics.
45 */
46func enter_lower_el_sync_ea
47 /*
48 * Explicitly save x30 so as to free up a register and to enable
49 * branching.
50 */
51 str x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
52
53 mrs x30, esr_el3
54 ubfx x30, x30, #ESR_EC_SHIFT, #ESR_EC_LENGTH
55
56 /* Check for I/D aborts from lower EL */
57 cmp x30, #EC_IABORT_LOWER_EL
58 b.eq 1f
59
60 cmp x30, #EC_DABORT_LOWER_EL
61 b.ne 2f
62
631:
64 /* Test for EA bit in the instruction syndrome */
65 mrs x30, esr_el3
66 tbz x30, #ESR_ISS_EABORT_EA_BIT, 2f
67
Alexei Fedorov503bbf32019-08-13 15:17:53 +010068 /*
Alexei Fedorovf41355c2019-09-13 14:11:59 +010069 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
70 * If Secure Cycle Counter is not disabled in MDCR_EL3 when
71 * ARMv8.5-PMU is implemented, save PMCR_EL0 and disable Cycle Counter.
Alexei Fedorov503bbf32019-08-13 15:17:53 +010072 */
Alexei Fedorovf41355c2019-09-13 14:11:59 +010073 bl save_gp_pmcr_pauth_regs
Alexei Fedorov503bbf32019-08-13 15:17:53 +010074
Antonio Nino Diaz25cda672019-02-19 11:53:51 +000075#if ENABLE_PAUTH
Alexei Fedorovf41355c2019-09-13 14:11:59 +010076 /* Load and program APIAKey firmware key */
77 bl pauth_load_bl31_apiakey
Antonio Nino Diaz25cda672019-02-19 11:53:51 +000078#endif
Antonio Nino Diaz594811b2019-01-31 11:58:00 +000079
Jeenu Viswambharane86a2472018-07-05 15:24:45 +010080 /* Setup exception class and syndrome arguments for platform handler */
81 mov x0, #ERROR_EA_SYNC
82 mrs x1, esr_el3
83 adr x30, el3_exit
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +010084 b delegate_sync_ea
Jeenu Viswambharane86a2472018-07-05 15:24:45 +010085
862:
87 /* Synchronous exceptions other than the above are assumed to be EA */
88 ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
89 no_ret report_unhandled_exception
90endfunc enter_lower_el_sync_ea
91
92
93/*
94 * This function handles SErrors from lower ELs.
95 *
96 * Since it's part of exception vector, this function doesn't expect any GP
97 * registers to have been saved. It delegates the handling of the EA to platform
98 * handler, and upon successfully handling the EA, exits EL3; otherwise panics.
99 */
100func enter_lower_el_async_ea
101 /*
102 * Explicitly save x30 so as to free up a register and to enable
103 * branching
104 */
105 str x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
106
Alexei Fedorov503bbf32019-08-13 15:17:53 +0100107 /*
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100108 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
109 * If Secure Cycle Counter is not disabled in MDCR_EL3 when
110 * ARMv8.5-PMU is implemented, save PMCR_EL0 and disable Cycle Counter.
Alexei Fedorov503bbf32019-08-13 15:17:53 +0100111 */
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100112 bl save_gp_pmcr_pauth_regs
Alexei Fedorov503bbf32019-08-13 15:17:53 +0100113
Antonio Nino Diaz25cda672019-02-19 11:53:51 +0000114#if ENABLE_PAUTH
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100115 /* Load and program APIAKey firmware key */
116 bl pauth_load_bl31_apiakey
Antonio Nino Diaz25cda672019-02-19 11:53:51 +0000117#endif
Antonio Nino Diaz594811b2019-01-31 11:58:00 +0000118
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100119 /* Setup exception class and syndrome arguments for platform handler */
120 mov x0, #ERROR_EA_ASYNC
121 mrs x1, esr_el3
122 adr x30, el3_exit
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +0100123 b delegate_async_ea
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100124endfunc enter_lower_el_async_ea
125
126
127/*
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +0100128 * Prelude for Synchronous External Abort handling. This function assumes that
129 * all GP registers have been saved by the caller.
130 *
131 * x0: EA reason
132 * x1: EA syndrome
133 */
134func delegate_sync_ea
135#if RAS_EXTENSION
136 /*
137 * Check for Uncontainable error type. If so, route to the platform
138 * fatal error handler rather than the generic EA one.
139 */
140 ubfx x2, x1, #EABORT_SET_SHIFT, #EABORT_SET_WIDTH
141 cmp x2, #ERROR_STATUS_SET_UC
142 b.ne 1f
143
144 /* Check fault status code */
145 ubfx x3, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
146 cmp x3, #SYNC_EA_FSC
147 b.ne 1f
148
149 no_ret plat_handle_uncontainable_ea
1501:
151#endif
152
153 b ea_proceed
154endfunc delegate_sync_ea
155
156
157/*
158 * Prelude for Asynchronous External Abort handling. This function assumes that
159 * all GP registers have been saved by the caller.
160 *
161 * x0: EA reason
162 * x1: EA syndrome
163 */
164func delegate_async_ea
165#if RAS_EXTENSION
166 /*
167 * Check for Implementation Defined Syndrome. If so, skip checking
168 * Uncontainable error type from the syndrome as the format is unknown.
169 */
170 tbnz x1, #SERROR_IDS_BIT, 1f
171
172 /*
173 * Check for Uncontainable error type. If so, route to the platform
174 * fatal error handler rather than the generic EA one.
175 */
176 ubfx x2, x1, #EABORT_AET_SHIFT, #EABORT_AET_WIDTH
177 cmp x2, #ERROR_STATUS_UET_UC
178 b.ne 1f
179
180 /* Check DFSC for SError type */
181 ubfx x3, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
182 cmp x3, #DFSC_SERROR
183 b.ne 1f
184
185 no_ret plat_handle_uncontainable_ea
1861:
187#endif
188
189 b ea_proceed
190endfunc delegate_async_ea
191
192
193/*
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100194 * Delegate External Abort handling to platform's EA handler. This function
195 * assumes that all GP registers have been saved by the caller.
196 *
197 * x0: EA reason
198 * x1: EA syndrome
199 */
200func ea_proceed
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +0100201 /*
202 * If the ESR loaded earlier is not zero, we were processing an EA
203 * already, and this is a double fault.
204 */
205 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_ESR_EL3]
206 cbz x5, 1f
207 no_ret plat_handle_double_fault
208
2091:
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100210 /* Save EL3 state */
211 mrs x2, spsr_el3
212 mrs x3, elr_el3
213 stp x2, x3, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
214
215 /*
216 * Save ESR as handling might involve lower ELs, and returning back to
217 * EL3 from there would trample the original ESR.
218 */
219 mrs x4, scr_el3
220 mrs x5, esr_el3
221 stp x4, x5, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
222
223 /*
224 * Setup rest of arguments, and call platform External Abort handler.
225 *
226 * x0: EA reason (already in place)
227 * x1: Exception syndrome (already in place).
228 * x2: Cookie (unused for now).
229 * x3: Context pointer.
230 * x4: Flags (security state from SCR for now).
231 */
232 mov x2, xzr
233 mov x3, sp
234 ubfx x4, x4, #0, #1
235
236 /* Switch to runtime stack */
237 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100238 msr spsel, #MODE_SP_EL0
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100239 mov sp, x5
240
241 mov x29, x30
Jeenu Viswambharan476c29f2018-02-19 12:25:53 +0000242#if ENABLE_ASSERTIONS
243 /* Stash the stack pointer */
244 mov x28, sp
245#endif
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100246 bl plat_ea_handler
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100247
Jeenu Viswambharan476c29f2018-02-19 12:25:53 +0000248#if ENABLE_ASSERTIONS
249 /*
250 * Error handling flows might involve long jumps; so upon returning from
251 * the platform error handler, validate that the we've completely
252 * unwound the stack.
253 */
254 mov x27, sp
255 cmp x28, x27
256 ASM_ASSERT(eq)
257#endif
258
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100259 /* Make SP point to context */
Alexei Fedorovf41355c2019-09-13 14:11:59 +0100260 msr spsel, #MODE_SP_ELX
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100261
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +0100262 /* Restore EL3 state and ESR */
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100263 ldp x1, x2, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
264 msr spsr_el3, x1
265 msr elr_el3, x2
266
267 /* Restore ESR_EL3 and SCR_EL3 */
268 ldp x3, x4, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
269 msr scr_el3, x3
270 msr esr_el3, x4
271
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +0100272#if ENABLE_ASSERTIONS
273 cmp x4, xzr
274 ASM_ASSERT(ne)
275#endif
276
277 /* Clear ESR storage */
278 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_ESR_EL3]
279
280 ret x29
Jeenu Viswambharane86a2472018-07-05 15:24:45 +0100281endfunc ea_proceed