blob: 1a5d26b5372e918ce27084fee5f44c118c944106 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hu0e58b512015-10-26 19:47:50 +08002/*
Meenakshi Aggarwal95a805b2020-09-09 14:06:05 +05303 * Copyright 2017-2020 NXP
Mingkai Hu0e58b512015-10-26 19:47:50 +08004 * Copyright 2014-2015 Freescale Semiconductor, Inc.
Mingkai Hu0e58b512015-10-26 19:47:50 +08005 */
6
7#include <common.h>
Simon Glass33d1e702019-11-14 12:57:32 -07008#include <cpu_func.h>
Simon Glassdb229612019-08-01 09:46:42 -06009#include <env.h>
Simon Glass0e0ac202017-04-06 12:47:04 -060010#include <fsl_ddr_sdram.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070011#include <init.h>
Simon Glassf11478f2019-12-28 10:45:07 -070012#include <hang.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070015#include <vsprintf.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <asm/cache.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080017#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060018#include <asm/ptrace.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080020#include <asm/system.h>
Joe Hershberger8f454d92018-07-16 15:33:51 -050021#include <fm_eth.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080022#include <asm/armv8/mmu.h>
23#include <asm/io.h>
24#include <asm/arch/fsl_serdes.h>
25#include <asm/arch/soc.h>
26#include <asm/arch/cpu.h>
27#include <asm/arch/speed.h>
Ashish Kumar11234062017-08-11 11:09:14 +053028#include <fsl_immap.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080029#include <asm/arch/mp.h>
Alexander Graf12be31c2016-11-17 01:03:01 +010030#include <efi_loader.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080031#include <fsl-mc/fsl_mc.h>
32#ifdef CONFIG_FSL_ESDHC
33#include <fsl_esdhc.h>
34#endif
Hou Zhiqiang21c4d552016-06-28 20:18:15 +080035#include <asm/armv8/sec_firmware.h>
Shengzhou Liu15875a52016-11-21 11:36:48 +080036#ifdef CONFIG_SYS_FSL_DDR
37#include <fsl_ddr.h>
38#endif
Simon Glass243182c2017-05-17 08:23:06 -060039#include <asm/arch/clock.h>
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +053040#include <hwconfig.h>
Ahmed Mansouraa270b42017-12-15 16:01:00 -050041#include <fsl_qbman.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080042
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000043#ifdef CONFIG_TFABOOT
Simon Glass9d1f6192019-08-02 09:44:25 -060044#include <env_internal.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000045#ifdef CONFIG_CHAIN_OF_TRUST
46#include <fsl_validate.h>
47#endif
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000048#endif
Simon Glasscaefa322019-11-14 12:57:31 -070049#include <linux/mii.h>
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000050
Mingkai Hu0e58b512015-10-26 19:47:50 +080051DECLARE_GLOBAL_DATA_PTR;
52
York Sunef4cef92018-11-05 18:01:06 +000053static struct cpu_type cpu_type_list[] = {
54 CPU_TYPE_ENTRY(LS2080A, LS2080A, 8),
55 CPU_TYPE_ENTRY(LS2085A, LS2085A, 8),
56 CPU_TYPE_ENTRY(LS2045A, LS2045A, 4),
57 CPU_TYPE_ENTRY(LS2088A, LS2088A, 8),
58 CPU_TYPE_ENTRY(LS2084A, LS2084A, 8),
59 CPU_TYPE_ENTRY(LS2048A, LS2048A, 4),
60 CPU_TYPE_ENTRY(LS2044A, LS2044A, 4),
61 CPU_TYPE_ENTRY(LS2081A, LS2081A, 8),
62 CPU_TYPE_ENTRY(LS2041A, LS2041A, 4),
63 CPU_TYPE_ENTRY(LS1043A, LS1043A, 4),
Hou Zhiqiangb9aedf92018-12-20 06:31:17 +000064 CPU_TYPE_ENTRY(LS1043A, LS1043A_P23, 4),
York Sunef4cef92018-11-05 18:01:06 +000065 CPU_TYPE_ENTRY(LS1023A, LS1023A, 2),
Hou Zhiqiangb9aedf92018-12-20 06:31:17 +000066 CPU_TYPE_ENTRY(LS1023A, LS1023A_P23, 2),
York Sunef4cef92018-11-05 18:01:06 +000067 CPU_TYPE_ENTRY(LS1046A, LS1046A, 4),
68 CPU_TYPE_ENTRY(LS1026A, LS1026A, 2),
69 CPU_TYPE_ENTRY(LS2040A, LS2040A, 4),
70 CPU_TYPE_ENTRY(LS1012A, LS1012A, 1),
Yuantian Tangf463d752019-09-18 16:50:52 +080071 CPU_TYPE_ENTRY(LS1017A, LS1017A, 1),
72 CPU_TYPE_ENTRY(LS1018A, LS1018A, 1),
73 CPU_TYPE_ENTRY(LS1027A, LS1027A, 2),
Yuantian Tang4aefa162019-04-10 16:43:33 +080074 CPU_TYPE_ENTRY(LS1028A, LS1028A, 2),
York Sunef4cef92018-11-05 18:01:06 +000075 CPU_TYPE_ENTRY(LS1088A, LS1088A, 8),
76 CPU_TYPE_ENTRY(LS1084A, LS1084A, 8),
77 CPU_TYPE_ENTRY(LS1048A, LS1048A, 4),
78 CPU_TYPE_ENTRY(LS1044A, LS1044A, 4),
Priyanka Jainef76b2e2018-10-29 09:17:09 +000079 CPU_TYPE_ENTRY(LX2160A, LX2160A, 16),
80 CPU_TYPE_ENTRY(LX2120A, LX2120A, 12),
81 CPU_TYPE_ENTRY(LX2080A, LX2080A, 8),
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +053082 CPU_TYPE_ENTRY(LX2162A, LX2162A, 16),
83 CPU_TYPE_ENTRY(LX2122A, LX2122A, 12),
84 CPU_TYPE_ENTRY(LX2082A, LX2082A, 8),
York Sunef4cef92018-11-05 18:01:06 +000085};
86
87#define EARLY_PGTABLE_SIZE 0x5000
88static struct mm_region early_map[] = {
89#ifdef CONFIG_FSL_LSCH3
90 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
91 CONFIG_SYS_FSL_CCSR_SIZE,
92 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
93 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
94 },
95 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
96 SYS_FSL_OCRAM_SPACE_SIZE,
97 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
98 },
99 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
100 CONFIG_SYS_FSL_QSPI_SIZE1,
101 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE},
102#ifdef CONFIG_FSL_IFC
103 /* For IFC Region #1, only the first 4MB is cache-enabled */
104 { CONFIG_SYS_FSL_IFC_BASE1, CONFIG_SYS_FSL_IFC_BASE1,
105 CONFIG_SYS_FSL_IFC_SIZE1_1,
106 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
107 },
108 { CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
109 CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
110 CONFIG_SYS_FSL_IFC_SIZE1 - CONFIG_SYS_FSL_IFC_SIZE1_1,
111 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
112 },
113 { CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FSL_IFC_BASE1,
114 CONFIG_SYS_FSL_IFC_SIZE1,
115 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
116 },
117#endif
118 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
119 CONFIG_SYS_FSL_DRAM_SIZE1,
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +0000120#if defined(CONFIG_TFABOOT) || \
121 (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD))
York Sunef4cef92018-11-05 18:01:06 +0000122 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
123#else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
124 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
125#endif
126 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
127 },
128#ifdef CONFIG_FSL_IFC
129 /* Map IFC region #2 up to CONFIG_SYS_FLASH_BASE for NAND boot */
130 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
131 CONFIG_SYS_FLASH_BASE - CONFIG_SYS_FSL_IFC_BASE2,
132 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
133 },
134#endif
135 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
136 CONFIG_SYS_FSL_DCSR_SIZE,
137 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
138 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
139 },
140 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
141 CONFIG_SYS_FSL_DRAM_SIZE2,
142 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
143 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
144 },
Priyanka Jain88c25662018-10-29 09:11:29 +0000145#ifdef CONFIG_SYS_FSL_DRAM_BASE3
146 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
147 CONFIG_SYS_FSL_DRAM_SIZE3,
148 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
149 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
150 },
151#endif
York Sunef4cef92018-11-05 18:01:06 +0000152#elif defined(CONFIG_FSL_LSCH2)
153 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
154 CONFIG_SYS_FSL_CCSR_SIZE,
155 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
156 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
157 },
158 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
159 SYS_FSL_OCRAM_SPACE_SIZE,
160 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
161 },
162 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
163 CONFIG_SYS_FSL_DCSR_SIZE,
164 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
165 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
166 },
167 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
168 CONFIG_SYS_FSL_QSPI_SIZE,
169 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
170 },
171#ifdef CONFIG_FSL_IFC
172 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
173 CONFIG_SYS_FSL_IFC_SIZE,
174 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
175 },
176#endif
177 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
178 CONFIG_SYS_FSL_DRAM_SIZE1,
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +0000179#if defined(CONFIG_TFABOOT) || \
180 (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD))
York Sunef4cef92018-11-05 18:01:06 +0000181 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
182#else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
183 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
184#endif
185 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
186 },
187 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
188 CONFIG_SYS_FSL_DRAM_SIZE2,
189 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
190 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
191 },
192#endif
193 {}, /* list terminator */
194};
195
196static struct mm_region final_map[] = {
197#ifdef CONFIG_FSL_LSCH3
198 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
199 CONFIG_SYS_FSL_CCSR_SIZE,
200 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
201 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
202 },
203 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
204 SYS_FSL_OCRAM_SPACE_SIZE,
205 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
206 },
207 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
208 CONFIG_SYS_FSL_DRAM_SIZE1,
209 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
210 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
211 },
212 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
213 CONFIG_SYS_FSL_QSPI_SIZE1,
214 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
215 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
216 },
217 { CONFIG_SYS_FSL_QSPI_BASE2, CONFIG_SYS_FSL_QSPI_BASE2,
218 CONFIG_SYS_FSL_QSPI_SIZE2,
219 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
220 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
221 },
222#ifdef CONFIG_FSL_IFC
223 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
224 CONFIG_SYS_FSL_IFC_SIZE2,
225 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
226 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
227 },
228#endif
229 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
230 CONFIG_SYS_FSL_DCSR_SIZE,
231 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
232 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
233 },
234 { CONFIG_SYS_FSL_MC_BASE, CONFIG_SYS_FSL_MC_BASE,
235 CONFIG_SYS_FSL_MC_SIZE,
236 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
237 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
238 },
239 { CONFIG_SYS_FSL_NI_BASE, CONFIG_SYS_FSL_NI_BASE,
240 CONFIG_SYS_FSL_NI_SIZE,
241 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
242 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
243 },
244 /* For QBMAN portal, only the first 64MB is cache-enabled */
245 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
246 CONFIG_SYS_FSL_QBMAN_SIZE_1,
247 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
248 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_NS
249 },
250 { CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
251 CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
252 CONFIG_SYS_FSL_QBMAN_SIZE - CONFIG_SYS_FSL_QBMAN_SIZE_1,
253 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
254 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
255 },
256 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
257 CONFIG_SYS_PCIE1_PHYS_SIZE,
258 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
259 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
260 },
261 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
262 CONFIG_SYS_PCIE2_PHYS_SIZE,
263 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
264 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
265 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800266#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000267 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
268 CONFIG_SYS_PCIE3_PHYS_SIZE,
269 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
270 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
271 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800272#endif
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000273#ifdef CONFIG_SYS_PCIE4_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000274 { CONFIG_SYS_PCIE4_PHYS_ADDR, CONFIG_SYS_PCIE4_PHYS_ADDR,
275 CONFIG_SYS_PCIE4_PHYS_SIZE,
276 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
277 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
278 },
279#endif
Hou Zhiqiangd08f9702019-04-08 10:15:41 +0000280#ifdef SYS_PCIE5_PHYS_ADDR
281 { SYS_PCIE5_PHYS_ADDR, SYS_PCIE5_PHYS_ADDR,
282 SYS_PCIE5_PHYS_SIZE,
283 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
284 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
285 },
286#endif
287#ifdef SYS_PCIE6_PHYS_ADDR
288 { SYS_PCIE6_PHYS_ADDR, SYS_PCIE6_PHYS_ADDR,
289 SYS_PCIE6_PHYS_SIZE,
290 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
291 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
292 },
293#endif
York Sunef4cef92018-11-05 18:01:06 +0000294 { CONFIG_SYS_FSL_WRIOP1_BASE, CONFIG_SYS_FSL_WRIOP1_BASE,
295 CONFIG_SYS_FSL_WRIOP1_SIZE,
296 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
297 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
298 },
299 { CONFIG_SYS_FSL_AIOP1_BASE, CONFIG_SYS_FSL_AIOP1_BASE,
300 CONFIG_SYS_FSL_AIOP1_SIZE,
301 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
302 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
303 },
304 { CONFIG_SYS_FSL_PEBUF_BASE, CONFIG_SYS_FSL_PEBUF_BASE,
305 CONFIG_SYS_FSL_PEBUF_SIZE,
306 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
307 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
308 },
309 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
310 CONFIG_SYS_FSL_DRAM_SIZE2,
311 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
312 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
313 },
Priyanka Jain88c25662018-10-29 09:11:29 +0000314#ifdef CONFIG_SYS_FSL_DRAM_BASE3
315 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
316 CONFIG_SYS_FSL_DRAM_SIZE3,
317 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
318 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
319 },
320#endif
York Sunef4cef92018-11-05 18:01:06 +0000321#elif defined(CONFIG_FSL_LSCH2)
322 { CONFIG_SYS_FSL_BOOTROM_BASE, CONFIG_SYS_FSL_BOOTROM_BASE,
323 CONFIG_SYS_FSL_BOOTROM_SIZE,
324 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
325 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
326 },
327 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
328 CONFIG_SYS_FSL_CCSR_SIZE,
329 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
330 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
331 },
332 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
333 SYS_FSL_OCRAM_SPACE_SIZE,
334 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
335 },
336 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
337 CONFIG_SYS_FSL_DCSR_SIZE,
338 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
339 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
340 },
341 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
342 CONFIG_SYS_FSL_QSPI_SIZE,
343 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
344 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
345 },
346#ifdef CONFIG_FSL_IFC
347 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
348 CONFIG_SYS_FSL_IFC_SIZE,
349 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
350 },
351#endif
352 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
353 CONFIG_SYS_FSL_DRAM_SIZE1,
354 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
355 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
356 },
357 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
358 CONFIG_SYS_FSL_QBMAN_SIZE,
359 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
360 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
361 },
362 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
363 CONFIG_SYS_FSL_DRAM_SIZE2,
364 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
365 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
366 },
367 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
368 CONFIG_SYS_PCIE1_PHYS_SIZE,
369 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
370 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
371 },
372 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
373 CONFIG_SYS_PCIE2_PHYS_SIZE,
374 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
375 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
376 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800377#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000378 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
379 CONFIG_SYS_PCIE3_PHYS_SIZE,
380 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
381 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
382 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800383#endif
York Sunef4cef92018-11-05 18:01:06 +0000384 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
385 CONFIG_SYS_FSL_DRAM_SIZE3,
386 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
387 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
388 },
389#endif
390#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
391 {}, /* space holder for secure mem */
392#endif
393 {},
394};
395
York Sun9da8f502016-06-24 16:46:23 -0700396struct mm_region *mem_map = early_map;
Alexander Grafce0a64e2016-03-04 01:09:54 +0100397
Mingkai Hu0e58b512015-10-26 19:47:50 +0800398void cpu_name(char *name)
399{
400 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
401 unsigned int i, svr, ver;
402
403 svr = gur_in32(&gur->svr);
404 ver = SVR_SOC_VER(svr);
405
406 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
407 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
408 strcpy(name, cpu_type_list[i].name);
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530409#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Priyanka Jainef76b2e2018-10-29 09:17:09 +0000410 if (IS_C_PROCESSOR(svr))
411 strcat(name, "C");
412#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +0800413
414 if (IS_E_PROCESSOR(svr))
415 strcat(name, "E");
Wenbin Song863a33a2016-09-13 16:13:54 +0800416
417 sprintf(name + strlen(name), " Rev%d.%d",
418 SVR_MAJ(svr), SVR_MIN(svr));
Mingkai Hu0e58b512015-10-26 19:47:50 +0800419 break;
420 }
421
422 if (i == ARRAY_SIZE(cpu_type_list))
423 strcpy(name, "unknown");
424}
425
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400426#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Mingkai Hu0e58b512015-10-26 19:47:50 +0800427/*
428 * To start MMU before DDR is available, we create MMU table in SRAM.
429 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
430 * levels of translation tables here to cover 40-bit address space.
431 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
York Sun9da8f502016-06-24 16:46:23 -0700432 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
433 * Note, the debug print in cache_v8.c is not usable for debugging
434 * these early MMU tables because UART is not yet available.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800435 */
436static inline void early_mmu_setup(void)
437{
York Sun9da8f502016-06-24 16:46:23 -0700438 unsigned int el = current_el();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800439
York Sun9da8f502016-06-24 16:46:23 -0700440 /* global data is already setup, no allocation yet */
Pankit Gargc4d39eb2018-11-05 18:01:28 +0000441 if (el == 3)
442 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
443 else
444 gd->arch.tlb_addr = CONFIG_SYS_DDR_SDRAM_BASE;
York Sun9da8f502016-06-24 16:46:23 -0700445 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
446 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800447
York Sun9da8f502016-06-24 16:46:23 -0700448 /* Create early page tables */
449 setup_pgtables();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800450
York Sun9da8f502016-06-24 16:46:23 -0700451 /* point TTBR to the new table */
452 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
453 get_tcr(el, NULL, NULL) &
454 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
Mingkai Hu0e58b512015-10-26 19:47:50 +0800455 MEMORY_ATTRIBUTES);
York Sun9da8f502016-06-24 16:46:23 -0700456
Mingkai Hu0e58b512015-10-26 19:47:50 +0800457 set_sctlr(get_sctlr() | CR_M);
458}
459
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800460static void fix_pcie_mmu_map(void)
461{
York Sun4ce6fbf2017-03-27 11:41:01 -0700462#ifdef CONFIG_ARCH_LS2080A
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800463 unsigned int i;
464 u32 svr, ver;
465 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
466
467 svr = gur_in32(&gur->svr);
468 ver = SVR_SOC_VER(svr);
469
470 /* Fix PCIE base and size for LS2088A */
471 if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
Priyanka Jain2b361782017-04-27 15:08:06 +0530472 (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
473 (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800474 for (i = 0; i < ARRAY_SIZE(final_map); i++) {
475 switch (final_map[i].phys) {
476 case CONFIG_SYS_PCIE1_PHYS_ADDR:
477 final_map[i].phys = 0x2000000000ULL;
478 final_map[i].virt = 0x2000000000ULL;
479 final_map[i].size = 0x800000000ULL;
480 break;
481 case CONFIG_SYS_PCIE2_PHYS_ADDR:
482 final_map[i].phys = 0x2800000000ULL;
483 final_map[i].virt = 0x2800000000ULL;
484 final_map[i].size = 0x800000000ULL;
485 break;
Yuantian Tang4aefa162019-04-10 16:43:33 +0800486#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800487 case CONFIG_SYS_PCIE3_PHYS_ADDR:
488 final_map[i].phys = 0x3000000000ULL;
489 final_map[i].virt = 0x3000000000ULL;
490 final_map[i].size = 0x800000000ULL;
491 break;
Yuantian Tang4aefa162019-04-10 16:43:33 +0800492#endif
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000493#ifdef CONFIG_SYS_PCIE4_PHYS_ADDR
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800494 case CONFIG_SYS_PCIE4_PHYS_ADDR:
495 final_map[i].phys = 0x3800000000ULL;
496 final_map[i].virt = 0x3800000000ULL;
497 final_map[i].size = 0x800000000ULL;
498 break;
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000499#endif
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800500 default:
501 break;
502 }
503 }
504 }
505#endif
506}
507
Mingkai Hu0e58b512015-10-26 19:47:50 +0800508/*
509 * The final tables look similar to early tables, but different in detail.
510 * These tables are in DRAM. Sub tables are added to enable cache for
511 * QBMan and OCRAM.
512 *
York Sun1ef95cc2016-06-24 16:46:18 -0700513 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
514 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800515 */
516static inline void final_mmu_setup(void)
517{
York Sun9da8f502016-06-24 16:46:23 -0700518 u64 tlb_addr_save = gd->arch.tlb_addr;
York Sun0804d562015-12-04 11:57:08 -0800519 unsigned int el = current_el();
York Sun9da8f502016-06-24 16:46:23 -0700520 int index;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800521
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800522 /* fix the final_map before filling in the block entries */
523 fix_pcie_mmu_map();
524
York Sun9da8f502016-06-24 16:46:23 -0700525 mem_map = final_map;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800526
York Sun75488ed2017-03-06 09:02:30 -0800527 /* Update mapping for DDR to actual size */
528 for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
529 /*
530 * Find the entry for DDR mapping and update the address and
531 * size. Zero-sized mapping will be skipped when creating MMU
532 * table.
533 */
534 switch (final_map[index].virt) {
535 case CONFIG_SYS_FSL_DRAM_BASE1:
536 final_map[index].virt = gd->bd->bi_dram[0].start;
537 final_map[index].phys = gd->bd->bi_dram[0].start;
538 final_map[index].size = gd->bd->bi_dram[0].size;
539 break;
540#ifdef CONFIG_SYS_FSL_DRAM_BASE2
541 case CONFIG_SYS_FSL_DRAM_BASE2:
542#if (CONFIG_NR_DRAM_BANKS >= 2)
543 final_map[index].virt = gd->bd->bi_dram[1].start;
544 final_map[index].phys = gd->bd->bi_dram[1].start;
545 final_map[index].size = gd->bd->bi_dram[1].size;
546#else
547 final_map[index].size = 0;
548#endif
549 break;
550#endif
551#ifdef CONFIG_SYS_FSL_DRAM_BASE3
552 case CONFIG_SYS_FSL_DRAM_BASE3:
553#if (CONFIG_NR_DRAM_BANKS >= 3)
554 final_map[index].virt = gd->bd->bi_dram[2].start;
555 final_map[index].phys = gd->bd->bi_dram[2].start;
556 final_map[index].size = gd->bd->bi_dram[2].size;
557#else
558 final_map[index].size = 0;
559#endif
560 break;
561#endif
562 default:
563 break;
564 }
565 }
566
York Sun0804d562015-12-04 11:57:08 -0800567#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
York Sun9da8f502016-06-24 16:46:23 -0700568 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
569 if (el == 3) {
570 /*
571 * Only use gd->arch.secure_ram if the address is
572 * recalculated. Align to 4KB for MMU table.
573 */
574 /* put page tables in secure ram */
575 index = ARRAY_SIZE(final_map) - 2;
576 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
577 final_map[index].virt = gd->arch.secure_ram & ~0x3;
578 final_map[index].phys = final_map[index].virt;
579 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
580 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
York Sun1ef95cc2016-06-24 16:46:18 -0700581 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
York Sun9da8f502016-06-24 16:46:23 -0700582 tlb_addr_save = gd->arch.tlb_addr;
York Sun0804d562015-12-04 11:57:08 -0800583 } else {
York Sun9da8f502016-06-24 16:46:23 -0700584 /* Use allocated (board_f.c) memory for TLB */
585 tlb_addr_save = gd->arch.tlb_allocated;
586 gd->arch.tlb_addr = tlb_addr_save;
York Sun0804d562015-12-04 11:57:08 -0800587 }
588 }
589#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +0800590
York Sun9da8f502016-06-24 16:46:23 -0700591 /* Reset the fill ptr */
592 gd->arch.tlb_fillptr = tlb_addr_save;
593
594 /* Create normal system page tables */
595 setup_pgtables();
596
597 /* Create emergency page tables */
598 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
599 gd->arch.tlb_emerg = gd->arch.tlb_addr;
600 setup_pgtables();
601 gd->arch.tlb_addr = tlb_addr_save;
602
York Suncf64ced2017-03-06 09:02:31 -0800603 /* Disable cache and MMU */
604 dcache_disable(); /* TLBs are invalidated */
605 invalidate_icache_all();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800606
607 /* point TTBR to the new table */
York Sun9da8f502016-06-24 16:46:23 -0700608 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
Mingkai Hu0e58b512015-10-26 19:47:50 +0800609 MEMORY_ATTRIBUTES);
York Suncf64ced2017-03-06 09:02:31 -0800610
York Suneb6eac12016-07-22 10:52:23 -0700611 set_sctlr(get_sctlr() | CR_M);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800612}
613
Alexander Grafbc78b922016-03-21 20:26:12 +0100614u64 get_page_table_size(void)
615{
616 return 0x10000;
617}
618
Mingkai Hu0e58b512015-10-26 19:47:50 +0800619int arch_cpu_init(void)
620{
York Sune6b871e2017-05-15 08:51:59 -0700621 /*
622 * This function is called before U-Boot relocates itself to speed up
623 * on system running. It is not necessary to run if performance is not
624 * critical. Skip if MMU is already enabled by SPL or other means.
625 */
626 if (get_sctlr() & CR_M)
627 return 0;
628
Mingkai Hu0e58b512015-10-26 19:47:50 +0800629 icache_enable();
630 __asm_invalidate_dcache_all();
631 __asm_invalidate_tlb_all();
632 early_mmu_setup();
633 set_sctlr(get_sctlr() | CR_C);
634 return 0;
635}
636
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800637void mmu_setup(void)
638{
639 final_mmu_setup();
640}
641
Mingkai Hu0e58b512015-10-26 19:47:50 +0800642/*
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800643 * This function is called from common/board_r.c.
644 * It recreates MMU table in main memory.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800645 */
646void enable_caches(void)
647{
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800648 mmu_setup();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800649 __asm_invalidate_tlb_all();
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800650 icache_enable();
651 dcache_enable();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800652}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400653#endif /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000654
655#ifdef CONFIG_TFABOOT
656enum boot_src __get_boot_src(u32 porsr1)
657{
658 enum boot_src src = BOOT_SOURCE_RESERVED;
659 u32 rcw_src = (porsr1 & RCW_SRC_MASK) >> RCW_SRC_BIT;
Priyanka Jain88c25662018-10-29 09:11:29 +0000660#if !defined(CONFIG_NXP_LSCH3_2)
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000661 u32 val;
662#endif
663 debug("%s: rcw_src 0x%x\n", __func__, rcw_src);
664
665#if defined(CONFIG_FSL_LSCH3)
Priyanka Jain88c25662018-10-29 09:11:29 +0000666#if defined(CONFIG_NXP_LSCH3_2)
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000667 switch (rcw_src) {
668 case RCW_SRC_SDHC1_VAL:
669 src = BOOT_SOURCE_SD_MMC;
670 break;
671 case RCW_SRC_SDHC2_VAL:
672 src = BOOT_SOURCE_SD_MMC2;
673 break;
674 case RCW_SRC_I2C1_VAL:
675 src = BOOT_SOURCE_I2C1_EXTENDED;
676 break;
677 case RCW_SRC_FLEXSPI_NAND2K_VAL:
678 src = BOOT_SOURCE_XSPI_NAND;
679 break;
680 case RCW_SRC_FLEXSPI_NAND4K_VAL:
681 src = BOOT_SOURCE_XSPI_NAND;
682 break;
683 case RCW_SRC_RESERVED_1_VAL:
684 src = BOOT_SOURCE_RESERVED;
685 break;
686 case RCW_SRC_FLEXSPI_NOR_24B:
687 src = BOOT_SOURCE_XSPI_NOR;
688 break;
689 default:
690 src = BOOT_SOURCE_RESERVED;
691 }
692#else
693 val = rcw_src & RCW_SRC_TYPE_MASK;
694 if (val == RCW_SRC_NOR_VAL) {
695 val = rcw_src & NOR_TYPE_MASK;
696
697 switch (val) {
698 case NOR_16B_VAL:
699 case NOR_32B_VAL:
700 src = BOOT_SOURCE_IFC_NOR;
701 break;
702 default:
703 src = BOOT_SOURCE_RESERVED;
704 }
705 } else {
706 /* RCW SRC Serial Flash */
707 val = rcw_src & RCW_SRC_SERIAL_MASK;
708 switch (val) {
709 case RCW_SRC_QSPI_VAL:
710 /* RCW SRC Serial NOR (QSPI) */
711 src = BOOT_SOURCE_QSPI_NOR;
712 break;
713 case RCW_SRC_SD_CARD_VAL:
714 /* RCW SRC SD Card */
715 src = BOOT_SOURCE_SD_MMC;
716 break;
717 case RCW_SRC_EMMC_VAL:
718 /* RCW SRC EMMC */
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000719 src = BOOT_SOURCE_SD_MMC;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000720 break;
721 case RCW_SRC_I2C1_VAL:
722 /* RCW SRC I2C1 Extended */
723 src = BOOT_SOURCE_I2C1_EXTENDED;
724 break;
725 default:
726 src = BOOT_SOURCE_RESERVED;
727 }
728 }
729#endif
730#elif defined(CONFIG_FSL_LSCH2)
731 /* RCW SRC NAND */
732 val = rcw_src & RCW_SRC_NAND_MASK;
733 if (val == RCW_SRC_NAND_VAL) {
734 val = rcw_src & NAND_RESERVED_MASK;
735 if (val != NAND_RESERVED_1 && val != NAND_RESERVED_2)
736 src = BOOT_SOURCE_IFC_NAND;
737
738 } else {
739 /* RCW SRC NOR */
740 val = rcw_src & RCW_SRC_NOR_MASK;
741 if (val == NOR_8B_VAL || val == NOR_16B_VAL) {
742 src = BOOT_SOURCE_IFC_NOR;
743 } else {
744 switch (rcw_src) {
745 case QSPI_VAL1:
746 case QSPI_VAL2:
747 src = BOOT_SOURCE_QSPI_NOR;
748 break;
749 case SD_VAL:
750 src = BOOT_SOURCE_SD_MMC;
751 break;
752 default:
753 src = BOOT_SOURCE_RESERVED;
754 }
755 }
756 }
757#endif
York Sun8f3f4ef2018-11-05 18:02:09 +0000758
759 if (CONFIG_IS_ENABLED(SYS_FSL_ERRATUM_A010539) && !rcw_src)
760 src = BOOT_SOURCE_QSPI_NOR;
761
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000762 debug("%s: src 0x%x\n", __func__, src);
763 return src;
764}
765
766enum boot_src get_boot_src(void)
767{
York Sun8f3f4ef2018-11-05 18:02:09 +0000768 struct pt_regs regs;
769 u32 porsr1 = 0;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000770
771#if defined(CONFIG_FSL_LSCH3)
772 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000773#elif defined(CONFIG_FSL_LSCH2)
774 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
York Sun8f3f4ef2018-11-05 18:02:09 +0000775#endif
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000776
York Sun8f3f4ef2018-11-05 18:02:09 +0000777 if (current_el() == 2) {
778 regs.regs[0] = SIP_SVC_RCW;
779
780 smc_call(&regs);
781 if (!regs.regs[0])
782 porsr1 = regs.regs[1];
783 }
784
785 if (current_el() == 3 || !porsr1) {
786#ifdef CONFIG_FSL_LSCH3
787 porsr1 = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
788#elif defined(CONFIG_FSL_LSCH2)
789 porsr1 = in_be32(&gur->porsr1);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800790#endif
York Sun8f3f4ef2018-11-05 18:02:09 +0000791 }
792
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000793 debug("%s: porsr1 0x%x\n", __func__, porsr1);
794
795 return __get_boot_src(porsr1);
796}
797
798#ifdef CONFIG_ENV_IS_IN_MMC
799int mmc_get_env_dev(void)
800{
801 enum boot_src src = get_boot_src();
802 int dev = CONFIG_SYS_MMC_ENV_DEV;
803
804 switch (src) {
805 case BOOT_SOURCE_SD_MMC:
806 dev = 0;
807 break;
808 case BOOT_SOURCE_SD_MMC2:
809 dev = 1;
810 break;
811 default:
812 break;
813 }
814
815 return dev;
816}
817#endif
818
819enum env_location env_get_location(enum env_operation op, int prio)
820{
821 enum boot_src src = get_boot_src();
822 enum env_location env_loc = ENVL_NOWHERE;
823
824 if (prio)
825 return ENVL_UNKNOWN;
826
Udit Agarwal5e9720c2019-04-23 06:06:04 +0000827#ifdef CONFIG_ENV_IS_NOWHERE
828 return env_loc;
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000829#endif
830
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000831 switch (src) {
832 case BOOT_SOURCE_IFC_NOR:
833 env_loc = ENVL_FLASH;
834 break;
835 case BOOT_SOURCE_QSPI_NOR:
836 /* FALLTHROUGH */
837 case BOOT_SOURCE_XSPI_NOR:
838 env_loc = ENVL_SPI_FLASH;
839 break;
840 case BOOT_SOURCE_IFC_NAND:
841 /* FALLTHROUGH */
842 case BOOT_SOURCE_QSPI_NAND:
843 /* FALLTHROUGH */
844 case BOOT_SOURCE_XSPI_NAND:
845 env_loc = ENVL_NAND;
846 break;
847 case BOOT_SOURCE_SD_MMC:
848 /* FALLTHROUGH */
849 case BOOT_SOURCE_SD_MMC2:
850 env_loc = ENVL_MMC;
851 break;
852 case BOOT_SOURCE_I2C1_EXTENDED:
853 /* FALLTHROUGH */
854 default:
855 break;
856 }
857
858 return env_loc;
859}
860#endif /* CONFIG_TFABOOT */
Mingkai Hu0e58b512015-10-26 19:47:50 +0800861
Priyanka Jain9a276702016-11-17 12:29:56 +0530862u32 initiator_type(u32 cluster, int init_id)
Mingkai Hu0e58b512015-10-26 19:47:50 +0800863{
864 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
865 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
866 u32 type = 0;
867
868 type = gur_in32(&gur->tp_ityp[idx]);
869 if (type & TP_ITYP_AV)
870 return type;
871
872 return 0;
873}
874
York Suned7fbe32016-09-13 12:40:30 -0700875u32 cpu_pos_mask(void)
876{
877 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
878 int i = 0;
879 u32 cluster, type, mask = 0;
880
881 do {
882 int j;
883
884 cluster = gur_in32(&gur->tp_cluster[i].lower);
885 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
886 type = initiator_type(cluster, j);
887 if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
888 mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
889 }
890 i++;
891 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
892
893 return mask;
894}
895
Mingkai Hu0e58b512015-10-26 19:47:50 +0800896u32 cpu_mask(void)
897{
898 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
899 int i = 0, count = 0;
900 u32 cluster, type, mask = 0;
901
902 do {
903 int j;
904
905 cluster = gur_in32(&gur->tp_cluster[i].lower);
906 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
907 type = initiator_type(cluster, j);
908 if (type) {
909 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
910 mask |= 1 << count;
911 count++;
912 }
913 }
914 i++;
915 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
916
917 return mask;
918}
919
920/*
921 * Return the number of cores on this SOC.
922 */
923int cpu_numcores(void)
924{
925 return hweight32(cpu_mask());
926}
927
928int fsl_qoriq_core_to_cluster(unsigned int core)
929{
930 struct ccsr_gur __iomem *gur =
931 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
932 int i = 0, count = 0;
933 u32 cluster;
934
935 do {
936 int j;
937
938 cluster = gur_in32(&gur->tp_cluster[i].lower);
939 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
940 if (initiator_type(cluster, j)) {
941 if (count == core)
942 return i;
943 count++;
944 }
945 }
946 i++;
947 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
948
949 return -1; /* cannot identify the cluster */
950}
951
952u32 fsl_qoriq_core_to_type(unsigned int core)
953{
954 struct ccsr_gur __iomem *gur =
955 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
956 int i = 0, count = 0;
957 u32 cluster, type;
958
959 do {
960 int j;
961
962 cluster = gur_in32(&gur->tp_cluster[i].lower);
963 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
964 type = initiator_type(cluster, j);
965 if (type) {
966 if (count == core)
967 return type;
968 count++;
969 }
970 }
971 i++;
972 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
973
974 return -1; /* cannot identify the cluster */
975}
976
Priyanka Jain96b001f2016-11-17 12:29:51 +0530977#ifndef CONFIG_FSL_LSCH3
Sriram Dash9282d262016-06-13 09:58:32 +0530978uint get_svr(void)
979{
980 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
981
982 return gur_in32(&gur->svr);
983}
Priyanka Jain96b001f2016-11-17 12:29:51 +0530984#endif
Sriram Dash9282d262016-06-13 09:58:32 +0530985
Mingkai Hu0e58b512015-10-26 19:47:50 +0800986#ifdef CONFIG_DISPLAY_CPUINFO
987int print_cpuinfo(void)
988{
989 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
990 struct sys_info sysinfo;
991 char buf[32];
992 unsigned int i, core;
York Suncbe8e1c2016-04-04 11:41:26 -0700993 u32 type, rcw, svr = gur_in32(&gur->svr);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800994
995 puts("SoC: ");
996
997 cpu_name(buf);
York Suncbe8e1c2016-04-04 11:41:26 -0700998 printf(" %s (0x%x)\n", buf, svr);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800999 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
1000 get_sys_info(&sysinfo);
1001 puts("Clock Configuration:");
1002 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
1003 if (!(i % 3))
1004 puts("\n ");
1005 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
1006 printf("CPU%d(%s):%-4s MHz ", core,
1007 type == TY_ITYP_VER_A7 ? "A7 " :
1008 (type == TY_ITYP_VER_A53 ? "A53" :
Alison Wang79808392016-07-05 16:01:52 +08001009 (type == TY_ITYP_VER_A57 ? "A57" :
1010 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
Mingkai Hu0e58b512015-10-26 19:47:50 +08001011 strmhz(buf, sysinfo.freq_processor[core]));
1012 }
Hou Zhiqiang3f91cda2017-01-10 16:44:15 +08001013 /* Display platform clock as Bus frequency. */
Mingkai Hu0e58b512015-10-26 19:47:50 +08001014 printf("\n Bus: %-4s MHz ",
Hou Zhiqiang3f91cda2017-01-10 16:44:15 +08001015 strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
Mingkai Hu0e58b512015-10-26 19:47:50 +08001016 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
Shaohui Xie04643262015-10-26 19:47:54 +08001017#ifdef CONFIG_SYS_DPAA_FMAN
1018 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
1019#endif
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +05301020#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Suncbe8e1c2016-04-04 11:41:26 -07001021 if (soc_has_dp_ddr()) {
1022 printf(" DP-DDR: %-4s MT/s",
1023 strmhz(buf, sysinfo.freq_ddrbus2));
1024 }
Mingkai Hu0e58b512015-10-26 19:47:50 +08001025#endif
1026 puts("\n");
1027
1028 /*
1029 * Display the RCW, so that no one gets confused as to what RCW
1030 * we're actually using for this boot.
1031 */
1032 puts("Reset Configuration Word (RCW):");
1033 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
1034 rcw = gur_in32(&gur->rcwsr[i]);
1035 if ((i % 4) == 0)
1036 printf("\n %08x:", i * 4);
1037 printf(" %08x", rcw);
1038 }
1039 puts("\n");
1040
1041 return 0;
1042}
1043#endif
1044
1045#ifdef CONFIG_FSL_ESDHC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001046int cpu_mmc_init(struct bd_info *bis)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001047{
1048 return fsl_esdhc_mmc_init(bis);
1049}
1050#endif
1051
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001052int cpu_eth_init(struct bd_info *bis)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001053{
1054 int error = 0;
1055
Santan Kumar1afa9002017-05-05 15:42:29 +05301056#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001057 error = fsl_mc_ldpaa_init(bis);
1058#endif
Shaohui Xie04643262015-10-26 19:47:54 +08001059#ifdef CONFIG_FMAN_ENET
1060 fm_standard_init(bis);
1061#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001062 return error;
1063}
1064
Yuantian Tangaec3b142017-04-19 13:27:39 +08001065static inline int check_psci(void)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001066{
Yuantian Tangaec3b142017-04-19 13:27:39 +08001067 unsigned int psci_ver;
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301068
Yuantian Tangaec3b142017-04-19 13:27:39 +08001069 psci_ver = sec_firmware_support_psci_version();
1070 if (psci_ver == PSCI_INVALID_VER)
1071 return 1;
1072
1073 return 0;
1074}
1075
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301076static void config_core_prefetch(void)
1077{
1078 char *buf = NULL;
1079 char buffer[HWCONFIG_BUFFER_SIZE];
1080 const char *prefetch_arg = NULL;
1081 size_t arglen;
1082 unsigned int mask;
1083 struct pt_regs regs;
1084
1085 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
1086 buf = buffer;
Pankaj Bansal6c772772019-10-31 05:41:09 +00001087 else
1088 return;
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301089
1090 prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable",
1091 &arglen, buf);
1092
1093 if (prefetch_arg) {
1094 mask = simple_strtoul(prefetch_arg, NULL, 0) & 0xff;
1095 if (mask & 0x1) {
1096 printf("Core0 prefetch can't be disabled\n");
1097 return;
1098 }
1099
1100#define SIP_PREFETCH_DISABLE_64 0xC200FF13
1101 regs.regs[0] = SIP_PREFETCH_DISABLE_64;
1102 regs.regs[1] = mask;
1103 smc_call(&regs);
1104
1105 if (regs.regs[0])
1106 printf("Prefetch disable config failed for mask ");
1107 else
1108 printf("Prefetch disable config passed for mask ");
1109 printf("0x%x\n", mask);
1110 }
1111}
1112
Alex Marginean762a2682019-11-27 17:19:32 +02001113#ifdef CONFIG_PCIE_ECAM_GENERIC
1114__weak void set_ecam_icids(void)
1115{
1116}
1117#endif
1118
Yuantian Tangaec3b142017-04-19 13:27:39 +08001119int arch_early_init_r(void)
1120{
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301121#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
Priyanka Jain823e0422017-02-14 10:34:31 +05301122 u32 svr_dev_id;
1123 /*
1124 * erratum A009635 is valid only for LS2080A SoC and
1125 * its personalitiesi
1126 */
Wenbin song5d8a61c2017-12-04 12:18:28 +08001127 svr_dev_id = get_svr();
1128 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
Priyanka Jain823e0422017-02-14 10:34:31 +05301129 erratum_a009635();
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301130#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +08001131#if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
1132 erratum_a009942_check_cpo();
1133#endif
Yuantian Tangaec3b142017-04-19 13:27:39 +08001134 if (check_psci()) {
1135 debug("PSCI: PSCI does not exist.\n");
1136
1137 /* if PSCI does not exist, boot secondary cores here */
1138 if (fsl_layerscape_wake_seconday_cores())
Hou Zhiqiang21c4d552016-06-28 20:18:15 +08001139 printf("Did not wake secondary cores\n");
1140 }
Mingkai Hu0e58b512015-10-26 19:47:50 +08001141
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301142 config_core_prefetch();
1143
Mingkai Hu0e58b512015-10-26 19:47:50 +08001144#ifdef CONFIG_SYS_HAS_SERDES
1145 fsl_serdes_init();
1146#endif
Pankaj Bansalcc840622018-10-29 11:28:26 +00001147#ifdef CONFIG_SYS_FSL_HAS_RGMII
1148 /* some dpmacs in armv8a based freescale layerscape SOCs can be
1149 * configured via both serdes(sgmii, xfi, xlaui etc) bits and via
1150 * EC*_PMUX(rgmii) bits in RCW.
1151 * e.g. dpmac 17 and 18 in LX2160A can be configured as SGMII from
1152 * serdes bits and as RGMII via EC1_PMUX/EC2_PMUX bits
Razvan Ionut Cirjan912f2d82020-10-23 16:20:38 +05301153 * Now if a dpmac is enabled as RGMII through ECx_PMUX then it takes
1154 * precedence over SerDes protocol. i.e. in LX2160A if we select serdes
1155 * protocol that configures dpmac17 as SGMII and set the EC1_PMUX as
1156 * RGMII, then the dpmac is RGMII and not SGMII.
Pankaj Bansalcc840622018-10-29 11:28:26 +00001157 *
Razvan Ionut Cirjan912f2d82020-10-23 16:20:38 +05301158 * Therefore, even thought fsl_rgmii_init is after fsl_serdes_init
1159 * function of SOC, the dpmac will be enabled as RGMII even if it was
1160 * also enabled before as SGMII. If ECx_PMUX is not configured for
1161 * RGMII, DPMAC will remain configured as SGMII from fsl_serdes_init().
Pankaj Bansalcc840622018-10-29 11:28:26 +00001162 */
1163 fsl_rgmii_init();
1164#endif
Shaohui Xie04643262015-10-26 19:47:54 +08001165#ifdef CONFIG_FMAN_ENET
Madalin Bucurb76b0a62020-04-23 16:25:19 +03001166#ifndef CONFIG_DM_ETH
Shaohui Xie04643262015-10-26 19:47:54 +08001167 fman_enet_init();
1168#endif
Madalin Bucurb76b0a62020-04-23 16:25:19 +03001169#endif
Ahmed Mansouraa270b42017-12-15 16:01:00 -05001170#ifdef CONFIG_SYS_DPAA_QBMAN
1171 setup_qbman_portals();
1172#endif
Alex Marginean762a2682019-11-27 17:19:32 +02001173#ifdef CONFIG_PCIE_ECAM_GENERIC
1174 set_ecam_icids();
1175#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001176 return 0;
1177}
1178
1179int timer_init(void)
1180{
1181 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
1182#ifdef CONFIG_FSL_LSCH3
1183 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
1184#endif
Thomas Schaefercbec2b82019-08-08 16:00:30 +08001185#if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
1186 defined(CONFIG_ARCH_LS1028A)
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001187 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301188 u32 svr_dev_id;
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001189#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001190#ifdef COUNTER_FREQUENCY_REAL
1191 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
1192
1193 /* Update with accurate clock frequency */
York Sune6b871e2017-05-15 08:51:59 -07001194 if (current_el() == 3)
1195 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
Mingkai Hu0e58b512015-10-26 19:47:50 +08001196#endif
1197
1198#ifdef CONFIG_FSL_LSCH3
1199 /* Enable timebase for all clusters.
1200 * It is safe to do so even some clusters are not enabled.
1201 */
1202 out_le32(cltbenr, 0xf);
1203#endif
1204
Thomas Schaefercbec2b82019-08-08 16:00:30 +08001205#if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
1206 defined(CONFIG_ARCH_LS1028A)
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001207 /*
1208 * In certain Layerscape SoCs, the clock for each core's
1209 * has an enable bit in the PMU Physical Core Time Base Enable
1210 * Register (PCTBENR), which allows the watchdog to operate.
1211 */
1212 setbits_le32(pctbenr, 0xff);
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301213 /*
1214 * For LS2080A SoC and its personalities, timer controller
1215 * offset is different
1216 */
Wenbin song5d8a61c2017-12-04 12:18:28 +08001217 svr_dev_id = get_svr();
1218 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301219 cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
1220
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001221#endif
1222
Mingkai Hu0e58b512015-10-26 19:47:50 +08001223 /* Enable clock for timer
1224 * This is a global setting.
1225 */
1226 out_le32(cntcr, 0x1);
1227
1228 return 0;
1229}
1230
Alexander Graf12be31c2016-11-17 01:03:01 +01001231__efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
1232
1233void __efi_runtime reset_cpu(ulong addr)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001234{
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +05301235#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Meenakshi Aggarwal95a805b2020-09-09 14:06:05 +05301236 /* clear the RST_REQ_MSK and SW_RST_REQ */
1237 out_le32(rstcr, 0x0);
1238
1239 /* initiate the sw reset request */
1240 out_le32(rstcr, 0x1);
Priyanka Jainef76b2e2018-10-29 09:17:09 +00001241#else
Meenakshi Aggarwal95a805b2020-09-09 14:06:05 +05301242 u32 val;
1243
Mingkai Hu0e58b512015-10-26 19:47:50 +08001244 /* Raise RESET_REQ_B */
1245 val = scfg_in32(rstcr);
1246 val |= 0x02;
1247 scfg_out32(rstcr, val);
Priyanka Jainef76b2e2018-10-29 09:17:09 +00001248#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001249}
York Sun928b6812015-12-07 11:08:58 -08001250
Mathew McBride8f137732019-10-18 14:27:54 +11001251#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_PSCI_RESET)
Alexander Graf12be31c2016-11-17 01:03:01 +01001252
1253void __efi_runtime EFIAPI efi_reset_system(
1254 enum efi_reset_type reset_type,
1255 efi_status_t reset_status,
1256 unsigned long data_size, void *reset_data)
1257{
1258 switch (reset_type) {
1259 case EFI_RESET_COLD:
1260 case EFI_RESET_WARM:
Heinrich Schuchardt450d4c82018-02-06 22:00:22 +01001261 case EFI_RESET_PLATFORM_SPECIFIC:
Alexander Graf12be31c2016-11-17 01:03:01 +01001262 reset_cpu(0);
1263 break;
1264 case EFI_RESET_SHUTDOWN:
1265 /* Nothing we can do */
1266 break;
1267 }
1268
1269 while (1) { }
1270}
1271
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +01001272efi_status_t efi_reset_system_init(void)
Alexander Graf12be31c2016-11-17 01:03:01 +01001273{
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +01001274 return efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
Alexander Graf12be31c2016-11-17 01:03:01 +01001275}
1276
1277#endif
1278
York Sun2db54082017-09-07 10:12:32 -07001279/*
1280 * Calculate reserved memory with given memory bank
1281 * Return aligned memory size on success
1282 * Return (ram_size + needed size) for failure
1283 */
York Sun928b6812015-12-07 11:08:58 -08001284phys_size_t board_reserve_ram_top(phys_size_t ram_size)
1285{
1286 phys_size_t ram_top = ram_size;
1287
Santan Kumar1afa9002017-05-05 15:42:29 +05301288#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun2db54082017-09-07 10:12:32 -07001289 ram_top = mc_get_dram_block_size();
1290 if (ram_top > ram_size)
1291 return ram_size + ram_top;
1292
1293 ram_top = ram_size - ram_top;
York Sun4de24ef2017-03-06 09:02:28 -08001294 /* The start address of MC reserved memory needs to be aligned. */
York Sun928b6812015-12-07 11:08:58 -08001295 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
1296#endif
York Sun4de24ef2017-03-06 09:02:28 -08001297
1298 return ram_size - ram_top;
1299}
1300
1301phys_size_t get_effective_memsize(void)
1302{
1303 phys_size_t ea_size, rem = 0;
1304
1305 /*
1306 * For ARMv8 SoCs, DDR memory is split into two or three regions. The
Sumit Garged0deea2017-10-04 03:20:49 +05301307 * first region is 2GB space at 0x8000_0000. Secure memory needs to
1308 * allocated from first region. If the memory extends to the second
1309 * region (or the third region if applicable), Management Complex (MC)
1310 * memory should be put into the highest region, i.e. the end of DDR
1311 * memory. CONFIG_MAX_MEM_MAPPED is set to the size of first region so
1312 * U-Boot doesn't relocate itself into higher address. Should DDR be
1313 * configured to skip the first region, this function needs to be
1314 * adjusted.
York Sun4de24ef2017-03-06 09:02:28 -08001315 */
1316 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
1317 ea_size = CONFIG_MAX_MEM_MAPPED;
1318 rem = gd->ram_size - ea_size;
1319 } else {
1320 ea_size = gd->ram_size;
1321 }
1322
1323#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1324 /* Check if we have enough space for secure memory */
Sumit Garged0deea2017-10-04 03:20:49 +05301325 if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE)
1326 ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
1327 else
1328 printf("Error: No enough space for secure memory.\n");
York Sun4de24ef2017-03-06 09:02:28 -08001329#endif
1330 /* Check if we have enough memory for MC */
1331 if (rem < board_reserve_ram_top(rem)) {
1332 /* Not enough memory in high region to reserve */
York Sun2db54082017-09-07 10:12:32 -07001333 if (ea_size > board_reserve_ram_top(ea_size))
1334 ea_size -= board_reserve_ram_top(ea_size);
York Sun4de24ef2017-03-06 09:02:28 -08001335 else
1336 printf("Error: No enough space for reserved memory.\n");
1337 }
1338
1339 return ea_size;
1340}
1341
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001342#ifdef CONFIG_TFABOOT
1343phys_size_t tfa_get_dram_size(void)
1344{
1345 struct pt_regs regs;
1346 phys_size_t dram_size = 0;
1347
1348 regs.regs[0] = SMC_DRAM_BANK_INFO;
1349 regs.regs[1] = -1;
1350
1351 smc_call(&regs);
1352 if (regs.regs[0])
1353 return 0;
1354
1355 dram_size = regs.regs[1];
1356 return dram_size;
1357}
1358
1359static int tfa_dram_init_banksize(void)
1360{
1361 int i = 0, ret = 0;
1362 struct pt_regs regs;
1363 phys_size_t dram_size = tfa_get_dram_size();
1364
1365 debug("dram_size %llx\n", dram_size);
1366
1367 if (!dram_size)
1368 return -EINVAL;
1369
1370 do {
1371 regs.regs[0] = SMC_DRAM_BANK_INFO;
1372 regs.regs[1] = i;
1373
1374 smc_call(&regs);
1375 if (regs.regs[0]) {
1376 ret = -EINVAL;
1377 break;
1378 }
1379
1380 debug("bank[%d]: start %lx, size %lx\n", i, regs.regs[1],
1381 regs.regs[2]);
1382 gd->bd->bi_dram[i].start = regs.regs[1];
1383 gd->bd->bi_dram[i].size = regs.regs[2];
1384
1385 dram_size -= gd->bd->bi_dram[i].size;
1386
1387 i++;
1388 } while (dram_size);
1389
1390 if (i > 0)
1391 ret = 0;
1392
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001393#if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD)
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001394 /* Assign memory for MC */
1395#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1396 if (gd->bd->bi_dram[2].size >=
1397 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
1398 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
1399 gd->bd->bi_dram[2].size -
1400 board_reserve_ram_top(gd->bd->bi_dram[2].size);
1401 } else
1402#endif
1403 {
1404 if (gd->bd->bi_dram[1].size >=
1405 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
1406 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
1407 gd->bd->bi_dram[1].size -
1408 board_reserve_ram_top(gd->bd->bi_dram[1].size);
1409 } else if (gd->bd->bi_dram[0].size >
1410 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
1411 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
1412 gd->bd->bi_dram[0].size -
1413 board_reserve_ram_top(gd->bd->bi_dram[0].size);
1414 }
1415 }
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001416#endif /* CONFIG_RESV_RAM */
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001417
1418 return ret;
1419}
1420#endif
1421
Simon Glass2f949c32017-03-31 08:40:32 -06001422int dram_init_banksize(void)
York Sun4de24ef2017-03-06 09:02:28 -08001423{
1424#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1425 phys_size_t dp_ddr_size;
1426#endif
1427
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001428#ifdef CONFIG_TFABOOT
1429 if (!tfa_dram_init_banksize())
1430 return 0;
1431#endif
York Sun4de24ef2017-03-06 09:02:28 -08001432 /*
1433 * gd->ram_size has the total size of DDR memory, less reserved secure
1434 * memory. The DDR extends from low region to high region(s) presuming
1435 * no hole is created with DDR configuration. gd->arch.secure_ram tracks
1436 * the location of secure memory. gd->arch.resv_ram tracks the location
York Sunc9e3e042017-09-28 08:42:12 -07001437 * of reserved memory for Management Complex (MC). Because gd->ram_size
1438 * is reduced by this function if secure memory is reserved, checking
1439 * gd->arch.secure_ram should be done to avoid running it repeatedly.
York Sun4de24ef2017-03-06 09:02:28 -08001440 */
York Sunc9e3e042017-09-28 08:42:12 -07001441
1442#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1443 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
1444 debug("No need to run again, skip %s\n", __func__);
1445
1446 return 0;
1447 }
1448#endif
1449
York Sun4de24ef2017-03-06 09:02:28 -08001450 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
1451 if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
1452 gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
1453 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
1454 gd->bd->bi_dram[1].size = gd->ram_size -
1455 CONFIG_SYS_DDR_BLOCK1_SIZE;
1456#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1457 if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
1458 gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
1459 gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
1460 CONFIG_SYS_DDR_BLOCK2_SIZE;
1461 gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
1462 }
1463#endif
1464 } else {
1465 gd->bd->bi_dram[0].size = gd->ram_size;
1466 }
1467#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
Sumit Garged0deea2017-10-04 03:20:49 +05301468 if (gd->bd->bi_dram[0].size >
1469 CONFIG_SYS_MEM_RESERVE_SECURE) {
1470 gd->bd->bi_dram[0].size -=
1471 CONFIG_SYS_MEM_RESERVE_SECURE;
1472 gd->arch.secure_ram = gd->bd->bi_dram[0].start +
1473 gd->bd->bi_dram[0].size;
York Sun4de24ef2017-03-06 09:02:28 -08001474 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
1475 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
York Sun4de24ef2017-03-06 09:02:28 -08001476 }
1477#endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
1478
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001479#if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD)
York Sun4de24ef2017-03-06 09:02:28 -08001480 /* Assign memory for MC */
1481#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1482 if (gd->bd->bi_dram[2].size >=
1483 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
1484 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
1485 gd->bd->bi_dram[2].size -
1486 board_reserve_ram_top(gd->bd->bi_dram[2].size);
1487 } else
1488#endif
1489 {
1490 if (gd->bd->bi_dram[1].size >=
1491 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
1492 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
1493 gd->bd->bi_dram[1].size -
1494 board_reserve_ram_top(gd->bd->bi_dram[1].size);
1495 } else if (gd->bd->bi_dram[0].size >
1496 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
1497 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
1498 gd->bd->bi_dram[0].size -
1499 board_reserve_ram_top(gd->bd->bi_dram[0].size);
1500 }
1501 }
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001502#endif /* CONFIG_RESV_RAM */
York Sun4de24ef2017-03-06 09:02:28 -08001503
1504#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1505#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1506#error "This SoC shouldn't have DP DDR"
1507#endif
1508 if (soc_has_dp_ddr()) {
1509 /* initialize DP-DDR here */
1510 puts("DP-DDR: ");
1511 /*
1512 * DDR controller use 0 as the base address for binding.
1513 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
1514 */
1515 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
1516 CONFIG_DP_DDR_CTRL,
1517 CONFIG_DP_DDR_NUM_CTRLS,
1518 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
1519 NULL, NULL, NULL);
1520 if (dp_ddr_size) {
1521 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
1522 gd->bd->bi_dram[2].size = dp_ddr_size;
1523 } else {
1524 puts("Not detected");
1525 }
1526 }
1527#endif
Simon Glass2f949c32017-03-31 08:40:32 -06001528
York Sunc9e3e042017-09-28 08:42:12 -07001529#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1530 debug("%s is called. gd->ram_size is reduced to %lu\n",
1531 __func__, (ulong)gd->ram_size);
1532#endif
1533
Simon Glass2f949c32017-03-31 08:40:32 -06001534 return 0;
York Sun4de24ef2017-03-06 09:02:28 -08001535}
1536
Stephen Warrend0de8062018-08-30 15:43:43 -06001537#if CONFIG_IS_ENABLED(EFI_LOADER)
York Sun4de24ef2017-03-06 09:02:28 -08001538void efi_add_known_memory(void)
1539{
1540 int i;
Michael Walle282d3862020-05-17 12:29:19 +02001541 phys_addr_t ram_start;
York Sun4de24ef2017-03-06 09:02:28 -08001542 phys_size_t ram_size;
York Sun928b6812015-12-07 11:08:58 -08001543
York Sun4de24ef2017-03-06 09:02:28 -08001544 /* Add RAM */
1545 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
1546#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1547#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1548#error "This SoC shouldn't have DP DDR"
1549#endif
1550 if (i == 2)
1551 continue; /* skip DP-DDR */
1552#endif
1553 ram_start = gd->bd->bi_dram[i].start;
1554 ram_size = gd->bd->bi_dram[i].size;
1555#ifdef CONFIG_RESV_RAM
1556 if (gd->arch.resv_ram >= ram_start &&
1557 gd->arch.resv_ram < ram_start + ram_size)
1558 ram_size = gd->arch.resv_ram - ram_start;
1559#endif
Michael Walle282d3862020-05-17 12:29:19 +02001560 efi_add_memory_map(ram_start, ram_size,
1561 EFI_CONVENTIONAL_MEMORY);
York Sun4de24ef2017-03-06 09:02:28 -08001562 }
York Sun928b6812015-12-07 11:08:58 -08001563}
York Sun4de24ef2017-03-06 09:02:28 -08001564#endif
York Sun729f2d12017-03-06 09:02:34 -08001565
1566/*
1567 * Before DDR size is known, early MMU table have DDR mapped as device memory
1568 * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
1569 * needs to be set for these mappings.
1570 * If a special case configures DDR with holes in the mapping, the holes need
1571 * to be marked as invalid. This is not implemented in this function.
1572 */
1573void update_early_mmu_table(void)
1574{
1575 if (!gd->arch.tlb_addr)
1576 return;
1577
1578 if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
1579 mmu_change_region_attr(
1580 CONFIG_SYS_SDRAM_BASE,
1581 gd->ram_size,
1582 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1583 PTE_BLOCK_OUTER_SHARE |
1584 PTE_BLOCK_NS |
1585 PTE_TYPE_VALID);
1586 } else {
1587 mmu_change_region_attr(
1588 CONFIG_SYS_SDRAM_BASE,
1589 CONFIG_SYS_DDR_BLOCK1_SIZE,
1590 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1591 PTE_BLOCK_OUTER_SHARE |
1592 PTE_BLOCK_NS |
1593 PTE_TYPE_VALID);
1594#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1595#ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
1596#error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
1597#endif
1598 if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
1599 CONFIG_SYS_DDR_BLOCK2_SIZE) {
1600 mmu_change_region_attr(
1601 CONFIG_SYS_DDR_BLOCK2_BASE,
1602 CONFIG_SYS_DDR_BLOCK2_SIZE,
1603 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1604 PTE_BLOCK_OUTER_SHARE |
1605 PTE_BLOCK_NS |
1606 PTE_TYPE_VALID);
1607 mmu_change_region_attr(
1608 CONFIG_SYS_DDR_BLOCK3_BASE,
1609 gd->ram_size -
1610 CONFIG_SYS_DDR_BLOCK1_SIZE -
1611 CONFIG_SYS_DDR_BLOCK2_SIZE,
1612 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1613 PTE_BLOCK_OUTER_SHARE |
1614 PTE_BLOCK_NS |
1615 PTE_TYPE_VALID);
1616 } else
1617#endif
1618 {
1619 mmu_change_region_attr(
1620 CONFIG_SYS_DDR_BLOCK2_BASE,
1621 gd->ram_size -
1622 CONFIG_SYS_DDR_BLOCK1_SIZE,
1623 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1624 PTE_BLOCK_OUTER_SHARE |
1625 PTE_BLOCK_NS |
1626 PTE_TYPE_VALID);
1627 }
1628 }
1629}
1630
1631__weak int dram_init(void)
1632{
Simon Glass0e0ac202017-04-06 12:47:04 -06001633 fsl_initdram();
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +00001634#if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
1635 defined(CONFIG_SPL_BUILD)
York Sun729f2d12017-03-06 09:02:34 -08001636 /* This will break-before-make MMU for DDR */
1637 update_early_mmu_table();
1638#endif
1639
1640 return 0;
1641}
Alex Marginean47568ce2020-01-11 01:05:40 +02001642
1643#ifdef CONFIG_ARCH_MISC_INIT
1644__weak int serdes_misc_init(void)
1645{
1646 return 0;
1647}
1648
1649int arch_misc_init(void)
1650{
1651 serdes_misc_init();
1652
1653 return 0;
1654}
1655#endif