summaryrefslogtreecommitdiffstats
path: root/plat/marvell/armada/common/aarch64/marvell_helpers.S
blob: 3038ec098e5b72b18862413e4108dd5c9a4a6ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Copyright (c) 2020, ARM Limited. All rights reserved.
 * Copyright (C) 2018 Marvell International Ltd.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 * https://spdx.org/licenses
 */

#include <asm_macros.S>
#include <cortex_a72.h>
#ifndef PLAT_a3700
#include <drivers/marvell/ccu.h>
#include <drivers/marvell/cache_llc.h>
#endif
#include <marvell_def.h>
#include <platform_def.h>

	.weak	plat_marvell_calc_core_pos
	.weak	plat_my_core_pos
	.globl	plat_crash_console_init
	.globl	plat_crash_console_putc
	.globl	plat_crash_console_flush
	.globl	platform_mem_init
	.globl	disable_mmu_dcache
	.globl	invalidate_tlb_all
	.globl	platform_unmap_sram
	.globl	disable_sram
	.globl	disable_icache
	.globl	invalidate_icache_all
	.globl	marvell_exit_bootrom
	.globl	ca72_l2_enable_unique_clean

	/* -----------------------------------------------------
	 *  unsigned int plat_my_core_pos(void)
	 *  This function uses the plat_marvell_calc_core_pos()
	 *  definition to get the index of the calling CPU.
	 * -----------------------------------------------------
	 */
func plat_my_core_pos
	mrs	x0, mpidr_el1
	b	plat_marvell_calc_core_pos
endfunc plat_my_core_pos

	/* -----------------------------------------------------
	 *  unsigned int plat_marvell_calc_core_pos(uint64_t mpidr)
	 *  Helper function to calculate the core position.
	 *  With this function: CorePos = (ClusterId * 2) +
	 *  				  CoreId
	 * -----------------------------------------------------
	 */
func plat_marvell_calc_core_pos
	and	x1, x0, #MPIDR_CPU_MASK
	and	x0, x0, #MPIDR_CLUSTER_MASK
	add	x0, x1, x0, LSR #7
	ret
endfunc plat_marvell_calc_core_pos

	/* ---------------------------------------------
	 * int plat_crash_console_init(void)
	 * Function to initialize the crash console
	 * without a C Runtime to print crash report.
	 * Clobber list : x0, x1, x2
	 * ---------------------------------------------
	 */
func plat_crash_console_init
#ifdef PLAT_a3700
	mov	x1, x30
	bl	get_ref_clk
	mov	x30, x1
	mov_imm	x1, 1000000
	mul	x1, x0, x1
#else
	mov_imm	x1, PLAT_MARVELL_UART_CLK_IN_HZ
#endif
	mov_imm	x0, PLAT_MARVELL_UART_BASE
	mov_imm	x2, MARVELL_CONSOLE_BAUDRATE
#ifdef PLAT_a3700
	b	console_a3700_core_init
#else
	b	console_16550_core_init
#endif
endfunc plat_crash_console_init

	/* ---------------------------------------------
	 * int plat_crash_console_putc(int c)
	 * Function to print a character on the crash
	 * console without a C Runtime.
	 * Clobber list : x1, x2
	 * ---------------------------------------------
	 */
func plat_crash_console_putc
	mov_imm	x1, PLAT_MARVELL_UART_BASE
#ifdef PLAT_a3700

	b	console_a3700_core_putc
#else
	b	console_16550_core_putc
#endif
endfunc plat_crash_console_putc

	/* ---------------------------------------------
	 * void plat_crash_console_flush()
	 * Function to force a write of all buffered
	 * data that hasn't been output.
	 * Out : void.
	 * Clobber list : r0
	 * ---------------------------------------------
	 */
func plat_crash_console_flush
	mov_imm	x0, PLAT_MARVELL_UART_BASE
#ifdef PLAT_a3700
	b	console_a3700_core_flush
#else
	b	console_16550_core_flush
