blob: 1a359d060e82e53f78d788704832fdd6e968e1d2 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080018#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060019#include <asm/ptrace.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090020#include <linux/errno.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080021#include <asm/system.h>
Joe Hershberger8f454d92018-07-16 15:33:51 -050022#include <fm_eth.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080023#include <asm/armv8/mmu.h>
24#include <asm/io.h>
25#include <asm/arch/fsl_serdes.h>
26#include <asm/arch/soc.h>
27#include <asm/arch/cpu.h>
28#include <asm/arch/speed.h>
Ashish Kumar11234062017-08-11 11:09:14 +053029#include <fsl_immap.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080030#include <asm/arch/mp.h>
Alexander Graf12be31c2016-11-17 01:03:01 +010031#include <efi_loader.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080032#include <fsl-mc/fsl_mc.h>
33#ifdef CONFIG_FSL_ESDHC
34#include <fsl_esdhc.h>
35#endif
Hou Zhiqiang21c4d552016-06-28 20:18:15 +080036#include <asm/armv8/sec_firmware.h>
Shengzhou Liu15875a52016-11-21 11:36:48 +080037#ifdef CONFIG_SYS_FSL_DDR
38#include <fsl_ddr.h>
39#endif
Simon Glass243182c2017-05-17 08:23:06 -060040#include <asm/arch/clock.h>
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +053041#include <hwconfig.h>
Ahmed Mansouraa270b42017-12-15 16:01:00 -050042#include <fsl_qbman.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080043
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000044#ifdef CONFIG_TFABOOT
Simon Glass9d1f6192019-08-02 09:44:25 -060045#include <env_internal.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000046#ifdef CONFIG_CHAIN_OF_TRUST
47#include <fsl_validate.h>
48#endif
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000049#endif
Simon Glasscaefa322019-11-14 12:57:31 -070050#include <linux/mii.h>
Rajesh Bhagat583da8b2018-11-05 18:01:42 +000051
Mingkai Hu0e58b512015-10-26 19:47:50 +080052DECLARE_GLOBAL_DATA_PTR;
53
York Sunef4cef92018-11-05 18:01:06 +000054static struct cpu_type cpu_type_list[] = {
55 CPU_TYPE_ENTRY(LS2080A, LS2080A, 8),
56 CPU_TYPE_ENTRY(LS2085A, LS2085A, 8),
57 CPU_TYPE_ENTRY(LS2045A, LS2045A, 4),
58 CPU_TYPE_ENTRY(LS2088A, LS2088A, 8),
59 CPU_TYPE_ENTRY(LS2084A, LS2084A, 8),
60 CPU_TYPE_ENTRY(LS2048A, LS2048A, 4),
61 CPU_TYPE_ENTRY(LS2044A, LS2044A, 4),
62 CPU_TYPE_ENTRY(LS2081A, LS2081A, 8),
63 CPU_TYPE_ENTRY(LS2041A, LS2041A, 4),
64 CPU_TYPE_ENTRY(LS1043A, LS1043A, 4),
Hou Zhiqiangb9aedf92018-12-20 06:31:17 +000065 CPU_TYPE_ENTRY(LS1043A, LS1043A_P23, 4),
York Sunef4cef92018-11-05 18:01:06 +000066 CPU_TYPE_ENTRY(LS1023A, LS1023A, 2),
Hou Zhiqiangb9aedf92018-12-20 06:31:17 +000067 CPU_TYPE_ENTRY(LS1023A, LS1023A_P23, 2),
York Sunef4cef92018-11-05 18:01:06 +000068 CPU_TYPE_ENTRY(LS1046A, LS1046A, 4),
69 CPU_TYPE_ENTRY(LS1026A, LS1026A, 2),
70 CPU_TYPE_ENTRY(LS2040A, LS2040A, 4),
71 CPU_TYPE_ENTRY(LS1012A, LS1012A, 1),
Yuantian Tangf463d752019-09-18 16:50:52 +080072 CPU_TYPE_ENTRY(LS1017A, LS1017A, 1),
73 CPU_TYPE_ENTRY(LS1018A, LS1018A, 1),
74 CPU_TYPE_ENTRY(LS1027A, LS1027A, 2),
Yuantian Tang4aefa162019-04-10 16:43:33 +080075 CPU_TYPE_ENTRY(LS1028A, LS1028A, 2),
York Sunef4cef92018-11-05 18:01:06 +000076 CPU_TYPE_ENTRY(LS1088A, LS1088A, 8),
77 CPU_TYPE_ENTRY(LS1084A, LS1084A, 8),
78 CPU_TYPE_ENTRY(LS1048A, LS1048A, 4),
79 CPU_TYPE_ENTRY(LS1044A, LS1044A, 4),
Priyanka Jainef76b2e2018-10-29 09:17:09 +000080 CPU_TYPE_ENTRY(LX2160A, LX2160A, 16),
81 CPU_TYPE_ENTRY(LX2120A, LX2120A, 12),
82 CPU_TYPE_ENTRY(LX2080A, LX2080A, 8),
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +053083 CPU_TYPE_ENTRY(LX2162A, LX2162A, 16),
84 CPU_TYPE_ENTRY(LX2122A, LX2122A, 12),
85 CPU_TYPE_ENTRY(LX2082A, LX2082A, 8),
York Sunef4cef92018-11-05 18:01:06 +000086};
87
88#define EARLY_PGTABLE_SIZE 0x5000
89static struct mm_region early_map[] = {
90#ifdef CONFIG_FSL_LSCH3
91 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
92 CONFIG_SYS_FSL_CCSR_SIZE,
93 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
94 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
95 },
96 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
97 SYS_FSL_OCRAM_SPACE_SIZE,
98 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
99 },
100 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
101 CONFIG_SYS_FSL_QSPI_SIZE1,
102 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE},
103#ifdef CONFIG_FSL_IFC
104 /* For IFC Region #1, only the first 4MB is cache-enabled */
105 { CONFIG_SYS_FSL_IFC_BASE1, CONFIG_SYS_FSL_IFC_BASE1,
106 CONFIG_SYS_FSL_IFC_SIZE1_1,
107 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
108 },
109 { CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
110 CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
111 CONFIG_SYS_FSL_IFC_SIZE1 - CONFIG_SYS_FSL_IFC_SIZE1_1,
112 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
113 },
114 { CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FSL_IFC_BASE1,
115 CONFIG_SYS_FSL_IFC_SIZE1,
116 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
117 },
118#endif
119 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
120 CONFIG_SYS_FSL_DRAM_SIZE1,
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +0000121#if defined(CONFIG_TFABOOT) || \
122 (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD))
York Sunef4cef92018-11-05 18:01:06 +0000123 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
124#else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
125 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
126#endif
127 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
128 },
129#ifdef CONFIG_FSL_IFC
130 /* Map IFC region #2 up to CONFIG_SYS_FLASH_BASE for NAND boot */
131 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
132 CONFIG_SYS_FLASH_BASE - CONFIG_SYS_FSL_IFC_BASE2,
133 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
134 },
135#endif
136 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
137 CONFIG_SYS_FSL_DCSR_SIZE,
138 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
139 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
140 },
141 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
142 CONFIG_SYS_FSL_DRAM_SIZE2,
143 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
144 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
145 },
Priyanka Jain88c25662018-10-29 09:11:29 +0000146#ifdef CONFIG_SYS_FSL_DRAM_BASE3
147 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
148 CONFIG_SYS_FSL_DRAM_SIZE3,
149 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
150 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
151 },
152#endif
York Sunef4cef92018-11-05 18:01:06 +0000153#elif defined(CONFIG_FSL_LSCH2)
154 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
155 CONFIG_SYS_FSL_CCSR_SIZE,
156 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
157 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
158 },
159 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
160 SYS_FSL_OCRAM_SPACE_SIZE,
161 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
162 },
163 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
164 CONFIG_SYS_FSL_DCSR_SIZE,
165 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
166 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
167 },
168 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
169 CONFIG_SYS_FSL_QSPI_SIZE,
170 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
171 },
172#ifdef CONFIG_FSL_IFC
173 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
174 CONFIG_SYS_FSL_IFC_SIZE,
175 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
176 },
177#endif
178 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
179 CONFIG_SYS_FSL_DRAM_SIZE1,
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +0000180#if defined(CONFIG_TFABOOT) || \
181 (defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD))
York Sunef4cef92018-11-05 18:01:06 +0000182 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
183#else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
184 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
185#endif
186 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
187 },
188 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
189 CONFIG_SYS_FSL_DRAM_SIZE2,
190 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
191 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
192 },
193#endif
194 {}, /* list terminator */
195};
196
197static struct mm_region final_map[] = {
198#ifdef CONFIG_FSL_LSCH3
199 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
200 CONFIG_SYS_FSL_CCSR_SIZE,
201 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
202 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
203 },
204 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
205 SYS_FSL_OCRAM_SPACE_SIZE,
206 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
207 },
208 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
209 CONFIG_SYS_FSL_DRAM_SIZE1,
210 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
211 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
212 },
213 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
214 CONFIG_SYS_FSL_QSPI_SIZE1,
215 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
216 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
217 },
218 { CONFIG_SYS_FSL_QSPI_BASE2, CONFIG_SYS_FSL_QSPI_BASE2,
219 CONFIG_SYS_FSL_QSPI_SIZE2,
220 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
221 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
222 },
223#ifdef CONFIG_FSL_IFC
224 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
225 CONFIG_SYS_FSL_IFC_SIZE2,
226 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
227 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
228 },
229#endif
230 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
231 CONFIG_SYS_FSL_DCSR_SIZE,
232 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
233 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
234 },
235 { CONFIG_SYS_FSL_MC_BASE, CONFIG_SYS_FSL_MC_BASE,
236 CONFIG_SYS_FSL_MC_SIZE,
237 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
238 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
239 },
240 { CONFIG_SYS_FSL_NI_BASE, CONFIG_SYS_FSL_NI_BASE,
241 CONFIG_SYS_FSL_NI_SIZE,
242 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
243 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
244 },
245 /* For QBMAN portal, only the first 64MB is cache-enabled */
246 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
247 CONFIG_SYS_FSL_QBMAN_SIZE_1,
248 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
249 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_NS
250 },
251 { CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
252 CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
253 CONFIG_SYS_FSL_QBMAN_SIZE - CONFIG_SYS_FSL_QBMAN_SIZE_1,
254 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
255 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
256 },
257 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
258 CONFIG_SYS_PCIE1_PHYS_SIZE,
259 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
260 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
261 },
262 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
263 CONFIG_SYS_PCIE2_PHYS_SIZE,
264 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
265 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
266 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800267#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000268 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
269 CONFIG_SYS_PCIE3_PHYS_SIZE,
270 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
271 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
272 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800273#endif
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000274#ifdef CONFIG_SYS_PCIE4_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000275 { CONFIG_SYS_PCIE4_PHYS_ADDR, CONFIG_SYS_PCIE4_PHYS_ADDR,
276 CONFIG_SYS_PCIE4_PHYS_SIZE,
277 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
278 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
279 },
280#endif
Hou Zhiqiangd08f9702019-04-08 10:15:41 +0000281#ifdef SYS_PCIE5_PHYS_ADDR
282 { SYS_PCIE5_PHYS_ADDR, SYS_PCIE5_PHYS_ADDR,
283 SYS_PCIE5_PHYS_SIZE,
284 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
285 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
286 },
287#endif
288#ifdef SYS_PCIE6_PHYS_ADDR
289 { SYS_PCIE6_PHYS_ADDR, SYS_PCIE6_PHYS_ADDR,
290 SYS_PCIE6_PHYS_SIZE,
291 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
292 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
293 },
294#endif
York Sunef4cef92018-11-05 18:01:06 +0000295 { CONFIG_SYS_FSL_WRIOP1_BASE, CONFIG_SYS_FSL_WRIOP1_BASE,
296 CONFIG_SYS_FSL_WRIOP1_SIZE,
297 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
298 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
299 },
300 { CONFIG_SYS_FSL_AIOP1_BASE, CONFIG_SYS_FSL_AIOP1_BASE,
301 CONFIG_SYS_FSL_AIOP1_SIZE,
302 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
303 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
304 },
305 { CONFIG_SYS_FSL_PEBUF_BASE, CONFIG_SYS_FSL_PEBUF_BASE,
306 CONFIG_SYS_FSL_PEBUF_SIZE,
307 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
308 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
309 },
310 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
311 CONFIG_SYS_FSL_DRAM_SIZE2,
312 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
313 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
314 },
Priyanka Jain88c25662018-10-29 09:11:29 +0000315#ifdef CONFIG_SYS_FSL_DRAM_BASE3
316 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
317 CONFIG_SYS_FSL_DRAM_SIZE3,
318 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
319 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
320 },
321#endif
York Sunef4cef92018-11-05 18:01:06 +0000322#elif defined(CONFIG_FSL_LSCH2)
323 { CONFIG_SYS_FSL_BOOTROM_BASE, CONFIG_SYS_FSL_BOOTROM_BASE,
324 CONFIG_SYS_FSL_BOOTROM_SIZE,
325 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
326 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
327 },
328 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
329 CONFIG_SYS_FSL_CCSR_SIZE,
330 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
331 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
332 },
333 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
334 SYS_FSL_OCRAM_SPACE_SIZE,
335 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
336 },
337 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
338 CONFIG_SYS_FSL_DCSR_SIZE,
339 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
340 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
341 },
342 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
343 CONFIG_SYS_FSL_QSPI_SIZE,
344 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
345 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
346 },
347#ifdef CONFIG_FSL_IFC
348 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
349 CONFIG_SYS_FSL_IFC_SIZE,
350 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
351 },
352#endif
353 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
354 CONFIG_SYS_FSL_DRAM_SIZE1,
355 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
356 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
357 },
358 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
359 CONFIG_SYS_FSL_QBMAN_SIZE,
360 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
361 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
362 },
363 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
364 CONFIG_SYS_FSL_DRAM_SIZE2,
365 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
366 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
367 },
368 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
369 CONFIG_SYS_PCIE1_PHYS_SIZE,
370 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
371 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
372 },
373 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
374 CONFIG_SYS_PCIE2_PHYS_SIZE,
375 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
376 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
377 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800378#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
York Sunef4cef92018-11-05 18:01:06 +0000379 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
380 CONFIG_SYS_PCIE3_PHYS_SIZE,
381 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
382 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
383 },
Yuantian Tang4aefa162019-04-10 16:43:33 +0800384#endif
York Sunef4cef92018-11-05 18:01:06 +0000385 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
386 CONFIG_SYS_FSL_DRAM_SIZE3,
387 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
388 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
389 },
390#endif
391#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
392 {}, /* space holder for secure mem */
393#endif
394 {},
395};
396
York Sun9da8f502016-06-24 16:46:23 -0700397struct mm_region *mem_map = early_map;
Alexander Grafce0a64e2016-03-04 01:09:54 +0100398
Mingkai Hu0e58b512015-10-26 19:47:50 +0800399void cpu_name(char *name)
400{
401 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
402 unsigned int i, svr, ver;
403
404 svr = gur_in32(&gur->svr);
405 ver = SVR_SOC_VER(svr);
406
407 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
408 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
409 strcpy(name, cpu_type_list[i].name);
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530410#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Priyanka Jainef76b2e2018-10-29 09:17:09 +0000411 if (IS_C_PROCESSOR(svr))
412 strcat(name, "C");
413#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +0800414
415 if (IS_E_PROCESSOR(svr))
416 strcat(name, "E");
Wenbin Song863a33a2016-09-13 16:13:54 +0800417
418 sprintf(name + strlen(name), " Rev%d.%d",
419 SVR_MAJ(svr), SVR_MIN(svr));
Mingkai Hu0e58b512015-10-26 19:47:50 +0800420 break;
421 }
422
423 if (i == ARRAY_SIZE(cpu_type_list))
424 strcpy(name, "unknown");
425}
426
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400427#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Mingkai Hu0e58b512015-10-26 19:47:50 +0800428/*
429 * To start MMU before DDR is available, we create MMU table in SRAM.
430 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
431 * levels of translation tables here to cover 40-bit address space.
432 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
York Sun9da8f502016-06-24 16:46:23 -0700433 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
434 * Note, the debug print in cache_v8.c is not usable for debugging
435 * these early MMU tables because UART is not yet available.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800436 */
437static inline void early_mmu_setup(void)
438{
York Sun9da8f502016-06-24 16:46:23 -0700439 unsigned int el = current_el();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800440
York Sun9da8f502016-06-24 16:46:23 -0700441 /* global data is already setup, no allocation yet */
Pankit Gargc4d39eb2018-11-05 18:01:28 +0000442 if (el == 3)
443 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
444 else
445 gd->arch.tlb_addr = CONFIG_SYS_DDR_SDRAM_BASE;
York Sun9da8f502016-06-24 16:46:23 -0700446 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
447 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800448
York Sun9da8f502016-06-24 16:46:23 -0700449 /* Create early page tables */
450 setup_pgtables();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800451
York Sun9da8f502016-06-24 16:46:23 -0700452 /* point TTBR to the new table */
453 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
454 get_tcr(el, NULL, NULL) &
455 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
Mingkai Hu0e58b512015-10-26 19:47:50 +0800456 MEMORY_ATTRIBUTES);
York Sun9da8f502016-06-24 16:46:23 -0700457
Mingkai Hu0e58b512015-10-26 19:47:50 +0800458 set_sctlr(get_sctlr() | CR_M);
459}
460
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800461static void fix_pcie_mmu_map(void)
462{
York Sun4ce6fbf2017-03-27 11:41:01 -0700463#ifdef CONFIG_ARCH_LS2080A
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800464 unsigned int i;
465 u32 svr, ver;
466 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
467
468 svr = gur_in32(&gur->svr);
469 ver = SVR_SOC_VER(svr);
470
471 /* Fix PCIE base and size for LS2088A */
472 if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
Priyanka Jain2b361782017-04-27 15:08:06 +0530473 (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
474 (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800475 for (i = 0; i < ARRAY_SIZE(final_map); i++) {
476 switch (final_map[i].phys) {
477 case CONFIG_SYS_PCIE1_PHYS_ADDR:
478 final_map[i].phys = 0x2000000000ULL;
479 final_map[i].virt = 0x2000000000ULL;
480 final_map[i].size = 0x800000000ULL;
481 break;
482 case CONFIG_SYS_PCIE2_PHYS_ADDR:
483 final_map[i].phys = 0x2800000000ULL;
484 final_map[i].virt = 0x2800000000ULL;
485 final_map[i].size = 0x800000000ULL;
486 break;
Yuantian Tang4aefa162019-04-10 16:43:33 +0800487#ifdef CONFIG_SYS_PCIE3_PHYS_ADDR
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800488 case CONFIG_SYS_PCIE3_PHYS_ADDR:
489 final_map[i].phys = 0x3000000000ULL;
490 final_map[i].virt = 0x3000000000ULL;
491 final_map[i].size = 0x800000000ULL;
492 break;
Yuantian Tang4aefa162019-04-10 16:43:33 +0800493#endif
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000494#ifdef CONFIG_SYS_PCIE4_PHYS_ADDR
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800495 case CONFIG_SYS_PCIE4_PHYS_ADDR:
496 final_map[i].phys = 0x3800000000ULL;
497 final_map[i].virt = 0x3800000000ULL;
498 final_map[i].size = 0x800000000ULL;
499 break;
Hou Zhiqiangd5d1ce32019-04-08 10:15:32 +0000500#endif
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800501 default:
502 break;
503 }
504 }
505 }
506#endif
507}
508
Mingkai Hu0e58b512015-10-26 19:47:50 +0800509/*
510 * The final tables look similar to early tables, but different in detail.
511 * These tables are in DRAM. Sub tables are added to enable cache for
512 * QBMan and OCRAM.
513 *
York Sun1ef95cc2016-06-24 16:46:18 -0700514 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
515 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800516 */
517static inline void final_mmu_setup(void)
518{
York Sun9da8f502016-06-24 16:46:23 -0700519 u64 tlb_addr_save = gd->arch.tlb_addr;
York Sun0804d562015-12-04 11:57:08 -0800520 unsigned int el = current_el();
York Sun9da8f502016-06-24 16:46:23 -0700521 int index;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800522
Hou Zhiqiang92fecb52017-03-03 12:35:09 +0800523 /* fix the final_map before filling in the block entries */
524 fix_pcie_mmu_map();
525
York Sun9da8f502016-06-24 16:46:23 -0700526 mem_map = final_map;
Mingkai Hu0e58b512015-10-26 19:47:50 +0800527
York Sun75488ed2017-03-06 09:02:30 -0800528 /* Update mapping for DDR to actual size */
529 for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
530 /*
531 * Find the entry for DDR mapping and update the address and
532 * size. Zero-sized mapping will be skipped when creating MMU
533 * table.
534 */
535 switch (final_map[index].virt) {
536 case CONFIG_SYS_FSL_DRAM_BASE1:
537 final_map[index].virt = gd->bd->bi_dram[0].start;
538 final_map[index].phys = gd->bd->bi_dram[0].start;
539 final_map[index].size = gd->bd->bi_dram[0].size;
540 break;
541#ifdef CONFIG_SYS_FSL_DRAM_BASE2
542 case CONFIG_SYS_FSL_DRAM_BASE2:
543#if (CONFIG_NR_DRAM_BANKS >= 2)
544 final_map[index].virt = gd->bd->bi_dram[1].start;
545 final_map[index].phys = gd->bd->bi_dram[1].start;
546 final_map[index].size = gd->bd->bi_dram[1].size;
547#else
548 final_map[index].size = 0;
549#endif
550 break;
551#endif
552#ifdef CONFIG_SYS_FSL_DRAM_BASE3
553 case CONFIG_SYS_FSL_DRAM_BASE3:
554#if (CONFIG_NR_DRAM_BANKS >= 3)
555 final_map[index].virt = gd->bd->bi_dram[2].start;
556 final_map[index].phys = gd->bd->bi_dram[2].start;
557 final_map[index].size = gd->bd->bi_dram[2].size;
558#else
559 final_map[index].size = 0;
560#endif
561 break;
562#endif
563 default:
564 break;
565 }
566 }
567
York Sun0804d562015-12-04 11:57:08 -0800568#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
York Sun9da8f502016-06-24 16:46:23 -0700569 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
570 if (el == 3) {
571 /*
572 * Only use gd->arch.secure_ram if the address is
573 * recalculated. Align to 4KB for MMU table.
574 */
575 /* put page tables in secure ram */
576 index = ARRAY_SIZE(final_map) - 2;
577 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
578 final_map[index].virt = gd->arch.secure_ram & ~0x3;
579 final_map[index].phys = final_map[index].virt;
580 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
581 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
York Sun1ef95cc2016-06-24 16:46:18 -0700582 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
York Sun9da8f502016-06-24 16:46:23 -0700583 tlb_addr_save = gd->arch.tlb_addr;
York Sun0804d562015-12-04 11:57:08 -0800584 } else {
York Sun9da8f502016-06-24 16:46:23 -0700585 /* Use allocated (board_f.c) memory for TLB */
586 tlb_addr_save = gd->arch.tlb_allocated;
587 gd->arch.tlb_addr = tlb_addr_save;
York Sun0804d562015-12-04 11:57:08 -0800588 }
589 }
590#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +0800591
York Sun9da8f502016-06-24 16:46:23 -0700592 /* Reset the fill ptr */
593 gd->arch.tlb_fillptr = tlb_addr_save;
594
595 /* Create normal system page tables */
596 setup_pgtables();
597
598 /* Create emergency page tables */
599 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
600 gd->arch.tlb_emerg = gd->arch.tlb_addr;
601 setup_pgtables();
602 gd->arch.tlb_addr = tlb_addr_save;
603
York Suncf64ced2017-03-06 09:02:31 -0800604 /* Disable cache and MMU */
605 dcache_disable(); /* TLBs are invalidated */
606 invalidate_icache_all();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800607
608 /* point TTBR to the new table */
York Sun9da8f502016-06-24 16:46:23 -0700609 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
Mingkai Hu0e58b512015-10-26 19:47:50 +0800610 MEMORY_ATTRIBUTES);
York Suncf64ced2017-03-06 09:02:31 -0800611
York Suneb6eac12016-07-22 10:52:23 -0700612 set_sctlr(get_sctlr() | CR_M);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800613}
614
Alexander Grafbc78b922016-03-21 20:26:12 +0100615u64 get_page_table_size(void)
616{
617 return 0x10000;
618}
619
Mingkai Hu0e58b512015-10-26 19:47:50 +0800620int arch_cpu_init(void)
621{
York Sune6b871e2017-05-15 08:51:59 -0700622 /*
623 * This function is called before U-Boot relocates itself to speed up
624 * on system running. It is not necessary to run if performance is not
625 * critical. Skip if MMU is already enabled by SPL or other means.
626 */
627 if (get_sctlr() & CR_M)
628 return 0;
629
Mingkai Hu0e58b512015-10-26 19:47:50 +0800630 icache_enable();
631 __asm_invalidate_dcache_all();
632 __asm_invalidate_tlb_all();
633 early_mmu_setup();
634 set_sctlr(get_sctlr() | CR_C);
635 return 0;
636}
637
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800638void mmu_setup(void)
639{
640 final_mmu_setup();
641}
642
Mingkai Hu0e58b512015-10-26 19:47:50 +0800643/*
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800644 * This function is called from common/board_r.c.
645 * It recreates MMU table in main memory.
Mingkai Hu0e58b512015-10-26 19:47:50 +0800646 */
647void enable_caches(void)
648{
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800649 mmu_setup();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800650 __asm_invalidate_tlb_all();
Hou Zhiqianga7befa52016-06-28 20:18:12 +0800651 icache_enable();
652 dcache_enable();
Mingkai Hu0e58b512015-10-26 19:47:50 +0800653}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400654#endif /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000655
656#ifdef CONFIG_TFABOOT
657enum boot_src __get_boot_src(u32 porsr1)
658{
659 enum boot_src src = BOOT_SOURCE_RESERVED;
660 u32 rcw_src = (porsr1 & RCW_SRC_MASK) >> RCW_SRC_BIT;
Priyanka Jain88c25662018-10-29 09:11:29 +0000661#if !defined(CONFIG_NXP_LSCH3_2)
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000662 u32 val;
663#endif
664 debug("%s: rcw_src 0x%x\n", __func__, rcw_src);
665
666#if defined(CONFIG_FSL_LSCH3)
Priyanka Jain88c25662018-10-29 09:11:29 +0000667#if defined(CONFIG_NXP_LSCH3_2)
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000668 switch (rcw_src) {
669 case RCW_SRC_SDHC1_VAL:
670 src = BOOT_SOURCE_SD_MMC;
671 break;
672 case RCW_SRC_SDHC2_VAL:
673 src = BOOT_SOURCE_SD_MMC2;
674 break;
675 case RCW_SRC_I2C1_VAL:
676 src = BOOT_SOURCE_I2C1_EXTENDED;
677 break;
678 case RCW_SRC_FLEXSPI_NAND2K_VAL:
679 src = BOOT_SOURCE_XSPI_NAND;
680 break;
681 case RCW_SRC_FLEXSPI_NAND4K_VAL:
682 src = BOOT_SOURCE_XSPI_NAND;
683 break;
684 case RCW_SRC_RESERVED_1_VAL:
685 src = BOOT_SOURCE_RESERVED;
686 break;
687 case RCW_SRC_FLEXSPI_NOR_24B:
688 src = BOOT_SOURCE_XSPI_NOR;
689 break;
690 default:
691 src = BOOT_SOURCE_RESERVED;
692 }
693#else
694 val = rcw_src & RCW_SRC_TYPE_MASK;
695 if (val == RCW_SRC_NOR_VAL) {
696 val = rcw_src & NOR_TYPE_MASK;
697
698 switch (val) {
699 case NOR_16B_VAL:
700 case NOR_32B_VAL:
701 src = BOOT_SOURCE_IFC_NOR;
702 break;
703 default:
704 src = BOOT_SOURCE_RESERVED;
705 }
706 } else {
707 /* RCW SRC Serial Flash */
708 val = rcw_src & RCW_SRC_SERIAL_MASK;
709 switch (val) {
710 case RCW_SRC_QSPI_VAL:
711 /* RCW SRC Serial NOR (QSPI) */
712 src = BOOT_SOURCE_QSPI_NOR;
713 break;
714 case RCW_SRC_SD_CARD_VAL:
715 /* RCW SRC SD Card */
716 src = BOOT_SOURCE_SD_MMC;
717 break;
718 case RCW_SRC_EMMC_VAL:
719 /* RCW SRC EMMC */
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000720 src = BOOT_SOURCE_SD_MMC;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000721 break;
722 case RCW_SRC_I2C1_VAL:
723 /* RCW SRC I2C1 Extended */
724 src = BOOT_SOURCE_I2C1_EXTENDED;
725 break;
726 default:
727 src = BOOT_SOURCE_RESERVED;
728 }
729 }
730#endif
731#elif defined(CONFIG_FSL_LSCH2)
732 /* RCW SRC NAND */
733 val = rcw_src & RCW_SRC_NAND_MASK;
734 if (val == RCW_SRC_NAND_VAL) {
735 val = rcw_src & NAND_RESERVED_MASK;
736 if (val != NAND_RESERVED_1 && val != NAND_RESERVED_2)
737 src = BOOT_SOURCE_IFC_NAND;
738
739 } else {
740 /* RCW SRC NOR */
741 val = rcw_src & RCW_SRC_NOR_MASK;
742 if (val == NOR_8B_VAL || val == NOR_16B_VAL) {
743 src = BOOT_SOURCE_IFC_NOR;
744 } else {
745 switch (rcw_src) {
746 case QSPI_VAL1:
747 case QSPI_VAL2:
748 src = BOOT_SOURCE_QSPI_NOR;
749 break;
750 case SD_VAL:
751 src = BOOT_SOURCE_SD_MMC;
752 break;
753 default:
754 src = BOOT_SOURCE_RESERVED;
755 }
756 }
757 }
758#endif
York Sun8f3f4ef2018-11-05 18:02:09 +0000759
760 if (CONFIG_IS_ENABLED(SYS_FSL_ERRATUM_A010539) && !rcw_src)
761 src = BOOT_SOURCE_QSPI_NOR;
762
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000763 debug("%s: src 0x%x\n", __func__, src);
764 return src;
765}
766
767enum boot_src get_boot_src(void)
768{
York Sun8f3f4ef2018-11-05 18:02:09 +0000769 struct pt_regs regs;
770 u32 porsr1 = 0;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000771
772#if defined(CONFIG_FSL_LSCH3)
773 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000774#elif defined(CONFIG_FSL_LSCH2)
775 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
York Sun8f3f4ef2018-11-05 18:02:09 +0000776#endif
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000777
York Sun8f3f4ef2018-11-05 18:02:09 +0000778 if (current_el() == 2) {
779 regs.regs[0] = SIP_SVC_RCW;
780
781 smc_call(&regs);
782 if (!regs.regs[0])
783 porsr1 = regs.regs[1];
784 }
785
786 if (current_el() == 3 || !porsr1) {
787#ifdef CONFIG_FSL_LSCH3
788 porsr1 = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
789#elif defined(CONFIG_FSL_LSCH2)
790 porsr1 = in_be32(&gur->porsr1);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800791#endif
York Sun8f3f4ef2018-11-05 18:02:09 +0000792 }
793
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000794 debug("%s: porsr1 0x%x\n", __func__, porsr1);
795
796 return __get_boot_src(porsr1);
797}
798
799#ifdef CONFIG_ENV_IS_IN_MMC
800int mmc_get_env_dev(void)
801{
802 enum boot_src src = get_boot_src();
803 int dev = CONFIG_SYS_MMC_ENV_DEV;
804
805 switch (src) {
806 case BOOT_SOURCE_SD_MMC:
807 dev = 0;
808 break;
809 case BOOT_SOURCE_SD_MMC2:
810 dev = 1;
811 break;
812 default:
813 break;
814 }
815
816 return dev;
817}
818#endif
819
820enum env_location env_get_location(enum env_operation op, int prio)
821{
822 enum boot_src src = get_boot_src();
823 enum env_location env_loc = ENVL_NOWHERE;
824
825 if (prio)
826 return ENVL_UNKNOWN;
827
Udit Agarwal5e9720c2019-04-23 06:06:04 +0000828#ifdef CONFIG_ENV_IS_NOWHERE
829 return env_loc;
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000830#endif
831
Rajesh Bhagat583da8b2018-11-05 18:01:42 +0000832 switch (src) {
833 case BOOT_SOURCE_IFC_NOR:
834 env_loc = ENVL_FLASH;
835 break;
836 case BOOT_SOURCE_QSPI_NOR:
837 /* FALLTHROUGH */
838 case BOOT_SOURCE_XSPI_NOR:
839 env_loc = ENVL_SPI_FLASH;
840 break;
841 case BOOT_SOURCE_IFC_NAND:
842 /* FALLTHROUGH */
843 case BOOT_SOURCE_QSPI_NAND:
844 /* FALLTHROUGH */
845 case BOOT_SOURCE_XSPI_NAND:
846 env_loc = ENVL_NAND;
847 break;
848 case BOOT_SOURCE_SD_MMC:
849 /* FALLTHROUGH */
850 case BOOT_SOURCE_SD_MMC2:
851 env_loc = ENVL_MMC;
852 break;
853 case BOOT_SOURCE_I2C1_EXTENDED:
854 /* FALLTHROUGH */
855 default:
856 break;
857 }
858
859 return env_loc;
860}
861#endif /* CONFIG_TFABOOT */
Mingkai Hu0e58b512015-10-26 19:47:50 +0800862
Priyanka Jain9a276702016-11-17 12:29:56 +0530863u32 initiator_type(u32 cluster, int init_id)
Mingkai Hu0e58b512015-10-26 19:47:50 +0800864{
865 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
866 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
867 u32 type = 0;
868
869 type = gur_in32(&gur->tp_ityp[idx]);
870 if (type & TP_ITYP_AV)
871 return type;
872
873 return 0;
874}
875
York Suned7fbe32016-09-13 12:40:30 -0700876u32 cpu_pos_mask(void)
877{
878 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
879 int i = 0;
880 u32 cluster, type, mask = 0;
881
882 do {
883 int j;
884
885 cluster = gur_in32(&gur->tp_cluster[i].lower);
886 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
887 type = initiator_type(cluster, j);
888 if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
889 mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
890 }
891 i++;
892 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
893
894 return mask;
895}
896
Mingkai Hu0e58b512015-10-26 19:47:50 +0800897u32 cpu_mask(void)
898{
899 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
900 int i = 0, count = 0;
901 u32 cluster, type, mask = 0;
902
903 do {
904 int j;
905
906 cluster = gur_in32(&gur->tp_cluster[i].lower);
907 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
908 type = initiator_type(cluster, j);
909 if (type) {
910 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
911 mask |= 1 << count;
912 count++;
913 }
914 }
915 i++;
916 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
917
918 return mask;
919}
920
921/*
922 * Return the number of cores on this SOC.
923 */
924int cpu_numcores(void)
925{
926 return hweight32(cpu_mask());
927}
928
929int fsl_qoriq_core_to_cluster(unsigned int core)
930{
931 struct ccsr_gur __iomem *gur =
932 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
933 int i = 0, count = 0;
934 u32 cluster;
935
936 do {
937 int j;
938
939 cluster = gur_in32(&gur->tp_cluster[i].lower);
940 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
941 if (initiator_type(cluster, j)) {
942 if (count == core)
943 return i;
944 count++;
945 }
946 }
947 i++;
948 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
949
950 return -1; /* cannot identify the cluster */
951}
952
953u32 fsl_qoriq_core_to_type(unsigned int core)
954{
955 struct ccsr_gur __iomem *gur =
956 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
957 int i = 0, count = 0;
958 u32 cluster, type;
959
960 do {
961 int j;
962
963 cluster = gur_in32(&gur->tp_cluster[i].lower);
964 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
965 type = initiator_type(cluster, j);
966 if (type) {
967 if (count == core)
968 return type;
969 count++;
970 }
971 }
972 i++;
973 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
974
975 return -1; /* cannot identify the cluster */
976}
977
Priyanka Jain96b001f2016-11-17 12:29:51 +0530978#ifndef CONFIG_FSL_LSCH3
Sriram Dash9282d262016-06-13 09:58:32 +0530979uint get_svr(void)
980{
981 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
982
983 return gur_in32(&gur->svr);
984}
Priyanka Jain96b001f2016-11-17 12:29:51 +0530985#endif
Sriram Dash9282d262016-06-13 09:58:32 +0530986
Mingkai Hu0e58b512015-10-26 19:47:50 +0800987#ifdef CONFIG_DISPLAY_CPUINFO
988int print_cpuinfo(void)
989{
990 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
991 struct sys_info sysinfo;
992 char buf[32];
993 unsigned int i, core;
York Suncbe8e1c2016-04-04 11:41:26 -0700994 u32 type, rcw, svr = gur_in32(&gur->svr);
Mingkai Hu0e58b512015-10-26 19:47:50 +0800995
996 puts("SoC: ");
997
998 cpu_name(buf);
York Suncbe8e1c2016-04-04 11:41:26 -0700999 printf(" %s (0x%x)\n", buf, svr);
Mingkai Hu0e58b512015-10-26 19:47:50 +08001000 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
1001 get_sys_info(&sysinfo);
1002 puts("Clock Configuration:");
1003 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
1004 if (!(i % 3))
1005 puts("\n ");
1006 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
1007 printf("CPU%d(%s):%-4s MHz ", core,
1008 type == TY_ITYP_VER_A7 ? "A7 " :
1009 (type == TY_ITYP_VER_A53 ? "A53" :
Alison Wang79808392016-07-05 16:01:52 +08001010 (type == TY_ITYP_VER_A57 ? "A57" :
1011 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
Mingkai Hu0e58b512015-10-26 19:47:50 +08001012 strmhz(buf, sysinfo.freq_processor[core]));
1013 }
Hou Zhiqiang3f91cda2017-01-10 16:44:15 +08001014 /* Display platform clock as Bus frequency. */
Mingkai Hu0e58b512015-10-26 19:47:50 +08001015 printf("\n Bus: %-4s MHz ",
Hou Zhiqiang3f91cda2017-01-10 16:44:15 +08001016 strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
Mingkai Hu0e58b512015-10-26 19:47:50 +08001017 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
Shaohui Xie04643262015-10-26 19:47:54 +08001018#ifdef CONFIG_SYS_DPAA_FMAN
1019 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
1020#endif
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +05301021#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Suncbe8e1c2016-04-04 11:41:26 -07001022 if (soc_has_dp_ddr()) {
1023 printf(" DP-DDR: %-4s MT/s",
1024 strmhz(buf, sysinfo.freq_ddrbus2));
1025 }
Mingkai Hu0e58b512015-10-26 19:47:50 +08001026#endif
1027 puts("\n");
1028
1029 /*
1030 * Display the RCW, so that no one gets confused as to what RCW
1031 * we're actually using for this boot.
1032 */
1033 puts("Reset Configuration Word (RCW):");
1034 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
1035 rcw = gur_in32(&gur->rcwsr[i]);
1036 if ((i % 4) == 0)
1037 printf("\n %08x:", i * 4);
1038 printf(" %08x", rcw);
1039 }
1040 puts("\n");
1041
1042 return 0;
1043}
1044#endif
1045
1046#ifdef CONFIG_FSL_ESDHC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001047int cpu_mmc_init(struct bd_info *bis)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001048{
1049 return fsl_esdhc_mmc_init(bis);
1050}
1051#endif
1052
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001053int cpu_eth_init(struct bd_info *bis)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001054{
1055 int error = 0;
1056
Santan Kumar1afa9002017-05-05 15:42:29 +05301057#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001058 error = fsl_mc_ldpaa_init(bis);
1059#endif
Shaohui Xie04643262015-10-26 19:47:54 +08001060#ifdef CONFIG_FMAN_ENET
1061 fm_standard_init(bis);
1062#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001063 return error;
1064}
1065
Jiafei Panded62e52021-04-21 12:12:49 +08001066int check_psci(void)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001067{
Yuantian Tangaec3b142017-04-19 13:27:39 +08001068 unsigned int psci_ver;
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301069
Yuantian Tangaec3b142017-04-19 13:27:39 +08001070 psci_ver = sec_firmware_support_psci_version();
1071 if (psci_ver == PSCI_INVALID_VER)
1072 return 1;
1073
1074 return 0;
1075}
1076
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301077static void config_core_prefetch(void)
1078{
1079 char *buf = NULL;
1080 char buffer[HWCONFIG_BUFFER_SIZE];
1081 const char *prefetch_arg = NULL;
1082 size_t arglen;
1083 unsigned int mask;
1084 struct pt_regs regs;
1085
1086 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
1087 buf = buffer;
Pankaj Bansal6c772772019-10-31 05:41:09 +00001088 else
1089 return;
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301090
1091 prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable",
1092 &arglen, buf);
1093
1094 if (prefetch_arg) {
1095 mask = simple_strtoul(prefetch_arg, NULL, 0) & 0xff;
1096 if (mask & 0x1) {
1097 printf("Core0 prefetch can't be disabled\n");
1098 return;
1099 }
1100
1101#define SIP_PREFETCH_DISABLE_64 0xC200FF13
1102 regs.regs[0] = SIP_PREFETCH_DISABLE_64;
1103 regs.regs[1] = mask;
1104 smc_call(&regs);
1105
1106 if (regs.regs[0])
1107 printf("Prefetch disable config failed for mask ");
1108 else
1109 printf("Prefetch disable config passed for mask ");
1110 printf("0x%x\n", mask);
1111 }
1112}
1113
Alex Marginean762a2682019-11-27 17:19:32 +02001114#ifdef CONFIG_PCIE_ECAM_GENERIC
1115__weak void set_ecam_icids(void)
1116{
1117}
1118#endif
1119
Yuantian Tangaec3b142017-04-19 13:27:39 +08001120int arch_early_init_r(void)
1121{
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301122#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
Priyanka Jain823e0422017-02-14 10:34:31 +05301123 u32 svr_dev_id;
1124 /*
1125 * erratum A009635 is valid only for LS2080A SoC and
1126 * its personalitiesi
1127 */
Wenbin song5d8a61c2017-12-04 12:18:28 +08001128 svr_dev_id = get_svr();
1129 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
Priyanka Jain823e0422017-02-14 10:34:31 +05301130 erratum_a009635();
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +05301131#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +08001132#if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
1133 erratum_a009942_check_cpo();
1134#endif
Yuantian Tangaec3b142017-04-19 13:27:39 +08001135 if (check_psci()) {
1136 debug("PSCI: PSCI does not exist.\n");
1137
1138 /* if PSCI does not exist, boot secondary cores here */
1139 if (fsl_layerscape_wake_seconday_cores())
Hou Zhiqiang21c4d552016-06-28 20:18:15 +08001140 printf("Did not wake secondary cores\n");
1141 }
Mingkai Hu0e58b512015-10-26 19:47:50 +08001142
Prabhakar Kushwaha0acce842017-11-10 11:32:52 +05301143 config_core_prefetch();
1144
Mingkai Hu0e58b512015-10-26 19:47:50 +08001145#ifdef CONFIG_SYS_HAS_SERDES
1146 fsl_serdes_init();
1147#endif
Pankaj Bansalcc840622018-10-29 11:28:26 +00001148#ifdef CONFIG_SYS_FSL_HAS_RGMII
1149 /* some dpmacs in armv8a based freescale layerscape SOCs can be
Vladimir Oltean6a6e4022021-09-18 15:32:34 +03001150 * configured via both serdes(sgmii, 10gbase-r, xlaui etc) bits and via
Pankaj Bansalcc840622018-10-29 11:28:26 +00001151 * EC*_PMUX(rgmii) bits in RCW.
1152 * e.g. dpmac 17 and 18 in LX2160A can be configured as SGMII from
1153 * serdes bits and as RGMII via EC1_PMUX/EC2_PMUX bits
Razvan Ionut Cirjan912f2d82020-10-23 16:20:38 +05301154 * Now if a dpmac is enabled as RGMII through ECx_PMUX then it takes
1155 * precedence over SerDes protocol. i.e. in LX2160A if we select serdes
1156 * protocol that configures dpmac17 as SGMII and set the EC1_PMUX as
1157 * RGMII, then the dpmac is RGMII and not SGMII.
Pankaj Bansalcc840622018-10-29 11:28:26 +00001158 *
Razvan Ionut Cirjan912f2d82020-10-23 16:20:38 +05301159 * Therefore, even thought fsl_rgmii_init is after fsl_serdes_init
1160 * function of SOC, the dpmac will be enabled as RGMII even if it was
1161 * also enabled before as SGMII. If ECx_PMUX is not configured for
1162 * RGMII, DPMAC will remain configured as SGMII from fsl_serdes_init().
Pankaj Bansalcc840622018-10-29 11:28:26 +00001163 */
1164 fsl_rgmii_init();
1165#endif
Shaohui Xie04643262015-10-26 19:47:54 +08001166#ifdef CONFIG_FMAN_ENET
Madalin Bucurb76b0a62020-04-23 16:25:19 +03001167#ifndef CONFIG_DM_ETH
Shaohui Xie04643262015-10-26 19:47:54 +08001168 fman_enet_init();
1169#endif
Madalin Bucurb76b0a62020-04-23 16:25:19 +03001170#endif
Ahmed Mansouraa270b42017-12-15 16:01:00 -05001171#ifdef CONFIG_SYS_DPAA_QBMAN
1172 setup_qbman_portals();
1173#endif
Alex Marginean762a2682019-11-27 17:19:32 +02001174#ifdef CONFIG_PCIE_ECAM_GENERIC
1175 set_ecam_icids();
1176#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001177 return 0;
1178}
1179
1180int timer_init(void)
1181{
1182 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
1183#ifdef CONFIG_FSL_LSCH3
1184 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
1185#endif
Thomas Schaefercbec2b82019-08-08 16:00:30 +08001186#if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
1187 defined(CONFIG_ARCH_LS1028A)
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001188 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301189 u32 svr_dev_id;
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001190#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001191#ifdef COUNTER_FREQUENCY_REAL
1192 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
1193
1194 /* Update with accurate clock frequency */
York Sune6b871e2017-05-15 08:51:59 -07001195 if (current_el() == 3)
1196 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
Mingkai Hu0e58b512015-10-26 19:47:50 +08001197#endif
1198
1199#ifdef CONFIG_FSL_LSCH3
1200 /* Enable timebase for all clusters.
1201 * It is safe to do so even some clusters are not enabled.
1202 */
1203 out_le32(cltbenr, 0xf);
1204#endif
1205
Thomas Schaefercbec2b82019-08-08 16:00:30 +08001206#if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
1207 defined(CONFIG_ARCH_LS1028A)
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001208 /*
1209 * In certain Layerscape SoCs, the clock for each core's
1210 * has an enable bit in the PMU Physical Core Time Base Enable
1211 * Register (PCTBENR), which allows the watchdog to operate.
1212 */
1213 setbits_le32(pctbenr, 0xff);
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301214 /*
1215 * For LS2080A SoC and its personalities, timer controller
1216 * offset is different
1217 */
Wenbin song5d8a61c2017-12-04 12:18:28 +08001218 svr_dev_id = get_svr();
1219 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
Priyanka Jain3d31ec72016-11-17 12:29:52 +05301220 cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
1221
Yunhui Cui3dfb82a2016-06-08 10:31:42 +08001222#endif
1223
Mingkai Hu0e58b512015-10-26 19:47:50 +08001224 /* Enable clock for timer
1225 * This is a global setting.
1226 */
1227 out_le32(cntcr, 0x1);
1228
1229 return 0;
1230}
1231
Alexander Graf12be31c2016-11-17 01:03:01 +01001232__efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
1233
Harald Seiler6f14d5f2020-12-15 16:47:52 +01001234void __efi_runtime reset_cpu(void)
Mingkai Hu0e58b512015-10-26 19:47:50 +08001235{
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +05301236#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Meenakshi Aggarwal95a805b2020-09-09 14:06:05 +05301237 /* clear the RST_REQ_MSK and SW_RST_REQ */
1238 out_le32(rstcr, 0x0);
1239
1240 /* initiate the sw reset request */
1241 out_le32(rstcr, 0x1);
Priyanka Jainef76b2e2018-10-29 09:17:09 +00001242#else
Meenakshi Aggarwal95a805b2020-09-09 14:06:05 +05301243 u32 val;
1244
Mingkai Hu0e58b512015-10-26 19:47:50 +08001245 /* Raise RESET_REQ_B */
1246 val = scfg_in32(rstcr);
1247 val |= 0x02;
1248 scfg_out32(rstcr, val);
Priyanka Jainef76b2e2018-10-29 09:17:09 +00001249#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +08001250}
York Sun928b6812015-12-07 11:08:58 -08001251
Mathew McBride8f137732019-10-18 14:27:54 +11001252#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_PSCI_RESET)
Alexander Graf12be31c2016-11-17 01:03:01 +01001253
1254void __efi_runtime EFIAPI efi_reset_system(
1255 enum efi_reset_type reset_type,
1256 efi_status_t reset_status,
1257 unsigned long data_size, void *reset_data)
1258{
1259 switch (reset_type) {
1260 case EFI_RESET_COLD:
1261 case EFI_RESET_WARM:
Heinrich Schuchardt450d4c82018-02-06 22:00:22 +01001262 case EFI_RESET_PLATFORM_SPECIFIC:
Harald Seiler6f14d5f2020-12-15 16:47:52 +01001263 reset_cpu();
Alexander Graf12be31c2016-11-17 01:03:01 +01001264 break;
1265 case EFI_RESET_SHUTDOWN:
1266 /* Nothing we can do */
1267 break;
1268 }
1269
1270 while (1) { }
1271}
1272
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +01001273efi_status_t efi_reset_system_init(void)
Alexander Graf12be31c2016-11-17 01:03:01 +01001274{
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +01001275 return efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
Alexander Graf12be31c2016-11-17 01:03:01 +01001276}
1277
1278#endif
1279
York Sun2db54082017-09-07 10:12:32 -07001280/*
1281 * Calculate reserved memory with given memory bank
1282 * Return aligned memory size on success
1283 * Return (ram_size + needed size) for failure
1284 */
York Sun928b6812015-12-07 11:08:58 -08001285phys_size_t board_reserve_ram_top(phys_size_t ram_size)
1286{
1287 phys_size_t ram_top = ram_size;
1288
Santan Kumar1afa9002017-05-05 15:42:29 +05301289#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun2db54082017-09-07 10:12:32 -07001290 ram_top = mc_get_dram_block_size();
1291 if (ram_top > ram_size)
1292 return ram_size + ram_top;
1293
1294 ram_top = ram_size - ram_top;
York Sun4de24ef2017-03-06 09:02:28 -08001295 /* The start address of MC reserved memory needs to be aligned. */
York Sun928b6812015-12-07 11:08:58 -08001296 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
1297#endif
York Sun4de24ef2017-03-06 09:02:28 -08001298
1299 return ram_size - ram_top;
1300}
1301
1302phys_size_t get_effective_memsize(void)
1303{
1304 phys_size_t ea_size, rem = 0;
1305
1306 /*
1307 * For ARMv8 SoCs, DDR memory is split into two or three regions. The
Sumit Garged0deea2017-10-04 03:20:49 +05301308 * first region is 2GB space at 0x8000_0000. Secure memory needs to
1309 * allocated from first region. If the memory extends to the second
1310 * region (or the third region if applicable), Management Complex (MC)
1311 * memory should be put into the highest region, i.e. the end of DDR
1312 * memory. CONFIG_MAX_MEM_MAPPED is set to the size of first region so
1313 * U-Boot doesn't relocate itself into higher address. Should DDR be
1314 * configured to skip the first region, this function needs to be
1315 * adjusted.
York Sun4de24ef2017-03-06 09:02:28 -08001316 */
1317 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
1318 ea_size = CONFIG_MAX_MEM_MAPPED;
1319 rem = gd->ram_size - ea_size;
1320 } else {
1321 ea_size = gd->ram_size;
1322 }
1323
1324#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1325 /* Check if we have enough space for secure memory */
Sumit Garged0deea2017-10-04 03:20:49 +05301326 if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE)
1327 ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
1328 else
1329 printf("Error: No enough space for secure memory.\n");
York Sun4de24ef2017-03-06 09:02:28 -08001330#endif
1331 /* Check if we have enough memory for MC */
1332 if (rem < board_reserve_ram_top(rem)) {
1333 /* Not enough memory in high region to reserve */
York Sun2db54082017-09-07 10:12:32 -07001334 if (ea_size > board_reserve_ram_top(ea_size))
1335 ea_size -= board_reserve_ram_top(ea_size);
York Sun4de24ef2017-03-06 09:02:28 -08001336 else
1337 printf("Error: No enough space for reserved memory.\n");
1338 }
1339
1340 return ea_size;
1341}
1342
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001343#ifdef CONFIG_TFABOOT
1344phys_size_t tfa_get_dram_size(void)
1345{
1346 struct pt_regs regs;
1347 phys_size_t dram_size = 0;
1348
1349 regs.regs[0] = SMC_DRAM_BANK_INFO;
1350 regs.regs[1] = -1;
1351
1352 smc_call(&regs);
1353 if (regs.regs[0])
1354 return 0;
1355
1356 dram_size = regs.regs[1];
1357 return dram_size;
1358}
1359
1360static int tfa_dram_init_banksize(void)
1361{
1362 int i = 0, ret = 0;
1363 struct pt_regs regs;
1364 phys_size_t dram_size = tfa_get_dram_size();
1365
1366 debug("dram_size %llx\n", dram_size);
1367
1368 if (!dram_size)
1369 return -EINVAL;
1370
1371 do {
1372 regs.regs[0] = SMC_DRAM_BANK_INFO;
1373 regs.regs[1] = i;
1374
1375 smc_call(&regs);
1376 if (regs.regs[0]) {
1377 ret = -EINVAL;
1378 break;
1379 }
1380
1381 debug("bank[%d]: start %lx, size %lx\n", i, regs.regs[1],
1382 regs.regs[2]);
1383 gd->bd->bi_dram[i].start = regs.regs[1];
1384 gd->bd->bi_dram[i].size = regs.regs[2];
1385
1386 dram_size -= gd->bd->bi_dram[i].size;
1387
1388 i++;
1389 } while (dram_size);
1390
1391 if (i > 0)
1392 ret = 0;
1393
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001394#if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD)
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001395 /* Assign memory for MC */
1396#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1397 if (gd->bd->bi_dram[2].size >=
1398 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
1399 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
1400 gd->bd->bi_dram[2].size -
1401 board_reserve_ram_top(gd->bd->bi_dram[2].size);
1402 } else
1403#endif
1404 {
1405 if (gd->bd->bi_dram[1].size >=
1406 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
1407 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
1408 gd->bd->bi_dram[1].size -
1409 board_reserve_ram_top(gd->bd->bi_dram[1].size);
1410 } else if (gd->bd->bi_dram[0].size >
1411 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
1412 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
1413 gd->bd->bi_dram[0].size -
1414 board_reserve_ram_top(gd->bd->bi_dram[0].size);
1415 }
1416 }
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001417#endif /* CONFIG_RESV_RAM */
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001418
1419 return ret;
1420}
1421#endif
1422
Simon Glass2f949c32017-03-31 08:40:32 -06001423int dram_init_banksize(void)
York Sun4de24ef2017-03-06 09:02:28 -08001424{
1425#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1426 phys_size_t dp_ddr_size;
1427#endif
1428
Rajesh Bhagat1dde2d22018-11-05 18:01:58 +00001429#ifdef CONFIG_TFABOOT
1430 if (!tfa_dram_init_banksize())
1431 return 0;
1432#endif
York Sun4de24ef2017-03-06 09:02:28 -08001433 /*
1434 * gd->ram_size has the total size of DDR memory, less reserved secure
1435 * memory. The DDR extends from low region to high region(s) presuming
1436 * no hole is created with DDR configuration. gd->arch.secure_ram tracks
1437 * the location of secure memory. gd->arch.resv_ram tracks the location
York Sunc9e3e042017-09-28 08:42:12 -07001438 * of reserved memory for Management Complex (MC). Because gd->ram_size
1439 * is reduced by this function if secure memory is reserved, checking
1440 * gd->arch.secure_ram should be done to avoid running it repeatedly.
York Sun4de24ef2017-03-06 09:02:28 -08001441 */
York Sunc9e3e042017-09-28 08:42:12 -07001442
1443#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1444 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
1445 debug("No need to run again, skip %s\n", __func__);
1446
1447 return 0;
1448 }
1449#endif
1450
York Sun4de24ef2017-03-06 09:02:28 -08001451 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
1452 if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
1453 gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
1454 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
1455 gd->bd->bi_dram[1].size = gd->ram_size -
1456 CONFIG_SYS_DDR_BLOCK1_SIZE;
1457#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1458 if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
1459 gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
1460 gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
1461 CONFIG_SYS_DDR_BLOCK2_SIZE;
1462 gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
1463 }
1464#endif
1465 } else {
1466 gd->bd->bi_dram[0].size = gd->ram_size;
1467 }
1468#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
Sumit Garged0deea2017-10-04 03:20:49 +05301469 if (gd->bd->bi_dram[0].size >
1470 CONFIG_SYS_MEM_RESERVE_SECURE) {
1471 gd->bd->bi_dram[0].size -=
1472 CONFIG_SYS_MEM_RESERVE_SECURE;
1473 gd->arch.secure_ram = gd->bd->bi_dram[0].start +
1474 gd->bd->bi_dram[0].size;
York Sun4de24ef2017-03-06 09:02:28 -08001475 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
1476 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
York Sun4de24ef2017-03-06 09:02:28 -08001477 }
1478#endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
1479
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001480#if defined(CONFIG_RESV_RAM) && !defined(CONFIG_SPL_BUILD)
York Sun4de24ef2017-03-06 09:02:28 -08001481 /* Assign memory for MC */
1482#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1483 if (gd->bd->bi_dram[2].size >=
1484 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
1485 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
1486 gd->bd->bi_dram[2].size -
1487 board_reserve_ram_top(gd->bd->bi_dram[2].size);
1488 } else
1489#endif
1490 {
1491 if (gd->bd->bi_dram[1].size >=
1492 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
1493 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
1494 gd->bd->bi_dram[1].size -
1495 board_reserve_ram_top(gd->bd->bi_dram[1].size);
1496 } else if (gd->bd->bi_dram[0].size >
1497 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
1498 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
1499 gd->bd->bi_dram[0].size -
1500 board_reserve_ram_top(gd->bd->bi_dram[0].size);
1501 }
1502 }
Hou Zhiqiang80de3732020-04-28 10:19:28 +08001503#endif /* CONFIG_RESV_RAM */
York Sun4de24ef2017-03-06 09:02:28 -08001504
1505#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1506#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1507#error "This SoC shouldn't have DP DDR"
1508#endif
1509 if (soc_has_dp_ddr()) {
1510 /* initialize DP-DDR here */
1511 puts("DP-DDR: ");
1512 /*
1513 * DDR controller use 0 as the base address for binding.
1514 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
1515 */
1516 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
1517 CONFIG_DP_DDR_CTRL,
1518 CONFIG_DP_DDR_NUM_CTRLS,
1519 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
1520 NULL, NULL, NULL);
1521 if (dp_ddr_size) {
1522 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
1523 gd->bd->bi_dram[2].size = dp_ddr_size;
1524 } else {
1525 puts("Not detected");
1526 }
1527 }
1528#endif
Simon Glass2f949c32017-03-31 08:40:32 -06001529
York Sunc9e3e042017-09-28 08:42:12 -07001530#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1531 debug("%s is called. gd->ram_size is reduced to %lu\n",
1532 __func__, (ulong)gd->ram_size);
1533#endif
1534
Simon Glass2f949c32017-03-31 08:40:32 -06001535 return 0;
York Sun4de24ef2017-03-06 09:02:28 -08001536}
1537
Stephen Warrend0de8062018-08-30 15:43:43 -06001538#if CONFIG_IS_ENABLED(EFI_LOADER)
York Sun4de24ef2017-03-06 09:02:28 -08001539void efi_add_known_memory(void)
1540{
1541 int i;
Michael Walle282d3862020-05-17 12:29:19 +02001542 phys_addr_t ram_start;
York Sun4de24ef2017-03-06 09:02:28 -08001543 phys_size_t ram_size;
York Sun928b6812015-12-07 11:08:58 -08001544
York Sun4de24ef2017-03-06 09:02:28 -08001545 /* Add RAM */
1546 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
1547#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1548#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1549#error "This SoC shouldn't have DP DDR"
1550#endif
1551 if (i == 2)
1552 continue; /* skip DP-DDR */
1553#endif
1554 ram_start = gd->bd->bi_dram[i].start;
1555 ram_size = gd->bd->bi_dram[i].size;
1556#ifdef CONFIG_RESV_RAM
1557 if (gd->arch.resv_ram >= ram_start &&
1558 gd->arch.resv_ram < ram_start + ram_size)
1559 ram_size = gd->arch.resv_ram - ram_start;
1560#endif
Michael Walle282d3862020-05-17 12:29:19 +02001561 efi_add_memory_map(ram_start, ram_size,
1562 EFI_CONVENTIONAL_MEMORY);
York Sun4de24ef2017-03-06 09:02:28 -08001563 }
York Sun928b6812015-12-07 11:08:58 -08001564}
York Sun4de24ef2017-03-06 09:02:28 -08001565#endif
York Sun729f2d12017-03-06 09:02:34 -08001566
1567/*
1568 * Before DDR size is known, early MMU table have DDR mapped as device memory
1569 * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
1570 * needs to be set for these mappings.
1571 * If a special case configures DDR with holes in the mapping, the holes need
1572 * to be marked as invalid. This is not implemented in this function.
1573 */
1574void update_early_mmu_table(void)
1575{
1576 if (!gd->arch.tlb_addr)
1577 return;
1578
1579 if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
1580 mmu_change_region_attr(
1581 CONFIG_SYS_SDRAM_BASE,
1582 gd->ram_size,
1583 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1584 PTE_BLOCK_OUTER_SHARE |
1585 PTE_BLOCK_NS |
1586 PTE_TYPE_VALID);
1587 } else {
1588 mmu_change_region_attr(
1589 CONFIG_SYS_SDRAM_BASE,
1590 CONFIG_SYS_DDR_BLOCK1_SIZE,
1591 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1592 PTE_BLOCK_OUTER_SHARE |
1593 PTE_BLOCK_NS |
1594 PTE_TYPE_VALID);
1595#ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1596#ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
1597#error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
1598#endif
1599 if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
1600 CONFIG_SYS_DDR_BLOCK2_SIZE) {
1601 mmu_change_region_attr(
1602 CONFIG_SYS_DDR_BLOCK2_BASE,
1603 CONFIG_SYS_DDR_BLOCK2_SIZE,
1604 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1605 PTE_BLOCK_OUTER_SHARE |
1606 PTE_BLOCK_NS |
1607 PTE_TYPE_VALID);
1608 mmu_change_region_attr(
1609 CONFIG_SYS_DDR_BLOCK3_BASE,
1610 gd->ram_size -
1611 CONFIG_SYS_DDR_BLOCK1_SIZE -
1612 CONFIG_SYS_DDR_BLOCK2_SIZE,
1613 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1614 PTE_BLOCK_OUTER_SHARE |
1615 PTE_BLOCK_NS |
1616 PTE_TYPE_VALID);
1617 } else
1618#endif
1619 {
1620 mmu_change_region_attr(
1621 CONFIG_SYS_DDR_BLOCK2_BASE,
1622 gd->ram_size -
1623 CONFIG_SYS_DDR_BLOCK1_SIZE,
1624 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1625 PTE_BLOCK_OUTER_SHARE |
1626 PTE_BLOCK_NS |
1627 PTE_TYPE_VALID);
1628 }
1629 }
1630}
1631
1632__weak int dram_init(void)
1633{
Simon Glass0e0ac202017-04-06 12:47:04 -06001634 fsl_initdram();
Rajesh Bhagat5efbecf2018-11-05 18:01:37 +00001635#if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
1636 defined(CONFIG_SPL_BUILD)
York Sun729f2d12017-03-06 09:02:34 -08001637 /* This will break-before-make MMU for DDR */
1638 update_early_mmu_table();
1639#endif
1640
1641 return 0;
1642}
Alex Marginean47568ce2020-01-11 01:05:40 +02001643
1644#ifdef CONFIG_ARCH_MISC_INIT
1645__weak int serdes_misc_init(void)
1646{
1647 return 0;
1648}
1649
1650int arch_misc_init(void)
1651{
1652 serdes_misc_init();
1653
1654 return 0;
1655}
1656#endif