xref: /rk3399_ARM-atf/plat/arm/css/common/aarch32/css_helpers.S (revision 6f249345e2aa2343ce67222e82dafc539e973ec5)
1*6f249345SYatharth Kochar/*
2*6f249345SYatharth Kochar * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3*6f249345SYatharth Kochar *
4*6f249345SYatharth Kochar * Redistribution and use in source and binary forms, with or without
5*6f249345SYatharth Kochar * modification, are permitted provided that the following conditions are met:
6*6f249345SYatharth Kochar *
7*6f249345SYatharth Kochar * Redistributions of source code must retain the above copyright notice, this
8*6f249345SYatharth Kochar * list of conditions and the following disclaimer.
9*6f249345SYatharth Kochar *
10*6f249345SYatharth Kochar * Redistributions in binary form must reproduce the above copyright notice,
11*6f249345SYatharth Kochar * this list of conditions and the following disclaimer in the documentation
12*6f249345SYatharth Kochar * and/or other materials provided with the distribution.
13*6f249345SYatharth Kochar *
14*6f249345SYatharth Kochar * Neither the name of ARM nor the names of its contributors may be used
15*6f249345SYatharth Kochar * to endorse or promote products derived from this software without specific
16*6f249345SYatharth Kochar * prior written permission.
17*6f249345SYatharth Kochar *
18*6f249345SYatharth Kochar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*6f249345SYatharth Kochar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*6f249345SYatharth Kochar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*6f249345SYatharth Kochar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*6f249345SYatharth Kochar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*6f249345SYatharth Kochar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*6f249345SYatharth Kochar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*6f249345SYatharth Kochar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*6f249345SYatharth Kochar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*6f249345SYatharth Kochar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*6f249345SYatharth Kochar * POSSIBILITY OF SUCH DAMAGE.
29*6f249345SYatharth Kochar */
30*6f249345SYatharth Kochar#include <arch.h>
31*6f249345SYatharth Kochar#include <asm_macros.S>
32*6f249345SYatharth Kochar#include <cpu_macros.S>
33*6f249345SYatharth Kochar#include <css_def.h>
34*6f249345SYatharth Kochar
35*6f249345SYatharth Kochar	.weak	plat_secondary_cold_boot_setup
36*6f249345SYatharth Kochar	.weak	plat_get_my_entrypoint
37*6f249345SYatharth Kochar	.globl	css_calc_core_pos_swap_cluster
38*6f249345SYatharth Kochar	.weak	plat_is_my_cpu_primary
39*6f249345SYatharth Kochar
40*6f249345SYatharth Kochar	/* ---------------------------------------------------------------------
41*6f249345SYatharth Kochar	 * void plat_secondary_cold_boot_setup(void);
42*6f249345SYatharth Kochar	 * In the normal boot flow, cold-booting secondary
43*6f249345SYatharth Kochar	 * CPUs is not yet implemented and they panic.
44*6f249345SYatharth Kochar	 * ---------------------------------------------------------------------
45*6f249345SYatharth Kochar	 */
46*6f249345SYatharth Kocharfunc plat_secondary_cold_boot_setup
47*6f249345SYatharth Kochar	/* TODO: Implement secondary CPU cold boot setup on CSS platforms */
48*6f249345SYatharth Kocharcb_panic:
49*6f249345SYatharth Kochar	b	cb_panic
50*6f249345SYatharth Kocharendfunc plat_secondary_cold_boot_setup
51*6f249345SYatharth Kochar
52*6f249345SYatharth Kochar	/* ---------------------------------------------------------------------
53*6f249345SYatharth Kochar	 * uintptr_t plat_get_my_entrypoint (void);
54*6f249345SYatharth Kochar	 *
55*6f249345SYatharth Kochar	 * Main job of this routine is to distinguish between a cold and a warm
56*6f249345SYatharth Kochar	 * boot. On CSS platforms, this distinction is based on the contents of
57*6f249345SYatharth Kochar	 * the Trusted Mailbox. It is initialised to zero by the SCP before the
58*6f249345SYatharth Kochar	 * AP cores are released from reset. Therefore, a zero mailbox means
59*6f249345SYatharth Kochar	 * it's a cold reset.
60*6f249345SYatharth Kochar	 *
61*6f249345SYatharth Kochar	 * This functions returns the contents of the mailbox, i.e.:
62*6f249345SYatharth Kochar	 *  - 0 for a cold boot;
63*6f249345SYatharth Kochar	 *  - the warm boot entrypoint for a warm boot.
64*6f249345SYatharth Kochar	 * ---------------------------------------------------------------------
65*6f249345SYatharth Kochar	 */
66*6f249345SYatharth Kocharfunc plat_get_my_entrypoint
67*6f249345SYatharth Kochar	ldr	r0, =PLAT_ARM_TRUSTED_MAILBOX_BASE
68*6f249345SYatharth Kochar	ldr	r0, [r0]
69*6f249345SYatharth Kochar	bx	lr
70*6f249345SYatharth Kocharendfunc plat_get_my_entrypoint
71*6f249345SYatharth Kochar
72*6f249345SYatharth Kochar	/* -----------------------------------------------------------
73*6f249345SYatharth Kochar	 * unsigned int css_calc_core_pos_swap_cluster(u_register_t mpidr)
74*6f249345SYatharth Kochar	 * Utility function to calculate the core position by
75*6f249345SYatharth Kochar	 * swapping the cluster order. This is necessary in order to
76*6f249345SYatharth Kochar	 * match the format of the boot information passed by the SCP
77*6f249345SYatharth Kochar	 * and read in plat_is_my_cpu_primary below.
78*6f249345SYatharth Kochar	 * -----------------------------------------------------------
79*6f249345SYatharth Kochar	 */
80*6f249345SYatharth Kocharfunc css_calc_core_pos_swap_cluster
81*6f249345SYatharth Kochar	and	r1, r0, #MPIDR_CPU_MASK
82*6f249345SYatharth Kochar	and	r0, r0, #MPIDR_CLUSTER_MASK
83*6f249345SYatharth Kochar	eor	r0, r0, #(1 << MPIDR_AFFINITY_BITS)  // swap cluster order
84*6f249345SYatharth Kochar	add	r0, r1, r0, LSR #6
85*6f249345SYatharth Kochar	bx	lr
86*6f249345SYatharth Kocharendfunc css_calc_core_pos_swap_cluster
87*6f249345SYatharth Kochar
88*6f249345SYatharth Kochar	/* -----------------------------------------------------
89*6f249345SYatharth Kochar	 * unsigned int plat_is_my_cpu_primary (void);
90*6f249345SYatharth Kochar	 *
91*6f249345SYatharth Kochar	 * Find out whether the current cpu is the primary
92*6f249345SYatharth Kochar	 * cpu (applicable ony after a cold boot)
93*6f249345SYatharth Kochar	 * -----------------------------------------------------
94*6f249345SYatharth Kochar	 */
95*6f249345SYatharth Kocharfunc plat_is_my_cpu_primary
96*6f249345SYatharth Kochar	mov	r10, lr
97*6f249345SYatharth Kochar	bl	plat_my_core_pos
98*6f249345SYatharth Kochar	ldr	r1, =SCP_BOOT_CFG_ADDR
99*6f249345SYatharth Kochar	ldr	r1, [r1]
100*6f249345SYatharth Kochar	ubfx	r1, r1, #PLAT_CSS_PRIMARY_CPU_SHIFT, \
101*6f249345SYatharth Kochar			#PLAT_CSS_PRIMARY_CPU_BIT_WIDTH
102*6f249345SYatharth Kochar	cmp	r0, r1
103*6f249345SYatharth Kochar	moveq	r0, #1
104*6f249345SYatharth Kochar	movne	r0, #0
105*6f249345SYatharth Kochar	bx	r10
106*6f249345SYatharth Kocharendfunc plat_is_my_cpu_primary
107