xref: /rk3399_ARM-atf/plat/arm/css/common/aarch64/css_helpers.S (revision 19af6fceaf039339f456d96b7a444b5d48217d77)
1b4315306SDan Handley/*
2b4315306SDan Handley * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley *
4b4315306SDan Handley * Redistribution and use in source and binary forms, with or without
5b4315306SDan Handley * modification, are permitted provided that the following conditions are met:
6b4315306SDan Handley *
7b4315306SDan Handley * Redistributions of source code must retain the above copyright notice, this
8b4315306SDan Handley * list of conditions and the following disclaimer.
9b4315306SDan Handley *
10b4315306SDan Handley * Redistributions in binary form must reproduce the above copyright notice,
11b4315306SDan Handley * this list of conditions and the following disclaimer in the documentation
12b4315306SDan Handley * and/or other materials provided with the distribution.
13b4315306SDan Handley *
14b4315306SDan Handley * Neither the name of ARM nor the names of its contributors may be used
15b4315306SDan Handley * to endorse or promote products derived from this software without specific
16b4315306SDan Handley * prior written permission.
17b4315306SDan Handley *
18b4315306SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19b4315306SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b4315306SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b4315306SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22b4315306SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23b4315306SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24b4315306SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25b4315306SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26b4315306SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27b4315306SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28b4315306SDan Handley * POSSIBILITY OF SUCH DAMAGE.
29b4315306SDan Handley */
30b4315306SDan Handley#include <arch.h>
31b4315306SDan Handley#include <asm_macros.S>
32b4315306SDan Handley#include <cpu_macros.S>
33b4315306SDan Handley#include <css_def.h>
34b4315306SDan Handley
35b4315306SDan Handley	.weak	plat_secondary_cold_boot_setup
36b4315306SDan Handley	.weak	platform_get_entrypoint
37b4315306SDan Handley	.weak	platform_mem_init
38b4315306SDan Handley	.globl	platform_get_core_pos
39b4315306SDan Handley	.weak	platform_is_primary_cpu
40b4315306SDan Handley
41b4315306SDan Handley
42b4315306SDan Handley	/* -----------------------------------------------------
43b4315306SDan Handley	 * void plat_secondary_cold_boot_setup (void);
44b4315306SDan Handley	 *
45b4315306SDan Handley	 * This function performs any platform specific actions
46b4315306SDan Handley	 * needed for a secondary cpu after a cold reset e.g
47b4315306SDan Handley	 * mark the cpu's presence, mechanism to place it in a
48b4315306SDan Handley	 * holding pen etc.
49b4315306SDan Handley	 * -----------------------------------------------------
50b4315306SDan Handley	 */
51b4315306SDan Handleyfunc plat_secondary_cold_boot_setup
52b4315306SDan Handley	/* todo: Implement secondary CPU cold boot setup on CSS platforms */
53b4315306SDan Handleycb_panic:
54b4315306SDan Handley	b	cb_panic
55b4315306SDan Handleyendfunc plat_secondary_cold_boot_setup
56b4315306SDan Handley
57b4315306SDan Handley	/* -----------------------------------------------------
58b4315306SDan Handley	 * void platform_get_entrypoint (unsigned int mpid);
59b4315306SDan Handley	 *
60b4315306SDan Handley	 * Main job of this routine is to distinguish between
61b4315306SDan Handley	 * a cold and warm boot.
62b4315306SDan Handley	 * On a cold boot the secondaries first wait for the
63b4315306SDan Handley	 * platform to be initialized after which they are
64b4315306SDan Handley	 * hotplugged in. The primary proceeds to perform the
65b4315306SDan Handley	 * platform initialization.
66b4315306SDan Handley	 * On a warm boot, each cpu jumps to the address in its
67b4315306SDan Handley	 * mailbox.
68b4315306SDan Handley	 *
69b4315306SDan Handley	 * TODO: Not a good idea to save lr in a temp reg
70b4315306SDan Handley	 * -----------------------------------------------------
71b4315306SDan Handley	 */
72b4315306SDan Handleyfunc platform_get_entrypoint
73b4315306SDan Handley	mov	x9, x30 // lr
74b4315306SDan Handley	bl	platform_get_core_pos
75b4315306SDan Handley	ldr	x1, =TRUSTED_MAILBOXES_BASE
76b4315306SDan Handley	lsl	x0, x0, #TRUSTED_MAILBOX_SHIFT
77b4315306SDan Handley	ldr	x0, [x1, x0]
78b4315306SDan Handley	ret	x9
79b4315306SDan Handleyendfunc platform_get_entrypoint
80b4315306SDan Handley
81b4315306SDan Handley	/*
82b4315306SDan Handley	 * Override the default implementation to swap the cluster order.
83b4315306SDan Handley	 * This is necessary in order to match the format of the boot
84b4315306SDan Handley	 * information passed by the SCP and read in platform_is_primary_cpu
85b4315306SDan Handley	 * below.
86b4315306SDan Handley	 */
87b4315306SDan Handleyfunc platform_get_core_pos
88b4315306SDan Handley	and	x1, x0, #MPIDR_CPU_MASK
89b4315306SDan Handley	and	x0, x0, #MPIDR_CLUSTER_MASK
90b4315306SDan Handley	eor	x0, x0, #(1 << MPIDR_AFFINITY_BITS)  // swap cluster order
91b4315306SDan Handley	add	x0, x1, x0, LSR #6
92b4315306SDan Handley	ret
93b4315306SDan Handleyendfunc platform_get_core_pos
94b4315306SDan Handley
95b4315306SDan Handley	/* -----------------------------------------------------
96b4315306SDan Handley	 * void platform_mem_init(void);
97b4315306SDan Handley	 *
98b4315306SDan Handley	 * We don't need to carry out any memory initialization
99b4315306SDan Handley	 * on CSS platforms. The Secure RAM is accessible straight away.
100b4315306SDan Handley	 * -----------------------------------------------------
101b4315306SDan Handley	 */
102b4315306SDan Handleyfunc platform_mem_init
103b4315306SDan Handley	ret
104b4315306SDan Handleyendfunc platform_mem_init
105b4315306SDan Handley
106b4315306SDan Handley	/* -----------------------------------------------------
107b4315306SDan Handley	 * unsigned int platform_is_primary_cpu (unsigned int mpid);
108b4315306SDan Handley	 *
109b4315306SDan Handley	 * Given the mpidr say whether this cpu is the primary
110b4315306SDan Handley	 * cpu (applicable ony after a cold boot)
111b4315306SDan Handley	 * -----------------------------------------------------
112b4315306SDan Handley	 */
113b4315306SDan Handleyfunc platform_is_primary_cpu
114b4315306SDan Handley	mov	x9, x30
115b4315306SDan Handley	bl	platform_get_core_pos
116b4315306SDan Handley	ldr	x1, =SCP_BOOT_CFG_ADDR
117b4315306SDan Handley	ldr	x1, [x1]
118*19af6fceSSoby Mathew	ubfx	x1, x1, #PRIMARY_CPU_SHIFT, #PRIMARY_CPU_BIT_WIDTH
119b4315306SDan Handley	cmp	x0, x1
120b4315306SDan Handley	cset	x0, eq
121b4315306SDan Handley	ret	x9
122b4315306SDan Handleyendfunc platform_is_primary_cpu
123