xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision 330ead806510ed36f440b3b3c93ef67cf12716e0)
14f6ad66aSAchin Gupta/*
288cfd9a6SAntonio Nino Diaz * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
34f6ad66aSAchin Gupta *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
54f6ad66aSAchin Gupta */
64f6ad66aSAchin Gupta
7931f7c61SSoby Mathew#include <platform_def.h>
809d40e0eSAntonio Nino Diaz
909d40e0eSAntonio Nino Diaz#include <arch.h>
1009d40e0eSAntonio Nino Diaz#include <common/bl_common.h>
1109d40e0eSAntonio Nino Diaz#include <el3_common_macros.S>
1209d40e0eSAntonio Nino Diaz#include <lib/pmf/pmf_asm_macros.S>
1309d40e0eSAntonio Nino Diaz#include <lib/runtime_instr.h>
1409d40e0eSAntonio Nino Diaz#include <lib/xlat_tables/xlat_mmu_helpers.h>
154f6ad66aSAchin Gupta
164f6ad66aSAchin Gupta	.globl	bl31_entrypoint
17cf0b1492SSoby Mathew	.globl	bl31_warm_entrypoint
184f6ad66aSAchin Gupta
194f6ad66aSAchin Gupta	/* -----------------------------------------------------
204f6ad66aSAchin Gupta	 * bl31_entrypoint() is the cold boot entrypoint,
214f6ad66aSAchin Gupta	 * executed only by the primary cpu.
224f6ad66aSAchin Gupta	 * -----------------------------------------------------
234f6ad66aSAchin Gupta	 */
244f6ad66aSAchin Gupta
250a30cf54SAndrew Thoelkefunc bl31_entrypoint
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
35*330ead80SLouis Mayencourt	/* --------------------------------------------------------------------
36*330ead80SLouis Mayencourt	 * If PIE is enabled, fixup the Global descriptor Table and dynamic
37*330ead80SLouis Mayencourt	 * relocations
38*330ead80SLouis Mayencourt	 * --------------------------------------------------------------------
39*330ead80SLouis Mayencourt	 */
40*330ead80SLouis Mayencourt#if ENABLE_PIE
41*330ead80SLouis Mayencourt	mov_imm	x0, BL31_BASE
42*330ead80SLouis Mayencourt	mov_imm	x1, BL31_LIMIT
43*330ead80SLouis Mayencourt	bl	fixup_gdt_reloc
44*330ead80SLouis Mayencourt#endif /* ENABLE_PIE */
45*330ead80SLouis Mayencourt
46*330ead80SLouis Mayencourt#if !RESET_TO_BL31
474f603683SHarry Liebel	/* ---------------------------------------------------------------------
4852010cc7SSandrine Bailleux	 * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
4952010cc7SSandrine Bailleux	 * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
5052010cc7SSandrine Bailleux	 * and primary/secondary CPU logic should not be executed in this case.
514f603683SHarry Liebel	 *
5218f2efd6SDavid Cunado	 * Also, assume that the previous bootloader has already initialised the
5318f2efd6SDavid Cunado	 * SCTLR_EL3, including the endianness, and has initialised the memory.
544f603683SHarry Liebel	 * ---------------------------------------------------------------------
554f603683SHarry Liebel	 */
5652010cc7SSandrine Bailleux	el3_entrypoint_common					\
5718f2efd6SDavid Cunado		_init_sctlr=0					\
5852010cc7SSandrine Bailleux		_warm_boot_mailbox=0				\
5952010cc7SSandrine Bailleux		_secondary_cold_boot=0				\
6052010cc7SSandrine Bailleux		_init_memory=0					\
6152010cc7SSandrine Bailleux		_init_c_runtime=1				\
6252010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
6352010cc7SSandrine Bailleux#else
64*330ead80SLouis Mayencourt
65bf031bbaSSandrine Bailleux	/* ---------------------------------------------------------------------
66bf031bbaSSandrine Bailleux	 * For RESET_TO_BL31 systems which have a programmable reset address,
67bf031bbaSSandrine Bailleux	 * bl31_entrypoint() is executed only on the cold boot path so we can
68bf031bbaSSandrine Bailleux	 * skip the warm boot mailbox mechanism.
69bf031bbaSSandrine Bailleux	 * ---------------------------------------------------------------------
70bf031bbaSSandrine Bailleux	 */
7152010cc7SSandrine Bailleux	el3_entrypoint_common					\
7218f2efd6SDavid Cunado		_init_sctlr=1					\
73bf031bbaSSandrine Bailleux		_warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS	\
74a9bec67dSSandrine Bailleux		_secondary_cold_boot=!COLD_BOOT_SINGLE_CPU	\
7552010cc7SSandrine Bailleux		_init_memory=1					\
7652010cc7SSandrine Bailleux		_init_c_runtime=1				\
7752010cc7SSandrine Bailleux		_exception_vectors=runtime_exceptions
784f6ad66aSAchin Gupta
7952010cc7SSandrine Bailleux	/* ---------------------------------------------------------------------
80d178637dSJuan Castillo	 * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so
8152010cc7SSandrine Bailleux	 * there's no argument to relay from a previous bootloader. Zero the
8252010cc7SSandrine Bailleux	 * arguments passed to the platform layer to reflect that.
8352010cc7SSandrine Bailleux	 * ---------------------------------------------------------------------
8465f546a1SSandrine Bailleux	 */
85a6f340feSSoby Mathew	mov	x20, 0
86a6f340feSSoby Mathew	mov	x21, 0
87a6f340feSSoby Mathew	mov	x22, 0
88a6f340feSSoby Mathew	mov	x23, 0
8952010cc7SSandrine Bailleux#endif /* RESET_TO_BL31 */
90931f7c61SSoby Mathew
91931f7c61SSoby Mathew	/* --------------------------------------------------------------------
9288cfd9a6SAntonio Nino Diaz	 * Perform BL31 setup
9388cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
944f6ad66aSAchin Gupta	 */
95a6f340feSSoby Mathew	mov	x0, x20
96a6f340feSSoby Mathew	mov	x1, x21
97a6f340feSSoby Mathew	mov	x2, x22
98a6f340feSSoby Mathew	mov	x3, x23
9988cfd9a6SAntonio Nino Diaz	bl	bl31_setup
1004f6ad66aSAchin Gupta
10188cfd9a6SAntonio Nino Diaz	/* --------------------------------------------------------------------
10288cfd9a6SAntonio Nino Diaz	 * Enable pointer authentication
10388cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
10488cfd9a6SAntonio Nino Diaz	 */
10588cfd9a6SAntonio Nino Diaz#if ENABLE_PAUTH
10688cfd9a6SAntonio Nino Diaz	mrs	x0, sctlr_el3
10788cfd9a6SAntonio Nino Diaz	orr	x0, x0, #SCTLR_EnIA_BIT
10888cfd9a6SAntonio Nino Diaz	msr	sctlr_el3, x0
10988cfd9a6SAntonio Nino Diaz	isb
11088cfd9a6SAntonio Nino Diaz#endif /* ENABLE_PAUTH */
11188cfd9a6SAntonio Nino Diaz
11288cfd9a6SAntonio Nino Diaz	/* --------------------------------------------------------------------
1134f6ad66aSAchin Gupta	 * Jump to main function.
11488cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
1154f6ad66aSAchin Gupta	 */
1164f6ad66aSAchin Gupta	bl	bl31_main
1174f6ad66aSAchin Gupta
11888cfd9a6SAntonio Nino Diaz	/* --------------------------------------------------------------------
11954dc71e7SAchin Gupta	 * Clean the .data & .bss sections to main memory. This ensures
12054dc71e7SAchin Gupta	 * that any global data which was initialised by the primary CPU
12154dc71e7SAchin Gupta	 * is visible to secondary CPUs before they enable their data
12254dc71e7SAchin Gupta	 * caches and participate in coherency.
12388cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
12454dc71e7SAchin Gupta	 */
12554dc71e7SAchin Gupta	adr	x0, __DATA_START__
12654dc71e7SAchin Gupta	adr	x1, __DATA_END__
12754dc71e7SAchin Gupta	sub	x1, x1, x0
12854dc71e7SAchin Gupta	bl	clean_dcache_range
12954dc71e7SAchin Gupta
13054dc71e7SAchin Gupta	adr	x0, __BSS_START__
13154dc71e7SAchin Gupta	adr	x1, __BSS_END__
13254dc71e7SAchin Gupta	sub	x1, x1, x0
13354dc71e7SAchin Gupta	bl	clean_dcache_range
13454dc71e7SAchin Gupta
135caa84939SJeenu Viswambharan	b	el3_exit
1368b779620SKévin Petitendfunc bl31_entrypoint
137cf0b1492SSoby Mathew
138cf0b1492SSoby Mathew	/* --------------------------------------------------------------------
139cf0b1492SSoby Mathew	 * This CPU has been physically powered up. It is either resuming from
140cf0b1492SSoby Mathew	 * suspend or has simply been turned on. In both cases, call the BL31
141cf0b1492SSoby Mathew	 * warmboot entrypoint
142cf0b1492SSoby Mathew	 * --------------------------------------------------------------------
143cf0b1492SSoby Mathew	 */
144cf0b1492SSoby Mathewfunc bl31_warm_entrypoint
145872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
146872be88aSdp-arm
147872be88aSdp-arm	/*
148872be88aSdp-arm	 * This timestamp update happens with cache off.  The next
149872be88aSdp-arm	 * timestamp collection will need to do cache maintenance prior
150872be88aSdp-arm	 * to timestamp update.
151872be88aSdp-arm	 */
15281542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_HW_LOW_PWR
153872be88aSdp-arm	mrs	x1, cntpct_el0
154872be88aSdp-arm	str	x1, [x0]
155872be88aSdp-arm#endif
156872be88aSdp-arm
157cf0b1492SSoby Mathew	/*
158cf0b1492SSoby Mathew	 * On the warm boot path, most of the EL3 initialisations performed by
159cf0b1492SSoby Mathew	 * 'el3_entrypoint_common' must be skipped:
160cf0b1492SSoby Mathew	 *
161cf0b1492SSoby Mathew	 *  - Only when the platform bypasses the BL1/BL31 entrypoint by
16218f2efd6SDavid Cunado	 *    programming the reset address do we need to initialise SCTLR_EL3.
163cf0b1492SSoby Mathew	 *    In other cases, we assume this has been taken care by the
164cf0b1492SSoby Mathew	 *    entrypoint code.
165cf0b1492SSoby Mathew	 *
166cf0b1492SSoby Mathew	 *  - No need to determine the type of boot, we know it is a warm boot.
167cf0b1492SSoby Mathew	 *
168cf0b1492SSoby Mathew	 *  - Do not try to distinguish between primary and secondary CPUs, this
169cf0b1492SSoby Mathew	 *    notion only exists for a cold boot.
170cf0b1492SSoby Mathew	 *
171cf0b1492SSoby Mathew	 *  - No need to initialise the memory or the C runtime environment,
172cf0b1492SSoby Mathew	 *    it has been done once and for all on the cold boot path.
173cf0b1492SSoby Mathew	 */
174cf0b1492SSoby Mathew	el3_entrypoint_common					\
17518f2efd6SDavid Cunado		_init_sctlr=PROGRAMMABLE_RESET_ADDRESS		\
176cf0b1492SSoby Mathew		_warm_boot_mailbox=0				\
177cf0b1492SSoby Mathew		_secondary_cold_boot=0				\
178cf0b1492SSoby Mathew		_init_memory=0					\
179cf0b1492SSoby Mathew		_init_c_runtime=0				\
180cf0b1492SSoby Mathew		_exception_vectors=runtime_exceptions
181cf0b1492SSoby Mathew
18225a93f7cSJeenu Viswambharan	/*
18325a93f7cSJeenu Viswambharan	 * We're about to enable MMU and participate in PSCI state coordination.
18425a93f7cSJeenu Viswambharan	 *
18525a93f7cSJeenu Viswambharan	 * The PSCI implementation invokes platform routines that enable CPUs to
18625a93f7cSJeenu Viswambharan	 * participate in coherency. On a system where CPUs are not
187bcc3c49cSSoby Mathew	 * cache-coherent without appropriate platform specific programming,
188bcc3c49cSSoby Mathew	 * having caches enabled until such time might lead to coherency issues
189bcc3c49cSSoby Mathew	 * (resulting from stale data getting speculatively fetched, among
190bcc3c49cSSoby Mathew	 * others). Therefore we keep data caches disabled even after enabling
191bcc3c49cSSoby Mathew	 * the MMU for such platforms.
19225a93f7cSJeenu Viswambharan	 *
193bcc3c49cSSoby Mathew	 * On systems with hardware-assisted coherency, or on single cluster
194bcc3c49cSSoby Mathew	 * platforms, such platform specific programming is not required to
195bcc3c49cSSoby Mathew	 * enter coherency (as CPUs already are); and there's no reason to have
196bcc3c49cSSoby Mathew	 * caches disabled either.
197cf0b1492SSoby Mathew	 */
198bcc3c49cSSoby Mathew#if HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY
19964ee263eSJeenu Viswambharan	mov	x0, xzr
20064ee263eSJeenu Viswambharan#else
20164ee263eSJeenu Viswambharan	mov	x0, #DISABLE_DCACHE
202bcc3c49cSSoby Mathew#endif
20364ee263eSJeenu Viswambharan	bl	bl31_plat_enable_mmu
204bcc3c49cSSoby Mathew
2057dcbb4f3SAlexei Fedorov	/* --------------------------------------------------------------------
2067dcbb4f3SAlexei Fedorov	 * Enable pointer authentication
2077dcbb4f3SAlexei Fedorov	 * --------------------------------------------------------------------
2087dcbb4f3SAlexei Fedorov	 */
2097dcbb4f3SAlexei Fedorov#if ENABLE_PAUTH
2107dcbb4f3SAlexei Fedorov	bl	pauth_load_bl_apiakey
2117dcbb4f3SAlexei Fedorov
2127dcbb4f3SAlexei Fedorov	mrs	x0, sctlr_el3
2137dcbb4f3SAlexei Fedorov	orr	x0, x0, #SCTLR_EnIA_BIT
2147dcbb4f3SAlexei Fedorov	msr	sctlr_el3, x0
2157dcbb4f3SAlexei Fedorov	isb
2167dcbb4f3SAlexei Fedorov#endif /* ENABLE_PAUTH */
2177dcbb4f3SAlexei Fedorov
218cf0b1492SSoby Mathew	bl	psci_warmboot_entrypoint
219cf0b1492SSoby Mathew
220872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
22181542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_PSCI
222872be88aSdp-arm	mov	x19, x0
223872be88aSdp-arm
224872be88aSdp-arm	/*
225872be88aSdp-arm	 * Invalidate before updating timestamp to ensure previous timestamp
226872be88aSdp-arm	 * updates on the same cache line with caches disabled are properly
227872be88aSdp-arm	 * seen by the same core. Without the cache invalidate, the core might
228872be88aSdp-arm	 * write into a stale cache line.
229872be88aSdp-arm	 */
230872be88aSdp-arm	mov	x1, #PMF_TS_SIZE
231872be88aSdp-arm	mov	x20, x30
232872be88aSdp-arm	bl	inv_dcache_range
233872be88aSdp-arm	mov	x30, x20
234872be88aSdp-arm
235872be88aSdp-arm	mrs	x0, cntpct_el0
236872be88aSdp-arm	str	x0, [x19]
237872be88aSdp-arm#endif
238cf0b1492SSoby Mathew	b	el3_exit
239cf0b1492SSoby Mathewendfunc bl31_warm_entrypoint
240