xref: /arm-trusted-firmware/plat/marvell/armada/common/aarch64/marvell_helpers.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2020, ARM Limited. All rights reserved.
3*91f16700Schasinglulu * Copyright (C) 2018 Marvell International Ltd.
4*91f16700Schasinglulu *
5*91f16700Schasinglulu * SPDX-License-Identifier:     BSD-3-Clause
6*91f16700Schasinglulu * https://spdx.org/licenses
7*91f16700Schasinglulu */
8*91f16700Schasinglulu
9*91f16700Schasinglulu#include <asm_macros.S>
10*91f16700Schasinglulu#include <cortex_a72.h>
11*91f16700Schasinglulu#ifndef PLAT_a3700
12*91f16700Schasinglulu#include <drivers/marvell/ccu.h>
13*91f16700Schasinglulu#include <drivers/marvell/cache_llc.h>
14*91f16700Schasinglulu#endif
15*91f16700Schasinglulu#include <marvell_def.h>
16*91f16700Schasinglulu#include <platform_def.h>
17*91f16700Schasinglulu
18*91f16700Schasinglulu	.weak	plat_marvell_calc_core_pos
19*91f16700Schasinglulu	.weak	plat_my_core_pos
20*91f16700Schasinglulu	.globl	plat_crash_console_init
21*91f16700Schasinglulu	.globl	plat_crash_console_putc
22*91f16700Schasinglulu	.globl	plat_crash_console_flush
23*91f16700Schasinglulu	.globl	platform_mem_init
24*91f16700Schasinglulu	.globl	disable_mmu_dcache
25*91f16700Schasinglulu	.globl	invalidate_tlb_all
26*91f16700Schasinglulu	.globl	platform_unmap_sram
27*91f16700Schasinglulu	.globl	disable_sram
28*91f16700Schasinglulu	.globl	disable_icache
29*91f16700Schasinglulu	.globl	invalidate_icache_all
30*91f16700Schasinglulu	.globl	marvell_exit_bootrom
31*91f16700Schasinglulu	.globl	ca72_l2_enable_unique_clean
32*91f16700Schasinglulu
33*91f16700Schasinglulu	/* -----------------------------------------------------
34*91f16700Schasinglulu	 *  unsigned int plat_my_core_pos(void)
35*91f16700Schasinglulu	 *  This function uses the plat_marvell_calc_core_pos()
36*91f16700Schasinglulu	 *  definition to get the index of the calling CPU.
37*91f16700Schasinglulu	 * -----------------------------------------------------
38*91f16700Schasinglulu	 */
39*91f16700Schasinglulufunc plat_my_core_pos
40*91f16700Schasinglulu	mrs	x0, mpidr_el1
41*91f16700Schasinglulu	b	plat_marvell_calc_core_pos
42*91f16700Schasingluluendfunc plat_my_core_pos
43*91f16700Schasinglulu
44*91f16700Schasinglulu	/* -----------------------------------------------------
45*91f16700Schasinglulu	 *  unsigned int plat_marvell_calc_core_pos(uint64_t mpidr)
46*91f16700Schasinglulu	 *  Helper function to calculate the core position.
47*91f16700Schasinglulu	 *  With this function: CorePos = (ClusterId * 2) +
48*91f16700Schasinglulu	 *  				  CoreId
49*91f16700Schasinglulu	 * -----------------------------------------------------
50*91f16700Schasinglulu	 */
51*91f16700Schasinglulufunc plat_marvell_calc_core_pos
52*91f16700Schasinglulu	and	x1, x0, #MPIDR_CPU_MASK
53*91f16700Schasinglulu	and	x0, x0, #MPIDR_CLUSTER_MASK
54*91f16700Schasinglulu	add	x0, x1, x0, LSR #7
55*91f16700Schasinglulu	ret
56*91f16700Schasingluluendfunc plat_marvell_calc_core_pos
57*91f16700Schasinglulu
58*91f16700Schasinglulu	/* ---------------------------------------------
59*91f16700Schasinglulu	 * int plat_crash_console_init(void)
60*91f16700Schasinglulu	 * Function to initialize the crash console
61*91f16700Schasinglulu	 * without a C Runtime to print crash report.
62*91f16700Schasinglulu	 * Clobber list : x0, x1, x2
63*91f16700Schasinglulu	 * ---------------------------------------------
64*91f16700Schasinglulu	 */
65*91f16700Schasinglulufunc plat_crash_console_init
66*91f16700Schasinglulu#ifdef PLAT_a3700
67*91f16700Schasinglulu	mov	x1, x30
68*91f16700Schasinglulu	bl	get_ref_clk
69*91f16700Schasinglulu	mov	x30, x1
70*91f16700Schasinglulu	mov_imm	x1, 1000000
71*91f16700Schasinglulu	mul	x1, x0, x1
72*91f16700Schasinglulu#else
73*91f16700Schasinglulu	mov_imm	x1, PLAT_MARVELL_UART_CLK_IN_HZ
74*91f16700Schasinglulu#endif
75*91f16700Schasinglulu	mov_imm	x0, PLAT_MARVELL_UART_BASE
76*91f16700Schasinglulu	mov_imm	x2, MARVELL_CONSOLE_BAUDRATE
77*91f16700Schasinglulu#ifdef PLAT_a3700
78*91f16700Schasinglulu	b	console_a3700_core_init
79*91f16700Schasinglulu#else
80*91f16700Schasinglulu	b	console_16550_core_init
81*91f16700Schasinglulu#endif
82*91f16700Schasingluluendfunc plat_crash_console_init
83*91f16700Schasinglulu
84*91f16700Schasinglulu	/* ---------------------------------------------
85*91f16700Schasinglulu	 * int plat_crash_console_putc(int c)
86*91f16700Schasinglulu	 * Function to print a character on the crash
87*91f16700Schasinglulu	 * console without a C Runtime.
88*91f16700Schasinglulu	 * Clobber list : x1, x2
89*91f16700Schasinglulu	 * ---------------------------------------------
90*91f16700Schasinglulu	 */
91*91f16700Schasinglulufunc plat_crash_console_putc
92*91f16700Schasinglulu	mov_imm	x1, PLAT_MARVELL_UART_BASE
93*91f16700Schasinglulu#ifdef PLAT_a3700
94*91f16700Schasinglulu
95*91f16700Schasinglulu	b	console_a3700_core_putc
96*91f16700Schasinglulu#else
97*91f16700Schasinglulu	b	console_16550_core_putc
98*91f16700Schasinglulu#endif
99*91f16700Schasingluluendfunc plat_crash_console_putc
100*91f16700Schasinglulu
101*91f16700Schasinglulu	/* ---------------------------------------------
102*91f16700Schasinglulu	 * void plat_crash_console_flush()
103*91f16700Schasinglulu	 * Function to force a write of all buffered
104*91f16700Schasinglulu	 * data that hasn't been output.
105*91f16700Schasinglulu	 * Out : void.
106*91f16700Schasinglulu	 * Clobber list : r0
107*91f16700Schasinglulu	 * ---------------------------------------------
108*91f16700Schasinglulu	 */
109*91f16700Schasinglulufunc plat_crash_console_flush
110*91f16700Schasinglulu	mov_imm	x0, PLAT_MARVELL_UART_BASE
111*91f16700Schasinglulu#ifdef PLAT_a3700
112*91f16700Schasinglulu	b	console_a3700_core_flush
113*91f16700Schasinglulu#else
114*91f16700Schasinglulu	b	console_16550_core_flush
115*91f16700Schasinglulu#endif
116*91f16700Schasingluluendfunc plat_crash_console_flush
117*91f16700Schasinglulu
118*91f16700Schasinglulu	/* ---------------------------------------------------------------------
119*91f16700Schasinglulu	 * We don't need to carry out any memory initialization on ARM
120*91f16700Schasinglulu	 * platforms. The Secure RAM is accessible straight away.
121*91f16700Schasinglulu	 * ---------------------------------------------------------------------
122*91f16700Schasinglulu	 */
123*91f16700Schasinglulufunc platform_mem_init
124*91f16700Schasinglulu	ret
125*91f16700Schasingluluendfunc platform_mem_init
126*91f16700Schasinglulu
127*91f16700Schasinglulu	/* -----------------------------------------------------
128*91f16700Schasinglulu	 * Disable icache, dcache, and MMU
129*91f16700Schasinglulu	 * -----------------------------------------------------
130*91f16700Schasinglulu	 */
131*91f16700Schasinglulufunc disable_mmu_dcache
132*91f16700Schasinglulu	mrs	x0, sctlr_el3
133*91f16700Schasinglulu	bic	x0, x0, 0x1		/* M bit - MMU */
134*91f16700Schasinglulu	bic	x0, x0, 0x4		/* C bit - Dcache L1 & L2 */
135*91f16700Schasinglulu	msr	sctlr_el3, x0
136*91f16700Schasinglulu	isb
137*91f16700Schasinglulu	b	mmu_off
138*91f16700Schasinglulummu_off:
139*91f16700Schasinglulu	ret
140*91f16700Schasingluluendfunc disable_mmu_dcache
141*91f16700Schasinglulu
142*91f16700Schasinglulu	/* -----------------------------------------------------
143*91f16700Schasinglulu	 * Disable all TLB entries
144*91f16700Schasinglulu	 * -----------------------------------------------------
145*91f16700Schasinglulu	 */
146*91f16700Schasinglulufunc invalidate_tlb_all
147*91f16700Schasinglulu	tlbi	alle3
148*91f16700Schasinglulu	dsb	sy
149*91f16700Schasinglulu	isb
150*91f16700Schasinglulu	ret
151*91f16700Schasingluluendfunc invalidate_tlb_all
152*91f16700Schasinglulu
153*91f16700Schasinglulu	/* -----------------------------------------------------
154*91f16700Schasinglulu	 * Disable the i cache
155*91f16700Schasinglulu	 * -----------------------------------------------------
156*91f16700Schasinglulu	 */
157*91f16700Schasinglulufunc disable_icache
158*91f16700Schasinglulu	mrs 	x0, sctlr_el3
159*91f16700Schasinglulu	bic	x0, x0, 0x1000	/* I bit - Icache L1 & L2 */
160*91f16700Schasinglulu	msr	sctlr_el3, x0
161*91f16700Schasinglulu	isb
162*91f16700Schasinglulu	ret
163*91f16700Schasingluluendfunc disable_icache
164*91f16700Schasinglulu
165*91f16700Schasinglulu	/* -----------------------------------------------------
166*91f16700Schasinglulu	 * Disable all of the i caches
167*91f16700Schasinglulu	 * -----------------------------------------------------
168*91f16700Schasinglulu	 */
169*91f16700Schasinglulufunc invalidate_icache_all
170*91f16700Schasinglulu	ic	ialluis
171*91f16700Schasinglulu	isb	sy
172*91f16700Schasinglulu	ret
173*91f16700Schasingluluendfunc invalidate_icache_all
174*91f16700Schasinglulu
175*91f16700Schasinglulu	/* -----------------------------------------------------
176*91f16700Schasinglulu	 * Clear the SRAM enabling bit to unmap SRAM
177*91f16700Schasinglulu	 * -----------------------------------------------------
178*91f16700Schasinglulu	 */
179*91f16700Schasinglulufunc platform_unmap_sram
180*91f16700Schasinglulu	ldr	x0, =CCU_SRAM_WIN_CR
181*91f16700Schasinglulu	str	wzr, [x0]
182*91f16700Schasinglulu	ret
183*91f16700Schasingluluendfunc platform_unmap_sram
184*91f16700Schasinglulu
185*91f16700Schasinglulu	/* -----------------------------------------------------
186*91f16700Schasinglulu	 * Disable the SRAM
187*91f16700Schasinglulu	 * -----------------------------------------------------
188*91f16700Schasinglulu	 */
189*91f16700Schasinglulufunc disable_sram
190*91f16700Schasinglulu	/* Disable the line lockings. They must be disabled expictly
191*91f16700Schasinglulu	 * or the OS will have problems using the cache */
192*91f16700Schasinglulu	ldr	x1, =MASTER_LLC_TC0_LOCK
193*91f16700Schasinglulu	str	wzr, [x1]
194*91f16700Schasinglulu
195*91f16700Schasinglulu	/* Invalidate all ways */
196*91f16700Schasinglulu	ldr	w1, =LLC_WAY_MASK
197*91f16700Schasinglulu	ldr	x0, =MASTER_LLC_INV_WAY
198*91f16700Schasinglulu	str	w1, [x0]
199*91f16700Schasinglulu
200*91f16700Schasinglulu	/* Finally disable LLC */
201*91f16700Schasinglulu	ldr	x0, =MASTER_LLC_CTRL
202*91f16700Schasinglulu	str	wzr, [x0]
203*91f16700Schasinglulu
204*91f16700Schasinglulu	ret
205*91f16700Schasingluluendfunc disable_sram
206*91f16700Schasinglulu
207*91f16700Schasinglulu	/* -----------------------------------------------------
208*91f16700Schasinglulu	 * Operation when exit bootROM:
209*91f16700Schasinglulu	 * Disable the MMU
210*91f16700Schasinglulu	 * Disable and invalidate the dcache
211*91f16700Schasinglulu	 * Unmap and disable the SRAM
212*91f16700Schasinglulu	 * Disable and invalidate the icache
213*91f16700Schasinglulu	 * -----------------------------------------------------
214*91f16700Schasinglulu	 */
215*91f16700Schasinglulufunc marvell_exit_bootrom
216*91f16700Schasinglulu	/* Save the system restore address */
217*91f16700Schasinglulu	mov	x28, x0
218*91f16700Schasinglulu
219*91f16700Schasinglulu	/* Close the caches and MMU */
220*91f16700Schasinglulu	bl	disable_mmu_dcache
221*91f16700Schasinglulu
222*91f16700Schasinglulu	/*
223*91f16700Schasinglulu	 * There is nothing important in the caches now,
224*91f16700Schasinglulu	 * so invalidate them instead of cleaning.
225*91f16700Schasinglulu	 */
226*91f16700Schasinglulu	adr	x0, __RW_START__
227*91f16700Schasinglulu	adr	x1, __RW_END__
228*91f16700Schasinglulu	sub	x1, x1, x0
229*91f16700Schasinglulu	bl	inv_dcache_range
230*91f16700Schasinglulu	bl	invalidate_tlb_all
231*91f16700Schasinglulu
232*91f16700Schasinglulu	/*
233*91f16700Schasinglulu	 * Clean the memory mapping of SRAM
234*91f16700Schasinglulu	 * the DDR mapping will remain to enable boot image to execute
235*91f16700Schasinglulu	 */
236*91f16700Schasinglulu	bl	platform_unmap_sram
237*91f16700Schasinglulu
238*91f16700Schasinglulu	/* Disable the SRAM */
239*91f16700Schasinglulu	bl	disable_sram
240*91f16700Schasinglulu
241*91f16700Schasinglulu	/* Disable and invalidate icache */
242*91f16700Schasinglulu	bl	disable_icache
243*91f16700Schasinglulu	bl	invalidate_icache_all
244*91f16700Schasinglulu
245*91f16700Schasinglulu	mov	x0, x28
246*91f16700Schasinglulu	br	x0
247*91f16700Schasingluluendfunc marvell_exit_bootrom
248*91f16700Schasinglulu
249*91f16700Schasinglulu	/*
250*91f16700Schasinglulu	 * Enable L2 UniqueClean evictions with data
251*91f16700Schasinglulu	 */
252*91f16700Schasinglulufunc ca72_l2_enable_unique_clean
253*91f16700Schasinglulu
254*91f16700Schasinglulu	mrs	x0, CORTEX_A72_L2ACTLR_EL1
255*91f16700Schasinglulu	orr	x0, x0, #CORTEX_A72_L2ACTLR_ENABLE_UNIQUE_CLEAN
256*91f16700Schasinglulu	msr	CORTEX_A72_L2ACTLR_EL1, x0
257*91f16700Schasinglulu
258*91f16700Schasinglulu	ret
259*91f16700Schasingluluendfunc ca72_l2_enable_unique_clean
260