1 /* 2 * Copyright (c) 2014-2024, 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 /* 49 * Helper function for platform_get_pos() when platform compatibility is 50 * disabled. This is to enable SPDs using the older platform API to continue 51 * to work. 52 */ 53 unsigned int platform_core_pos_helper(unsigned long mpidr) 54 { 55 int idx = plat_core_pos_by_mpidr(mpidr); 56 assert(idx >= 0); 57 return idx; 58 } 59 60 #if SDEI_SUPPORT 61 /* 62 * Function that handles spurious SDEI interrupts while events are masked. 63 */ 64 void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr) 65 { 66 WARN("Spurious SDEI interrupt %u on masked PE %" PRIx64 "\n", intr, mpidr); 67 } 68 69 /* 70 * Default Function to validate SDEI entry point, which returns success. 71 * Platforms may override this with their own validation mechanism. 72 */ 73 int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode) 74 { 75 return 0; 76 } 77 #endif 78 79 const char *get_el_str(unsigned int el) 80 { 81 const char *mode = NULL; 82 83 switch (el) { 84 case MODE_EL3: 85 mode = "EL3"; 86 break; 87 case MODE_EL2: 88 mode = "EL2"; 89 break; 90 case MODE_EL1: 91 mode = "EL1"; 92 break; 93 case MODE_EL0: 94 mode = "EL0"; 95 break; 96 default: 97 assert(false); 98 break; 99 } 100 101 return mode; 102 } 103 104 #if FFH_SUPPORT 105 /* Handler for External Aborts from lower EL including RAS errors */ 106 void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, 107 void *handle, uint64_t flags) 108 { 109 #if ENABLE_FEAT_RAS 110 /* Call RAS EA handler */ 111 int handled = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags); 112 if (handled != 0) 113 return; 114 #endif 115 unsigned int level = (unsigned int)GET_EL(read_spsr_el3()); 116 117 ERROR_NL(); 118 ERROR("Unhandled External Abort received on 0x%lx from %s\n", 119 read_mpidr_el1(), get_el_str(level)); 120 ERROR("exception reason=%u syndrome=0x%" PRIx64 "\n", ea_reason, syndrome); 121 122 /* We reached here due to a panic from a lower EL and assuming this is the default 123 * platform registered handler that we could call on a lower EL panic. 124 */ 125 lower_el_panic(); 126 } 127 #endif 128