xref: /rk3399_ARM-atf/plat/arm/board/fvp/aarch64/fvp_helpers.S (revision 3fc4124c7513554dc14a83a0b94010ce771e7e1c)
1*3fc4124cSDan Handley/*
2*3fc4124cSDan Handley * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
3*3fc4124cSDan Handley *
4*3fc4124cSDan Handley * Redistribution and use in source and binary forms, with or without
5*3fc4124cSDan Handley * modification, are permitted provided that the following conditions are met:
6*3fc4124cSDan Handley *
7*3fc4124cSDan Handley * Redistributions of source code must retain the above copyright notice, this
8*3fc4124cSDan Handley * list of conditions and the following disclaimer.
9*3fc4124cSDan Handley *
10*3fc4124cSDan Handley * Redistributions in binary form must reproduce the above copyright notice,
11*3fc4124cSDan Handley * this list of conditions and the following disclaimer in the documentation
12*3fc4124cSDan Handley * and/or other materials provided with the distribution.
13*3fc4124cSDan Handley *
14*3fc4124cSDan Handley * Neither the name of ARM nor the names of its contributors may be used
15*3fc4124cSDan Handley * to endorse or promote products derived from this software without specific
16*3fc4124cSDan Handley * prior written permission.
17*3fc4124cSDan Handley *
18*3fc4124cSDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*3fc4124cSDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*3fc4124cSDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*3fc4124cSDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*3fc4124cSDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*3fc4124cSDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*3fc4124cSDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*3fc4124cSDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*3fc4124cSDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*3fc4124cSDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*3fc4124cSDan Handley * POSSIBILITY OF SUCH DAMAGE.
29*3fc4124cSDan Handley */
30*3fc4124cSDan Handley
31*3fc4124cSDan Handley#include <arch.h>
32*3fc4124cSDan Handley#include <asm_macros.S>
33*3fc4124cSDan Handley#include <gic_v2.h>
34*3fc4124cSDan Handley#include <platform_def.h>
35*3fc4124cSDan Handley#include <v2m_def.h>
36*3fc4124cSDan Handley#include "../drivers/pwrc/fvp_pwrc.h"
37*3fc4124cSDan Handley#include "../fvp_def.h"
38*3fc4124cSDan Handley
39*3fc4124cSDan Handley	.globl	plat_secondary_cold_boot_setup
40*3fc4124cSDan Handley	.globl	platform_get_entrypoint
41*3fc4124cSDan Handley	.globl	platform_mem_init
42*3fc4124cSDan Handley	.globl	platform_is_primary_cpu
43*3fc4124cSDan Handley
44*3fc4124cSDan Handley	.macro	fvp_choose_gicmmap  param1, param2, x_tmp, w_tmp, res
45*3fc4124cSDan Handley	ldr	\x_tmp, =V2M_SYSREGS_BASE + V2M_SYS_ID
46*3fc4124cSDan Handley	ldr	\w_tmp, [\x_tmp]
47*3fc4124cSDan Handley	ubfx	\w_tmp, \w_tmp, #V2M_SYS_ID_BLD_SHIFT, #V2M_SYS_ID_BLD_LENGTH
48*3fc4124cSDan Handley	cmp	\w_tmp, #BLD_GIC_VE_MMAP
49*3fc4124cSDan Handley	csel	\res, \param1, \param2, eq
50*3fc4124cSDan Handley	.endm
51*3fc4124cSDan Handley
52*3fc4124cSDan Handley	/* -----------------------------------------------------
53*3fc4124cSDan Handley	 * void plat_secondary_cold_boot_setup (void);
54*3fc4124cSDan Handley	 *
55*3fc4124cSDan Handley	 * This function performs any platform specific actions
56*3fc4124cSDan Handley	 * needed for a secondary cpu after a cold reset e.g
57*3fc4124cSDan Handley	 * mark the cpu's presence, mechanism to place it in a
58*3fc4124cSDan Handley	 * holding pen etc.
59*3fc4124cSDan Handley	 * TODO: Should we read the PSYS register to make sure
60*3fc4124cSDan Handley	 * that the request has gone through.
61*3fc4124cSDan Handley	 * -----------------------------------------------------
62*3fc4124cSDan Handley	 */
63*3fc4124cSDan Handleyfunc plat_secondary_cold_boot_setup
64*3fc4124cSDan Handley	/* ---------------------------------------------
65*3fc4124cSDan Handley	 * Power down this cpu.
66*3fc4124cSDan Handley	 * TODO: Do we need to worry about powering the
67*3fc4124cSDan Handley	 * cluster down as well here. That will need
68*3fc4124cSDan Handley	 * locks which we won't have unless an elf-
69*3fc4124cSDan Handley	 * loader zeroes out the zi section.
70*3fc4124cSDan Handley	 * ---------------------------------------------
71*3fc4124cSDan Handley	 */
72*3fc4124cSDan Handley	mrs	x0, mpidr_el1
73*3fc4124cSDan Handley	ldr	x1, =PWRC_BASE
74*3fc4124cSDan Handley	str	w0, [x1, #PPOFFR_OFF]
75*3fc4124cSDan Handley
76*3fc4124cSDan Handley	/* ---------------------------------------------
77*3fc4124cSDan Handley	 * Deactivate the gic cpu interface as well
78*3fc4124cSDan Handley	 * ---------------------------------------------
79*3fc4124cSDan Handley	 */
80*3fc4124cSDan Handley	ldr	x0, =VE_GICC_BASE
81*3fc4124cSDan Handley	ldr	x1, =BASE_GICC_BASE
82*3fc4124cSDan Handley	fvp_choose_gicmmap	x0, x1, x2, w2, x1
83*3fc4124cSDan Handley	mov	w0, #(IRQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP1)
84*3fc4124cSDan Handley	orr	w0, w0, #(IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP0)
85*3fc4124cSDan Handley	str	w0, [x1, #GICC_CTLR]
86*3fc4124cSDan Handley
87*3fc4124cSDan Handley	/* ---------------------------------------------
88*3fc4124cSDan Handley	 * There is no sane reason to come out of this
89*3fc4124cSDan Handley	 * wfi so panic if we do. This cpu will be pow-
90*3fc4124cSDan Handley	 * ered on and reset by the cpu_on pm api
91*3fc4124cSDan Handley	 * ---------------------------------------------
92*3fc4124cSDan Handley	 */
93*3fc4124cSDan Handley	dsb	sy
94*3fc4124cSDan Handley	wfi
95*3fc4124cSDan Handleycb_panic:
96*3fc4124cSDan Handley	b	cb_panic
97*3fc4124cSDan Handleyendfunc plat_secondary_cold_boot_setup
98*3fc4124cSDan Handley
99*3fc4124cSDan Handley
100*3fc4124cSDan Handley	/* -----------------------------------------------------
101*3fc4124cSDan Handley	 * void platform_get_entrypoint (unsigned int mpid);
102*3fc4124cSDan Handley	 *
103*3fc4124cSDan Handley	 * Main job of this routine is to distinguish between
104*3fc4124cSDan Handley	 * a cold and warm boot.
105*3fc4124cSDan Handley	 * On a cold boot the secondaries first wait for the
106*3fc4124cSDan Handley	 * platform to be initialized after which they are
107*3fc4124cSDan Handley	 * hotplugged in. The primary proceeds to perform the
108*3fc4124cSDan Handley	 * platform initialization.
109*3fc4124cSDan Handley	 * On a warm boot, each cpu jumps to the address in its
110*3fc4124cSDan Handley	 * mailbox.
111*3fc4124cSDan Handley	 *
112*3fc4124cSDan Handley	 * TODO: Not a good idea to save lr in a temp reg
113*3fc4124cSDan Handley	 * TODO: PSYSR is a common register and should be
114*3fc4124cSDan Handley	 * 	accessed using locks. Since its not possible
115*3fc4124cSDan Handley	 * 	to use locks immediately after a cold reset
116*3fc4124cSDan Handley	 * 	we are relying on the fact that after a cold
117*3fc4124cSDan Handley	 * 	reset all cpus will read the same WK field
118*3fc4124cSDan Handley	 * -----------------------------------------------------
119*3fc4124cSDan Handley	 */
120*3fc4124cSDan Handleyfunc platform_get_entrypoint
121*3fc4124cSDan Handley	mov	x9, x30 // lr
122*3fc4124cSDan Handley	mov	x2, x0
123*3fc4124cSDan Handley	ldr	x1, =PWRC_BASE
124*3fc4124cSDan Handley	str	w2, [x1, #PSYSR_OFF]
125*3fc4124cSDan Handley	ldr	w2, [x1, #PSYSR_OFF]
126*3fc4124cSDan Handley	ubfx	w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_MASK
127*3fc4124cSDan Handley	cmp	w2, #WKUP_PPONR
128*3fc4124cSDan Handley	beq	warm_reset
129*3fc4124cSDan Handley	cmp	w2, #WKUP_GICREQ
130*3fc4124cSDan Handley	beq	warm_reset
131*3fc4124cSDan Handley	mov	x0, #0
132*3fc4124cSDan Handley	b	exit
133*3fc4124cSDan Handleywarm_reset:
134*3fc4124cSDan Handley	/* ---------------------------------------------
135*3fc4124cSDan Handley	 * A per-cpu mailbox is maintained in the tru-
136*3fc4124cSDan Handley	 * sted DRAM. Its flushed out of the caches
137*3fc4124cSDan Handley	 * after every update using normal memory so
138*3fc4124cSDan Handley	 * its safe to read it here with SO attributes
139*3fc4124cSDan Handley	 * ---------------------------------------------
140*3fc4124cSDan Handley	 */
141*3fc4124cSDan Handley	ldr	x10, =MBOX_BASE
142*3fc4124cSDan Handley	bl	platform_get_core_pos
143*3fc4124cSDan Handley	lsl	x0, x0, #ARM_CACHE_WRITEBACK_SHIFT
144*3fc4124cSDan Handley	ldr	x0, [x10, x0]
145*3fc4124cSDan Handley	cbz	x0, _panic
146*3fc4124cSDan Handleyexit:
147*3fc4124cSDan Handley	ret	x9
148*3fc4124cSDan Handley_panic:	b	_panic
149*3fc4124cSDan Handleyendfunc platform_get_entrypoint
150*3fc4124cSDan Handley
151*3fc4124cSDan Handley
152*3fc4124cSDan Handley	/* -----------------------------------------------------
153*3fc4124cSDan Handley	 * void platform_mem_init (void);
154*3fc4124cSDan Handley	 *
155*3fc4124cSDan Handley	 * Zero out the mailbox registers in the shared memory.
156*3fc4124cSDan Handley	 * The mmu is turned off right now and only the primary can
157*3fc4124cSDan Handley	 * ever execute this code. Secondaries will read the
158*3fc4124cSDan Handley	 * mailboxes using SO accesses. In short, BL31 will
159*3fc4124cSDan Handley	 * update the mailboxes after mapping the tzdram as
160*3fc4124cSDan Handley	 * normal memory. It will flush its copy after update.
161*3fc4124cSDan Handley	 * BL1 will always read the mailboxes with the MMU off
162*3fc4124cSDan Handley	 * -----------------------------------------------------
163*3fc4124cSDan Handley	 */
164*3fc4124cSDan Handleyfunc platform_mem_init
165*3fc4124cSDan Handley	ldr	x0, =MBOX_BASE
166*3fc4124cSDan Handley	mov	w1, #PLATFORM_CORE_COUNT
167*3fc4124cSDan Handleyloop:
168*3fc4124cSDan Handley	str	xzr, [x0], #CACHE_WRITEBACK_GRANULE
169*3fc4124cSDan Handley	subs	w1, w1, #1
170*3fc4124cSDan Handley	b.gt	loop
171*3fc4124cSDan Handley	ret
172*3fc4124cSDan Handleyendfunc platform_mem_init
173*3fc4124cSDan Handley
174*3fc4124cSDan Handley
175*3fc4124cSDan Handleyfunc platform_is_primary_cpu
176*3fc4124cSDan Handley	and	x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
177*3fc4124cSDan Handley	cmp	x0, #FVP_PRIMARY_CPU
178*3fc4124cSDan Handley	cset	x0, eq
179*3fc4124cSDan Handley	ret
180*3fc4124cSDan Handleyendfunc platform_is_primary_cpu
181