1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright 2014-2015 Freescale Semiconductor, Inc.
8 #include <fsl_ddr_sdram.h>
10 #include <linux/errno.h>
11 #include <asm/system.h>
13 #include <asm/armv8/mmu.h>
15 #include <asm/arch/fsl_serdes.h>
16 #include <asm/arch/soc.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/speed.h>
19 #include <fsl_immap.h>
20 #include <asm/arch/mp.h>
21 #include <efi_loader.h>
22 #include <fsl-mc/fsl_mc.h>
23 #ifdef CONFIG_FSL_ESDHC
24 #include <fsl_esdhc.h>
26 #include <asm/armv8/sec_firmware.h>
27 #ifdef CONFIG_SYS_FSL_DDR
30 #include <asm/arch/clock.h>
32 #include <fsl_qbman.h>
34 DECLARE_GLOBAL_DATA_PTR;
36 static struct cpu_type cpu_type_list[] = {
37 CPU_TYPE_ENTRY(LS2080A, LS2080A, 8),
38 CPU_TYPE_ENTRY(LS2085A, LS2085A, 8),
39 CPU_TYPE_ENTRY(LS2045A, LS2045A, 4),
40 CPU_TYPE_ENTRY(LS2088A, LS2088A, 8),
41 CPU_TYPE_ENTRY(LS2084A, LS2084A, 8),
42 CPU_TYPE_ENTRY(LS2048A, LS2048A, 4),
43 CPU_TYPE_ENTRY(LS2044A, LS2044A, 4),
44 CPU_TYPE_ENTRY(LS2081A, LS2081A, 8),
45 CPU_TYPE_ENTRY(LS2041A, LS2041A, 4),
46 CPU_TYPE_ENTRY(LS1043A, LS1043A, 4),
47 CPU_TYPE_ENTRY(LS1023A, LS1023A, 2),
48 CPU_TYPE_ENTRY(LS1046A, LS1046A, 4),
49 CPU_TYPE_ENTRY(LS1026A, LS1026A, 2),
50 CPU_TYPE_ENTRY(LS2040A, LS2040A, 4),
51 CPU_TYPE_ENTRY(LS1012A, LS1012A, 1),
52 CPU_TYPE_ENTRY(LS1088A, LS1088A, 8),
53 CPU_TYPE_ENTRY(LS1084A, LS1084A, 8),
54 CPU_TYPE_ENTRY(LS1048A, LS1048A, 4),
55 CPU_TYPE_ENTRY(LS1044A, LS1044A, 4),
58 #define EARLY_PGTABLE_SIZE 0x5000
59 static struct mm_region early_map[] = {
60 #ifdef CONFIG_FSL_LSCH3
61 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
62 CONFIG_SYS_FSL_CCSR_SIZE,
63 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
64 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
66 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
67 SYS_FSL_OCRAM_SPACE_SIZE,
68 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
70 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
71 CONFIG_SYS_FSL_QSPI_SIZE1,
72 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE},
74 /* For IFC Region #1, only the first 4MB is cache-enabled */
75 { CONFIG_SYS_FSL_IFC_BASE1, CONFIG_SYS_FSL_IFC_BASE1,
76 CONFIG_SYS_FSL_IFC_SIZE1_1,
77 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
79 { CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
80 CONFIG_SYS_FSL_IFC_BASE1 + CONFIG_SYS_FSL_IFC_SIZE1_1,
81 CONFIG_SYS_FSL_IFC_SIZE1 - CONFIG_SYS_FSL_IFC_SIZE1_1,
82 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
84 { CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FSL_IFC_BASE1,
85 CONFIG_SYS_FSL_IFC_SIZE1,
86 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
89 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
90 CONFIG_SYS_FSL_DRAM_SIZE1,
91 #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
92 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
93 #else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
94 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
96 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
99 /* Map IFC region #2 up to CONFIG_SYS_FLASH_BASE for NAND boot */
100 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
101 CONFIG_SYS_FLASH_BASE - CONFIG_SYS_FSL_IFC_BASE2,
102 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
105 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
106 CONFIG_SYS_FSL_DCSR_SIZE,
107 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
108 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
110 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
111 CONFIG_SYS_FSL_DRAM_SIZE2,
112 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
113 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
115 #elif defined(CONFIG_FSL_LSCH2)
116 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
117 CONFIG_SYS_FSL_CCSR_SIZE,
118 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
119 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
121 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
122 SYS_FSL_OCRAM_SPACE_SIZE,
123 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
125 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
126 CONFIG_SYS_FSL_DCSR_SIZE,
127 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
128 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
130 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
131 CONFIG_SYS_FSL_QSPI_SIZE,
132 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
134 #ifdef CONFIG_FSL_IFC
135 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
136 CONFIG_SYS_FSL_IFC_SIZE,
137 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
140 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
141 CONFIG_SYS_FSL_DRAM_SIZE1,
142 #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
143 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
144 #else /* Start with nGnRnE and PXN and UXN to prevent speculative access */
145 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
147 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
149 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
150 CONFIG_SYS_FSL_DRAM_SIZE2,
151 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
152 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
155 {}, /* list terminator */
158 static struct mm_region final_map[] = {
159 #ifdef CONFIG_FSL_LSCH3
160 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
161 CONFIG_SYS_FSL_CCSR_SIZE,
162 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
163 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
165 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
166 SYS_FSL_OCRAM_SPACE_SIZE,
167 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
169 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
170 CONFIG_SYS_FSL_DRAM_SIZE1,
171 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
172 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
174 { CONFIG_SYS_FSL_QSPI_BASE1, CONFIG_SYS_FSL_QSPI_BASE1,
175 CONFIG_SYS_FSL_QSPI_SIZE1,
176 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
177 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
179 { CONFIG_SYS_FSL_QSPI_BASE2, CONFIG_SYS_FSL_QSPI_BASE2,
180 CONFIG_SYS_FSL_QSPI_SIZE2,
181 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
182 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
184 #ifdef CONFIG_FSL_IFC
185 { CONFIG_SYS_FSL_IFC_BASE2, CONFIG_SYS_FSL_IFC_BASE2,
186 CONFIG_SYS_FSL_IFC_SIZE2,
187 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
188 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
191 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
192 CONFIG_SYS_FSL_DCSR_SIZE,
193 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
194 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
196 { CONFIG_SYS_FSL_MC_BASE, CONFIG_SYS_FSL_MC_BASE,
197 CONFIG_SYS_FSL_MC_SIZE,
198 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
199 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
201 { CONFIG_SYS_FSL_NI_BASE, CONFIG_SYS_FSL_NI_BASE,
202 CONFIG_SYS_FSL_NI_SIZE,
203 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
204 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
206 /* For QBMAN portal, only the first 64MB is cache-enabled */
207 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
208 CONFIG_SYS_FSL_QBMAN_SIZE_1,
209 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
210 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_NS
212 { CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
213 CONFIG_SYS_FSL_QBMAN_BASE + CONFIG_SYS_FSL_QBMAN_SIZE_1,
214 CONFIG_SYS_FSL_QBMAN_SIZE - CONFIG_SYS_FSL_QBMAN_SIZE_1,
215 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
216 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
218 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
219 CONFIG_SYS_PCIE1_PHYS_SIZE,
220 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
221 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
223 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
224 CONFIG_SYS_PCIE2_PHYS_SIZE,
225 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
226 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
228 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
229 CONFIG_SYS_PCIE3_PHYS_SIZE,
230 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
231 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
233 #ifdef CONFIG_ARCH_LS2080A
234 { CONFIG_SYS_PCIE4_PHYS_ADDR, CONFIG_SYS_PCIE4_PHYS_ADDR,
235 CONFIG_SYS_PCIE4_PHYS_SIZE,
236 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
237 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
240 { CONFIG_SYS_FSL_WRIOP1_BASE, CONFIG_SYS_FSL_WRIOP1_BASE,
241 CONFIG_SYS_FSL_WRIOP1_SIZE,
242 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
243 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
245 { CONFIG_SYS_FSL_AIOP1_BASE, CONFIG_SYS_FSL_AIOP1_BASE,
246 CONFIG_SYS_FSL_AIOP1_SIZE,
247 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
248 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
250 { CONFIG_SYS_FSL_PEBUF_BASE, CONFIG_SYS_FSL_PEBUF_BASE,
251 CONFIG_SYS_FSL_PEBUF_SIZE,
252 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
253 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
255 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
256 CONFIG_SYS_FSL_DRAM_SIZE2,
257 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
258 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
260 #elif defined(CONFIG_FSL_LSCH2)
261 { CONFIG_SYS_FSL_BOOTROM_BASE, CONFIG_SYS_FSL_BOOTROM_BASE,
262 CONFIG_SYS_FSL_BOOTROM_SIZE,
263 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
264 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
266 { CONFIG_SYS_FSL_CCSR_BASE, CONFIG_SYS_FSL_CCSR_BASE,
267 CONFIG_SYS_FSL_CCSR_SIZE,
268 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
269 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
271 { CONFIG_SYS_FSL_OCRAM_BASE, CONFIG_SYS_FSL_OCRAM_BASE,
272 SYS_FSL_OCRAM_SPACE_SIZE,
273 PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_NON_SHARE
275 { CONFIG_SYS_FSL_DCSR_BASE, CONFIG_SYS_FSL_DCSR_BASE,
276 CONFIG_SYS_FSL_DCSR_SIZE,
277 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
278 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
280 { CONFIG_SYS_FSL_QSPI_BASE, CONFIG_SYS_FSL_QSPI_BASE,
281 CONFIG_SYS_FSL_QSPI_SIZE,
282 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
283 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
285 #ifdef CONFIG_FSL_IFC
286 { CONFIG_SYS_FSL_IFC_BASE, CONFIG_SYS_FSL_IFC_BASE,
287 CONFIG_SYS_FSL_IFC_SIZE,
288 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE
291 { CONFIG_SYS_FSL_DRAM_BASE1, CONFIG_SYS_FSL_DRAM_BASE1,
292 CONFIG_SYS_FSL_DRAM_SIZE1,
293 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
294 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
296 { CONFIG_SYS_FSL_QBMAN_BASE, CONFIG_SYS_FSL_QBMAN_BASE,
297 CONFIG_SYS_FSL_QBMAN_SIZE,
298 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
299 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
301 { CONFIG_SYS_FSL_DRAM_BASE2, CONFIG_SYS_FSL_DRAM_BASE2,
302 CONFIG_SYS_FSL_DRAM_SIZE2,
303 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
304 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
306 { CONFIG_SYS_PCIE1_PHYS_ADDR, CONFIG_SYS_PCIE1_PHYS_ADDR,
307 CONFIG_SYS_PCIE1_PHYS_SIZE,
308 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
309 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
311 { CONFIG_SYS_PCIE2_PHYS_ADDR, CONFIG_SYS_PCIE2_PHYS_ADDR,
312 CONFIG_SYS_PCIE2_PHYS_SIZE,
313 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
314 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
316 { CONFIG_SYS_PCIE3_PHYS_ADDR, CONFIG_SYS_PCIE3_PHYS_ADDR,
317 CONFIG_SYS_PCIE3_PHYS_SIZE,
318 PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
319 PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN
321 { CONFIG_SYS_FSL_DRAM_BASE3, CONFIG_SYS_FSL_DRAM_BASE3,
322 CONFIG_SYS_FSL_DRAM_SIZE3,
323 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
324 PTE_BLOCK_OUTER_SHARE | PTE_BLOCK_NS
327 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
328 {}, /* space holder for secure mem */
333 struct mm_region *mem_map = early_map;
335 void cpu_name(char *name)
337 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
338 unsigned int i, svr, ver;
340 svr = gur_in32(&gur->svr);
341 ver = SVR_SOC_VER(svr);
343 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
344 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
345 strcpy(name, cpu_type_list[i].name);
347 if (IS_E_PROCESSOR(svr))
350 sprintf(name + strlen(name), " Rev%d.%d",
351 SVR_MAJ(svr), SVR_MIN(svr));
355 if (i == ARRAY_SIZE(cpu_type_list))
356 strcpy(name, "unknown");
359 #ifndef CONFIG_SYS_DCACHE_OFF
361 * To start MMU before DDR is available, we create MMU table in SRAM.
362 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
363 * levels of translation tables here to cover 40-bit address space.
364 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
365 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
366 * Note, the debug print in cache_v8.c is not usable for debugging
367 * these early MMU tables because UART is not yet available.
369 static inline void early_mmu_setup(void)
371 unsigned int el = current_el();
373 /* global data is already setup, no allocation yet */
374 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
375 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
376 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
378 /* Create early page tables */
381 /* point TTBR to the new table */
382 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
383 get_tcr(el, NULL, NULL) &
384 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
387 set_sctlr(get_sctlr() | CR_M);
390 static void fix_pcie_mmu_map(void)
392 #ifdef CONFIG_ARCH_LS2080A
395 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
397 svr = gur_in32(&gur->svr);
398 ver = SVR_SOC_VER(svr);
400 /* Fix PCIE base and size for LS2088A */
401 if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
402 (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
403 (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
404 for (i = 0; i < ARRAY_SIZE(final_map); i++) {
405 switch (final_map[i].phys) {
406 case CONFIG_SYS_PCIE1_PHYS_ADDR:
407 final_map[i].phys = 0x2000000000ULL;
408 final_map[i].virt = 0x2000000000ULL;
409 final_map[i].size = 0x800000000ULL;
411 case CONFIG_SYS_PCIE2_PHYS_ADDR:
412 final_map[i].phys = 0x2800000000ULL;
413 final_map[i].virt = 0x2800000000ULL;
414 final_map[i].size = 0x800000000ULL;
416 case CONFIG_SYS_PCIE3_PHYS_ADDR:
417 final_map[i].phys = 0x3000000000ULL;
418 final_map[i].virt = 0x3000000000ULL;
419 final_map[i].size = 0x800000000ULL;
421 case CONFIG_SYS_PCIE4_PHYS_ADDR:
422 final_map[i].phys = 0x3800000000ULL;
423 final_map[i].virt = 0x3800000000ULL;
424 final_map[i].size = 0x800000000ULL;
435 * The final tables look similar to early tables, but different in detail.
436 * These tables are in DRAM. Sub tables are added to enable cache for
439 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
440 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
442 static inline void final_mmu_setup(void)
444 u64 tlb_addr_save = gd->arch.tlb_addr;
445 unsigned int el = current_el();
448 /* fix the final_map before filling in the block entries */
453 /* Update mapping for DDR to actual size */
454 for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
456 * Find the entry for DDR mapping and update the address and
457 * size. Zero-sized mapping will be skipped when creating MMU
460 switch (final_map[index].virt) {
461 case CONFIG_SYS_FSL_DRAM_BASE1:
462 final_map[index].virt = gd->bd->bi_dram[0].start;
463 final_map[index].phys = gd->bd->bi_dram[0].start;
464 final_map[index].size = gd->bd->bi_dram[0].size;
466 #ifdef CONFIG_SYS_FSL_DRAM_BASE2
467 case CONFIG_SYS_FSL_DRAM_BASE2:
468 #if (CONFIG_NR_DRAM_BANKS >= 2)
469 final_map[index].virt = gd->bd->bi_dram[1].start;
470 final_map[index].phys = gd->bd->bi_dram[1].start;
471 final_map[index].size = gd->bd->bi_dram[1].size;
473 final_map[index].size = 0;
477 #ifdef CONFIG_SYS_FSL_DRAM_BASE3
478 case CONFIG_SYS_FSL_DRAM_BASE3:
479 #if (CONFIG_NR_DRAM_BANKS >= 3)
480 final_map[index].virt = gd->bd->bi_dram[2].start;
481 final_map[index].phys = gd->bd->bi_dram[2].start;
482 final_map[index].size = gd->bd->bi_dram[2].size;
484 final_map[index].size = 0;
493 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
494 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
497 * Only use gd->arch.secure_ram if the address is
498 * recalculated. Align to 4KB for MMU table.
500 /* put page tables in secure ram */
501 index = ARRAY_SIZE(final_map) - 2;
502 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
503 final_map[index].virt = gd->arch.secure_ram & ~0x3;
504 final_map[index].phys = final_map[index].virt;
505 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
506 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
507 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
508 tlb_addr_save = gd->arch.tlb_addr;
510 /* Use allocated (board_f.c) memory for TLB */
511 tlb_addr_save = gd->arch.tlb_allocated;
512 gd->arch.tlb_addr = tlb_addr_save;
517 /* Reset the fill ptr */
518 gd->arch.tlb_fillptr = tlb_addr_save;
520 /* Create normal system page tables */
523 /* Create emergency page tables */
524 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
525 gd->arch.tlb_emerg = gd->arch.tlb_addr;
527 gd->arch.tlb_addr = tlb_addr_save;
529 /* Disable cache and MMU */
530 dcache_disable(); /* TLBs are invalidated */
531 invalidate_icache_all();
533 /* point TTBR to the new table */
534 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
537 set_sctlr(get_sctlr() | CR_M);
540 u64 get_page_table_size(void)
545 int arch_cpu_init(void)
548 * This function is called before U-Boot relocates itself to speed up
549 * on system running. It is not necessary to run if performance is not
550 * critical. Skip if MMU is already enabled by SPL or other means.
552 if (get_sctlr() & CR_M)
556 __asm_invalidate_dcache_all();
557 __asm_invalidate_tlb_all();
559 set_sctlr(get_sctlr() | CR_C);
569 * This function is called from common/board_r.c.
570 * It recreates MMU table in main memory.
572 void enable_caches(void)
575 __asm_invalidate_tlb_all();
581 u32 initiator_type(u32 cluster, int init_id)
583 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
584 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
587 type = gur_in32(&gur->tp_ityp[idx]);
588 if (type & TP_ITYP_AV)
594 u32 cpu_pos_mask(void)
596 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
598 u32 cluster, type, mask = 0;
603 cluster = gur_in32(&gur->tp_cluster[i].lower);
604 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
605 type = initiator_type(cluster, j);
606 if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
607 mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
610 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
617 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
618 int i = 0, count = 0;
619 u32 cluster, type, mask = 0;
624 cluster = gur_in32(&gur->tp_cluster[i].lower);
625 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
626 type = initiator_type(cluster, j);
628 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
634 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
640 * Return the number of cores on this SOC.
642 int cpu_numcores(void)
644 return hweight32(cpu_mask());
647 int fsl_qoriq_core_to_cluster(unsigned int core)
649 struct ccsr_gur __iomem *gur =
650 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
651 int i = 0, count = 0;
657 cluster = gur_in32(&gur->tp_cluster[i].lower);
658 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
659 if (initiator_type(cluster, j)) {
666 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
668 return -1; /* cannot identify the cluster */
671 u32 fsl_qoriq_core_to_type(unsigned int core)
673 struct ccsr_gur __iomem *gur =
674 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
675 int i = 0, count = 0;
681 cluster = gur_in32(&gur->tp_cluster[i].lower);
682 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
683 type = initiator_type(cluster, j);
691 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
693 return -1; /* cannot identify the cluster */
696 #ifndef CONFIG_FSL_LSCH3
699 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
701 return gur_in32(&gur->svr);
705 #ifdef CONFIG_DISPLAY_CPUINFO
706 int print_cpuinfo(void)
708 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
709 struct sys_info sysinfo;
711 unsigned int i, core;
712 u32 type, rcw, svr = gur_in32(&gur->svr);
717 printf(" %s (0x%x)\n", buf, svr);
718 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
719 get_sys_info(&sysinfo);
720 puts("Clock Configuration:");
721 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
724 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
725 printf("CPU%d(%s):%-4s MHz ", core,
726 type == TY_ITYP_VER_A7 ? "A7 " :
727 (type == TY_ITYP_VER_A53 ? "A53" :
728 (type == TY_ITYP_VER_A57 ? "A57" :
729 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
730 strmhz(buf, sysinfo.freq_processor[core]));
732 /* Display platform clock as Bus frequency. */
733 printf("\n Bus: %-4s MHz ",
734 strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
735 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
736 #ifdef CONFIG_SYS_DPAA_FMAN
737 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
739 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
740 if (soc_has_dp_ddr()) {
741 printf(" DP-DDR: %-4s MT/s",
742 strmhz(buf, sysinfo.freq_ddrbus2));
748 * Display the RCW, so that no one gets confused as to what RCW
749 * we're actually using for this boot.
751 puts("Reset Configuration Word (RCW):");
752 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
753 rcw = gur_in32(&gur->rcwsr[i]);
755 printf("\n %08x:", i * 4);
756 printf(" %08x", rcw);
764 #ifdef CONFIG_FSL_ESDHC
765 int cpu_mmc_init(bd_t *bis)
767 return fsl_esdhc_mmc_init(bis);
771 int cpu_eth_init(bd_t *bis)
775 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
776 error = fsl_mc_ldpaa_init(bis);
778 #ifdef CONFIG_FMAN_ENET
779 fm_standard_init(bis);
784 static inline int check_psci(void)
786 unsigned int psci_ver;
788 psci_ver = sec_firmware_support_psci_version();
789 if (psci_ver == PSCI_INVALID_VER)
795 static void config_core_prefetch(void)
798 char buffer[HWCONFIG_BUFFER_SIZE];
799 const char *prefetch_arg = NULL;
804 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
807 prefetch_arg = hwconfig_subarg_f("core_prefetch", "disable",
811 mask = simple_strtoul(prefetch_arg, NULL, 0) & 0xff;
813 printf("Core0 prefetch can't be disabled\n");
817 #define SIP_PREFETCH_DISABLE_64 0xC200FF13
818 regs.regs[0] = SIP_PREFETCH_DISABLE_64;
823 printf("Prefetch disable config failed for mask ");
825 printf("Prefetch disable config passed for mask ");
826 printf("0x%x\n", mask);
830 int arch_early_init_r(void)
832 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
835 * erratum A009635 is valid only for LS2080A SoC and
838 svr_dev_id = get_svr();
839 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
842 #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
843 erratum_a009942_check_cpo();
846 debug("PSCI: PSCI does not exist.\n");
848 /* if PSCI does not exist, boot secondary cores here */
849 if (fsl_layerscape_wake_seconday_cores())
850 printf("Did not wake secondary cores\n");
853 #ifdef CONFIG_SYS_FSL_HAS_RGMII
857 config_core_prefetch();
859 #ifdef CONFIG_SYS_HAS_SERDES
862 #ifdef CONFIG_FMAN_ENET
865 #ifdef CONFIG_SYS_DPAA_QBMAN
866 setup_qbman_portals();
873 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
874 #ifdef CONFIG_FSL_LSCH3
875 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
877 #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
878 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
881 #ifdef COUNTER_FREQUENCY_REAL
882 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
884 /* Update with accurate clock frequency */
885 if (current_el() == 3)
886 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
889 #ifdef CONFIG_FSL_LSCH3
890 /* Enable timebase for all clusters.
891 * It is safe to do so even some clusters are not enabled.
893 out_le32(cltbenr, 0xf);
896 #if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
898 * In certain Layerscape SoCs, the clock for each core's
899 * has an enable bit in the PMU Physical Core Time Base Enable
900 * Register (PCTBENR), which allows the watchdog to operate.
902 setbits_le32(pctbenr, 0xff);
904 * For LS2080A SoC and its personalities, timer controller
905 * offset is different
907 svr_dev_id = get_svr();
908 if (IS_SVR_DEV(svr_dev_id, SVR_DEV(SVR_LS2080A)))
909 cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
913 /* Enable clock for timer
914 * This is a global setting.
916 out_le32(cntcr, 0x1);
921 __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
923 void __efi_runtime reset_cpu(ulong addr)
927 /* Raise RESET_REQ_B */
928 val = scfg_in32(rstcr);
930 scfg_out32(rstcr, val);
933 #ifdef CONFIG_EFI_LOADER
935 void __efi_runtime EFIAPI efi_reset_system(
936 enum efi_reset_type reset_type,
937 efi_status_t reset_status,
938 unsigned long data_size, void *reset_data)
940 switch (reset_type) {
943 case EFI_RESET_PLATFORM_SPECIFIC:
946 case EFI_RESET_SHUTDOWN:
947 /* Nothing we can do */
954 efi_status_t efi_reset_system_init(void)
956 return efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
962 * Calculate reserved memory with given memory bank
963 * Return aligned memory size on success
964 * Return (ram_size + needed size) for failure
966 phys_size_t board_reserve_ram_top(phys_size_t ram_size)
968 phys_size_t ram_top = ram_size;
970 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
971 ram_top = mc_get_dram_block_size();
972 if (ram_top > ram_size)
973 return ram_size + ram_top;
975 ram_top = ram_size - ram_top;
976 /* The start address of MC reserved memory needs to be aligned. */
977 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
980 return ram_size - ram_top;
983 phys_size_t get_effective_memsize(void)
985 phys_size_t ea_size, rem = 0;
988 * For ARMv8 SoCs, DDR memory is split into two or three regions. The
989 * first region is 2GB space at 0x8000_0000. Secure memory needs to
990 * allocated from first region. If the memory extends to the second
991 * region (or the third region if applicable), Management Complex (MC)
992 * memory should be put into the highest region, i.e. the end of DDR
993 * memory. CONFIG_MAX_MEM_MAPPED is set to the size of first region so
994 * U-Boot doesn't relocate itself into higher address. Should DDR be
995 * configured to skip the first region, this function needs to be
998 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
999 ea_size = CONFIG_MAX_MEM_MAPPED;
1000 rem = gd->ram_size - ea_size;
1002 ea_size = gd->ram_size;
1005 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1006 /* Check if we have enough space for secure memory */
1007 if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE)
1008 ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
1010 printf("Error: No enough space for secure memory.\n");
1012 /* Check if we have enough memory for MC */
1013 if (rem < board_reserve_ram_top(rem)) {
1014 /* Not enough memory in high region to reserve */
1015 if (ea_size > board_reserve_ram_top(ea_size))
1016 ea_size -= board_reserve_ram_top(ea_size);
1018 printf("Error: No enough space for reserved memory.\n");
1024 int dram_init_banksize(void)
1026 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1027 phys_size_t dp_ddr_size;
1031 * gd->ram_size has the total size of DDR memory, less reserved secure
1032 * memory. The DDR extends from low region to high region(s) presuming
1033 * no hole is created with DDR configuration. gd->arch.secure_ram tracks
1034 * the location of secure memory. gd->arch.resv_ram tracks the location
1035 * of reserved memory for Management Complex (MC). Because gd->ram_size
1036 * is reduced by this function if secure memory is reserved, checking
1037 * gd->arch.secure_ram should be done to avoid running it repeatedly.
1040 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1041 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
1042 debug("No need to run again, skip %s\n", __func__);
1048 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
1049 if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
1050 gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
1051 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
1052 gd->bd->bi_dram[1].size = gd->ram_size -
1053 CONFIG_SYS_DDR_BLOCK1_SIZE;
1054 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1055 if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
1056 gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
1057 gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
1058 CONFIG_SYS_DDR_BLOCK2_SIZE;
1059 gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
1063 gd->bd->bi_dram[0].size = gd->ram_size;
1065 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1066 if (gd->bd->bi_dram[0].size >
1067 CONFIG_SYS_MEM_RESERVE_SECURE) {
1068 gd->bd->bi_dram[0].size -=
1069 CONFIG_SYS_MEM_RESERVE_SECURE;
1070 gd->arch.secure_ram = gd->bd->bi_dram[0].start +
1071 gd->bd->bi_dram[0].size;
1072 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
1073 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
1075 #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
1077 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
1078 /* Assign memory for MC */
1079 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1080 if (gd->bd->bi_dram[2].size >=
1081 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
1082 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
1083 gd->bd->bi_dram[2].size -
1084 board_reserve_ram_top(gd->bd->bi_dram[2].size);
1088 if (gd->bd->bi_dram[1].size >=
1089 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
1090 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
1091 gd->bd->bi_dram[1].size -
1092 board_reserve_ram_top(gd->bd->bi_dram[1].size);
1093 } else if (gd->bd->bi_dram[0].size >
1094 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
1095 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
1096 gd->bd->bi_dram[0].size -
1097 board_reserve_ram_top(gd->bd->bi_dram[0].size);
1100 #endif /* CONFIG_FSL_MC_ENET */
1102 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1103 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1104 #error "This SoC shouldn't have DP DDR"
1106 if (soc_has_dp_ddr()) {
1107 /* initialize DP-DDR here */
1110 * DDR controller use 0 as the base address for binding.
1111 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
1113 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
1115 CONFIG_DP_DDR_NUM_CTRLS,
1116 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
1119 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
1120 gd->bd->bi_dram[2].size = dp_ddr_size;
1122 puts("Not detected");
1127 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
1128 debug("%s is called. gd->ram_size is reduced to %lu\n",
1129 __func__, (ulong)gd->ram_size);
1135 #if CONFIG_IS_ENABLED(EFI_LOADER)
1136 void efi_add_known_memory(void)
1139 phys_addr_t ram_start, start;
1140 phys_size_t ram_size;
1144 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
1145 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
1146 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1147 #error "This SoC shouldn't have DP DDR"
1150 continue; /* skip DP-DDR */
1152 ram_start = gd->bd->bi_dram[i].start;
1153 ram_size = gd->bd->bi_dram[i].size;
1154 #ifdef CONFIG_RESV_RAM
1155 if (gd->arch.resv_ram >= ram_start &&
1156 gd->arch.resv_ram < ram_start + ram_size)
1157 ram_size = gd->arch.resv_ram - ram_start;
1159 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
1160 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
1162 efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
1169 * Before DDR size is known, early MMU table have DDR mapped as device memory
1170 * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
1171 * needs to be set for these mappings.
1172 * If a special case configures DDR with holes in the mapping, the holes need
1173 * to be marked as invalid. This is not implemented in this function.
1175 void update_early_mmu_table(void)
1177 if (!gd->arch.tlb_addr)
1180 if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
1181 mmu_change_region_attr(
1182 CONFIG_SYS_SDRAM_BASE,
1184 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1185 PTE_BLOCK_OUTER_SHARE |
1189 mmu_change_region_attr(
1190 CONFIG_SYS_SDRAM_BASE,
1191 CONFIG_SYS_DDR_BLOCK1_SIZE,
1192 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1193 PTE_BLOCK_OUTER_SHARE |
1196 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
1197 #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
1198 #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
1200 if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
1201 CONFIG_SYS_DDR_BLOCK2_SIZE) {
1202 mmu_change_region_attr(
1203 CONFIG_SYS_DDR_BLOCK2_BASE,
1204 CONFIG_SYS_DDR_BLOCK2_SIZE,
1205 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1206 PTE_BLOCK_OUTER_SHARE |
1209 mmu_change_region_attr(
1210 CONFIG_SYS_DDR_BLOCK3_BASE,
1212 CONFIG_SYS_DDR_BLOCK1_SIZE -
1213 CONFIG_SYS_DDR_BLOCK2_SIZE,
1214 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1215 PTE_BLOCK_OUTER_SHARE |
1221 mmu_change_region_attr(
1222 CONFIG_SYS_DDR_BLOCK2_BASE,
1224 CONFIG_SYS_DDR_BLOCK1_SIZE,
1225 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
1226 PTE_BLOCK_OUTER_SHARE |
1233 __weak int dram_init(void)
1236 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
1237 /* This will break-before-make MMU for DDR */
1238 update_early_mmu_table();