blob: 4423863bb67029da99c6f7964b587449cc76f71d [file] [log] [blame]
Dan Handleydff8e472014-05-16 14:08:45 +01001/*
Boyan Karatotev96e46f52025-04-03 14:47:20 +01002 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
Dan Handleydff8e472014-05-16 14:08:45 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handleydff8e472014-05-16 14:08:45 +01005 */
Jeenu Viswambharanb7cb1332017-10-16 08:43:14 +01006
Soby Mathew5c8babc2015-07-13 16:26:11 +01007#include <assert.h>
Scott Branden4ce3e992020-08-25 13:49:32 -07008#include <inttypes.h>
9#include <stdint.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
Claus Pedersen885e2682022-09-12 22:42:58 +000012#include <common/debug.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000013#include <drivers/console.h>
Manish Pandeyf87e54f2023-10-10 15:42:19 +010014#if ENABLE_FEAT_RAS
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000015#include <lib/extensions/ras.h>
Jeenu Viswambharan362599e2017-12-08 15:38:21 +000016#endif
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000017#include <lib/xlat_tables/xlat_mmu_helpers.h>
18#include <plat/common/platform.h>
Dan Handleydff8e472014-05-16 14:08:45 +010019
Yann Gautiera03dafe2024-04-10 12:03:33 +020020/* Pointer and function to register platform function to load alernate images */
21const struct plat_try_images_ops *plat_try_img_ops;
22
23void 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
Dan Handleydff8e472014-05-16 14:08:45 +010028/*
Soby Mathew78e61612015-12-09 11:28:43 +000029 * The following platform setup functions are weakly defined. They
Dan Handleydff8e472014-05-16 14:08:45 +010030 * provide typical implementations that may be re-used by multiple
31 * platforms but may also be overridden by a platform if required.
32 */
Soby Mathew78e61612015-12-09 11:28:43 +000033#pragma weak bl31_plat_runtime_setup
Dan Handleydff8e472014-05-16 14:08:45 +010034
Jeenu Viswambharanb7cb1332017-10-16 08:43:14 +010035#if SDEI_SUPPORT
36#pragma weak plat_sdei_handle_masked_trigger
37#pragma weak plat_sdei_validate_entry_point
38#endif
39
Manish Pandeyf87e54f2023-10-10 15:42:19 +010040#if FFH_SUPPORT
Pali Rohár30e8fa72021-06-21 17:22:27 +020041#pragma weak plat_ea_handler = plat_default_ea_handler
Manish Pandeyf87e54f2023-10-10 15:42:19 +010042#endif
Jeenu Viswambharan76454ab2017-11-30 12:54:15 +000043
Soby Mathew78e61612015-12-09 11:28:43 +000044void bl31_plat_runtime_setup(void)
45{
Soby Mathew78e61612015-12-09 11:28:43 +000046}
47
Jeenu Viswambharanb7cb1332017-10-16 08:43:14 +010048#if SDEI_SUPPORT
49/*
50 * Function that handles spurious SDEI interrupts while events are masked.
51 */
52void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr)
53{
Scott Branden4ce3e992020-08-25 13:49:32 -070054 WARN("Spurious SDEI interrupt %u on masked PE %" PRIx64 "\n", intr, mpidr);
Jeenu Viswambharanb7cb1332017-10-16 08:43:14 +010055}
56
57/*
58 * Default Function to validate SDEI entry point, which returns success.
59 * Platforms may override this with their own validation mechanism.
60 */
61int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode)
62{
63 return 0;
64}
65#endif
Jeenu Viswambharan76454ab2017-11-30 12:54:15 +000066
Manish Pandey0ae4a3a2022-11-01 16:16:55 +000067const char *get_el_str(unsigned int el)
Alexei Fedorovb4292bc2020-03-03 13:31:58 +000068{
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053069 const char *mode = NULL;
70
Arvind Ram Prakashc42d0d82024-03-04 16:33:27 -060071 switch (el) {
72 case MODE_EL3:
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053073 mode = "EL3";
74 break;
Arvind Ram Prakashc42d0d82024-03-04 16:33:27 -060075 case MODE_EL2:
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053076 mode = "EL2";
77 break;
Arvind Ram Prakashc42d0d82024-03-04 16:33:27 -060078 case MODE_EL1:
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053079 mode = "EL1";
80 break;
Arvind Ram Prakashc42d0d82024-03-04 16:33:27 -060081 case MODE_EL0:
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053082 mode = "EL0";
83 break;
Arvind Ram Prakashc42d0d82024-03-04 16:33:27 -060084 default:
85 assert(false);
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053086 break;
Alexei Fedorovb4292bc2020-03-03 13:31:58 +000087 }
Maheedhar Bollapalli50029b92024-04-25 14:46:28 +053088
89 return mode;
Alexei Fedorovb4292bc2020-03-03 13:31:58 +000090}
Alexei Fedorovb4292bc2020-03-03 13:31:58 +000091
Manish Pandeyf87e54f2023-10-10 15:42:19 +010092#if FFH_SUPPORT
Govindraj Rajaf4be8682022-12-01 16:47:28 +000093/* Handler for External Aborts from lower EL including RAS errors */
Pali Rohár30e8fa72021-06-21 17:22:27 +020094void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
Jeenu Viswambharan76454ab2017-11-30 12:54:15 +000095 void *handle, uint64_t flags)
96{
Manish Pandeyf87e54f2023-10-10 15:42:19 +010097#if ENABLE_FEAT_RAS
Jeenu Viswambharan362599e2017-12-08 15:38:21 +000098 /* Call RAS EA handler */
99 int handled = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags);
100 if (handled != 0)
101 return;
102#endif
Alexei Fedorovb4292bc2020-03-03 13:31:58 +0000103 unsigned int level = (unsigned int)GET_EL(read_spsr_el3());
Jeenu Viswambharan362599e2017-12-08 15:38:21 +0000104
Pali Rohára5fea812021-06-22 20:23:38 +0200105 ERROR_NL();
Alexei Fedorovb4292bc2020-03-03 13:31:58 +0000106 ERROR("Unhandled External Abort received on 0x%lx from %s\n",
107 read_mpidr_el1(), get_el_str(level));
Scott Branden4ce3e992020-08-25 13:49:32 -0700108 ERROR("exception reason=%u syndrome=0x%" PRIx64 "\n", ea_reason, syndrome);
Govindraj Rajaf4be8682022-12-01 16:47:28 +0000109
Govindraj Raja7e619ec2023-01-16 15:11:47 +0000110 /* 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();
Jeenu Viswambharan76454ab2017-11-30 12:54:15 +0000114}
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100115#endif