blob: 8a07f8f54cd0e253ac945f9cb0a4d1417ae9f407 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +09002 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
7#include <arch.h>
Andrew Thoelke38bde412014-03-18 13:46:55 +00008#include <asm_macros.S>
Julius Werneraae9bb12017-09-18 16:49:48 -07009#include <console.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010010#include <platform_def.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010011
Achin Gupta4f6ad662013-10-25 09:08:21 +010012 .weak plat_report_exception
Soby Mathew066f7132014-07-14 16:57:23 +010013 .weak plat_crash_console_init
14 .weak plat_crash_console_putc
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +000015 .weak plat_crash_console_flush
Soby Mathewf1785fd2014-08-14 12:22:32 +010016 .weak plat_reset_handler
Soby Mathew8e2f2872014-08-14 12:49:05 +010017 .weak plat_disable_acp
Juan Castillod1413b22015-10-05 16:59:38 +010018 .weak bl1_plat_prepare_exit
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +000019 .weak plat_panic_handler
Jeenu Viswambharane834ee12018-04-27 15:17:03 +010020 .weak bl31_plat_enable_mmu
21 .weak bl32_plat_enable_mmu
Achin Gupta4f6ad662013-10-25 09:08:21 +010022
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +010023 .weak plat_handle_uncontainable_ea
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +010024 .weak plat_handle_double_fault
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +010025
Soby Mathew70716d62015-07-13 16:26:11 +010026#if !ENABLE_PLAT_COMPAT
27 .globl platform_get_core_pos
28
29#define MPIDR_RES_BIT_MASK 0xff000000
30
31 /* ------------------------------------------------------------------
32 * int platform_get_core_pos(int mpidr)
33 * Returns the CPU index of the CPU specified by mpidr. This is
34 * defined when platform compatibility is disabled to enable Trusted
35 * Firmware components like SPD using the old platform API to work.
36 * This API is deprecated and it assumes that the mpidr specified is
37 * that of a valid and present CPU. Instead, plat_my_core_pos()
38 * should be used for CPU index of the current CPU and
39 * plat_core_pos_by_mpidr() should be used for CPU index of a
40 * CPU specified by its mpidr.
41 * ------------------------------------------------------------------
42 */
43func_deprecated platform_get_core_pos
44 bic x0, x0, #MPIDR_RES_BIT_MASK
45 mrs x1, mpidr_el1
46 bic x1, x1, #MPIDR_RES_BIT_MASK
47 cmp x0, x1
48 beq plat_my_core_pos
49 b platform_core_pos_helper
50endfunc_deprecated platform_get_core_pos
51#endif
52
Achin Gupta4f6ad662013-10-25 09:08:21 +010053 /* -----------------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +010054 * Placeholder function which should be redefined by
55 * each platform.
56 * -----------------------------------------------------
57 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000058func plat_report_exception
Achin Gupta4f6ad662013-10-25 09:08:21 +010059 ret
Kévin Petita877c252015-03-24 14:03:57 +000060endfunc plat_report_exception
Soby Mathew066f7132014-07-14 16:57:23 +010061
Julius Werneraae9bb12017-09-18 16:49:48 -070062#if MULTI_CONSOLE_API
Soby Mathew066f7132014-07-14 16:57:23 +010063 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -070064 * int plat_crash_console_init(void)
65 * Use normal console by default. Switch it to crash
66 * mode so serial consoles become active again.
67 * NOTE: This default implementation will only work for
68 * crashes that occur after a normal console (marked
69 * valid for the crash state) has been registered with
70 * the console framework. To debug crashes that occur
71 * earlier, the platform has to override these functions
72 * with an implementation that initializes a console
73 * driver with hardcoded parameters. See
74 * docs/porting-guide.rst for more information.
Soby Mathew066f7132014-07-14 16:57:23 +010075 * -----------------------------------------------------
76 */
77func plat_crash_console_init
Julius Werneraae9bb12017-09-18 16:49:48 -070078#if defined(IMAGE_BL1)
79 /*
80 * BL1 code can possibly crash so early that the data segment is not yet
81 * accessible. Don't risk undefined behavior by trying to run the normal
82 * console framework. Platforms that want to debug BL1 will need to
83 * override this with custom functions that can run from registers only.
84 */
Soby Mathew066f7132014-07-14 16:57:23 +010085 mov x0, #0
86 ret
Julius Werneraae9bb12017-09-18 16:49:48 -070087#else /* IMAGE_BL1 */
88 mov x3, x30
89 mov x0, #CONSOLE_FLAG_CRASH
90 bl console_switch_state
91 mov x0, #1
92 ret x3
93#endif
Kévin Petita877c252015-03-24 14:03:57 +000094endfunc plat_crash_console_init
Soby Mathew066f7132014-07-14 16:57:23 +010095
96 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -070097 * void plat_crash_console_putc(int character)
98 * Output through the normal console by default.
Soby Mathew066f7132014-07-14 16:57:23 +010099 * -----------------------------------------------------
100 */
101func plat_crash_console_putc
Julius Werneraae9bb12017-09-18 16:49:48 -0700102 b console_putc
Kévin Petita877c252015-03-24 14:03:57 +0000103endfunc plat_crash_console_putc
Soby Mathewf1785fd2014-08-14 12:22:32 +0100104
105 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -0700106 * void plat_crash_console_flush(void)
107 * Flush normal console by default.
108 * -----------------------------------------------------
109 */
110func plat_crash_console_flush
111 b console_flush
112endfunc plat_crash_console_flush
113
114#else /* MULTI_CONSOLE_API */
115
116 /* -----------------------------------------------------
117 * In the old API these are all no-op stubs that need to
118 * be overridden by the platform to be useful.
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000119 * -----------------------------------------------------
120 */
Julius Werneraae9bb12017-09-18 16:49:48 -0700121func plat_crash_console_init
122 mov x0, #0
123 ret
124endfunc plat_crash_console_init
125
126func plat_crash_console_putc
127 ret
128endfunc plat_crash_console_putc
129
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000130func plat_crash_console_flush
131 ret
132endfunc plat_crash_console_flush
Julius Werneraae9bb12017-09-18 16:49:48 -0700133#endif
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000134
135 /* -----------------------------------------------------
136 * Placeholder function which should be redefined by
Masahiro Yamada4c165ca2016-09-24 18:07:46 +0900137 * each platform. This function should preserve x19 - x29.
Soby Mathewf1785fd2014-08-14 12:22:32 +0100138 * -----------------------------------------------------
139 */
140func plat_reset_handler
141 ret
Kévin Petita877c252015-03-24 14:03:57 +0000142endfunc plat_reset_handler
Soby Mathew8e2f2872014-08-14 12:49:05 +0100143
144 /* -----------------------------------------------------
145 * Placeholder function which should be redefined by
146 * each platform. This function is allowed to use
147 * registers x0 - x17.
148 * -----------------------------------------------------
149 */
150func plat_disable_acp
151 ret
Kévin Petita877c252015-03-24 14:03:57 +0000152endfunc plat_disable_acp
Juan Castillod1413b22015-10-05 16:59:38 +0100153
154 /* -----------------------------------------------------
Sandrine Bailleux87322b32015-11-10 15:01:57 +0000155 * void bl1_plat_prepare_exit(entry_point_info_t *ep_info);
Juan Castillod1413b22015-10-05 16:59:38 +0100156 * Called before exiting BL1. Default: do nothing
157 * -----------------------------------------------------
158 */
159func bl1_plat_prepare_exit
160 ret
161endfunc bl1_plat_prepare_exit
Juan Castillo26ae5832015-09-25 15:41:14 +0100162
163 /* -----------------------------------------------------
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000164 * void plat_panic_handler(void) __dead2;
165 * Endless loop by default.
166 * -----------------------------------------------------
167 */
168func plat_panic_handler
Sandrine Bailleux628198b2016-08-18 09:24:40 +0100169 wfi
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000170 b plat_panic_handler
171endfunc plat_panic_handler
Jeenu Viswambharane834ee12018-04-27 15:17:03 +0100172
173 /* -----------------------------------------------------
174 * void bl31_plat_enable_mmu(uint32_t flags);
175 *
176 * Enable MMU in BL31.
177 * -----------------------------------------------------
178 */
179func bl31_plat_enable_mmu
180 b enable_mmu_direct_el3
181endfunc bl31_plat_enable_mmu
182
183 /* -----------------------------------------------------
184 * void bl32_plat_enable_mmu(uint32_t flags);
185 *
186 * Enable MMU in BL32.
187 * -----------------------------------------------------
188 */
189func bl32_plat_enable_mmu
190 b enable_mmu_direct_el1
191endfunc bl32_plat_enable_mmu
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +0100192
193
194 /* -----------------------------------------------------
195 * Platform handler for Uncontainable External Abort.
196 *
197 * x0: EA reason
198 * x1: EA syndrome
199 * -----------------------------------------------------
200 */
201func plat_handle_uncontainable_ea
202 b report_unhandled_exception
203endfunc plat_handle_uncontainable_ea
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +0100204
205 /* -----------------------------------------------------
206 * Platform handler for Double Fault.
207 *
208 * x0: EA reason
209 * x1: EA syndrome
210 * -----------------------------------------------------
211 */
212func plat_handle_double_fault
213 b report_unhandled_exception
214endfunc plat_handle_double_fault