blob: fce17e1d3a55245f96afc7dca4083956a111fc9e [file] [log] [blame]
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +01001/*
Daniel Boulby97215e02022-01-19 11:20:05 +00002 * Copyright (c) 2018-2022, ARM Limited and Contributors. All rights reserved.
Varun Wadekardf56e9d2022-08-03 12:01:36 +01003 * Copyright (c) 2022, NVIDIA Corporation. All rights reserved.
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +01004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8
Jeenu Viswambharand5a23af2018-05-17 11:24:01 +01009#include <assert_macros.S>
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010010#include <asm_macros.S>
Jeenu Viswambharanee6ff1b2018-02-19 12:25:53 +000011#include <assert_macros.S>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000012#include <bl31/ea_handle.h>
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010013#include <context.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000014#include <lib/extensions/ras_arch.h>
laurenw-arm80942622019-08-20 15:51:24 -050015#include <cpu_macros.S>
16#include <context.h>
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010017
Manish Pandey6f7de9a2023-01-11 21:53:02 +000018 .globl handle_lower_el_sync_ea
19 .globl handle_lower_el_async_ea
Manish Pandeyd04c04a2023-05-25 13:46:14 +010020 .globl handle_pending_async_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010021/*
Manish Pandey6d22b082023-10-11 11:52:24 +010022 * This function handles Synchronous External Aborts from lower EL.
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010023 *
Manish Pandey6f7de9a2023-01-11 21:53:02 +000024 * It delegates the handling of the EA to platform handler, and upon successfully
25 * handling the EA, exits EL3; otherwise panics.
26 *
27 * This function assumes x30 has been saved.
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010028 */
Manish Pandey6f7de9a2023-01-11 21:53:02 +000029func handle_lower_el_sync_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010030 mrs x30, esr_el3
31 ubfx x30, x30, #ESR_EC_SHIFT, #ESR_EC_LENGTH
32
33 /* Check for I/D aborts from lower EL */
34 cmp x30, #EC_IABORT_LOWER_EL
35 b.eq 1f
36
37 cmp x30, #EC_DABORT_LOWER_EL
laurenw-arm80942622019-08-20 15:51:24 -050038 b.eq 1f
39
Manish Pandey6d22b082023-10-11 11:52:24 +010040 /* EA other than above are unhandled exceptions */
41 no_ret report_unhandled_exception
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100421:
Alexei Fedorove290a8f2019-08-13 15:17:53 +010043 /*
Alexei Fedoroved108b52019-09-13 14:11:59 +010044 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
Boyan Karatotev1d6d6802022-12-06 09:03:42 +000045 * Also save PMCR_EL0 and set the PSTATE to a known state.
Alexei Fedorove290a8f2019-08-13 15:17:53 +010046 */
Daniel Boulby97215e02022-01-19 11:20:05 +000047 bl prepare_el3_entry
Alexei Fedorove290a8f2019-08-13 15:17:53 +010048
Antonio Nino Diazb86048c2019-02-19 11:53:51 +000049#if ENABLE_PAUTH
Alexei Fedoroved108b52019-09-13 14:11:59 +010050 /* Load and program APIAKey firmware key */
51 bl pauth_load_bl31_apiakey
Antonio Nino Diazb86048c2019-02-19 11:53:51 +000052#endif
Antonio Nino Diaz52839622019-01-31 11:58:00 +000053
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010054 /* Setup exception class and syndrome arguments for platform handler */
55 mov x0, #ERROR_EA_SYNC
56 mrs x1, esr_el3
Jan Dabrosbb9549b2019-12-02 13:30:03 +010057 bl delegate_sync_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010058
Jan Dabrosbb9549b2019-12-02 13:30:03 +010059 /* el3_exit assumes SP_EL0 on entry */
60 msr spsel, #MODE_SP_EL0
61 b el3_exit
Manish Pandey6f7de9a2023-01-11 21:53:02 +000062endfunc handle_lower_el_sync_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010063
64
65/*
66 * This function handles SErrors from lower ELs.
67 *
Manish Pandey6f7de9a2023-01-11 21:53:02 +000068 * It delegates the handling of the EA to platform handler, and upon successfully
69 * handling the EA, exits EL3; otherwise panics.
70 *
71 * This function assumes x30 has been saved.
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010072 */
Manish Pandey6f7de9a2023-01-11 21:53:02 +000073func handle_lower_el_async_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010074
Alexei Fedorove290a8f2019-08-13 15:17:53 +010075 /*
Alexei Fedoroved108b52019-09-13 14:11:59 +010076 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
Boyan Karatotev1d6d6802022-12-06 09:03:42 +000077 * Also save PMCR_EL0 and set the PSTATE to a known state.
Alexei Fedorove290a8f2019-08-13 15:17:53 +010078 */
Daniel Boulby97215e02022-01-19 11:20:05 +000079 bl prepare_el3_entry
Alexei Fedorove290a8f2019-08-13 15:17:53 +010080
Antonio Nino Diazb86048c2019-02-19 11:53:51 +000081#if ENABLE_PAUTH
Alexei Fedoroved108b52019-09-13 14:11:59 +010082 /* Load and program APIAKey firmware key */
83 bl pauth_load_bl31_apiakey
Antonio Nino Diazb86048c2019-02-19 11:53:51 +000084#endif
Antonio Nino Diaz52839622019-01-31 11:58:00 +000085
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010086 /* Setup exception class and syndrome arguments for platform handler */
87 mov x0, #ERROR_EA_ASYNC
88 mrs x1, esr_el3
Jan Dabrosbb9549b2019-12-02 13:30:03 +010089 bl delegate_async_ea
90
91 /* el3_exit assumes SP_EL0 on entry */
92 msr spsel, #MODE_SP_EL0
93 b el3_exit
Manish Pandey6f7de9a2023-01-11 21:53:02 +000094endfunc handle_lower_el_async_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +010095
Manish Pandeyd04c04a2023-05-25 13:46:14 +010096/*
Manish Pandey6d22b082023-10-11 11:52:24 +010097 * Handler for async EA from lower EL synchronized at EL3 entry in FFH mode.
Manish Pandeyd04c04a2023-05-25 13:46:14 +010098 *
99 * This scenario may arise when there is an error (EA) in the system which is not
100 * yet signaled to PE while executing in lower EL. During entry into EL3, the errors
101 * are synchronized either implicitly or explicitly causing async EA to pend at EL3.
102 *
Manish Pandey6d22b082023-10-11 11:52:24 +0100103 * On detecting the pending EA (via ISR_EL1.A), if the EA routing model is Firmware
104 * First handling (FFH, SCR_EL3.EA = 1) this handler first handles the pending EA
105 * and then handles the original exception.
Manish Pandeyd04c04a2023-05-25 13:46:14 +0100106 *
107 * This function assumes x30 has been saved.
108 */
Manish Pandeyd04c04a2023-05-25 13:46:14 +0100109func handle_pending_async_ea
110 /*
111 * Prepare for nested handling of EA. Stash sysregs clobbered by nested
112 * exception and handler
113 */
114 str x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_GPREG_LR]
115 mrs x30, esr_el3
116 str x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ESR_EL3]
117 mrs x30, spsr_el3
118 str x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_SPSR_EL3]
119 mrs x30, elr_el3
120 str x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ELR_EL3]
121
122 mov x30, #1
123 str x30, [sp, #CTX_EL3STATE_OFFSET + CTX_NESTED_EA_FLAG]
124 /*
125 * Restore the original x30 saved as part of entering EL3. This is not
126 * required for the current function but for EL3 SError vector entry
127 * once PSTATE.A bit is unmasked. We restore x30 and then the same
128 * value is stored in EL3 SError vector entry.
129 */
130 ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
131
132 /*
133 * After clearing PSTATE.A bit pending SError will trigger at current EL.
134 * Put explicit synchronization event to ensure newly unmasked interrupt
135 * is taken immediately.
136 */
137 unmask_async_ea
138
139 /* Restore the original exception information along with zeroing the storage */
140 ldr x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ELR_EL3]
141 msr elr_el3, x30
142 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ELR_EL3]
143 ldr x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_SPSR_EL3]
144 msr spsr_el3, x30
145 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_SPSR_EL3]
146 ldr x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ESR_EL3]
147 msr esr_el3, x30
148 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_ESR_EL3]
149
150 /*
151 * If the original exception corresponds to SError from lower El, eret back
152 * to lower EL, otherwise return to vector table for original exception handling.
153 */
154 ubfx x30, x30, #ESR_EC_SHIFT, #ESR_EC_LENGTH
155 cmp x30, #EC_SERROR
156 ldr x30, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_GPREG_LR]
157 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_SAVED_GPREG_LR]
158 b.eq 1f
159 ret
1601:
Jaiprakash Singh0bc31152024-12-22 22:13:57 -0800161 ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
162 str xzr, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
Manish Pandeyd04c04a2023-05-25 13:46:14 +0100163 exception_return
164endfunc handle_pending_async_ea
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100165
166/*
Jeenu Viswambharanb56dc2a2018-05-17 09:52:36 +0100167 * Prelude for Synchronous External Abort handling. This function assumes that
168 * all GP registers have been saved by the caller.
169 *
170 * x0: EA reason
171 * x1: EA syndrome
172 */
173func delegate_sync_ea
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100174#if ENABLE_FEAT_RAS
Jeenu Viswambharanb56dc2a2018-05-17 09:52:36 +0100175 /*
176 * Check for Uncontainable error type. If so, route to the platform
177 * fatal error handler rather than the generic EA one.
178 */
179 ubfx x2, x1, #EABORT_SET_SHIFT, #EABORT_SET_WIDTH
180 cmp x2, #ERROR_STATUS_SET_UC
181 b.ne 1f
182
183 /* Check fault status code */
184 ubfx x3, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
185 cmp x3, #SYNC_EA_FSC
186 b.ne 1f
187
188 no_ret plat_handle_uncontainable_ea
1891:
190#endif
191
192 b ea_proceed
193endfunc delegate_sync_ea
194
195
196/*
197 * Prelude for Asynchronous External Abort handling. This function assumes that
198 * all GP registers have been saved by the caller.
199 *
200 * x0: EA reason
201 * x1: EA syndrome
202 */
203func delegate_async_ea
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100204#if ENABLE_FEAT_RAS
Manish Pandeyd4352382022-10-11 17:28:14 +0100205 /* Check Exception Class to ensure SError, as this function should
206 * only be invoked for SError. If that is not the case, which implies
207 * either an HW error or programming error, panic.
208 */
209 ubfx x2, x1, #ESR_EC_SHIFT, #ESR_EC_LENGTH
210 cmp x2, EC_SERROR
Govindraj Rajabd62ce92023-01-16 17:35:07 +0000211 b.ne el3_panic
Jeenu Viswambharanb56dc2a2018-05-17 09:52:36 +0100212 /*
213 * Check for Implementation Defined Syndrome. If so, skip checking
214 * Uncontainable error type from the syndrome as the format is unknown.
215 */
216 tbnz x1, #SERROR_IDS_BIT, 1f
217
Manish Pandeyd4352382022-10-11 17:28:14 +0100218 /* AET only valid when DFSC is 0x11 */
219 ubfx x2, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
220 cmp x2, #DFSC_SERROR
221 b.ne 1f
222
Jeenu Viswambharanb56dc2a2018-05-17 09:52:36 +0100223 /*
224 * Check for Uncontainable error type. If so, route to the platform
225 * fatal error handler rather than the generic EA one.
226 */
Manish Pandeyd4352382022-10-11 17:28:14 +0100227 ubfx x3, x1, #EABORT_AET_SHIFT, #EABORT_AET_WIDTH
228 cmp x3, #ERROR_STATUS_UET_UC
Jeenu Viswambharanb56dc2a2018-05-17 09:52:36 +0100229 b.ne 1f
230
231 no_ret plat_handle_uncontainable_ea
2321:
233#endif
234
235 b ea_proceed
236endfunc delegate_async_ea
237
238
239/*
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100240 * Delegate External Abort handling to platform's EA handler. This function
241 * assumes that all GP registers have been saved by the caller.
242 *
243 * x0: EA reason
244 * x1: EA syndrome
245 */
246func ea_proceed
Jeenu Viswambharand5a23af2018-05-17 11:24:01 +0100247 /*
Manish Pandeyc7220032025-02-03 12:00:56 +0000248 * If it is a double fault invoke platform handler.
249 * Double fault scenario would arise when platform is handling a fault in
250 * lower EL using plat_ea_handler() and another fault happens which would
251 * trap into EL3 as FFH_SUPPORT is enabled for the platform.
Jeenu Viswambharand5a23af2018-05-17 11:24:01 +0100252 */
Manish Pandeyc7220032025-02-03 12:00:56 +0000253 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_DOUBLE_FAULT_ESR]
Jeenu Viswambharand5a23af2018-05-17 11:24:01 +0100254 cbz x5, 1f
255 no_ret plat_handle_double_fault
256
2571:
Manish Pandeyc7220032025-02-03 12:00:56 +0000258 /* Save EL3 state as handling might involve lower ELs */
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100259 mrs x2, spsr_el3
260 mrs x3, elr_el3
261 stp x2, x3, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
Manish Pandeyc7220032025-02-03 12:00:56 +0000262 mrs x4, scr_el3
263 str x4, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100264
265 /*
Manish Pandeyc7220032025-02-03 12:00:56 +0000266 * Save CTX_DOUBLE_FAULT_ESR, so that if another fault happens in lower EL, we
267 * catch it as DoubleFault in next invocation of ea_proceed() along with
268 * preserving original ESR_EL3.
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100269 */
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100270 mrs x5, esr_el3
Manish Pandeyc7220032025-02-03 12:00:56 +0000271 str x5, [sp, #CTX_EL3STATE_OFFSET + CTX_DOUBLE_FAULT_ESR]
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100272
273 /*
274 * Setup rest of arguments, and call platform External Abort handler.
275 *
276 * x0: EA reason (already in place)
277 * x1: Exception syndrome (already in place).
278 * x2: Cookie (unused for now).
279 * x3: Context pointer.
280 * x4: Flags (security state from SCR for now).
281 */
282 mov x2, xzr
283 mov x3, sp
284 ubfx x4, x4, #0, #1
285
286 /* Switch to runtime stack */
287 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]
Alexei Fedoroved108b52019-09-13 14:11:59 +0100288 msr spsel, #MODE_SP_EL0
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100289 mov sp, x5
290
291 mov x29, x30
Jeenu Viswambharanee6ff1b2018-02-19 12:25:53 +0000292#if ENABLE_ASSERTIONS
293 /* Stash the stack pointer */
294 mov x28, sp
295#endif
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100296 bl plat_ea_handler
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100297
Jeenu Viswambharanee6ff1b2018-02-19 12:25:53 +0000298#if ENABLE_ASSERTIONS
299 /*
300 * Error handling flows might involve long jumps; so upon returning from
301 * the platform error handler, validate that the we've completely
302 * unwound the stack.
303 */
304 mov x27, sp
305 cmp x28, x27
306 ASM_ASSERT(eq)
307#endif
308
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100309 /* Make SP point to context */
Alexei Fedoroved108b52019-09-13 14:11:59 +0100310 msr spsel, #MODE_SP_ELX
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100311
Manish Pandeyc7220032025-02-03 12:00:56 +0000312 /* Clear Double Fault storage */
313 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_DOUBLE_FAULT_ESR]
314
315 /* Restore EL3 state */
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100316 ldp x1, x2, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
317 msr spsr_el3, x1
318 msr elr_el3, x2
Manish Pandeyc7220032025-02-03 12:00:56 +0000319 ldr x3, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100320 msr scr_el3, x3
Jeenu Viswambharand5a23af2018-05-17 11:24:01 +0100321
322 ret x29
Jeenu Viswambharandf8f3182018-07-05 15:24:45 +0100323endfunc ea_proceed