1*fe38cc68SManish Pandey /*
2*fe38cc68SManish Pandey * Copyright (c) 2023, Arm Limited. All rights reserved.
3*fe38cc68SManish Pandey *
4*fe38cc68SManish Pandey * SPDX-License-Identifier: BSD-3-Clause
5*fe38cc68SManish Pandey */
6*fe38cc68SManish Pandey
7*fe38cc68SManish Pandey #include <inttypes.h>
8*fe38cc68SManish Pandey #include <stdint.h>
9*fe38cc68SManish Pandey
10*fe38cc68SManish Pandey #include <arch_helpers.h>
11*fe38cc68SManish Pandey #include <bl31/ea_handle.h>
12*fe38cc68SManish Pandey #include <common/bl_common.h>
13*fe38cc68SManish Pandey #include <common/debug.h>
14*fe38cc68SManish Pandey #include <context.h>
15*fe38cc68SManish Pandey #include <lib/el3_runtime/context_mgmt.h>
16*fe38cc68SManish Pandey #include <plat/common/platform.h>
17*fe38cc68SManish Pandey
18*fe38cc68SManish Pandey /*
19*fe38cc68SManish Pandey * This source file with custom plat_ea_handler function is compiled only when
20*fe38cc68SManish Pandey * building TF-A with compile option PLATFORM_TEST_EA_FFH
21*fe38cc68SManish Pandey */
22*fe38cc68SManish Pandey
23*fe38cc68SManish Pandey /* Test address(non-existent) used in tftf to cause External aborts */
24*fe38cc68SManish Pandey #define TEST_ADDRESS UL(0x7FFFF000)
25*fe38cc68SManish Pandey
plat_ea_handler(unsigned int ea_reason,uint64_t syndrome,void * cookie,void * handle,uint64_t flags)26*fe38cc68SManish Pandey void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
27*fe38cc68SManish Pandey void *handle, uint64_t flags)
28*fe38cc68SManish Pandey {
29*fe38cc68SManish Pandey #ifdef PLATFORM_TEST_EA_FFH
30*fe38cc68SManish Pandey u_register_t elr_el3;
31*fe38cc68SManish Pandey u_register_t fault_address;
32*fe38cc68SManish Pandey cpu_context_t *ctx = cm_get_context(NON_SECURE);
33*fe38cc68SManish Pandey el3_state_t *el3_ctx = get_el3state_ctx(ctx);
34*fe38cc68SManish Pandey gp_regs_t *gpregs_ctx = get_gpregs_ctx(ctx);
35*fe38cc68SManish Pandey unsigned int level = (unsigned int)GET_EL(read_spsr_el3());
36*fe38cc68SManish Pandey
37*fe38cc68SManish Pandey fault_address = read_ctx_reg(gpregs_ctx, CTX_GPREG_X0);
38*fe38cc68SManish Pandey
39*fe38cc68SManish Pandey if ((level < MODE_EL3) && (fault_address == TEST_ADDRESS)) {
40*fe38cc68SManish Pandey if (ea_reason == ERROR_EA_SYNC) {
41*fe38cc68SManish Pandey INFO("Handled sync EA from lower EL at address 0x%lx\n", fault_address);
42*fe38cc68SManish Pandey /* To avoid continuous faults, forward return address */
43*fe38cc68SManish Pandey elr_el3 = read_ctx_reg(el3_ctx, CTX_ELR_EL3);
44*fe38cc68SManish Pandey elr_el3 += 4;
45*fe38cc68SManish Pandey write_ctx_reg(el3_ctx, CTX_ELR_EL3, elr_el3);
46*fe38cc68SManish Pandey return;
47*fe38cc68SManish Pandey } else if (ea_reason == ERROR_EA_ASYNC) {
48*fe38cc68SManish Pandey INFO("Handled Serror from lower EL at address 0x%lx\n", fault_address);
49*fe38cc68SManish Pandey return;
50*fe38cc68SManish Pandey }
51*fe38cc68SManish Pandey }
52*fe38cc68SManish Pandey #endif
53*fe38cc68SManish Pandey plat_default_ea_handler(ea_reason, syndrome, cookie, handle, flags);
54*fe38cc68SManish Pandey }
55