xref: /rk3399_ARM-atf/bl31/aarch64/bl31_entrypoint.S (revision 7303319b3823e9e33748d963e9173f3678aba4da)
14f6ad66aSAchin Gupta/*
2*98859b99SSammit Joshi * Copyright (c) 2013-2025, 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>
120531ada5SBence Szépkúti#include <lib/pmf/aarch64/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
35330ead80SLouis Mayencourt#if !RESET_TO_BL31
364f603683SHarry Liebel	/* ---------------------------------------------------------------------
3752010cc7SSandrine Bailleux	 * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
3852010cc7SSandrine Bailleux	 * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
3952010cc7SSandrine Bailleux	 * and primary/secondary CPU logic should not be executed in this case.
404f603683SHarry Liebel	 *
4118f2efd6SDavid Cunado	 * Also, assume that the previous bootloader has already initialised the
4218f2efd6SDavid Cunado	 * SCTLR_EL3, including the endianness, and has initialised the memory.
434f603683SHarry Liebel	 * ---------------------------------------------------------------------
444f603683SHarry Liebel	 */
4552010cc7SSandrine Bailleux	el3_entrypoint_common					\
4618f2efd6SDavid Cunado		_init_sctlr=0					\
4752010cc7SSandrine Bailleux		_warm_boot_mailbox=0				\
4852010cc7SSandrine Bailleux		_secondary_cold_boot=0				\
4952010cc7SSandrine Bailleux		_init_memory=0					\
5052010cc7SSandrine Bailleux		_init_c_runtime=1				\
51da90359bSManish Pandey		_exception_vectors=runtime_exceptions		\
52da90359bSManish Pandey		_pie_fixup_size=BL31_LIMIT - BL31_BASE
5352010cc7SSandrine Bailleux#else
54330ead80SLouis Mayencourt
55bf031bbaSSandrine Bailleux	/* ---------------------------------------------------------------------
56bf031bbaSSandrine Bailleux	 * For RESET_TO_BL31 systems which have a programmable reset address,
57bf031bbaSSandrine Bailleux	 * bl31_entrypoint() is executed only on the cold boot path so we can
58bf031bbaSSandrine Bailleux	 * skip the warm boot mailbox mechanism.
59bf031bbaSSandrine Bailleux	 * ---------------------------------------------------------------------
60bf031bbaSSandrine Bailleux	 */
6152010cc7SSandrine Bailleux	el3_entrypoint_common					\
6218f2efd6SDavid Cunado		_init_sctlr=1					\
63bf031bbaSSandrine Bailleux		_warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS	\
64a9bec67dSSandrine Bailleux		_secondary_cold_boot=!COLD_BOOT_SINGLE_CPU	\
6552010cc7SSandrine Bailleux		_init_memory=1					\
6652010cc7SSandrine Bailleux		_init_c_runtime=1				\
67da90359bSManish Pandey		_exception_vectors=runtime_exceptions		\
68da90359bSManish Pandey		_pie_fixup_size=BL31_LIMIT - BL31_BASE
6952010cc7SSandrine Bailleux#endif /* RESET_TO_BL31 */
70931f7c61SSoby Mathew
71931f7c61SSoby Mathew	/* --------------------------------------------------------------------
7288cfd9a6SAntonio Nino Diaz	 * Perform BL31 setup
7388cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
744f6ad66aSAchin Gupta	 */
75a6f340feSSoby Mathew	mov	x0, x20
76a6f340feSSoby Mathew	mov	x1, x21
77a6f340feSSoby Mathew	mov	x2, x22
78a6f340feSSoby Mathew	mov	x3, x23
7988cfd9a6SAntonio Nino Diaz
8088cfd9a6SAntonio Nino Diaz	/* --------------------------------------------------------------------
81ed108b56SAlexei Fedorov	 * Jump to main function
8288cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
834f6ad66aSAchin Gupta	 */
844f6ad66aSAchin Gupta	bl	bl31_main
854f6ad66aSAchin Gupta
8688cfd9a6SAntonio Nino Diaz	/* --------------------------------------------------------------------
8754dc71e7SAchin Gupta	 * Clean the .data & .bss sections to main memory. This ensures
8854dc71e7SAchin Gupta	 * that any global data which was initialised by the primary CPU
8954dc71e7SAchin Gupta	 * is visible to secondary CPUs before they enable their data
9054dc71e7SAchin Gupta	 * caches and participate in coherency.
9188cfd9a6SAntonio Nino Diaz	 * --------------------------------------------------------------------
9254dc71e7SAchin Gupta	 */
93c367b75eSMadhukar Pappireddy	adrp	x0, __DATA_START__
94c367b75eSMadhukar Pappireddy	add	x0, x0, :lo12:__DATA_START__
95c367b75eSMadhukar Pappireddy	adrp	x1, __DATA_END__
96c367b75eSMadhukar Pappireddy	add	x1, x1, :lo12:__DATA_END__
9754dc71e7SAchin Gupta	sub	x1, x1, x0
9854dc71e7SAchin Gupta	bl	clean_dcache_range
9954dc71e7SAchin Gupta
100c367b75eSMadhukar Pappireddy	adrp	x0, __BSS_START__
101c367b75eSMadhukar Pappireddy	add	x0, x0, :lo12:__BSS_START__
102c367b75eSMadhukar Pappireddy	adrp	x1, __BSS_END__
103c367b75eSMadhukar Pappireddy	add	x1, x1, :lo12:__BSS_END__
10454dc71e7SAchin Gupta	sub	x1, x1, x0
10554dc71e7SAchin Gupta	bl	clean_dcache_range
10654dc71e7SAchin Gupta
107*98859b99SSammit Joshi	adrp	x0, __PER_CPU_START__
108*98859b99SSammit Joshi	add	x0, x0, :lo12:__PER_CPU_START__
109*98859b99SSammit Joshi	adrp	x1, __PER_CPU_END__
110*98859b99SSammit Joshi	add	x1, x1, :lo12:__PER_CPU_END__
111*98859b99SSammit Joshi	sub	x1, x1, x0
112*98859b99SSammit Joshi	bl	clean_dcache_range
113*98859b99SSammit Joshi
114*98859b99SSammit Joshi#if (PLATFORM_NODE_COUNT > 1)
115*98859b99SSammit Joshi	/*
116*98859b99SSammit Joshi	 * dcache clean per-cpu sections defined by the platform.
117*98859b99SSammit Joshi	 * Care must be taken to preserve and retain the clobbered
118*98859b99SSammit Joshi	 * registers. A standard around the container for per-cpu nodes
119*98859b99SSammit Joshi	 * is not yet defined.
120*98859b99SSammit Joshi	 */
121*98859b99SSammit Joshi
122*98859b99SSammit Joshi	bl	plat_per_cpu_dcache_clean
123*98859b99SSammit Joshi#endif /* (PLATFORM_NODE_COUNT > 1) */
124caa84939SJeenu Viswambharan	b	el3_exit
1258b779620SKévin Petitendfunc bl31_entrypoint
126cf0b1492SSoby Mathew
127cf0b1492SSoby Mathew	/* --------------------------------------------------------------------
128cf0b1492SSoby Mathew	 * This CPU has been physically powered up. It is either resuming from
129cf0b1492SSoby Mathew	 * suspend or has simply been turned on. In both cases, call the BL31
130cf0b1492SSoby Mathew	 * warmboot entrypoint
131cf0b1492SSoby Mathew	 * --------------------------------------------------------------------
132cf0b1492SSoby Mathew	 */
133cf0b1492SSoby Mathewfunc bl31_warm_entrypoint
134872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
135872be88aSdp-arm
136872be88aSdp-arm	/*
137872be88aSdp-arm	 * This timestamp update happens with cache off.  The next
138872be88aSdp-arm	 * timestamp collection will need to do cache maintenance prior
139872be88aSdp-arm	 * to timestamp update.
140872be88aSdp-arm	 */
14181542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_HW_LOW_PWR
142872be88aSdp-arm	mrs	x1, cntpct_el0
143872be88aSdp-arm	str	x1, [x0]
144872be88aSdp-arm#endif
145872be88aSdp-arm
146cf0b1492SSoby Mathew	/*
147cf0b1492SSoby Mathew	 * On the warm boot path, most of the EL3 initialisations performed by
148cf0b1492SSoby Mathew	 * 'el3_entrypoint_common' must be skipped:
149cf0b1492SSoby Mathew	 *
150cf0b1492SSoby Mathew	 *  - Only when the platform bypasses the BL1/BL31 entrypoint by
15118f2efd6SDavid Cunado	 *    programming the reset address do we need to initialise SCTLR_EL3.
152cf0b1492SSoby Mathew	 *    In other cases, we assume this has been taken care by the
153cf0b1492SSoby Mathew	 *    entrypoint code.
154cf0b1492SSoby Mathew	 *
155cf0b1492SSoby Mathew	 *  - No need to determine the type of boot, we know it is a warm boot.
156cf0b1492SSoby Mathew	 *
157cf0b1492SSoby Mathew	 *  - Do not try to distinguish between primary and secondary CPUs, this
158cf0b1492SSoby Mathew	 *    notion only exists for a cold boot.
159cf0b1492SSoby Mathew	 *
160cf0b1492SSoby Mathew	 *  - No need to initialise the memory or the C runtime environment,
161cf0b1492SSoby Mathew	 *    it has been done once and for all on the cold boot path.
162cf0b1492SSoby Mathew	 */
163cf0b1492SSoby Mathew	el3_entrypoint_common					\
16418f2efd6SDavid Cunado		_init_sctlr=PROGRAMMABLE_RESET_ADDRESS		\
165cf0b1492SSoby Mathew		_warm_boot_mailbox=0				\
166cf0b1492SSoby Mathew		_secondary_cold_boot=0				\
167cf0b1492SSoby Mathew		_init_memory=0					\
168cf0b1492SSoby Mathew		_init_c_runtime=0				\
169da90359bSManish Pandey		_exception_vectors=runtime_exceptions		\
170da90359bSManish Pandey		_pie_fixup_size=0
171cf0b1492SSoby Mathew
172d158d425SBoyan Karatotev	bl	bl31_warmboot
173cf0b1492SSoby Mathew
174872be88aSdp-arm#if ENABLE_RUNTIME_INSTRUMENTATION
17581542c00SAntonio Nino Diaz	pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_PSCI
176872be88aSdp-arm	mov	x19, x0
177872be88aSdp-arm
178872be88aSdp-arm	/*
179872be88aSdp-arm	 * Invalidate before updating timestamp to ensure previous timestamp
180872be88aSdp-arm	 * updates on the same cache line with caches disabled are properly
181872be88aSdp-arm	 * seen by the same core. Without the cache invalidate, the core might
182872be88aSdp-arm	 * write into a stale cache line.
183872be88aSdp-arm	 */
184872be88aSdp-arm	mov	x1, #PMF_TS_SIZE
185872be88aSdp-arm	mov	x20, x30
186872be88aSdp-arm	bl	inv_dcache_range
187872be88aSdp-arm	mov	x30, x20
188872be88aSdp-arm
189872be88aSdp-arm	mrs	x0, cntpct_el0
190872be88aSdp-arm	str	x0, [x19]
191872be88aSdp-arm#endif
192cf0b1492SSoby Mathew	b	el3_exit
193cf0b1492SSoby Mathewendfunc bl31_warm_entrypoint
194