xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision 54dc71e7ec9f2a069907e8c0c24b5c8f8cc5f66a)
14f6ad66aSAchin Gupta/*
252010cc7SSandrine Bailleux * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without
54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met:
64f6ad66aSAchin Gupta *
74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this
84f6ad66aSAchin Gupta * list of conditions and the following disclaimer.
94f6ad66aSAchin Gupta *
104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice,
114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation
124f6ad66aSAchin Gupta * and/or other materials provided with the distribution.
134f6ad66aSAchin Gupta *
144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used
154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific
164f6ad66aSAchin Gupta * prior written permission.
174f6ad66aSAchin Gupta *
184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE.
294f6ad66aSAchin Gupta */
304f6ad66aSAchin Gupta
31c10bd2ceSSandrine Bailleux#include <arch.h>
3297043ac9SDan Handley#include <bl_common.h>
3352010cc7SSandrine Bailleux#include <el3_common_macros.S>
344f6ad66aSAchin Gupta
354f6ad66aSAchin Gupta	.globl	bl31_entrypoint
364f6ad66aSAchin Gupta
374f6ad66aSAchin Gupta
384f6ad66aSAchin Gupta	/* -----------------------------------------------------
394f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
404f6ad66aSAchin Gupta	 * executed only by the primary cpu.
414f6ad66aSAchin Gupta	 * -----------------------------------------------------
424f6ad66aSAchin Gupta	 */
434f6ad66aSAchin Gupta
440a30cf54SAndrew Thoelkefunc bl31_entrypoint
4552010cc7SSandrine Bailleux#if !RESET_TO_BL31
464112bfa0SVikram Kanigiri	/* ---------------------------------------------------------------
474112bfa0SVikram Kanigiri	 * Preceding bootloader has populated x0 with a pointer to a
484112bfa0SVikram Kanigiri	 * 'bl31_params' structure & x1 with a pointer to platform
494112bfa0SVikram Kanigiri	 * specific structure
504112bfa0SVikram Kanigiri	 * ---------------------------------------------------------------
51c10bd2ceSSandrine Bailleux	 */
5229fb905dSVikram Kanigiri	mov	x20, x0
5329fb905dSVikram Kanigiri	mov	x21, x1
54c10bd2ceSSandrine Bailleux
554f603683SHarry Liebel	/* ---------------------------------------------------------------------
5652010cc7SSandrine Bailleux	 * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
5752010cc7SSandrine Bailleux	 * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
5852010cc7SSandrine Bailleux	 * and primary/secondary CPU logic should not be executed in this case.
594f603683SHarry Liebel	 *
6052010cc7SSandrine Bailleux	 * Also, assume that the previous bootloader has already set up the CPU
6152010cc7SSandrine Bailleux	 * endianness and has initialised the memory.
624f603683SHarry Liebel	 * ---------------------------------------------------------------------
634f603683SHarry Liebel	 */
6452010cc7SSandrine Bailleux	el3_entrypoint_common					\
6552010cc7SSandrine Bailleux		_set_endian=0					\
6652010cc7SSandrine Bailleux		_warm_boot_mailbox=0				\
6752010cc7SSandrine Bailleux		_secondary_cold_boot=0				\
6852010cc7SSandrine Bailleux		_init_memory=0					\
6952010cc7SSandrine Bailleux		_init_c_runtime=1				\
7052010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
714f603683SHarry Liebel
7252010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
7352010cc7SSandrine Bailleux	 * Relay the previous bootloader's arguments to the platform layer
7452010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
7503396c43SVikram Kanigiri	 */
7652010cc7SSandrine Bailleux	mov	x0, x20
7752010cc7SSandrine Bailleux	mov	x1, x21
7852010cc7SSandrine Bailleux#else
79bf031bbaSSandrine Bailleux	/* ---------------------------------------------------------------------
80bf031bbaSSandrine Bailleux	 * For RESET_TO_BL31 systems which have a programmable reset address,
81bf031bbaSSandrine Bailleux	 * bl31_entrypoint() is executed only on the cold boot path so we can
82bf031bbaSSandrine Bailleux	 * skip the warm boot mailbox mechanism.
83bf031bbaSSandrine Bailleux	 * ---------------------------------------------------------------------
84bf031bbaSSandrine Bailleux	 */
8552010cc7SSandrine Bailleux	el3_entrypoint_common					\
8652010cc7SSandrine Bailleux		_set_endian=1					\
87bf031bbaSSandrine Bailleux		_warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS	\
8852010cc7SSandrine Bailleux		_secondary_cold_boot=1				\
8952010cc7SSandrine Bailleux		_init_memory=1					\
9052010cc7SSandrine Bailleux		_init_c_runtime=1				\
9152010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
924f6ad66aSAchin Gupta
9352010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
9452010cc7SSandrine Bailleux	 * For RESET_TO_BL31 systems, BL3-1 is the first bootloader to run so
9552010cc7SSandrine Bailleux	 * there's no argument to relay from a previous bootloader. Zero the
9652010cc7SSandrine Bailleux	 * arguments passed to the platform layer to reflect that.
9752010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
9865f546a1SSandrine Bailleux	 */
9952010cc7SSandrine Bailleux	mov	x0, 0
10052010cc7SSandrine Bailleux	mov	x1, 0
10152010cc7SSandrine Bailleux#endif /* RESET_TO_BL31 */
1024f6ad66aSAchin Gupta
1034f6ad66aSAchin Gupta	/* ---------------------------------------------
1044f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
1054f6ad66aSAchin Gupta	 * ---------------------------------------------
1064f6ad66aSAchin Gupta	 */
1074f6ad66aSAchin Gupta	bl	bl31_early_platform_setup
1084f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
1094f6ad66aSAchin Gupta
1104f6ad66aSAchin Gupta	/* ---------------------------------------------
1114f6ad66aSAchin Gupta	 * Jump to main function.
1124f6ad66aSAchin Gupta	 * ---------------------------------------------
1134f6ad66aSAchin Gupta	 */
1144f6ad66aSAchin Gupta	bl	bl31_main
1154f6ad66aSAchin Gupta
116*54dc71e7SAchin Gupta	/* -------------------------------------------------------------
117*54dc71e7SAchin Gupta	 * Clean the .data & .bss sections to main memory. This ensures
118*54dc71e7SAchin Gupta	 * that any global data which was initialised by the primary CPU
119*54dc71e7SAchin Gupta	 * is visible to secondary CPUs before they enable their data
120*54dc71e7SAchin Gupta	 * caches and participate in coherency.
121*54dc71e7SAchin Gupta	 * -------------------------------------------------------------
122*54dc71e7SAchin Gupta	 */
123*54dc71e7SAchin Gupta	adr	x0, __DATA_START__
124*54dc71e7SAchin Gupta	adr	x1, __DATA_END__
125*54dc71e7SAchin Gupta	sub	x1, x1, x0
126*54dc71e7SAchin Gupta	bl	clean_dcache_range
127*54dc71e7SAchin Gupta
128*54dc71e7SAchin Gupta	adr	x0, __BSS_START__
129*54dc71e7SAchin Gupta	adr	x1, __BSS_END__
130*54dc71e7SAchin Gupta	sub	x1, x1, x0
131*54dc71e7SAchin Gupta	bl	clean_dcache_range
132*54dc71e7SAchin Gupta
133caa84939SJeenu Viswambharan	b	el3_exit
1348b779620SKévin Petitendfunc bl31_entrypoint
135