#endif
endfunc plat_crash_console_flush

	/* ---------------------------------------------------------------------
	 * We don't need to carry out any memory initialization on ARM
	 * platforms. The Secure RAM is accessible straight away.
	 * ---------------------------------------------------------------------
	 */
func platform_mem_init
	ret
endfunc platform_mem_init

	/* -----------------------------------------------------
	 * Disable icache, dcache, and MMU
	 * -----------------------------------------------------
	 */
func disable_mmu_dcache
	mrs	x0, sctlr_el3
	bic	x0, x0, 0x1		/* M bit - MMU */
	bic	x0, x0, 0x4		/* C bit - Dcache L1 & L2 */
	msr	sctlr_el3, x0
	isb
	b	mmu_off
mmu_off:
	ret
endfunc disable_mmu_dcache

	/* -----------------------------------------------------
	 * Disable all TLB entries
	 * -----------------------------------------------------
	 */
func invalidate_tlb_all
	tlbi	alle3
	dsb	sy
	isb
	ret
endfunc invalidate_tlb_all

	/* -----------------------------------------------------
	 * Disable the i cache
	 * -----------------------------------------------------
	 */
func disable_icache
	mrs 	x0, sctlr_el3
	bic	x0, x0, 0x1000	/* I bit - Icache L1 & L2 */
	msr	sctlr_el3, x0
	isb
	ret
endfunc disable_icache

	/* -----------------------------------------------------
	 * Disable all of the i caches
	 * -----------------------------------------------------
	 */
func invalidate_icache_all
	ic	ialluis
	isb	sy
	ret
endfunc invalidate_icache_all

	/* -----------------------------------------------------
	 * Clear the SRAM enabling bit to unmap SRAM
	 * -----------------------------------------------------
	 */
func platform_unmap_sram
	ldr	x0, =CCU_SRAM_WIN_CR
	str	wzr, [x0]
	ret
endfunc platform_unmap_sram

	/* -----------------------------------------------------
	 * Disable the SRAM
	 * -----------------------------------------------------
	 */
func disable_sram
	/* Disable the line lockings. They must be disabled expictly
	 * or the OS will have problems using the cache */
	ldr	x1, =MASTER_LLC_TC0_LOCK
	str	wzr, [x1]

	/* Invalidate all ways */
	ldr	w1, =LLC_WAY_MASK
	ldr	x0, =MASTER_LLC_INV_WAY
	str	w1, [x0]

	/* Finally disable LLC */
	ldr	x0, =MASTER_LLC_CTRL
	str	wzr, [x0]

	ret
endfunc disable_sram

	/* -----------------------------------------------------
	 * Operation when exit bootROM:
	 * Disable the MMU
	 * Disable and invalidate the dcache
	 * Unmap and disable the SRAM
	 * Disable and invalidate the icache
	 * -----------------------------------------------------
	 */
func marvell_exit_bootrom
	/* Save the system restore address */
	mov	x28, x0

	/* Close the caches and MMU */
	bl	disable_mmu_dcache

	/*
	 * There is nothing important in the caches now,
	 * so invalidate them instead of cleaning.
	 */
	adr	x0, __RW_START__
	adr	x1, __RW_END__
	sub	x1, x1, x0
	bl	inv_dcache_range
	bl	invalidate_tlb_all

	/*
	 * Clean the memory mapping of SRAM
	 * the DDR mapping will remain to enable boot image to execute
	 */
	bl	platform_unmap_sram

	/* Disable the SRAM */
	bl	disable_sram

	/* Disable and invalidate icache */
	bl	disable_icache
	bl	invalidate_icache_all

	mov	x0, x28
	br	x0
endfunc marvell_exit_bootrom

	/*
	 * Enable L2 UniqueClean evictions with data
	 */
func ca72_l2_enable_unique_clean

	mrs	x0, CORTEX_A72_L2ACTLR_EL1
	orr	x0, x0, #CORTEX_A72_L2ACTLR_ENABLE_UNIQUE_CLEAN
	msr	CORTEX_A72_L2ACTLR_EL1, x0

	ret
endfunc ca72_l2_enable_unique_clean