1 /* 2 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <inttypes.h> 9 #include <stdint.h> 10 11 #include <arch_helpers.h> 12 #include <common/debug.h> 13 #include <drivers/console.h> 14 #if ENABLE_FEAT_RAS 15 #include <lib/extensions/ras.h> 16 #endif 17 #include <lib/xlat_tables/xlat_mmu_helpers.h> 18 #include <plat/common/platform.h> 19 20 /* Pointer and function to register platform function to load alernate images */ 21 const struct plat_try_images_ops *plat_try_img_ops; 22 23 void plat_setup_try_img_ops(const struct plat_try_images_ops *plat_try_ops) 24 { 25 plat_try_img_ops = plat_try_ops; 26 } 27 28 /* 29 * The following platform setup functions are weakly defined. They 30 * provide typical implementations that may be re-used by multiple 31 * platforms but may also be overridden by a platform if required. 32 */ 33 #pragma weak bl31_plat_runtime_setup 34 35 #if SDEI_SUPPORT 36 #pragma weak plat_sdei_handle_masked_trigger 37 #pragma weak plat_sdei_validate_entry_point 38 #endif 39 40 #if FFH_SUPPORT 41 #pragma weak plat_ea_handler = plat_default_ea_handler 42 #endif 43 44 void bl31_plat_runtime_setup(void) 45 { 46 } 47 48 #if SDEI_SUPPORT 49 /* 50 * Function that handles spurious SDEI interrupts while events are masked. 51 */ 52 void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr) 53 { 54 WARN("Spurious SDEI interrupt %u on masked PE %" PRIx64 "\n", intr, mpidr); 55 } 56 57 /* 58 * Default Function to validate SDEI entry point, which returns success. 59 * Platforms may override this with their own validation mechanism. 60 */ 61 int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode) 62 { 63 return 0; 64 } 65 #endif 66 67 const char *get_el_str(unsigned int el) 68 { 69 const char *mode = NULL; 70 71 switch (el) { 72 case MODE_EL3: 73 mode = "EL3"; 74 break; 75 case MODE_EL2: 76 mode = "EL2"; 77 break; 78 case MODE_EL1: 79 mode = "EL1"; 80 break; 81 case MODE_EL0: 82 mode = "EL0"; 83 break; 84 default: 85 assert(false); 86 break; 87 } 88 89 return mode; 90 } 91 92 #if FFH_SUPPORT 93 /* Handler for External Aborts from lower EL including RAS errors */ 94 void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, 95 void *handle, uint64_t flags) 96 { 97 #if ENABLE_FEAT_RAS 98 /* Call RAS EA handler */ 99 int handled = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags); 100 if (handled != 0) 101 return; 102 #endif 103 unsigned int level = (unsigned int)GET_EL(read_spsr_el3()); 104 105 ERROR_NL(); 106 ERROR("Unhandled External Abort received on 0x%lx from %s\n", 107 read_mpidr_el1(), get_el_str(level)); 108 ERROR("exception reason=%u syndrome=0x%" PRIx64 "\n", ea_reason, syndrome); 109 110 /* We reached here due to a panic from a lower EL and assuming this is the default 111 * platform registered handler that we could call on a lower EL panic. 112 */ 113 lower_el_panic(); 114 } 115 #endif 116