xref: /arm-trusted-firmware/plat/arm/board/juno/aarch32/juno_helpers.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <common/bl_common.h>
10*91f16700Schasinglulu#include <cortex_a53.h>
11*91f16700Schasinglulu#include <cortex_a57.h>
12*91f16700Schasinglulu#include <cortex_a72.h>
13*91f16700Schasinglulu#include <cpu_macros.S>
14*91f16700Schasinglulu#include <platform_def.h>
15*91f16700Schasinglulu
16*91f16700Schasinglulu	.globl	plat_reset_handler
17*91f16700Schasinglulu	.globl	plat_arm_calc_core_pos
18*91f16700Schasinglulu
19*91f16700Schasinglulu#define JUNO_REVISION(rev)	REV_JUNO_R##rev
20*91f16700Schasinglulu#define JUNO_HANDLER(rev)	plat_reset_handler_juno_r##rev
21*91f16700Schasinglulu#define JUMP_TO_HANDLER_IF_JUNO_R(revision)	\
22*91f16700Schasinglulu	jump_to_handler JUNO_REVISION(revision), JUNO_HANDLER(revision)
23*91f16700Schasinglulu
24*91f16700Schasinglulu	/* --------------------------------------------------------------------
25*91f16700Schasinglulu	 * Helper macro to jump to the given handler if the board revision
26*91f16700Schasinglulu	 * matches.
27*91f16700Schasinglulu	 * Expects the Juno board revision in x0.
28*91f16700Schasinglulu	 * --------------------------------------------------------------------
29*91f16700Schasinglulu	 */
30*91f16700Schasinglulu	.macro jump_to_handler _revision, _handler
31*91f16700Schasinglulu	cmp	r0, #\_revision
32*91f16700Schasinglulu	beq	\_handler
33*91f16700Schasinglulu	.endm
34*91f16700Schasinglulu
35*91f16700Schasinglulu	/* --------------------------------------------------------------------
36*91f16700Schasinglulu	 * Platform reset handler for Juno R0.
37*91f16700Schasinglulu	 *
38*91f16700Schasinglulu	 * Juno R0 has the following topology:
39*91f16700Schasinglulu	 * - Quad core Cortex-A53 processor cluster;
40*91f16700Schasinglulu	 * - Dual core Cortex-A57 processor cluster.
41*91f16700Schasinglulu	 *
42*91f16700Schasinglulu	 * This handler does the following:
43*91f16700Schasinglulu	 * - Implement workaround for defect id 831273 by enabling an event
44*91f16700Schasinglulu	 *   stream every 65536 cycles.
45*91f16700Schasinglulu	 * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57
46*91f16700Schasinglulu	 * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57
47*91f16700Schasinglulu	 * --------------------------------------------------------------------
48*91f16700Schasinglulu	 */
49*91f16700Schasinglulufunc JUNO_HANDLER(0)
50*91f16700Schasinglulu	/* --------------------------------------------------------------------
51*91f16700Schasinglulu	 * Enable the event stream every 65536 cycles
52*91f16700Schasinglulu	 * --------------------------------------------------------------------
53*91f16700Schasinglulu	 */
54*91f16700Schasinglulu	mov	r0, #(0xf << EVNTI_SHIFT)
55*91f16700Schasinglulu	orr	r0, r0, #EVNTEN_BIT
56*91f16700Schasinglulu	stcopr	r0, CNTKCTL
57*91f16700Schasinglulu
58*91f16700Schasinglulu	/* --------------------------------------------------------------------
59*91f16700Schasinglulu	 * Nothing else to do on Cortex-A53.
60*91f16700Schasinglulu	 * --------------------------------------------------------------------
61*91f16700Schasinglulu	 */
62*91f16700Schasinglulu	jump_if_cpu_midr CORTEX_A53_MIDR, 1f
63*91f16700Schasinglulu
64*91f16700Schasinglulu	/* --------------------------------------------------------------------
65*91f16700Schasinglulu	 * Cortex-A57 specific settings
66*91f16700Schasinglulu	 * --------------------------------------------------------------------
67*91f16700Schasinglulu	 */
68*91f16700Schasinglulu	mov	r0, #((CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) |	\
69*91f16700Schasinglulu		      (CORTEX_A57_L2_TAG_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_TAG_RAM_LATENCY_SHIFT))
70*91f16700Schasinglulu	stcopr	r0, CORTEX_A57_L2CTLR
71*91f16700Schasinglulu1:
72*91f16700Schasinglulu	isb
73*91f16700Schasinglulu	bx	lr
74*91f16700Schasingluluendfunc JUNO_HANDLER(0)
75*91f16700Schasinglulu
76*91f16700Schasinglulu	/* --------------------------------------------------------------------
77*91f16700Schasinglulu	 * Platform reset handler for Juno R1.
78*91f16700Schasinglulu	 *
79*91f16700Schasinglulu	 * Juno R1 has the following topology:
80*91f16700Schasinglulu	 * - Quad core Cortex-A53 processor cluster;
81*91f16700Schasinglulu	 * - Dual core Cortex-A57 processor cluster.
82*91f16700Schasinglulu	 *
83*91f16700Schasinglulu	 * This handler does the following:
84*91f16700Schasinglulu	 * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57
85*91f16700Schasinglulu	 *
86*91f16700Schasinglulu	 * Note that:
87*91f16700Schasinglulu	 * - The default value for the L2 Tag RAM latency for Cortex-A57 is
88*91f16700Schasinglulu	 *   suitable.
89*91f16700Schasinglulu	 * - Defect #831273 doesn't affect Juno R1.
90*91f16700Schasinglulu	 * --------------------------------------------------------------------
91*91f16700Schasinglulu	 */
92*91f16700Schasinglulufunc JUNO_HANDLER(1)
93*91f16700Schasinglulu	/* --------------------------------------------------------------------
94*91f16700Schasinglulu	 * Nothing to do on Cortex-A53.
95*91f16700Schasinglulu	 * --------------------------------------------------------------------
96*91f16700Schasinglulu	 */
97*91f16700Schasinglulu	jump_if_cpu_midr CORTEX_A57_MIDR, A57
98*91f16700Schasinglulu	bx	lr
99*91f16700Schasinglulu
100*91f16700SchasingluluA57:
101*91f16700Schasinglulu	/* --------------------------------------------------------------------
102*91f16700Schasinglulu	 * Cortex-A57 specific settings
103*91f16700Schasinglulu	 * --------------------------------------------------------------------
104*91f16700Schasinglulu	 */
105*91f16700Schasinglulu	mov	r0, #(CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT)
106*91f16700Schasinglulu	stcopr	r0, CORTEX_A57_L2CTLR
107*91f16700Schasinglulu	isb
108*91f16700Schasinglulu	bx	lr
109*91f16700Schasingluluendfunc JUNO_HANDLER(1)
110*91f16700Schasinglulu
111*91f16700Schasinglulu	/* --------------------------------------------------------------------
112*91f16700Schasinglulu	 * Platform reset handler for Juno R2.
113*91f16700Schasinglulu	 *
114*91f16700Schasinglulu	 * Juno R2 has the following topology:
115*91f16700Schasinglulu	 * - Quad core Cortex-A53 processor cluster;
116*91f16700Schasinglulu	 * - Dual core Cortex-A72 processor cluster.
117*91f16700Schasinglulu	 *
118*91f16700Schasinglulu	 * This handler does the following:
119*91f16700Schasinglulu	 * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A72
120*91f16700Schasinglulu	 * - Set the L2 Tag RAM latency to 1 (i.e. 2 cycles) for Cortex-A72
121*91f16700Schasinglulu	 *
122*91f16700Schasinglulu	 * Note that:
123*91f16700Schasinglulu	 * - Defect #831273 doesn't affect Juno R2.
124*91f16700Schasinglulu	 * --------------------------------------------------------------------
125*91f16700Schasinglulu	 */
126*91f16700Schasinglulufunc JUNO_HANDLER(2)
127*91f16700Schasinglulu	/* --------------------------------------------------------------------
128*91f16700Schasinglulu	 * Nothing to do on Cortex-A53.
129*91f16700Schasinglulu	 * --------------------------------------------------------------------
130*91f16700Schasinglulu	 */
131*91f16700Schasinglulu	jump_if_cpu_midr CORTEX_A72_MIDR, A72
132*91f16700Schasinglulu	bx	lr
133*91f16700Schasinglulu
134*91f16700SchasingluluA72:
135*91f16700Schasinglulu	/* --------------------------------------------------------------------
136*91f16700Schasinglulu	 * Cortex-A72 specific settings
137*91f16700Schasinglulu	 * --------------------------------------------------------------------
138*91f16700Schasinglulu	 */
139*91f16700Schasinglulu	mov	r0, #((CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT) |	\
140*91f16700Schasinglulu		      (CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES << CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT))
141*91f16700Schasinglulu	stcopr	r0, CORTEX_A72_L2CTLR
142*91f16700Schasinglulu	isb
143*91f16700Schasinglulu	bx	lr
144*91f16700Schasingluluendfunc JUNO_HANDLER(2)
145*91f16700Schasinglulu
146*91f16700Schasinglulu	/* --------------------------------------------------------------------
147*91f16700Schasinglulu	 * void plat_reset_handler(void);
148*91f16700Schasinglulu	 *
149*91f16700Schasinglulu	 * Determine the Juno board revision and call the appropriate reset
150*91f16700Schasinglulu	 * handler.
151*91f16700Schasinglulu	 * --------------------------------------------------------------------
152*91f16700Schasinglulu	 */
153*91f16700Schasinglulufunc plat_reset_handler
154*91f16700Schasinglulu	/* Read the V2M SYS_ID register */
155*91f16700Schasinglulu	ldr	r0, =(V2M_SYSREGS_BASE + V2M_SYS_ID)
156*91f16700Schasinglulu	ldr	r1, [r0]
157*91f16700Schasinglulu	/* Extract board revision from the SYS_ID */
158*91f16700Schasinglulu	ubfx	r0, r1, #V2M_SYS_ID_REV_SHIFT, #4
159*91f16700Schasinglulu
160*91f16700Schasinglulu	JUMP_TO_HANDLER_IF_JUNO_R(0)
161*91f16700Schasinglulu	JUMP_TO_HANDLER_IF_JUNO_R(1)
162*91f16700Schasinglulu	JUMP_TO_HANDLER_IF_JUNO_R(2)
163*91f16700Schasinglulu
164*91f16700Schasinglulu	/* Board revision is not supported */
165*91f16700Schasinglulu	no_ret	plat_panic_handler
166*91f16700Schasinglulu
167*91f16700Schasingluluendfunc plat_reset_handler
168*91f16700Schasinglulu
169*91f16700Schasinglulu	/* -----------------------------------------------------
170*91f16700Schasinglulu	 *  unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
171*91f16700Schasinglulu	 *  Helper function to calculate the core position.
172*91f16700Schasinglulu	 * -----------------------------------------------------
173*91f16700Schasinglulu	 */
174*91f16700Schasinglulufunc plat_arm_calc_core_pos
175*91f16700Schasinglulu	b	css_calc_core_pos_swap_cluster
176*91f16700Schasingluluendfunc plat_arm_calc_core_pos
177