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