xref: /rk3399_ARM-atf/plat/arm/css/common/aarch64/css_helpers.S (revision 9f0f203d7e180480e95f5a261125a96dee1d65e4)
1b4315306SDan Handley/*
218e279ebSSoby Mathew * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
5b4315306SDan Handley */
6*234bc7f8SAntonio Nino Diaz
7b4315306SDan Handley#include <arch.h>
8b4315306SDan Handley#include <asm_macros.S>
9b4315306SDan Handley#include <cpu_macros.S>
10*234bc7f8SAntonio Nino Diaz#include <platform_def.h>
11b4315306SDan Handley
12b4315306SDan Handley	.weak	plat_secondary_cold_boot_setup
1338dce70fSSoby Mathew	.weak	plat_get_my_entrypoint
14371d4399SDavid Wang	.globl	css_calc_core_pos_swap_cluster
1538dce70fSSoby Mathew	.weak	plat_is_my_cpu_primary
16b4315306SDan Handley
172bc42067SSandrine Bailleux	/* ---------------------------------------------------------------------
18b4315306SDan Handley	 * void plat_secondary_cold_boot_setup(void);
19b4315306SDan Handley	 *
202bc42067SSandrine Bailleux	 * In the normal boot flow, cold-booting secondary CPUs is not yet
212bc42067SSandrine Bailleux	 * implemented and they panic.
222bc42067SSandrine Bailleux	 *
232bc42067SSandrine Bailleux	 * When booting an EL3 payload, secondary CPUs are placed in a holding
242bc42067SSandrine Bailleux	 * pen, waiting for their mailbox to be populated. Note that all CPUs
252bc42067SSandrine Bailleux	 * share the same mailbox ; therefore, populating it will release all
262bc42067SSandrine Bailleux	 * CPUs from their holding pen. If finer-grained control is needed then
272bc42067SSandrine Bailleux	 * this should be handled in the code that secondary CPUs jump to.
282bc42067SSandrine Bailleux	 * ---------------------------------------------------------------------
29b4315306SDan Handley	 */
30b4315306SDan Handleyfunc plat_secondary_cold_boot_setup
312bc42067SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE
322bc42067SSandrine Bailleux	/* TODO: Implement secondary CPU cold boot setup on CSS platforms */
33b4315306SDan Handleycb_panic:
34b4315306SDan Handley	b	cb_panic
352bc42067SSandrine Bailleux#else
362bc42067SSandrine Bailleux	mov_imm	x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
372bc42067SSandrine Bailleux
382bc42067SSandrine Bailleux	/* Wait until the mailbox gets populated */
392bc42067SSandrine Bailleuxpoll_mailbox:
402bc42067SSandrine Bailleux	ldr	x1, [x0]
412bc42067SSandrine Bailleux	cbz	x1, 1f
422bc42067SSandrine Bailleux	br	x1
432bc42067SSandrine Bailleux1:
442bc42067SSandrine Bailleux	wfe
452bc42067SSandrine Bailleux	b	poll_mailbox
462bc42067SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */
47b4315306SDan Handleyendfunc plat_secondary_cold_boot_setup
48b4315306SDan Handley
49804040d1SSandrine Bailleux	/* ---------------------------------------------------------------------
504c0d0390SSoby Mathew	 * uintptr_t plat_get_my_entrypoint (void);
51b4315306SDan Handley	 *
52804040d1SSandrine Bailleux	 * Main job of this routine is to distinguish between a cold and a warm
53804040d1SSandrine Bailleux	 * boot. On CSS platforms, this distinction is based on the contents of
54804040d1SSandrine Bailleux	 * the Trusted Mailbox. It is initialised to zero by the SCP before the
55804040d1SSandrine Bailleux	 * AP cores are released from reset. Therefore, a zero mailbox means
56804040d1SSandrine Bailleux	 * it's a cold reset.
57b4315306SDan Handley	 *
58804040d1SSandrine Bailleux	 * This functions returns the contents of the mailbox, i.e.:
59804040d1SSandrine Bailleux	 *  - 0 for a cold boot;
60804040d1SSandrine Bailleux	 *  - the warm boot entrypoint for a warm boot.
61804040d1SSandrine Bailleux	 * ---------------------------------------------------------------------
62b4315306SDan Handley	 */
6338dce70fSSoby Mathewfunc plat_get_my_entrypoint
64785fb92bSSoby Mathew	mov_imm	x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
65804040d1SSandrine Bailleux	ldr	x0, [x0]
66804040d1SSandrine Bailleux	ret
6738dce70fSSoby Mathewendfunc plat_get_my_entrypoint
68b4315306SDan Handley
6938dce70fSSoby Mathew	/* -----------------------------------------------------------
704c0d0390SSoby Mathew	 * unsigned int css_calc_core_pos_swap_cluster(u_register_t mpidr)
71371d4399SDavid Wang	 * Utility function to calculate the core position by
7238dce70fSSoby Mathew	 * swapping the cluster order. This is necessary in order to
7338dce70fSSoby Mathew	 * match the format of the boot information passed by the SCP
7458523c07SSoby Mathew	 * and read in plat_is_my_cpu_primary below.
7538dce70fSSoby Mathew	 * -----------------------------------------------------------
76b4315306SDan Handley	 */
77371d4399SDavid Wangfunc css_calc_core_pos_swap_cluster
78b4315306SDan Handley	and	x1, x0, #MPIDR_CPU_MASK
79b4315306SDan Handley	and	x0, x0, #MPIDR_CLUSTER_MASK
80b4315306SDan Handley	eor	x0, x0, #(1 << MPIDR_AFFINITY_BITS)  // swap cluster order
81b4315306SDan Handley	add	x0, x1, x0, LSR #6
82b4315306SDan Handley	ret
83371d4399SDavid Wangendfunc css_calc_core_pos_swap_cluster
84b4315306SDan Handley
85b4315306SDan Handley	/* -----------------------------------------------------
8638dce70fSSoby Mathew	 * unsigned int plat_is_my_cpu_primary (void);
87b4315306SDan Handley	 *
8838dce70fSSoby Mathew	 * Find out whether the current cpu is the primary
89b4315306SDan Handley	 * cpu (applicable ony after a cold boot)
90b4315306SDan Handley	 * -----------------------------------------------------
91b4315306SDan Handley	 */
9218e279ebSSoby Mathew#if CSS_USE_SCMI_SDS_DRIVER
9318e279ebSSoby Mathewfunc plat_is_my_cpu_primary
9418e279ebSSoby Mathew	mov	x9, x30
9518e279ebSSoby Mathew	bl	plat_my_core_pos
9618e279ebSSoby Mathew	mov	x4, x0
9718e279ebSSoby Mathew	bl	sds_get_primary_cpu_id
9818e279ebSSoby Mathew	/* Check for error */
9918e279ebSSoby Mathew	mov	x1, #0xffffffff
10018e279ebSSoby Mathew	cmp	x0, x1
10118e279ebSSoby Mathew	b.eq	1f
10218e279ebSSoby Mathew	cmp	x0, x4
10318e279ebSSoby Mathew	cset	w0, eq
10418e279ebSSoby Mathew	ret	x9
10518e279ebSSoby Mathew1:
10618e279ebSSoby Mathew	no_ret	plat_panic_handler
10718e279ebSSoby Mathewendfunc plat_is_my_cpu_primary
10818e279ebSSoby Mathew#else
10938dce70fSSoby Mathewfunc plat_is_my_cpu_primary
110b4315306SDan Handley	mov	x9, x30
11138dce70fSSoby Mathew	bl	plat_my_core_pos
112bd83b396SSoby Mathew	mov_imm	x1, SCP_BOOT_CFG_ADDR
113b4315306SDan Handley	ldr	x1, [x1]
1148e083ecdSVikram Kanigiri	ubfx	x1, x1, #PLAT_CSS_PRIMARY_CPU_SHIFT, \
1158e083ecdSVikram Kanigiri			#PLAT_CSS_PRIMARY_CPU_BIT_WIDTH
116b4315306SDan Handley	cmp	x0, x1
11758523c07SSoby Mathew	cset	w0, eq
118b4315306SDan Handley	ret	x9
11938dce70fSSoby Mathewendfunc plat_is_my_cpu_primary
12018e279ebSSoby Mathew#endif
121