3 * Copyright 2014-2015 Freescale Semiconductor, Inc.
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <fsl_ddr_sdram.h>
11 #include <linux/errno.h>
12 #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 <asm/arch/mp.h>
20 #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 DECLARE_GLOBAL_DATA_PTR;
34 struct mm_region *mem_map = early_map;
36 void cpu_name(char *name)
38 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
39 unsigned int i, svr, ver;
41 svr = gur_in32(&gur->svr);
42 ver = SVR_SOC_VER(svr);
44 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
45 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
46 strcpy(name, cpu_type_list[i].name);
48 if (IS_E_PROCESSOR(svr))
51 sprintf(name + strlen(name), " Rev%d.%d",
52 SVR_MAJ(svr), SVR_MIN(svr));
56 if (i == ARRAY_SIZE(cpu_type_list))
57 strcpy(name, "unknown");
60 #ifndef CONFIG_SYS_DCACHE_OFF
62 * To start MMU before DDR is available, we create MMU table in SRAM.
63 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
64 * levels of translation tables here to cover 40-bit address space.
65 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
66 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
67 * Note, the debug print in cache_v8.c is not usable for debugging
68 * these early MMU tables because UART is not yet available.
70 static inline void early_mmu_setup(void)
72 unsigned int el = current_el();
74 /* global data is already setup, no allocation yet */
75 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
76 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
77 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
79 /* Create early page tables */
82 /* point TTBR to the new table */
83 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
84 get_tcr(el, NULL, NULL) &
85 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
88 set_sctlr(get_sctlr() | CR_M);
91 static void fix_pcie_mmu_map(void)
93 #ifdef CONFIG_ARCH_LS2080A
96 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
98 svr = gur_in32(&gur->svr);
99 ver = SVR_SOC_VER(svr);
101 /* Fix PCIE base and size for LS2088A */
102 if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
103 (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
104 (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
105 for (i = 0; i < ARRAY_SIZE(final_map); i++) {
106 switch (final_map[i].phys) {
107 case CONFIG_SYS_PCIE1_PHYS_ADDR:
108 final_map[i].phys = 0x2000000000ULL;
109 final_map[i].virt = 0x2000000000ULL;
110 final_map[i].size = 0x800000000ULL;
112 case CONFIG_SYS_PCIE2_PHYS_ADDR:
113 final_map[i].phys = 0x2800000000ULL;
114 final_map[i].virt = 0x2800000000ULL;
115 final_map[i].size = 0x800000000ULL;
117 case CONFIG_SYS_PCIE3_PHYS_ADDR:
118 final_map[i].phys = 0x3000000000ULL;
119 final_map[i].virt = 0x3000000000ULL;
120 final_map[i].size = 0x800000000ULL;
122 case CONFIG_SYS_PCIE4_PHYS_ADDR:
123 final_map[i].phys = 0x3800000000ULL;
124 final_map[i].virt = 0x3800000000ULL;
125 final_map[i].size = 0x800000000ULL;
136 * The final tables look similar to early tables, but different in detail.
137 * These tables are in DRAM. Sub tables are added to enable cache for
140 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
141 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
143 static inline void final_mmu_setup(void)
145 u64 tlb_addr_save = gd->arch.tlb_addr;
146 unsigned int el = current_el();
149 /* fix the final_map before filling in the block entries */
154 /* Update mapping for DDR to actual size */
155 for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
157 * Find the entry for DDR mapping and update the address and
158 * size. Zero-sized mapping will be skipped when creating MMU
161 switch (final_map[index].virt) {
162 case CONFIG_SYS_FSL_DRAM_BASE1:
163 final_map[index].virt = gd->bd->bi_dram[0].start;
164 final_map[index].phys = gd->bd->bi_dram[0].start;
165 final_map[index].size = gd->bd->bi_dram[0].size;
167 #ifdef CONFIG_SYS_FSL_DRAM_BASE2
168 case CONFIG_SYS_FSL_DRAM_BASE2:
169 #if (CONFIG_NR_DRAM_BANKS >= 2)
170 final_map[index].virt = gd->bd->bi_dram[1].start;
171 final_map[index].phys = gd->bd->bi_dram[1].start;
172 final_map[index].size = gd->bd->bi_dram[1].size;
174 final_map[index].size = 0;
178 #ifdef CONFIG_SYS_FSL_DRAM_BASE3
179 case CONFIG_SYS_FSL_DRAM_BASE3:
180 #if (CONFIG_NR_DRAM_BANKS >= 3)
181 final_map[index].virt = gd->bd->bi_dram[2].start;
182 final_map[index].phys = gd->bd->bi_dram[2].start;
183 final_map[index].size = gd->bd->bi_dram[2].size;
185 final_map[index].size = 0;
194 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
195 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
198 * Only use gd->arch.secure_ram if the address is
199 * recalculated. Align to 4KB for MMU table.
201 /* put page tables in secure ram */
202 index = ARRAY_SIZE(final_map) - 2;
203 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
204 final_map[index].virt = gd->arch.secure_ram & ~0x3;
205 final_map[index].phys = final_map[index].virt;
206 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
207 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
208 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
209 tlb_addr_save = gd->arch.tlb_addr;
211 /* Use allocated (board_f.c) memory for TLB */
212 tlb_addr_save = gd->arch.tlb_allocated;
213 gd->arch.tlb_addr = tlb_addr_save;
218 /* Reset the fill ptr */
219 gd->arch.tlb_fillptr = tlb_addr_save;
221 /* Create normal system page tables */
224 /* Create emergency page tables */
225 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
226 gd->arch.tlb_emerg = gd->arch.tlb_addr;
228 gd->arch.tlb_addr = tlb_addr_save;
230 /* Disable cache and MMU */
231 dcache_disable(); /* TLBs are invalidated */
232 invalidate_icache_all();
234 /* point TTBR to the new table */
235 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
238 set_sctlr(get_sctlr() | CR_M);
241 u64 get_page_table_size(void)
246 int arch_cpu_init(void)
249 * This function is called before U-Boot relocates itself to speed up
250 * on system running. It is not necessary to run if performance is not
251 * critical. Skip if MMU is already enabled by SPL or other means.
253 if (get_sctlr() & CR_M)
257 __asm_invalidate_dcache_all();
258 __asm_invalidate_tlb_all();
260 set_sctlr(get_sctlr() | CR_C);
270 * This function is called from common/board_r.c.
271 * It recreates MMU table in main memory.
273 void enable_caches(void)
276 __asm_invalidate_tlb_all();
282 u32 initiator_type(u32 cluster, int init_id)
284 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
285 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
288 type = gur_in32(&gur->tp_ityp[idx]);
289 if (type & TP_ITYP_AV)
295 u32 cpu_pos_mask(void)
297 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
299 u32 cluster, type, mask = 0;
304 cluster = gur_in32(&gur->tp_cluster[i].lower);
305 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
306 type = initiator_type(cluster, j);
307 if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
308 mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
311 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
318 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
319 int i = 0, count = 0;
320 u32 cluster, type, mask = 0;
325 cluster = gur_in32(&gur->tp_cluster[i].lower);
326 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
327 type = initiator_type(cluster, j);
329 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
335 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
341 * Return the number of cores on this SOC.
343 int cpu_numcores(void)
345 return hweight32(cpu_mask());
348 int fsl_qoriq_core_to_cluster(unsigned int core)
350 struct ccsr_gur __iomem *gur =
351 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
352 int i = 0, count = 0;
358 cluster = gur_in32(&gur->tp_cluster[i].lower);
359 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
360 if (initiator_type(cluster, j)) {
367 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
369 return -1; /* cannot identify the cluster */
372 u32 fsl_qoriq_core_to_type(unsigned int core)
374 struct ccsr_gur __iomem *gur =
375 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
376 int i = 0, count = 0;
382 cluster = gur_in32(&gur->tp_cluster[i].lower);
383 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
384 type = initiator_type(cluster, j);
392 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
394 return -1; /* cannot identify the cluster */
397 #ifndef CONFIG_FSL_LSCH3
400 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
402 return gur_in32(&gur->svr);
406 #ifdef CONFIG_DISPLAY_CPUINFO
407 int print_cpuinfo(void)
409 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
410 struct sys_info sysinfo;
412 unsigned int i, core;
413 u32 type, rcw, svr = gur_in32(&gur->svr);
418 printf(" %s (0x%x)\n", buf, svr);
419 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
420 get_sys_info(&sysinfo);
421 puts("Clock Configuration:");
422 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
425 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
426 printf("CPU%d(%s):%-4s MHz ", core,
427 type == TY_ITYP_VER_A7 ? "A7 " :
428 (type == TY_ITYP_VER_A53 ? "A53" :
429 (type == TY_ITYP_VER_A57 ? "A57" :
430 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
431 strmhz(buf, sysinfo.freq_processor[core]));
433 /* Display platform clock as Bus frequency. */
434 printf("\n Bus: %-4s MHz ",
435 strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
436 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
437 #ifdef CONFIG_SYS_DPAA_FMAN
438 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
440 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
441 if (soc_has_dp_ddr()) {
442 printf(" DP-DDR: %-4s MT/s",
443 strmhz(buf, sysinfo.freq_ddrbus2));
449 * Display the RCW, so that no one gets confused as to what RCW
450 * we're actually using for this boot.
452 puts("Reset Configuration Word (RCW):");
453 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
454 rcw = gur_in32(&gur->rcwsr[i]);
456 printf("\n %08x:", i * 4);
457 printf(" %08x", rcw);
465 #ifdef CONFIG_FSL_ESDHC
466 int cpu_mmc_init(bd_t *bis)
468 return fsl_esdhc_mmc_init(bis);
472 int cpu_eth_init(bd_t *bis)
476 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
477 error = fsl_mc_ldpaa_init(bis);
479 #ifdef CONFIG_FMAN_ENET
480 fm_standard_init(bis);
485 static inline int check_psci(void)
487 unsigned int psci_ver;
489 psci_ver = sec_firmware_support_psci_version();
490 if (psci_ver == PSCI_INVALID_VER)
496 int arch_early_init_r(void)
498 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
501 * erratum A009635 is valid only for LS2080A SoC and
504 svr_dev_id = get_svr() >> 16;
505 if (svr_dev_id == SVR_DEV_LS2080A)
508 #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
509 erratum_a009942_check_cpo();
512 debug("PSCI: PSCI does not exist.\n");
514 /* if PSCI does not exist, boot secondary cores here */
515 if (fsl_layerscape_wake_seconday_cores())
516 printf("Did not wake secondary cores\n");
519 #ifdef CONFIG_SYS_HAS_SERDES
522 #ifdef CONFIG_FMAN_ENET
530 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
531 #ifdef CONFIG_FSL_LSCH3
532 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
534 #ifdef CONFIG_ARCH_LS2080A
535 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
538 #ifdef COUNTER_FREQUENCY_REAL
539 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
541 /* Update with accurate clock frequency */
542 if (current_el() == 3)
543 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
546 #ifdef CONFIG_FSL_LSCH3
547 /* Enable timebase for all clusters.
548 * It is safe to do so even some clusters are not enabled.
550 out_le32(cltbenr, 0xf);
553 #ifdef CONFIG_ARCH_LS2080A
555 * In certain Layerscape SoCs, the clock for each core's
556 * has an enable bit in the PMU Physical Core Time Base Enable
557 * Register (PCTBENR), which allows the watchdog to operate.
559 setbits_le32(pctbenr, 0xff);
561 * For LS2080A SoC and its personalities, timer controller
562 * offset is different
564 svr_dev_id = get_svr() >> 16;
565 if (svr_dev_id == SVR_DEV_LS2080A)
566 cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
570 /* Enable clock for timer
571 * This is a global setting.
573 out_le32(cntcr, 0x1);
578 __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
580 void __efi_runtime reset_cpu(ulong addr)
584 /* Raise RESET_REQ_B */
585 val = scfg_in32(rstcr);
587 scfg_out32(rstcr, val);
590 #ifdef CONFIG_EFI_LOADER
592 void __efi_runtime EFIAPI efi_reset_system(
593 enum efi_reset_type reset_type,
594 efi_status_t reset_status,
595 unsigned long data_size, void *reset_data)
597 switch (reset_type) {
602 case EFI_RESET_SHUTDOWN:
603 /* Nothing we can do */
610 void efi_reset_system_init(void)
612 efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
617 phys_size_t board_reserve_ram_top(phys_size_t ram_size)
619 phys_size_t ram_top = ram_size;
621 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
622 /* The start address of MC reserved memory needs to be aligned. */
623 ram_top -= mc_get_dram_block_size();
624 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
627 return ram_size - ram_top;
630 phys_size_t get_effective_memsize(void)
632 phys_size_t ea_size, rem = 0;
635 * For ARMv8 SoCs, DDR memory is split into two or three regions. The
636 * first region is 2GB space at 0x8000_0000. If the memory extends to
637 * the second region (or the third region if applicable), the secure
638 * memory and Management Complex (MC) memory should be put into the
639 * highest region, i.e. the end of DDR memory. CONFIG_MAX_MEM_MAPPED
640 * is set to the size of first region so U-Boot doesn't relocate itself
641 * into higher address. Should DDR be configured to skip the first
642 * region, this function needs to be adjusted.
644 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
645 ea_size = CONFIG_MAX_MEM_MAPPED;
646 rem = gd->ram_size - ea_size;
648 ea_size = gd->ram_size;
651 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
652 /* Check if we have enough space for secure memory */
653 if (rem > CONFIG_SYS_MEM_RESERVE_SECURE) {
654 rem -= CONFIG_SYS_MEM_RESERVE_SECURE;
656 if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE) {
657 ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
658 rem = 0; /* Presume MC requires more memory */
660 printf("Error: No enough space for secure memory.\n");
664 /* Check if we have enough memory for MC */
665 if (rem < board_reserve_ram_top(rem)) {
666 /* Not enough memory in high region to reserve */
667 if (ea_size > board_reserve_ram_top(rem))
668 ea_size -= board_reserve_ram_top(rem);
670 printf("Error: No enough space for reserved memory.\n");
676 int dram_init_banksize(void)
678 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
679 phys_size_t dp_ddr_size;
683 * gd->ram_size has the total size of DDR memory, less reserved secure
684 * memory. The DDR extends from low region to high region(s) presuming
685 * no hole is created with DDR configuration. gd->arch.secure_ram tracks
686 * the location of secure memory. gd->arch.resv_ram tracks the location
687 * of reserved memory for Management Complex (MC).
689 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
690 if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
691 gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
692 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
693 gd->bd->bi_dram[1].size = gd->ram_size -
694 CONFIG_SYS_DDR_BLOCK1_SIZE;
695 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
696 if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
697 gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
698 gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
699 CONFIG_SYS_DDR_BLOCK2_SIZE;
700 gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
704 gd->bd->bi_dram[0].size = gd->ram_size;
706 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
707 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
708 if (gd->bd->bi_dram[2].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
709 gd->bd->bi_dram[2].size -= CONFIG_SYS_MEM_RESERVE_SECURE;
710 gd->arch.secure_ram = gd->bd->bi_dram[2].start +
711 gd->bd->bi_dram[2].size;
712 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
713 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
717 if (gd->bd->bi_dram[1].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
718 gd->bd->bi_dram[1].size -=
719 CONFIG_SYS_MEM_RESERVE_SECURE;
720 gd->arch.secure_ram = gd->bd->bi_dram[1].start +
721 gd->bd->bi_dram[1].size;
722 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
723 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
724 } else if (gd->bd->bi_dram[0].size >
725 CONFIG_SYS_MEM_RESERVE_SECURE) {
726 gd->bd->bi_dram[0].size -=
727 CONFIG_SYS_MEM_RESERVE_SECURE;
728 gd->arch.secure_ram = gd->bd->bi_dram[0].start +
729 gd->bd->bi_dram[0].size;
730 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
731 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
734 #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
736 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
737 /* Assign memory for MC */
738 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
739 if (gd->bd->bi_dram[2].size >=
740 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
741 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
742 gd->bd->bi_dram[2].size -
743 board_reserve_ram_top(gd->bd->bi_dram[2].size);
747 if (gd->bd->bi_dram[1].size >=
748 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
749 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
750 gd->bd->bi_dram[1].size -
751 board_reserve_ram_top(gd->bd->bi_dram[1].size);
752 } else if (gd->bd->bi_dram[0].size >
753 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
754 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
755 gd->bd->bi_dram[0].size -
756 board_reserve_ram_top(gd->bd->bi_dram[0].size);
759 #endif /* CONFIG_FSL_MC_ENET */
761 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
762 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
763 #error "This SoC shouldn't have DP DDR"
765 if (soc_has_dp_ddr()) {
766 /* initialize DP-DDR here */
769 * DDR controller use 0 as the base address for binding.
770 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
772 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
774 CONFIG_DP_DDR_NUM_CTRLS,
775 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
778 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
779 gd->bd->bi_dram[2].size = dp_ddr_size;
781 puts("Not detected");
789 #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
790 void efi_add_known_memory(void)
793 phys_addr_t ram_start, start;
794 phys_size_t ram_size;
798 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
799 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
800 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
801 #error "This SoC shouldn't have DP DDR"
804 continue; /* skip DP-DDR */
806 ram_start = gd->bd->bi_dram[i].start;
807 ram_size = gd->bd->bi_dram[i].size;
808 #ifdef CONFIG_RESV_RAM
809 if (gd->arch.resv_ram >= ram_start &&
810 gd->arch.resv_ram < ram_start + ram_size)
811 ram_size = gd->arch.resv_ram - ram_start;
813 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
814 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
816 efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
823 * Before DDR size is known, early MMU table have DDR mapped as device memory
824 * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
825 * needs to be set for these mappings.
826 * If a special case configures DDR with holes in the mapping, the holes need
827 * to be marked as invalid. This is not implemented in this function.
829 void update_early_mmu_table(void)
831 if (!gd->arch.tlb_addr)
834 if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
835 mmu_change_region_attr(
836 CONFIG_SYS_SDRAM_BASE,
838 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
839 PTE_BLOCK_OUTER_SHARE |
843 mmu_change_region_attr(
844 CONFIG_SYS_SDRAM_BASE,
845 CONFIG_SYS_DDR_BLOCK1_SIZE,
846 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
847 PTE_BLOCK_OUTER_SHARE |
850 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
851 #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
852 #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
854 if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
855 CONFIG_SYS_DDR_BLOCK2_SIZE) {
856 mmu_change_region_attr(
857 CONFIG_SYS_DDR_BLOCK2_BASE,
858 CONFIG_SYS_DDR_BLOCK2_SIZE,
859 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
860 PTE_BLOCK_OUTER_SHARE |
863 mmu_change_region_attr(
864 CONFIG_SYS_DDR_BLOCK3_BASE,
866 CONFIG_SYS_DDR_BLOCK1_SIZE -
867 CONFIG_SYS_DDR_BLOCK2_SIZE,
868 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
869 PTE_BLOCK_OUTER_SHARE |
875 mmu_change_region_attr(
876 CONFIG_SYS_DDR_BLOCK2_BASE,
878 CONFIG_SYS_DDR_BLOCK1_SIZE,
879 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
880 PTE_BLOCK_OUTER_SHARE |
887 __weak int dram_init(void)
890 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
891 /* This will break-before-make MMU for DDR */
892 update_early_mmu_table();