xref: /rk3399_ARM-atf/plat/common/aarch64/platform_helpers.S (revision 17cd67d2af885913427be5c0d8af47647d72896e)
14f6ad66aSAchin Gupta/*
2801cf93cSAntonio Nino Diaz * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
74f6ad66aSAchin Gupta#include <arch.h>
80a30cf54SAndrew Thoelke#include <asm_macros.S>
9*17cd67d2SJulius Werner#include <console.h>
105f0cdb05SDan Handley#include <platform_def.h>
114f6ad66aSAchin Gupta
124f6ad66aSAchin Gupta	.weak	plat_report_exception
13c67b09bdSSoby Mathew	.weak	plat_crash_console_init
14c67b09bdSSoby Mathew	.weak	plat_crash_console_putc
15801cf93cSAntonio Nino Diaz	.weak	plat_crash_console_flush
1624fb838fSSoby Mathew	.weak	plat_reset_handler
17add40351SSoby Mathew	.weak	plat_disable_acp
18e3f67124SJuan Castillo	.weak	bl1_plat_prepare_exit
1940fc6cd1SJuan Castillo	.weak	plat_error_handler
201c3ea103SAntonio Nino Diaz	.weak	plat_panic_handler
2101f62b6dSRoberto Vargas	.weak	bl2_plat_preload_setup
2201f62b6dSRoberto Vargas	.weak	plat_try_next_boot_source
234f6ad66aSAchin Gupta
245c8babcdSSoby Mathew#if !ENABLE_PLAT_COMPAT
255c8babcdSSoby Mathew	.globl	platform_get_core_pos
265c8babcdSSoby Mathew
275c8babcdSSoby Mathew#define MPIDR_RES_BIT_MASK	0xff000000
285c8babcdSSoby Mathew
295c8babcdSSoby Mathew	/* ------------------------------------------------------------------
305c8babcdSSoby Mathew	 *  int platform_get_core_pos(int mpidr)
315c8babcdSSoby Mathew	 *  Returns the CPU index of the CPU specified by mpidr. This is
325c8babcdSSoby Mathew	 *  defined when platform compatibility is disabled to enable Trusted
335c8babcdSSoby Mathew	 *  Firmware components like SPD using the old  platform API to work.
345c8babcdSSoby Mathew	 *  This API is deprecated and it assumes that the mpidr specified is
355c8babcdSSoby Mathew	 *  that of a valid and present CPU. Instead, plat_my_core_pos()
365c8babcdSSoby Mathew	 *  should be used for CPU index of the current CPU and
375c8babcdSSoby Mathew	 *  plat_core_pos_by_mpidr() should be used for CPU index of a
385c8babcdSSoby Mathew	 *  CPU specified by its mpidr.
395c8babcdSSoby Mathew	 * ------------------------------------------------------------------
405c8babcdSSoby Mathew	 */
415c8babcdSSoby Mathewfunc_deprecated platform_get_core_pos
425c8babcdSSoby Mathew	bic	x0, x0, #MPIDR_RES_BIT_MASK
435c8babcdSSoby Mathew	mrs	x1, mpidr_el1
445c8babcdSSoby Mathew	bic	x1, x1, #MPIDR_RES_BIT_MASK
455c8babcdSSoby Mathew	cmp	x0, x1
465c8babcdSSoby Mathew	beq	plat_my_core_pos
475c8babcdSSoby Mathew	b	platform_core_pos_helper
485c8babcdSSoby Mathewendfunc_deprecated platform_get_core_pos
495c8babcdSSoby Mathew#endif
505c8babcdSSoby Mathew
514f6ad66aSAchin Gupta	/* -----------------------------------------------------
524f6ad66aSAchin Gupta	 * Placeholder function which should be redefined by
534f6ad66aSAchin Gupta	 * each platform.
544f6ad66aSAchin Gupta	 * -----------------------------------------------------
554f6ad66aSAchin Gupta	 */
560a30cf54SAndrew Thoelkefunc plat_report_exception
574f6ad66aSAchin Gupta	ret
588b779620SKévin Petitendfunc plat_report_exception
59c67b09bdSSoby Mathew
60*17cd67d2SJulius Werner#if MULTI_CONSOLE_API
61c67b09bdSSoby Mathew	/* -----------------------------------------------------
62*17cd67d2SJulius Werner	 * int plat_crash_console_init(void)
63*17cd67d2SJulius Werner	 * Use normal console by default. Switch it to crash
64*17cd67d2SJulius Werner	 * mode so serial consoles become active again.
65*17cd67d2SJulius Werner	 * NOTE: This default implementation will only work for
66*17cd67d2SJulius Werner	 * crashes that occur after a normal console (marked
67*17cd67d2SJulius Werner	 * valid for the crash state) has been registered with
68*17cd67d2SJulius Werner	 * the console framework. To debug crashes that occur
69*17cd67d2SJulius Werner	 * earlier, the platform has to override these functions
70*17cd67d2SJulius Werner	 * with an implementation that initializes a console
71*17cd67d2SJulius Werner	 * driver with hardcoded parameters. See
72*17cd67d2SJulius Werner	 * docs/porting-guide.rst for more information.
73*17cd67d2SJulius Werner	 * -----------------------------------------------------
74*17cd67d2SJulius Werner	 */
75*17cd67d2SJulius Wernerfunc plat_crash_console_init
76*17cd67d2SJulius Werner#if defined(IMAGE_BL1)
77*17cd67d2SJulius Werner	/*
78*17cd67d2SJulius Werner	 * BL1 code can possibly crash so early that the data segment is not yet
79*17cd67d2SJulius Werner	 * accessible. Don't risk undefined behavior by trying to run the normal
80*17cd67d2SJulius Werner	 * console framework. Platforms that want to debug BL1 will need to
81*17cd67d2SJulius Werner	 * override this with custom functions that can run from registers only.
82*17cd67d2SJulius Werner	 */
83*17cd67d2SJulius Werner	mov	x0, #0
84*17cd67d2SJulius Werner	ret
85*17cd67d2SJulius Werner#else	/* IMAGE_BL1 */
86*17cd67d2SJulius Werner	mov	x3, x30
87*17cd67d2SJulius Werner	mov	x0, #CONSOLE_FLAG_CRASH
88*17cd67d2SJulius Werner	bl	console_switch_state
89*17cd67d2SJulius Werner	mov	x0, #1
90*17cd67d2SJulius Werner	ret	x3
91*17cd67d2SJulius Werner#endif
92*17cd67d2SJulius Wernerendfunc plat_crash_console_init
93*17cd67d2SJulius Werner
94*17cd67d2SJulius Werner	/* -----------------------------------------------------
95*17cd67d2SJulius Werner	 * void plat_crash_console_putc(int character)
96*17cd67d2SJulius Werner	 * Output through the normal console by default.
97*17cd67d2SJulius Werner	 * -----------------------------------------------------
98*17cd67d2SJulius Werner	 */
99*17cd67d2SJulius Wernerfunc plat_crash_console_putc
100*17cd67d2SJulius Werner	b	console_putc
101*17cd67d2SJulius Wernerendfunc plat_crash_console_putc
102*17cd67d2SJulius Werner
103*17cd67d2SJulius Werner	/* -----------------------------------------------------
104*17cd67d2SJulius Werner	 * void plat_crash_console_flush(void)
105*17cd67d2SJulius Werner	 * Flush normal console by default.
106*17cd67d2SJulius Werner	 * -----------------------------------------------------
107*17cd67d2SJulius Werner	 */
108*17cd67d2SJulius Wernerfunc plat_crash_console_flush
109*17cd67d2SJulius Werner	b	console_flush
110*17cd67d2SJulius Wernerendfunc plat_crash_console_flush
111*17cd67d2SJulius Werner
112*17cd67d2SJulius Werner#else	/* MULTI_CONSOLE_API */
113*17cd67d2SJulius Werner
114*17cd67d2SJulius Werner	/* -----------------------------------------------------
115*17cd67d2SJulius Werner	 * In the old API these are all no-op stubs that need to
116*17cd67d2SJulius Werner	 * be overridden by the platform to be useful.
117c67b09bdSSoby Mathew	 * -----------------------------------------------------
118c67b09bdSSoby Mathew	 */
119c67b09bdSSoby Mathewfunc plat_crash_console_init
120c67b09bdSSoby Mathew	mov	x0, #0
121c67b09bdSSoby Mathew	ret
1228b779620SKévin Petitendfunc plat_crash_console_init
123c67b09bdSSoby Mathew
124c67b09bdSSoby Mathewfunc plat_crash_console_putc
125c67b09bdSSoby Mathew	ret
1268b779620SKévin Petitendfunc plat_crash_console_putc
12724fb838fSSoby Mathew
128801cf93cSAntonio Nino Diazfunc plat_crash_console_flush
129801cf93cSAntonio Nino Diaz	ret
130801cf93cSAntonio Nino Diazendfunc plat_crash_console_flush
131*17cd67d2SJulius Werner#endif
132801cf93cSAntonio Nino Diaz
133801cf93cSAntonio Nino Diaz	/* -----------------------------------------------------
134801cf93cSAntonio Nino Diaz	 * Placeholder function which should be redefined by
135240b3140SMasahiro Yamada	 * each platform. This function should preserve x19 - x29.
13624fb838fSSoby Mathew	 * -----------------------------------------------------
13724fb838fSSoby Mathew	 */
13824fb838fSSoby Mathewfunc plat_reset_handler
13924fb838fSSoby Mathew	ret
1408b779620SKévin Petitendfunc plat_reset_handler
141add40351SSoby Mathew
142add40351SSoby Mathew	/* -----------------------------------------------------
143add40351SSoby Mathew	 * Placeholder function which should be redefined by
144add40351SSoby Mathew	 * each platform. This function is allowed to use
145add40351SSoby Mathew	 * registers x0 - x17.
146add40351SSoby Mathew	 * -----------------------------------------------------
147add40351SSoby Mathew	 */
148add40351SSoby Mathewfunc plat_disable_acp
149add40351SSoby Mathew	ret
1508b779620SKévin Petitendfunc plat_disable_acp
151e3f67124SJuan Castillo
152e3f67124SJuan Castillo	/* -----------------------------------------------------
153862b5dc2SSandrine Bailleux	 * void bl1_plat_prepare_exit(entry_point_info_t *ep_info);
154e3f67124SJuan Castillo	 * Called before exiting BL1. Default: do nothing
155e3f67124SJuan Castillo	 * -----------------------------------------------------
156e3f67124SJuan Castillo	 */
157e3f67124SJuan Castillofunc bl1_plat_prepare_exit
158e3f67124SJuan Castillo	ret
159e3f67124SJuan Castilloendfunc bl1_plat_prepare_exit
16040fc6cd1SJuan Castillo
16140fc6cd1SJuan Castillo	/* -----------------------------------------------------
16240fc6cd1SJuan Castillo	 * void plat_error_handler(int err) __dead2;
16340fc6cd1SJuan Castillo	 * Endless loop by default.
16440fc6cd1SJuan Castillo	 * -----------------------------------------------------
16540fc6cd1SJuan Castillo	 */
16640fc6cd1SJuan Castillofunc plat_error_handler
1678c9e1af0SSandrine Bailleux	wfi
16840fc6cd1SJuan Castillo	b	plat_error_handler
16940fc6cd1SJuan Castilloendfunc plat_error_handler
1701c3ea103SAntonio Nino Diaz
1711c3ea103SAntonio Nino Diaz	/* -----------------------------------------------------
1721c3ea103SAntonio Nino Diaz	 * void plat_panic_handler(void) __dead2;
1731c3ea103SAntonio Nino Diaz	 * Endless loop by default.
1741c3ea103SAntonio Nino Diaz	 * -----------------------------------------------------
1751c3ea103SAntonio Nino Diaz	 */
1761c3ea103SAntonio Nino Diazfunc plat_panic_handler
1778c9e1af0SSandrine Bailleux	wfi
1781c3ea103SAntonio Nino Diaz	b	plat_panic_handler
1791c3ea103SAntonio Nino Diazendfunc plat_panic_handler
18001f62b6dSRoberto Vargas
18101f62b6dSRoberto Vargas	/* -----------------------------------------------------
18201f62b6dSRoberto Vargas	 * Placeholder function which should be redefined by
18301f62b6dSRoberto Vargas	 * each platfrom.
18401f62b6dSRoberto Vargas	 * -----------------------------------------------------
18501f62b6dSRoberto Vargas	 */
18601f62b6dSRoberto Vargasfunc bl2_plat_preload_setup
18701f62b6dSRoberto Vargas	ret
18801f62b6dSRoberto Vargasendfunc bl2_plat_preload_setup
18901f62b6dSRoberto Vargas
19001f62b6dSRoberto Vargas	/* -----------------------------------------------------
19101f62b6dSRoberto Vargas	 * Placeholder function which should be redefined by
19201f62b6dSRoberto Vargas	 * each platfrom.
19301f62b6dSRoberto Vargas	 * -----------------------------------------------------
19401f62b6dSRoberto Vargas	 */
19501f62b6dSRoberto Vargasfunc plat_try_next_boot_source
19601f62b6dSRoberto Vargas	mov	x0, #0
19701f62b6dSRoberto Vargas	ret
19801f62b6dSRoberto Vargasendfunc plat_try_next_boot_source
199