blob: a5d26c0133e0b62430b0f336263dc3d45691d2bc [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 Viswambharan911fcc92018-07-06 16:50:06 +010025 .weak plat_handle_el3_ea
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +010026
Soby Mathew70716d62015-07-13 16:26:11 +010027#if !ENABLE_PLAT_COMPAT
28 .globl platform_get_core_pos
29
30#define MPIDR_RES_BIT_MASK 0xff000000
31
32 /* ------------------------------------------------------------------
33 * int platform_get_core_pos(int mpidr)
34 * Returns the CPU index of the CPU specified by mpidr. This is
35 * defined when platform compatibility is disabled to enable Trusted
36 * Firmware components like SPD using the old platform API to work.
37 * This API is deprecated and it assumes that the mpidr specified is
38 * that of a valid and present CPU. Instead, plat_my_core_pos()
39 * should be used for CPU index of the current CPU and
40 * plat_core_pos_by_mpidr() should be used for CPU index of a
41 * CPU specified by its mpidr.
42 * ------------------------------------------------------------------
43 */
44func_deprecated platform_get_core_pos
45 bic x0, x0, #MPIDR_RES_BIT_MASK
46 mrs x1, mpidr_el1
47 bic x1, x1, #MPIDR_RES_BIT_MASK
48 cmp x0, x1
49 beq plat_my_core_pos
50 b platform_core_pos_helper
51endfunc_deprecated platform_get_core_pos
52#endif
53
Achin Gupta4f6ad662013-10-25 09:08:21 +010054 /* -----------------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +010055 * Placeholder function which should be redefined by
56 * each platform.
57 * -----------------------------------------------------
58 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000059func plat_report_exception
Achin Gupta4f6ad662013-10-25 09:08:21 +010060 ret
Kévin Petita877c252015-03-24 14:03:57 +000061endfunc plat_report_exception
Soby Mathew066f7132014-07-14 16:57:23 +010062
Julius Werneraae9bb12017-09-18 16:49:48 -070063#if MULTI_CONSOLE_API
Soby Mathew066f7132014-07-14 16:57:23 +010064 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -070065 * int plat_crash_console_init(void)
66 * Use normal console by default. Switch it to crash
67 * mode so serial consoles become active again.
68 * NOTE: This default implementation will only work for
69 * crashes that occur after a normal console (marked
70 * valid for the crash state) has been registered with
71 * the console framework. To debug crashes that occur
72 * earlier, the platform has to override these functions
73 * with an implementation that initializes a console
74 * driver with hardcoded parameters. See
75 * docs/porting-guide.rst for more information.
Soby Mathew066f7132014-07-14 16:57:23 +010076 * -----------------------------------------------------
77 */
78func plat_crash_console_init
Julius Werneraae9bb12017-09-18 16:49:48 -070079#if defined(IMAGE_BL1)
80 /*
81 * BL1 code can possibly crash so early that the data segment is not yet
82 * accessible. Don't risk undefined behavior by trying to run the normal
83 * console framework. Platforms that want to debug BL1 will need to
84 * override this with custom functions that can run from registers only.
85 */
Soby Mathew066f7132014-07-14 16:57:23 +010086 mov x0, #0
87 ret
Julius Werneraae9bb12017-09-18 16:49:48 -070088#else /* IMAGE_BL1 */
89 mov x3, x30
90 mov x0, #CONSOLE_FLAG_CRASH
91 bl console_switch_state
92 mov x0, #1
93 ret x3
94#endif
Kévin Petita877c252015-03-24 14:03:57 +000095endfunc plat_crash_console_init
Soby Mathew066f7132014-07-14 16:57:23 +010096
97 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -070098 * void plat_crash_console_putc(int character)
99 * Output through the normal console by default.
Soby Mathew066f7132014-07-14 16:57:23 +0100100 * -----------------------------------------------------
101 */
102func plat_crash_console_putc
Julius Werneraae9bb12017-09-18 16:49:48 -0700103 b console_putc
Kévin Petita877c252015-03-24 14:03:57 +0000104endfunc plat_crash_console_putc
Soby Mathewf1785fd2014-08-14 12:22:32 +0100105
106 /* -----------------------------------------------------
Julius Werneraae9bb12017-09-18 16:49:48 -0700107 * void plat_crash_console_flush(void)
108 * Flush normal console by default.
109 * -----------------------------------------------------
110 */
111func plat_crash_console_flush
112 b console_flush
113endfunc plat_crash_console_flush
114
115#else /* MULTI_CONSOLE_API */
116
117 /* -----------------------------------------------------
118 * In the old API these are all no-op stubs that need to
119 * be overridden by the platform to be useful.
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000120 * -----------------------------------------------------
121 */
Julius Werneraae9bb12017-09-18 16:49:48 -0700122func plat_crash_console_init
123 mov x0, #0
124 ret
125endfunc plat_crash_console_init
126
127func plat_crash_console_putc
128 ret
129endfunc plat_crash_console_putc
130
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000131func plat_crash_console_flush
132 ret
133endfunc plat_crash_console_flush
Julius Werneraae9bb12017-09-18 16:49:48 -0700134#endif
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000135
136 /* -----------------------------------------------------
137 * Placeholder function which should be redefined by
Masahiro Yamada4c165ca2016-09-24 18:07:46 +0900138 * each platform. This function should preserve x19 - x29.
Soby Mathewf1785fd2014-08-14 12:22:32 +0100139 * -----------------------------------------------------
140 */
141func plat_reset_handler
142 ret
Kévin Petita877c252015-03-24 14:03:57 +0000143endfunc plat_reset_handler
Soby Mathew8e2f2872014-08-14 12:49:05 +0100144
145 /* -----------------------------------------------------
146 * Placeholder function which should be redefined by
147 * each platform. This function is allowed to use
148 * registers x0 - x17.
149 * -----------------------------------------------------
150 */
151func plat_disable_acp
152 ret
Kévin Petita877c252015-03-24 14:03:57 +0000153endfunc plat_disable_acp
Juan Castillod1413b22015-10-05 16:59:38 +0100154
155 /* -----------------------------------------------------
Sandrine Bailleux87322b32015-11-10 15:01:57 +0000156 * void bl1_plat_prepare_exit(entry_point_info_t *ep_info);
Juan Castillod1413b22015-10-05 16:59:38 +0100157 * Called before exiting BL1. Default: do nothing
158 * -----------------------------------------------------
159 */
160func bl1_plat_prepare_exit
161 ret
162endfunc bl1_plat_prepare_exit
Juan Castillo26ae5832015-09-25 15:41:14 +0100163
164 /* -----------------------------------------------------
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000165 * void plat_panic_handler(void) __dead2;
166 * Endless loop by default.
167 * -----------------------------------------------------
168 */
169func plat_panic_handler
Sandrine Bailleux628198b2016-08-18 09:24:40 +0100170 wfi
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000171 b plat_panic_handler
172endfunc plat_panic_handler
Jeenu Viswambharane834ee12018-04-27 15:17:03 +0100173
174 /* -----------------------------------------------------
175 * void bl31_plat_enable_mmu(uint32_t flags);
176 *
177 * Enable MMU in BL31.
178 * -----------------------------------------------------
179 */
180func bl31_plat_enable_mmu
181 b enable_mmu_direct_el3
182endfunc bl31_plat_enable_mmu
183
184 /* -----------------------------------------------------
185 * void bl32_plat_enable_mmu(uint32_t flags);
186 *
187 * Enable MMU in BL32.
188 * -----------------------------------------------------
189 */
190func bl32_plat_enable_mmu
191 b enable_mmu_direct_el1
192endfunc bl32_plat_enable_mmu
Jeenu Viswambharan9d4c9c12018-05-17 09:52:36 +0100193
194
195 /* -----------------------------------------------------
196 * Platform handler for Uncontainable External Abort.
197 *
198 * x0: EA reason
199 * x1: EA syndrome
200 * -----------------------------------------------------
201 */
202func plat_handle_uncontainable_ea
203 b report_unhandled_exception
204endfunc plat_handle_uncontainable_ea
Jeenu Viswambharan93bc4bd2018-05-17 11:24:01 +0100205
206 /* -----------------------------------------------------
207 * Platform handler for Double Fault.
208 *
209 * x0: EA reason
210 * x1: EA syndrome
211 * -----------------------------------------------------
212 */
213func plat_handle_double_fault
214 b report_unhandled_exception
215endfunc plat_handle_double_fault
Jeenu Viswambharan911fcc92018-07-06 16:50:06 +0100216
217 /* -----------------------------------------------------
218 * Platform handler for EL3 External Abort.
219 * -----------------------------------------------------
220 */
221func plat_handle_el3_ea
222 b report_unhandled_exception
223endfunc plat_handle_el3_ea