xref: /rk3399_ARM-atf/plat/arm/board/fvp/aarch64/fvp_helpers.S (revision 560293bb6f92fa4bbebea13113bac56ab50b7905)
13fc4124cSDan Handley/*
211ad8f20SJeenu Viswambharan * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
33fc4124cSDan Handley *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
53fc4124cSDan Handley */
63fc4124cSDan Handley
73fc4124cSDan Handley#include <arch.h>
83fc4124cSDan Handley#include <asm_macros.S>
909d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv2.h>
1009d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv3.h>
11*560293bbSAntonio Nino Diaz#include <drivers/arm/fvp/fvp_pwrc.h>
123fc4124cSDan Handley#include <platform_def.h>
13234bc7f8SAntonio Nino Diaz
143fc4124cSDan Handley	.globl	plat_secondary_cold_boot_setup
1538dce70fSSoby Mathew	.globl	plat_get_my_entrypoint
1638dce70fSSoby Mathew	.globl	plat_is_my_cpu_primary
1711ad8f20SJeenu Viswambharan	.globl	plat_arm_calc_core_pos
183fc4124cSDan Handley
193fc4124cSDan Handley	.macro	fvp_choose_gicmmap  param1, param2, x_tmp, w_tmp, res
20bd83b396SSoby Mathew	mov_imm	\x_tmp, V2M_SYSREGS_BASE + V2M_SYS_ID
213fc4124cSDan Handley	ldr	\w_tmp, [\x_tmp]
223fc4124cSDan Handley	ubfx	\w_tmp, \w_tmp, #V2M_SYS_ID_BLD_SHIFT, #V2M_SYS_ID_BLD_LENGTH
233fc4124cSDan Handley	cmp	\w_tmp, #BLD_GIC_VE_MMAP
243fc4124cSDan Handley	csel	\res, \param1, \param2, eq
253fc4124cSDan Handley	.endm
263fc4124cSDan Handley
273fc4124cSDan Handley	/* -----------------------------------------------------
283fc4124cSDan Handley	 * void plat_secondary_cold_boot_setup (void);
293fc4124cSDan Handley	 *
303fc4124cSDan Handley	 * This function performs any platform specific actions
313fc4124cSDan Handley	 * needed for a secondary cpu after a cold reset e.g
323fc4124cSDan Handley	 * mark the cpu's presence, mechanism to place it in a
333fc4124cSDan Handley	 * holding pen etc.
343fc4124cSDan Handley	 * TODO: Should we read the PSYS register to make sure
353fc4124cSDan Handley	 * that the request has gone through.
363fc4124cSDan Handley	 * -----------------------------------------------------
373fc4124cSDan Handley	 */
383fc4124cSDan Handleyfunc plat_secondary_cold_boot_setup
39cdf14088SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE
403fc4124cSDan Handley	/* ---------------------------------------------
413fc4124cSDan Handley	 * Power down this cpu.
423fc4124cSDan Handley	 * TODO: Do we need to worry about powering the
433fc4124cSDan Handley	 * cluster down as well here. That will need
443fc4124cSDan Handley	 * locks which we won't have unless an elf-
453fc4124cSDan Handley	 * loader zeroes out the zi section.
463fc4124cSDan Handley	 * ---------------------------------------------
473fc4124cSDan Handley	 */
483fc4124cSDan Handley	mrs	x0, mpidr_el1
49bd83b396SSoby Mathew	mov_imm	x1, PWRC_BASE
503fc4124cSDan Handley	str	w0, [x1, #PPOFFR_OFF]
513fc4124cSDan Handley
523fc4124cSDan Handley	/* ---------------------------------------------
53f14d1886SSoby Mathew	 * Disable GIC bypass as well
543fc4124cSDan Handley	 * ---------------------------------------------
553fc4124cSDan Handley	 */
56f14d1886SSoby Mathew	/* Check for GICv3 system register access */
57f14d1886SSoby Mathew	mrs	x0, id_aa64pfr0_el1
58f14d1886SSoby Mathew	ubfx	x0, x0, #ID_AA64PFR0_GIC_SHIFT, #ID_AA64PFR0_GIC_WIDTH
59f14d1886SSoby Mathew	cmp	x0, #1
60f14d1886SSoby Mathew	b.ne	gicv2_bypass_disable
61f14d1886SSoby Mathew
62f14d1886SSoby Mathew	/* Check for SRE enable */
63f14d1886SSoby Mathew	mrs	x1, ICC_SRE_EL3
64f14d1886SSoby Mathew	tst	x1, #ICC_SRE_SRE_BIT
65f14d1886SSoby Mathew	b.eq	gicv2_bypass_disable
66f14d1886SSoby Mathew
67f14d1886SSoby Mathew	mrs	x2, ICC_SRE_EL3
68f14d1886SSoby Mathew	orr	x2, x2, #(ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT)
69f14d1886SSoby Mathew	msr	ICC_SRE_EL3, x2
70f14d1886SSoby Mathew	b	secondary_cold_boot_wait
71f14d1886SSoby Mathew
72f14d1886SSoby Mathewgicv2_bypass_disable:
73bd83b396SSoby Mathew	mov_imm	x0, VE_GICC_BASE
74bd83b396SSoby Mathew	mov_imm	x1, BASE_GICC_BASE
753fc4124cSDan Handley	fvp_choose_gicmmap	x0, x1, x2, w2, x1
763fc4124cSDan Handley	mov	w0, #(IRQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP1)
773fc4124cSDan Handley	orr	w0, w0, #(IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP0)
783fc4124cSDan Handley	str	w0, [x1, #GICC_CTLR]
793fc4124cSDan Handley
80f14d1886SSoby Mathewsecondary_cold_boot_wait:
813fc4124cSDan Handley	/* ---------------------------------------------
823fc4124cSDan Handley	 * There is no sane reason to come out of this
833fc4124cSDan Handley	 * wfi so panic if we do. This cpu will be pow-
843fc4124cSDan Handley	 * ered on and reset by the cpu_on pm api
853fc4124cSDan Handley	 * ---------------------------------------------
863fc4124cSDan Handley	 */
873fc4124cSDan Handley	dsb	sy
883fc4124cSDan Handley	wfi
89a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
90cdf14088SSandrine Bailleux#else
91cdf14088SSandrine Bailleux	mov_imm	x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
92cdf14088SSandrine Bailleux
93cdf14088SSandrine Bailleux	/* Wait until the entrypoint gets populated */
94cdf14088SSandrine Bailleuxpoll_mailbox:
95cdf14088SSandrine Bailleux	ldr	x1, [x0]
96cdf14088SSandrine Bailleux	cbz	x1, 1f
97cdf14088SSandrine Bailleux	br	x1
98cdf14088SSandrine Bailleux1:
99cdf14088SSandrine Bailleux	wfe
100cdf14088SSandrine Bailleux	b	poll_mailbox
101cdf14088SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */
1023fc4124cSDan Handleyendfunc plat_secondary_cold_boot_setup
1033fc4124cSDan Handley
104804040d1SSandrine Bailleux	/* ---------------------------------------------------------------------
1054c0d0390SSoby Mathew	 * uintptr_t plat_get_my_entrypoint (void);
1063fc4124cSDan Handley	 *
107804040d1SSandrine Bailleux	 * Main job of this routine is to distinguish between a cold and warm
108804040d1SSandrine Bailleux	 * boot. On FVP, this information can be queried from the power
109804040d1SSandrine Bailleux	 * controller. The Power Control SYS Status Register (PSYSR) indicates
110804040d1SSandrine Bailleux	 * the wake-up reason for the CPU.
1113fc4124cSDan Handley	 *
112804040d1SSandrine Bailleux	 * For a cold boot, return 0.
113804040d1SSandrine Bailleux	 * For a warm boot, read the mailbox and return the address it contains.
114804040d1SSandrine Bailleux	 *
1153fc4124cSDan Handley	 * TODO: PSYSR is a common register and should be
1161645d3eeSSandrine Bailleux	 * 	accessed using locks. Since it is not possible
1173fc4124cSDan Handley	 * 	to use locks immediately after a cold reset
1183fc4124cSDan Handley	 * 	we are relying on the fact that after a cold
1193fc4124cSDan Handley	 * 	reset all cpus will read the same WK field
120804040d1SSandrine Bailleux	 * ---------------------------------------------------------------------
1213fc4124cSDan Handley	 */
12238dce70fSSoby Mathewfunc plat_get_my_entrypoint
123804040d1SSandrine Bailleux	/* ---------------------------------------------------------------------
124804040d1SSandrine Bailleux	 * When bit PSYSR.WK indicates either "Wake by PPONR" or "Wake by GIC
125804040d1SSandrine Bailleux	 * WakeRequest signal" then it is a warm boot.
126804040d1SSandrine Bailleux	 * ---------------------------------------------------------------------
127804040d1SSandrine Bailleux	 */
12838dce70fSSoby Mathew	mrs	x2, mpidr_el1
129bd83b396SSoby Mathew	mov_imm	x1, PWRC_BASE
1303fc4124cSDan Handley	str	w2, [x1, #PSYSR_OFF]
1313fc4124cSDan Handley	ldr	w2, [x1, #PSYSR_OFF]
132c8f0c3f7SSoby Mathew	ubfx	w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_WIDTH
1333fc4124cSDan Handley	cmp	w2, #WKUP_PPONR
1343fc4124cSDan Handley	beq	warm_reset
1353fc4124cSDan Handley	cmp	w2, #WKUP_GICREQ
1363fc4124cSDan Handley	beq	warm_reset
137804040d1SSandrine Bailleux
138804040d1SSandrine Bailleux	/* Cold reset */
1393fc4124cSDan Handley	mov	x0, #0
140804040d1SSandrine Bailleux	ret
141804040d1SSandrine Bailleux
1423fc4124cSDan Handleywarm_reset:
143804040d1SSandrine Bailleux	/* ---------------------------------------------------------------------
144804040d1SSandrine Bailleux	 * A mailbox is maintained in the trusted SRAM. It is flushed out of the
145804040d1SSandrine Bailleux	 * caches after every update using normal memory so it is safe to read
146804040d1SSandrine Bailleux	 * it here with SO attributes.
147804040d1SSandrine Bailleux	 * ---------------------------------------------------------------------
1483fc4124cSDan Handley	 */
149785fb92bSSoby Mathew	mov_imm	x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
150804040d1SSandrine Bailleux	ldr	x0, [x0]
1511c3ea103SAntonio Nino Diaz	cbz	x0, _panic_handler
152804040d1SSandrine Bailleux	ret
153804040d1SSandrine Bailleux
154804040d1SSandrine Bailleux	/* ---------------------------------------------------------------------
155804040d1SSandrine Bailleux	 * The power controller indicates this is a warm reset but the mailbox
156804040d1SSandrine Bailleux	 * is empty. This should never happen!
157804040d1SSandrine Bailleux	 * ---------------------------------------------------------------------
158804040d1SSandrine Bailleux	 */
1591c3ea103SAntonio Nino Diaz_panic_handler:
160a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
16138dce70fSSoby Mathewendfunc plat_get_my_entrypoint
1623fc4124cSDan Handley
16358523c07SSoby Mathew	/* -----------------------------------------------------
16458523c07SSoby Mathew	 * unsigned int plat_is_my_cpu_primary (void);
16558523c07SSoby Mathew	 *
16658523c07SSoby Mathew	 * Find out whether the current cpu is the primary
16758523c07SSoby Mathew	 * cpu.
16858523c07SSoby Mathew	 * -----------------------------------------------------
16958523c07SSoby Mathew	 */
17038dce70fSSoby Mathewfunc plat_is_my_cpu_primary
17138dce70fSSoby Mathew	mrs	x0, mpidr_el1
172bd83b396SSoby Mathew	mov_imm	x1, MPIDR_AFFINITY_MASK
17311ad8f20SJeenu Viswambharan	and	x0, x0, x1
1743fc4124cSDan Handley	cmp	x0, #FVP_PRIMARY_CPU
17558523c07SSoby Mathew	cset	w0, eq
1763fc4124cSDan Handley	ret
17738dce70fSSoby Mathewendfunc plat_is_my_cpu_primary
17811ad8f20SJeenu Viswambharan
17939b21d19SWang Feng	/* ---------------------------------------------------------------------
18011ad8f20SJeenu Viswambharan	 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
18111ad8f20SJeenu Viswambharan	 *
18211ad8f20SJeenu Viswambharan	 * Function to calculate the core position on FVP.
18311ad8f20SJeenu Viswambharan	 *
18439b21d19SWang Feng	 * (ClusterId * FVP_MAX_CPUS_PER_CLUSTER * FVP_MAX_PE_PER_CPU) +
18511ad8f20SJeenu Viswambharan	 * (CPUId * FVP_MAX_PE_PER_CPU) +
18611ad8f20SJeenu Viswambharan	 * ThreadId
18739b21d19SWang Feng	 *
18839b21d19SWang Feng	 * which can be simplified as:
18939b21d19SWang Feng	 *
19039b21d19SWang Feng	 * ((ClusterId * FVP_MAX_CPUS_PER_CLUSTER + CPUId) * FVP_MAX_PE_PER_CPU)
19139b21d19SWang Feng	 * + ThreadId
19239b21d19SWang Feng	 * ---------------------------------------------------------------------
19311ad8f20SJeenu Viswambharan	 */
19411ad8f20SJeenu Viswambharanfunc plat_arm_calc_core_pos
19511ad8f20SJeenu Viswambharan	/*
19611ad8f20SJeenu Viswambharan	 * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it
19711ad8f20SJeenu Viswambharan	 * look as if in a multi-threaded implementation.
19811ad8f20SJeenu Viswambharan	 */
19911ad8f20SJeenu Viswambharan	tst	x0, #MPIDR_MT_MASK
20011ad8f20SJeenu Viswambharan	lsl	x3, x0, #MPIDR_AFFINITY_BITS
20111ad8f20SJeenu Viswambharan	csel	x3, x3, x0, eq
20211ad8f20SJeenu Viswambharan
20311ad8f20SJeenu Viswambharan	/* Extract individual affinity fields from MPIDR */
20411ad8f20SJeenu Viswambharan	ubfx	x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS
20511ad8f20SJeenu Viswambharan	ubfx	x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS
20611ad8f20SJeenu Viswambharan	ubfx	x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS
20711ad8f20SJeenu Viswambharan
20811ad8f20SJeenu Viswambharan	/* Compute linear position */
20939b21d19SWang Feng	mov	x4, #FVP_MAX_CPUS_PER_CLUSTER
21039b21d19SWang Feng	madd	x1, x2, x4, x1
21139b21d19SWang Feng	mov	x5, #FVP_MAX_PE_PER_CPU
21239b21d19SWang Feng	madd	x0, x1, x5, x0
21311ad8f20SJeenu Viswambharan	ret
21411ad8f20SJeenu Viswambharanendfunc plat_arm_calc_core_pos
215