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