| 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 |
switch (el) { |
| 82 |
case MODE_EL3: |
| 83 |
return "EL3"; |
| 84 |
case MODE_EL2: |
| 85 |
return "EL2"; |
| 86 |
case MODE_EL1: |
| 87 |
return "EL1"; |
| 88 |
case MODE_EL0: |
| 89 |
return "EL0"; |
| 90 |
default: |
| 91 |
assert(false); |
| 92 |
return NULL; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
#if FFH_SUPPORT |
| 97 |
/* Handler for External Aborts from lower EL including RAS errors */ |
| 98 |
void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, |
| 99 |
void *handle, uint64_t flags) |
| 100 |
{ |
| 101 |
#if ENABLE_FEAT_RAS |
| 102 |
/* Call RAS EA handler */ |
| 103 |
int handled = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags); |
| 104 |
if (handled != 0) |
| 105 |
return; |
| 106 |
#endif |
| 107 |
unsigned int level = (unsigned int)GET_EL(read_spsr_el3()); |
| 108 |
|
| 109 |
ERROR_NL(); |
| 110 |
ERROR("Unhandled External Abort received on 0x%lx from %s\n", |
| 111 |
read_mpidr_el1(), get_el_str(level)); |
| 112 |
ERROR("exception reason=%u syndrome=0x%" PRIx64 "\n", ea_reason, syndrome); |
| 113 |
|
| 114 |
/* We reached here due to a panic from a lower EL and assuming this is the default |
| 115 |
* platform registered handler that we could call on a lower EL panic. |
| 116 |
*/ |
| 117 |
lower_el_panic(); |
| 118 |
} |
| 119 |
#endif |