xref: /rk3399_ARM-atf/plat/common/aarch64/plat_common.c (revision 30d81c36da441bcd0fbccbc3ac1a7268d2cc5ad2)
1 /*
2  * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <assert.h>
9 #include <console.h>
10 #include <platform.h>
11 #include <xlat_mmu_helpers.h>
12 
13 /*
14  * The following platform setup functions are weakly defined. They
15  * provide typical implementations that may be re-used by multiple
16  * platforms but may also be overridden by a platform if required.
17  */
18 #pragma weak bl31_plat_enable_mmu
19 #pragma weak bl32_plat_enable_mmu
20 #pragma weak bl31_plat_runtime_setup
21 #if !ERROR_DEPRECATED
22 #pragma weak plat_get_syscnt_freq2
23 #pragma weak bl31_early_platform_setup2
24 #endif /* ERROR_DEPRECATED */
25 
26 #if SDEI_SUPPORT
27 #pragma weak plat_sdei_handle_masked_trigger
28 #pragma weak plat_sdei_validate_entry_point
29 #endif
30 
31 #pragma weak plat_ea_handler
32 
33 void bl31_plat_enable_mmu(uint32_t flags)
34 {
35 	enable_mmu_el3(flags);
36 }
37 
38 void bl32_plat_enable_mmu(uint32_t flags)
39 {
40 	enable_mmu_el1(flags);
41 }
42 
43 void bl31_plat_runtime_setup(void)
44 {
45 #if MULTI_CONSOLE_API
46 	console_switch_state(CONSOLE_FLAG_RUNTIME);
47 #else
48 	console_uninit();
49 #endif
50 }
51 
52 #if !ENABLE_PLAT_COMPAT
53 /*
54  * Helper function for platform_get_pos() when platform compatibility is
55  * disabled. This is to enable SPDs using the older platform API to continue
56  * to work.
57  */
58 unsigned int platform_core_pos_helper(unsigned long mpidr)
59 {
60 	int idx = plat_core_pos_by_mpidr(mpidr);
61 	assert(idx >= 0);
62 	return idx;
63 }
64 #endif
65 
66 
67 #if !ERROR_DEPRECATED
68 unsigned int plat_get_syscnt_freq2(void)
69 {
70 	WARN("plat_get_syscnt_freq() is deprecated\n");
71 	WARN("Please define plat_get_syscnt_freq2()\n");
72 	/*
73 	 * Suppress deprecated declaration warning in compatibility function
74 	 */
75 #pragma GCC diagnostic push
76 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
77 	unsigned long long freq = plat_get_syscnt_freq();
78 #pragma GCC diagnostic pop
79 
80 	assert(freq >> 32 == 0);
81 
82 	return (unsigned int)freq;
83 }
84 
85 void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
86 			u_register_t arg2, u_register_t arg3)
87 {
88 	bl31_early_platform_setup((void *) arg0, (void *)arg1);
89 }
90 #endif /* ERROR_DEPRECATED */
91 
92 #if SDEI_SUPPORT
93 /*
94  * Function that handles spurious SDEI interrupts while events are masked.
95  */
96 void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr)
97 {
98 	WARN("Spurious SDEI interrupt %u on masked PE %llx\n", intr, mpidr);
99 }
100 
101 /*
102  * Default Function to validate SDEI entry point, which returns success.
103  * Platforms may override this with their own validation mechanism.
104  */
105 int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode)
106 {
107 	return 0;
108 }
109 #endif
110 
111 /* RAS functions common to AArch64 ARM platforms */
112 void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
113 		void *handle, uint64_t flags)
114 {
115 	ERROR("Unhandled External Abort received on 0x%lx at EL3!\n",
116 			read_mpidr_el1());
117 	ERROR(" exception reason=%u syndrome=0x%lx\n", ea_reason, syndrome);
118 	panic();
119 }
120