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