xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision 931f7c615643e5d0fb2cbab68e4093c980b0e271)
14f6ad66aSAchin Gupta/*
2a6f340feSSoby Mathew * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
7c10bd2ceSSandrine Bailleux#include <arch.h>
897043ac9SDan Handley#include <bl_common.h>
952010cc7SSandrine Bailleux#include <el3_common_macros.S>
10*931f7c61SSoby Mathew#include <platform_def.h>
11872be88aSdp-arm#include <pmf_asm_macros.S>
12872be88aSdp-arm#include <runtime_instr.h>
13883d1b5dSAntonio Nino Diaz#include <xlat_mmu_helpers.h>
144f6ad66aSAchin Gupta
154f6ad66aSAchin Gupta	.globl	bl31_entrypoint
16cf0b1492SSoby Mathew	.globl	bl31_warm_entrypoint
174f6ad66aSAchin Gupta
184f6ad66aSAchin Gupta	/* -----------------------------------------------------
194f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
204f6ad66aSAchin Gupta	 * executed only by the primary cpu.
214f6ad66aSAchin Gupta	 * -----------------------------------------------------
224f6ad66aSAchin Gupta	 */
234f6ad66aSAchin Gupta
240a30cf54SAndrew Thoelkefunc bl31_entrypoint
2552010cc7SSandrine Bailleux#if !RESET_TO_BL31
264112bfa0SVikram Kanigiri	/* ---------------------------------------------------------------
27a6f340feSSoby Mathew	 * Stash the previous bootloader arguments x0 - x3 for later use.
284112bfa0SVikram Kanigiri	 * ---------------------------------------------------------------
29c10bd2ceSSandrine Bailleux	 */
3029fb905dSVikram Kanigiri	mov	x20, x0
3129fb905dSVikram Kanigiri	mov	x21, x1
32a6f340feSSoby Mathew	mov	x22, x2
33a6f340feSSoby Mathew	mov	x23, x3
34c10bd2ceSSandrine Bailleux
354f603683SHarry Liebel	/* ---------------------------------------------------------------------
3652010cc7SSandrine Bailleux	 * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
3752010cc7SSandrine Bailleux	 * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
3852010cc7SSandrine Bailleux	 * and primary/secondary CPU logic should not be executed in this case.
394f603683SHarry Liebel	 *
4018f2efd6SDavid Cunado	 * Also, assume that the previous bootloader has already initialised the
4118f2efd6SDavid Cunado	 * SCTLR_EL3, including the endianness, and has initialised the memory.
424f603683SHarry Liebel	 * ---------------------------------------------------------------------
434f603683SHarry Liebel	 */
4452010cc7SSandrine Bailleux	el3_entrypoint_common					\
4518f2efd6SDavid Cunado		_init_sctlr=0					\
4652010cc7SSandrine Bailleux		_warm_boot_mailbox=0				\
4752010cc7SSandrine Bailleux		_secondary_cold_boot=0				\
4852010cc7SSandrine Bailleux		_init_memory=0					\
4952010cc7SSandrine Bailleux		_init_c_runtime=1				\
5052010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
5152010cc7SSandrine Bailleux#else
52bf031bbaSSandrine Bailleux	/* ---------------------------------------------------------------------
53bf031bbaSSandrine Bailleux	 * For RESET_TO_BL31 systems which have a programmable reset address,
54bf031bbaSSandrine Bailleux	 * bl31_entrypoint() is executed only on the cold boot path so we can
55bf031bbaSSandrine Bailleux	 * skip the warm boot mailbox mechanism.
56bf031bbaSSandrine Bailleux	 * ---------------------------------------------------------------------
57bf031bbaSSandrine Bailleux	 */
5852010cc7SSandrine Bailleux	el3_entrypoint_common					\
5918f2efd6SDavid Cunado		_init_sctlr=1					\
60bf031bbaSSandrine Bailleux		_warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS	\
61a9bec67dSSandrine Bailleux		_secondary_cold_boot=!COLD_BOOT_SINGLE_CPU	\
6252010cc7SSandrine Bailleux		_init_memory=1					\
6352010cc7SSandrine Bailleux		_init_c_runtime=1				\
6452010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
654f6ad66aSAchin Gupta
6652010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
67d178637dSJuan Castillo	 * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so
6852010cc7SSandrine Bailleux	 * there's no argument to relay from a previous bootloader. Zero the
6952010cc7SSandrine Bailleux	 * arguments passed to the platform layer to reflect that.
7052010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
7165f546a1SSandrine Bailleux	 */
72a6f340feSSoby Mathew	mov	x20, 0
73a6f340feSSoby Mathew	mov	x21, 0
74a6f340feSSoby Mathew	mov	x22, 0
75a6f340feSSoby Mathew	mov	x23, 0
7652010cc7SSandrine Bailleux#endif /* RESET_TO_BL31 */
77*931f7c61SSoby Mathew
78*931f7c61SSoby Mathew	/* --------------------------------------------------------------------
79*931f7c61SSoby Mathew	 * If PIE is enabled, fixup the Global descriptor Table and dynamic
80*931f7c61SSoby Mathew	 * relocations
81*931f7c61SSoby Mathew	 * --------------------------------------------------------------------
82*931f7c61SSoby Mathew	 */
83*931f7c61SSoby Mathew#if ENABLE_PIE
84*931f7c61SSoby Mathew	mov_imm	x0, BL31_BASE
85*931f7c61SSoby Mathew	mov_imm	x1, BL31_LIMIT
86*931f7c61SSoby Mathew	bl	fixup_gdt_reloc
87*931f7c61SSoby Mathew#endif /* ENABLE_PIE */
88*931f7c61SSoby Mathew
894f6ad66aSAchin Gupta	/* ---------------------------------------------
904f6ad66aSAchin Gupta	 * Perform platform specific early arch. setup
914f6ad66aSAchin Gupta	 * ---------------------------------------------
924f6ad66aSAchin Gupta	 */
93a6f340feSSoby Mathew	mov	x0, x20
94a6f340feSSoby Mathew	mov	x1, x21
95a6f340feSSoby Mathew	mov	x2, x22
96a6f340feSSoby Mathew	mov	x3, x23
97a6f340feSSoby Mathew	bl	bl31_early_platform_setup2
984f6ad66aSAchin Gupta	bl	bl31_plat_arch_setup
994f6ad66aSAchin Gupta
1004f6ad66aSAchin Gupta	/* ---------------------------------------------
1014f6ad66aSAchin Gupta	 * Jump to main function.
1024f6ad66aSAchin Gupta	 * ---------------------------------------------
1034f6ad66aSAchin Gupta	 */
1044f6ad66aSAchin Gupta	bl	bl31_main
1054f6ad66aSAchin Gupta
10654dc71e7SAchin Gupta	/* -------------------------------------------------------------
10754dc71e7SAchin Gupta	 * Clean the .data & .bss sections to main memory. This ensures
10854dc71e7SAchin Gupta	 * that any global data which was initialised by the primary CPU
10954dc71e7SAchin Gupta	 * is visible to secondary CPUs before they enable their data
11054dc71e7SAchin Gupta	 * caches and participate in coherency.
11154dc71e7SAchin Gupta	 * -------------------------------------------------------------
11254dc71e7SAchin Gupta	 */
11354dc71e7SAchin Gupta	adr	x0, __DATA_START__
11454dc71e7SAchin Gupta	adr	x1, __DATA_END__
11554dc71e7SAchin Gupta	sub	x1, x1, x0
11654dc71e7SAchin Gupta	bl	clean_dcache_range
11754dc71e7SAchin Gupta
11854dc71e7SAchin Gupta	adr	x0, __BSS_START__
11954dc71e7SAchin Gupta	adr	x1, __BSS_END__
12054dc71e7SAchin Gupta	sub	x1, x1, x0
12154dc71e7SAchin Gupta	bl	clean_dcache_range
12254dc71e7SAchin Gupta
123caa84939SJeenu Viswambharan	b	el3_exit
1248b779620SKévin Petitendfunc bl31_entrypoint
125cf0b1492SSoby Mathew
126cf0b1492SSoby Mathew	/* --------------------------------------------------------------------
127cf0b1492SSoby Mathew	 * This CPU has been physically powered up. It is either resuming from
128cf0b1492SSoby Mathew	 * suspend or has simply been turned on. In both cases, call the BL31
129cf0b1492SSoby Mathew	 * warmboot entrypoint
130cf0b1492SSoby Mathew	 * --------------------------------------------------------------------
131cf0b1492SSoby Mathew	 */
132cf0b1492SSoby Mathewfunc bl31_warm_entrypoint
133872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
134872be88aSdp-arm
135872be88aSdp-arm	/*
136872be88aSdp-arm	 * This timestamp update happens with cache off.  The next
137872be88aSdp-arm	 * timestamp collection will need to do cache maintenance prior
138872be88aSdp-arm	 * to timestamp update.
139872be88aSdp-arm	 */
14081542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_HW_LOW_PWR
141872be88aSdp-arm	mrs	x1, cntpct_el0
142872be88aSdp-arm	str	x1, [x0]
143872be88aSdp-arm#endif
144872be88aSdp-arm
145cf0b1492SSoby Mathew	/*
146cf0b1492SSoby Mathew	 * On the warm boot path, most of the EL3 initialisations performed by
147cf0b1492SSoby Mathew	 * 'el3_entrypoint_common' must be skipped:
148cf0b1492SSoby Mathew	 *
149cf0b1492SSoby Mathew	 *  - Only when the platform bypasses the BL1/BL31 entrypoint by
15018f2efd6SDavid Cunado	 *    programming the reset address do we need to initialise SCTLR_EL3.
151cf0b1492SSoby Mathew	 *    In other cases, we assume this has been taken care by the
152cf0b1492SSoby Mathew	 *    entrypoint code.
153cf0b1492SSoby Mathew	 *
154cf0b1492SSoby Mathew	 *  - No need to determine the type of boot, we know it is a warm boot.
155cf0b1492SSoby Mathew	 *
156cf0b1492SSoby Mathew	 *  - Do not try to distinguish between primary and secondary CPUs, this
157cf0b1492SSoby Mathew	 *    notion only exists for a cold boot.
158cf0b1492SSoby Mathew	 *
159cf0b1492SSoby Mathew	 *  - No need to initialise the memory or the C runtime environment,
160cf0b1492SSoby Mathew	 *    it has been done once and for all on the cold boot path.
161cf0b1492SSoby Mathew	 */
162cf0b1492SSoby Mathew	el3_entrypoint_common					\
16318f2efd6SDavid Cunado		_init_sctlr=PROGRAMMABLE_RESET_ADDRESS		\
164cf0b1492SSoby Mathew		_warm_boot_mailbox=0				\
165cf0b1492SSoby Mathew		_secondary_cold_boot=0				\
166cf0b1492SSoby Mathew		_init_memory=0					\
167cf0b1492SSoby Mathew		_init_c_runtime=0				\
168cf0b1492SSoby Mathew		_exception_vectors=runtime_exceptions
169cf0b1492SSoby Mathew
17025a93f7cSJeenu Viswambharan	/*
17125a93f7cSJeenu Viswambharan	 * We're about to enable MMU and participate in PSCI state coordination.
17225a93f7cSJeenu Viswambharan	 *
17325a93f7cSJeenu Viswambharan	 * The PSCI implementation invokes platform routines that enable CPUs to
17425a93f7cSJeenu Viswambharan	 * participate in coherency. On a system where CPUs are not
175bcc3c49cSSoby Mathew	 * cache-coherent without appropriate platform specific programming,
176bcc3c49cSSoby Mathew	 * having caches enabled until such time might lead to coherency issues
177bcc3c49cSSoby Mathew	 * (resulting from stale data getting speculatively fetched, among
178bcc3c49cSSoby Mathew	 * others). Therefore we keep data caches disabled even after enabling
179bcc3c49cSSoby Mathew	 * the MMU for such platforms.
18025a93f7cSJeenu Viswambharan	 *
181bcc3c49cSSoby Mathew	 * On systems with hardware-assisted coherency, or on single cluster
182bcc3c49cSSoby Mathew	 * platforms, such platform specific programming is not required to
183bcc3c49cSSoby Mathew	 * enter coherency (as CPUs already are); and there's no reason to have
184bcc3c49cSSoby Mathew	 * caches disabled either.
185cf0b1492SSoby Mathew	 */
186bcc3c49cSSoby Mathew#if HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY
18764ee263eSJeenu Viswambharan	mov	x0, xzr
18864ee263eSJeenu Viswambharan#else
18964ee263eSJeenu Viswambharan	mov	x0, #DISABLE_DCACHE
190bcc3c49cSSoby Mathew#endif
19164ee263eSJeenu Viswambharan	bl	bl31_plat_enable_mmu
192bcc3c49cSSoby Mathew
193cf0b1492SSoby Mathew	bl	psci_warmboot_entrypoint
194cf0b1492SSoby Mathew
195872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
19681542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_PSCI
197872be88aSdp-arm	mov	x19, x0
198872be88aSdp-arm
199872be88aSdp-arm	/*
200872be88aSdp-arm	 * Invalidate before updating timestamp to ensure previous timestamp
201872be88aSdp-arm	 * updates on the same cache line with caches disabled are properly
202872be88aSdp-arm	 * seen by the same core. Without the cache invalidate, the core might
203872be88aSdp-arm	 * write into a stale cache line.
204872be88aSdp-arm	 */
205872be88aSdp-arm	mov	x1, #PMF_TS_SIZE
206872be88aSdp-arm	mov	x20, x30
207872be88aSdp-arm	bl	inv_dcache_range
208872be88aSdp-arm	mov	x30, x20
209872be88aSdp-arm
210872be88aSdp-arm	mrs	x0, cntpct_el0
211872be88aSdp-arm	str	x0, [x19]
212872be88aSdp-arm#endif
213cf0b1492SSoby Mathew	b	el3_exit
214cf0b1492SSoby Mathewendfunc bl31_warm_entrypoint
215