xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision cf0b1492ede6cbbf788144a56d276d8d7924500a)
14f6ad66aSAchin Gupta/*
2*cf0b1492SSoby Mathew * Copyright (c) 2013-2016, 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>
34*cf0b1492SSoby Mathew#include <xlat_tables.h>
354f6ad66aSAchin Gupta
364f6ad66aSAchin Gupta	.globl	bl31_entrypoint
37*cf0b1492SSoby Mathew	.globl	bl31_warm_entrypoint
384f6ad66aSAchin Gupta
394f6ad66aSAchin Gupta	/* -----------------------------------------------------
404f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
414f6ad66aSAchin Gupta	 * executed only by the primary cpu.
424f6ad66aSAchin Gupta	 * -----------------------------------------------------
434f6ad66aSAchin Gupta	 */
444f6ad66aSAchin Gupta
450a30cf54SAndrew Thoelkefunc bl31_entrypoint
4652010cc7SSandrine Bailleux#if !RESET_TO_BL31
474112bfa0SVikram Kanigiri	/* ---------------------------------------------------------------
484112bfa0SVikram Kanigiri	 * Preceding bootloader has populated x0 with a pointer to a
494112bfa0SVikram Kanigiri	 * 'bl31_params' structure & x1 with a pointer to platform
504112bfa0SVikram Kanigiri	 * specific structure
514112bfa0SVikram Kanigiri	 * ---------------------------------------------------------------
52c10bd2ceSSandrine Bailleux	 */
5329fb905dSVikram Kanigiri	mov	x20, x0
5429fb905dSVikram Kanigiri	mov	x21, x1
55c10bd2ceSSandrine Bailleux
564f603683SHarry Liebel	/* ---------------------------------------------------------------------
5752010cc7SSandrine Bailleux	 * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
5852010cc7SSandrine Bailleux	 * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
5952010cc7SSandrine Bailleux	 * and primary/secondary CPU logic should not be executed in this case.
604f603683SHarry Liebel	 *
6152010cc7SSandrine Bailleux	 * Also, assume that the previous bootloader has already set up the CPU
6252010cc7SSandrine Bailleux	 * endianness and has initialised the memory.
634f603683SHarry Liebel	 * ---------------------------------------------------------------------
644f603683SHarry Liebel	 */
6552010cc7SSandrine Bailleux	el3_entrypoint_common					\
6652010cc7SSandrine Bailleux		_set_endian=0					\
6752010cc7SSandrine Bailleux		_warm_boot_mailbox=0				\
6852010cc7SSandrine Bailleux		_secondary_cold_boot=0				\
6952010cc7SSandrine Bailleux		_init_memory=0					\
7052010cc7SSandrine Bailleux		_init_c_runtime=1				\
7152010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
724f603683SHarry Liebel
7352010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
7452010cc7SSandrine Bailleux	 * Relay the previous bootloader's arguments to the platform layer
7552010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
7603396c43SVikram Kanigiri	 */
7752010cc7SSandrine Bailleux	mov	x0, x20
7852010cc7SSandrine Bailleux	mov	x1, x21
7952010cc7SSandrine Bailleux#else
80bf031bbaSSandrine Bailleux	/* ---------------------------------------------------------------------
81bf031bbaSSandrine Bailleux	 * For RESET_TO_BL31 systems which have a programmable reset address,
82bf031bbaSSandrine Bailleux	 * bl31_entrypoint() is executed only on the cold boot path so we can
83bf031bbaSSandrine Bailleux	 * skip the warm boot mailbox mechanism.
84bf031bbaSSandrine Bailleux	 * ---------------------------------------------------------------------
85bf031bbaSSandrine Bailleux	 */
8652010cc7SSandrine Bailleux	el3_entrypoint_common					\
8752010cc7SSandrine Bailleux		_set_endian=1					\
88bf031bbaSSandrine Bailleux		_warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS	\
89a9bec67dSSandrine Bailleux		_secondary_cold_boot=!COLD_BOOT_SINGLE_CPU	\
9052010cc7SSandrine Bailleux		_init_memory=1					\
9152010cc7SSandrine Bailleux		_init_c_runtime=1				\
9252010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
934f6ad66aSAchin Gupta
9452010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
95d178637dSJuan Castillo	 * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so
9652010cc7SSandrine Bailleux	 * there's no argument to relay from a previous bootloader. Zero the
9752010cc7SSandrine Bailleux	 * arguments passed to the platform layer to reflect that.
9852010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
9965f546a1SSandrine Bailleux	 */
10052010cc7SSandrine Bailleux	mov	x0, 0
10152010cc7SSandrine Bailleux	mov	x1, 0
10252010cc7SSandrine Bailleux#endif /* RESET_TO_BL31 */
1034f6ad66aSAchin Gupta
1044f6ad66aSAchin Gupta	/* ---------------------------------------------
1054f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
1064f6ad66aSAchin Gupta	 * ---------------------------------------------
1074f6ad66aSAchin Gupta	 */
1084f6ad66aSAchin Gupta	bl	bl31_early_platform_setup
1094f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
1104f6ad66aSAchin Gupta
1114f6ad66aSAchin Gupta	/* ---------------------------------------------
1124f6ad66aSAchin Gupta	 * Jump to main function.
1134f6ad66aSAchin Gupta	 * ---------------------------------------------
1144f6ad66aSAchin Gupta	 */
1154f6ad66aSAchin Gupta	bl	bl31_main
1164f6ad66aSAchin Gupta
11754dc71e7SAchin Gupta	/* -------------------------------------------------------------
11854dc71e7SAchin Gupta	 * Clean the .data & .bss sections to main memory. This ensures
11954dc71e7SAchin Gupta	 * that any global data which was initialised by the primary CPU
12054dc71e7SAchin Gupta	 * is visible to secondary CPUs before they enable their data
12154dc71e7SAchin Gupta	 * caches and participate in coherency.
12254dc71e7SAchin Gupta	 * -------------------------------------------------------------
12354dc71e7SAchin Gupta	 */
12454dc71e7SAchin Gupta	adr	x0, __DATA_START__
12554dc71e7SAchin Gupta	adr	x1, __DATA_END__
12654dc71e7SAchin Gupta	sub	x1, x1, x0
12754dc71e7SAchin Gupta	bl	clean_dcache_range
12854dc71e7SAchin Gupta
12954dc71e7SAchin Gupta	adr	x0, __BSS_START__
13054dc71e7SAchin Gupta	adr	x1, __BSS_END__
13154dc71e7SAchin Gupta	sub	x1, x1, x0
13254dc71e7SAchin Gupta	bl	clean_dcache_range
13354dc71e7SAchin Gupta
134caa84939SJeenu Viswambharan	b	el3_exit
1358b779620SKévin Petitendfunc bl31_entrypoint
136*cf0b1492SSoby Mathew
137*cf0b1492SSoby Mathew	/* --------------------------------------------------------------------
138*cf0b1492SSoby Mathew	 * This CPU has been physically powered up. It is either resuming from
139*cf0b1492SSoby Mathew	 * suspend or has simply been turned on. In both cases, call the BL31
140*cf0b1492SSoby Mathew	 * warmboot entrypoint
141*cf0b1492SSoby Mathew	 * --------------------------------------------------------------------
142*cf0b1492SSoby Mathew	 */
143*cf0b1492SSoby Mathewfunc bl31_warm_entrypoint
144*cf0b1492SSoby Mathew	/*
145*cf0b1492SSoby Mathew	 * On the warm boot path, most of the EL3 initialisations performed by
146*cf0b1492SSoby Mathew	 * 'el3_entrypoint_common' must be skipped:
147*cf0b1492SSoby Mathew	 *
148*cf0b1492SSoby Mathew	 *  - Only when the platform bypasses the BL1/BL31 entrypoint by
149*cf0b1492SSoby Mathew	 *    programming the reset address do we need to set the CPU endianness.
150*cf0b1492SSoby Mathew	 *    In other cases, we assume this has been taken care by the
151*cf0b1492SSoby Mathew	 *    entrypoint code.
152*cf0b1492SSoby Mathew	 *
153*cf0b1492SSoby Mathew	 *  - No need to determine the type of boot, we know it is a warm boot.
154*cf0b1492SSoby Mathew	 *
155*cf0b1492SSoby Mathew	 *  - Do not try to distinguish between primary and secondary CPUs, this
156*cf0b1492SSoby Mathew	 *    notion only exists for a cold boot.
157*cf0b1492SSoby Mathew	 *
158*cf0b1492SSoby Mathew	 *  - No need to initialise the memory or the C runtime environment,
159*cf0b1492SSoby Mathew	 *    it has been done once and for all on the cold boot path.
160*cf0b1492SSoby Mathew	 */
161*cf0b1492SSoby Mathew	el3_entrypoint_common					\
162*cf0b1492SSoby Mathew		_set_endian=PROGRAMMABLE_RESET_ADDRESS		\
163*cf0b1492SSoby Mathew		_warm_boot_mailbox=0				\
164*cf0b1492SSoby Mathew		_secondary_cold_boot=0				\
165*cf0b1492SSoby Mathew		_init_memory=0					\
166*cf0b1492SSoby Mathew		_init_c_runtime=0				\
167*cf0b1492SSoby Mathew		_exception_vectors=runtime_exceptions
168*cf0b1492SSoby Mathew
169*cf0b1492SSoby Mathew	/* --------------------------------------------
170*cf0b1492SSoby Mathew	 * Enable the MMU with the DCache disabled. It
171*cf0b1492SSoby Mathew	 * is safe to use stacks allocated in normal
172*cf0b1492SSoby Mathew	 * memory as a result. All memory accesses are
173*cf0b1492SSoby Mathew	 * marked nGnRnE when the MMU is disabled. So
174*cf0b1492SSoby Mathew	 * all the stack writes will make it to memory.
175*cf0b1492SSoby Mathew	 * All memory accesses are marked Non-cacheable
176*cf0b1492SSoby Mathew	 * when the MMU is enabled but D$ is disabled.
177*cf0b1492SSoby Mathew	 * So used stack memory is guaranteed to be
178*cf0b1492SSoby Mathew	 * visible immediately after the MMU is enabled
179*cf0b1492SSoby Mathew	 * Enabling the DCache at the same time as the
180*cf0b1492SSoby Mathew	 * MMU can lead to speculatively fetched and
181*cf0b1492SSoby Mathew	 * possibly stale stack memory being read from
182*cf0b1492SSoby Mathew	 * other caches. This can lead to coherency
183*cf0b1492SSoby Mathew	 * issues.
184*cf0b1492SSoby Mathew	 * --------------------------------------------
185*cf0b1492SSoby Mathew	 */
186*cf0b1492SSoby Mathew	mov	x0, #DISABLE_DCACHE
187*cf0b1492SSoby Mathew	bl	bl31_plat_enable_mmu
188*cf0b1492SSoby Mathew
189*cf0b1492SSoby Mathew	bl	psci_warmboot_entrypoint
190*cf0b1492SSoby Mathew
191*cf0b1492SSoby Mathew	b	el3_exit
192*cf0b1492SSoby Mathewendfunc bl31_warm_entrypoint
193