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 <fsl_immap.h>
20 #include <asm/arch/mp.h>
21 #include <efi_loader.h>
23 #include <fsl-mc/fsl_mc.h>
24 #ifdef CONFIG_FSL_ESDHC
25 #include <fsl_esdhc.h>
27 #include <asm/armv8/sec_firmware.h>
28 #ifdef CONFIG_SYS_FSL_DDR
31 #include <asm/arch/clock.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 struct mm_region *mem_map = early_map;
37 void cpu_name(char *name)
39 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
40 unsigned int i, svr, ver;
42 svr = gur_in32(&gur->svr);
43 ver = SVR_SOC_VER(svr);
45 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
46 if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
47 strcpy(name, cpu_type_list[i].name);
49 if (IS_E_PROCESSOR(svr))
52 sprintf(name + strlen(name), " Rev%d.%d",
53 SVR_MAJ(svr), SVR_MIN(svr));
57 if (i == ARRAY_SIZE(cpu_type_list))
58 strcpy(name, "unknown");
61 #ifndef CONFIG_SYS_DCACHE_OFF
63 * To start MMU before DDR is available, we create MMU table in SRAM.
64 * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
65 * levels of translation tables here to cover 40-bit address space.
66 * We use 4KB granule size, with 40 bits physical address, T0SZ=24
67 * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
68 * Note, the debug print in cache_v8.c is not usable for debugging
69 * these early MMU tables because UART is not yet available.
71 static inline void early_mmu_setup(void)
73 unsigned int el = current_el();
75 /* global data is already setup, no allocation yet */
76 gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
77 gd->arch.tlb_fillptr = gd->arch.tlb_addr;
78 gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
80 /* Create early page tables */
83 /* point TTBR to the new table */
84 set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
85 get_tcr(el, NULL, NULL) &
86 ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
89 set_sctlr(get_sctlr() | CR_M);
92 static void fix_pcie_mmu_map(void)
94 #ifdef CONFIG_ARCH_LS2080A
97 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
99 svr = gur_in32(&gur->svr);
100 ver = SVR_SOC_VER(svr);
102 /* Fix PCIE base and size for LS2088A */
103 if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
104 (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
105 (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
106 for (i = 0; i < ARRAY_SIZE(final_map); i++) {
107 switch (final_map[i].phys) {
108 case CONFIG_SYS_PCIE1_PHYS_ADDR:
109 final_map[i].phys = 0x2000000000ULL;
110 final_map[i].virt = 0x2000000000ULL;
111 final_map[i].size = 0x800000000ULL;
113 case CONFIG_SYS_PCIE2_PHYS_ADDR:
114 final_map[i].phys = 0x2800000000ULL;
115 final_map[i].virt = 0x2800000000ULL;
116 final_map[i].size = 0x800000000ULL;
118 case CONFIG_SYS_PCIE3_PHYS_ADDR:
119 final_map[i].phys = 0x3000000000ULL;
120 final_map[i].virt = 0x3000000000ULL;
121 final_map[i].size = 0x800000000ULL;
123 case CONFIG_SYS_PCIE4_PHYS_ADDR:
124 final_map[i].phys = 0x3800000000ULL;
125 final_map[i].virt = 0x3800000000ULL;
126 final_map[i].size = 0x800000000ULL;
137 * The final tables look similar to early tables, but different in detail.
138 * These tables are in DRAM. Sub tables are added to enable cache for
141 * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
142 * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
144 static inline void final_mmu_setup(void)
146 u64 tlb_addr_save = gd->arch.tlb_addr;
147 unsigned int el = current_el();
150 /* fix the final_map before filling in the block entries */
155 /* Update mapping for DDR to actual size */
156 for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
158 * Find the entry for DDR mapping and update the address and
159 * size. Zero-sized mapping will be skipped when creating MMU
162 switch (final_map[index].virt) {
163 case CONFIG_SYS_FSL_DRAM_BASE1:
164 final_map[index].virt = gd->bd->bi_dram[0].start;
165 final_map[index].phys = gd->bd->bi_dram[0].start;
166 final_map[index].size = gd->bd->bi_dram[0].size;
168 #ifdef CONFIG_SYS_FSL_DRAM_BASE2
169 case CONFIG_SYS_FSL_DRAM_BASE2:
170 #if (CONFIG_NR_DRAM_BANKS >= 2)
171 final_map[index].virt = gd->bd->bi_dram[1].start;
172 final_map[index].phys = gd->bd->bi_dram[1].start;
173 final_map[index].size = gd->bd->bi_dram[1].size;
175 final_map[index].size = 0;
179 #ifdef CONFIG_SYS_FSL_DRAM_BASE3
180 case CONFIG_SYS_FSL_DRAM_BASE3:
181 #if (CONFIG_NR_DRAM_BANKS >= 3)
182 final_map[index].virt = gd->bd->bi_dram[2].start;
183 final_map[index].phys = gd->bd->bi_dram[2].start;
184 final_map[index].size = gd->bd->bi_dram[2].size;
186 final_map[index].size = 0;
195 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
196 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
199 * Only use gd->arch.secure_ram if the address is
200 * recalculated. Align to 4KB for MMU table.
202 /* put page tables in secure ram */
203 index = ARRAY_SIZE(final_map) - 2;
204 gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
205 final_map[index].virt = gd->arch.secure_ram & ~0x3;
206 final_map[index].phys = final_map[index].virt;
207 final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
208 final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
209 gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
210 tlb_addr_save = gd->arch.tlb_addr;
212 /* Use allocated (board_f.c) memory for TLB */
213 tlb_addr_save = gd->arch.tlb_allocated;
214 gd->arch.tlb_addr = tlb_addr_save;
219 /* Reset the fill ptr */
220 gd->arch.tlb_fillptr = tlb_addr_save;
222 /* Create normal system page tables */
225 /* Create emergency page tables */
226 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
227 gd->arch.tlb_emerg = gd->arch.tlb_addr;
229 gd->arch.tlb_addr = tlb_addr_save;
231 /* Disable cache and MMU */
232 dcache_disable(); /* TLBs are invalidated */
233 invalidate_icache_all();
235 /* point TTBR to the new table */
236 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
239 set_sctlr(get_sctlr() | CR_M);
242 u64 get_page_table_size(void)
247 int arch_cpu_init(void)
250 * This function is called before U-Boot relocates itself to speed up
251 * on system running. It is not necessary to run if performance is not
252 * critical. Skip if MMU is already enabled by SPL or other means.
254 if (get_sctlr() & CR_M)
258 __asm_invalidate_dcache_all();
259 __asm_invalidate_tlb_all();
261 set_sctlr(get_sctlr() | CR_C);
271 * This function is called from common/board_r.c.
272 * It recreates MMU table in main memory.
274 void enable_caches(void)
277 __asm_invalidate_tlb_all();
283 u32 initiator_type(u32 cluster, int init_id)
285 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
286 u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
289 type = gur_in32(&gur->tp_ityp[idx]);
290 if (type & TP_ITYP_AV)
296 u32 cpu_pos_mask(void)
298 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
300 u32 cluster, type, mask = 0;
305 cluster = gur_in32(&gur->tp_cluster[i].lower);
306 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
307 type = initiator_type(cluster, j);
308 if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
309 mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
312 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
319 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
320 int i = 0, count = 0;
321 u32 cluster, type, mask = 0;
326 cluster = gur_in32(&gur->tp_cluster[i].lower);
327 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
328 type = initiator_type(cluster, j);
330 if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
336 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
342 * Return the number of cores on this SOC.
344 int cpu_numcores(void)
346 return hweight32(cpu_mask());
349 int fsl_qoriq_core_to_cluster(unsigned int core)
351 struct ccsr_gur __iomem *gur =
352 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
353 int i = 0, count = 0;
359 cluster = gur_in32(&gur->tp_cluster[i].lower);
360 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
361 if (initiator_type(cluster, j)) {
368 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
370 return -1; /* cannot identify the cluster */
373 u32 fsl_qoriq_core_to_type(unsigned int core)
375 struct ccsr_gur __iomem *gur =
376 (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
377 int i = 0, count = 0;
383 cluster = gur_in32(&gur->tp_cluster[i].lower);
384 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
385 type = initiator_type(cluster, j);
393 } while ((cluster & TP_CLUSTER_EOC) == 0x0);
395 return -1; /* cannot identify the cluster */
398 #ifndef CONFIG_FSL_LSCH3
401 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
403 return gur_in32(&gur->svr);
407 #ifdef CONFIG_DISPLAY_CPUINFO
408 int print_cpuinfo(void)
410 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
411 struct sys_info sysinfo;
413 unsigned int i, core;
414 u32 type, rcw, svr = gur_in32(&gur->svr);
419 printf(" %s (0x%x)\n", buf, svr);
420 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
421 get_sys_info(&sysinfo);
422 puts("Clock Configuration:");
423 for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
426 type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
427 printf("CPU%d(%s):%-4s MHz ", core,
428 type == TY_ITYP_VER_A7 ? "A7 " :
429 (type == TY_ITYP_VER_A53 ? "A53" :
430 (type == TY_ITYP_VER_A57 ? "A57" :
431 (type == TY_ITYP_VER_A72 ? "A72" : " "))),
432 strmhz(buf, sysinfo.freq_processor[core]));
434 /* Display platform clock as Bus frequency. */
435 printf("\n Bus: %-4s MHz ",
436 strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
437 printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
438 #ifdef CONFIG_SYS_DPAA_FMAN
439 printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
441 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
442 if (soc_has_dp_ddr()) {
443 printf(" DP-DDR: %-4s MT/s",
444 strmhz(buf, sysinfo.freq_ddrbus2));
450 * Display the RCW, so that no one gets confused as to what RCW
451 * we're actually using for this boot.
453 puts("Reset Configuration Word (RCW):");
454 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
455 rcw = gur_in32(&gur->rcwsr[i]);
457 printf("\n %08x:", i * 4);
458 printf(" %08x", rcw);
466 #ifdef CONFIG_FSL_ESDHC
467 int cpu_mmc_init(bd_t *bis)
469 return fsl_esdhc_mmc_init(bis);
473 int cpu_eth_init(bd_t *bis)
477 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
478 error = fsl_mc_ldpaa_init(bis);
480 #ifdef CONFIG_FMAN_ENET
481 fm_standard_init(bis);
486 static inline int check_psci(void)
488 unsigned int psci_ver;
490 psci_ver = sec_firmware_support_psci_version();
491 if (psci_ver == PSCI_INVALID_VER)
497 int arch_early_init_r(void)
499 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
502 * erratum A009635 is valid only for LS2080A SoC and
505 svr_dev_id = get_svr() >> 16;
506 if (svr_dev_id == SVR_DEV_LS2080A)
509 #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
510 erratum_a009942_check_cpo();
513 debug("PSCI: PSCI does not exist.\n");
515 /* if PSCI does not exist, boot secondary cores here */
516 if (fsl_layerscape_wake_seconday_cores())
517 printf("Did not wake secondary cores\n");
520 #ifdef CONFIG_SYS_FSL_HAS_RGMII
524 #ifdef CONFIG_SYS_HAS_SERDES
527 #ifdef CONFIG_FMAN_ENET
535 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
536 #ifdef CONFIG_FSL_LSCH3
537 u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
539 #ifdef CONFIG_ARCH_LS2080A
540 u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
543 #ifdef COUNTER_FREQUENCY_REAL
544 unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
546 /* Update with accurate clock frequency */
547 if (current_el() == 3)
548 asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
551 #ifdef CONFIG_FSL_LSCH3
552 /* Enable timebase for all clusters.
553 * It is safe to do so even some clusters are not enabled.
555 out_le32(cltbenr, 0xf);
558 #ifdef CONFIG_ARCH_LS2080A
560 * In certain Layerscape SoCs, the clock for each core's
561 * has an enable bit in the PMU Physical Core Time Base Enable
562 * Register (PCTBENR), which allows the watchdog to operate.
564 setbits_le32(pctbenr, 0xff);
566 * For LS2080A SoC and its personalities, timer controller
567 * offset is different
569 svr_dev_id = get_svr() >> 16;
570 if (svr_dev_id == SVR_DEV_LS2080A)
571 cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
575 /* Enable clock for timer
576 * This is a global setting.
578 out_le32(cntcr, 0x1);
583 __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
585 void __efi_runtime reset_cpu(ulong addr)
589 /* Raise RESET_REQ_B */
590 val = scfg_in32(rstcr);
592 scfg_out32(rstcr, val);
595 #ifdef CONFIG_EFI_LOADER
597 void __efi_runtime EFIAPI efi_reset_system(
598 enum efi_reset_type reset_type,
599 efi_status_t reset_status,
600 unsigned long data_size, void *reset_data)
602 switch (reset_type) {
607 case EFI_RESET_SHUTDOWN:
608 /* Nothing we can do */
615 void efi_reset_system_init(void)
617 efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
623 * Calculate reserved memory with given memory bank
624 * Return aligned memory size on success
625 * Return (ram_size + needed size) for failure
627 phys_size_t board_reserve_ram_top(phys_size_t ram_size)
629 phys_size_t ram_top = ram_size;
631 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
632 ram_top = mc_get_dram_block_size();
633 if (ram_top > ram_size)
634 return ram_size + ram_top;
636 ram_top = ram_size - ram_top;
637 /* The start address of MC reserved memory needs to be aligned. */
638 ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
641 return ram_size - ram_top;
644 phys_size_t get_effective_memsize(void)
646 phys_size_t ea_size, rem = 0;
649 * For ARMv8 SoCs, DDR memory is split into two or three regions. The
650 * first region is 2GB space at 0x8000_0000. Secure memory needs to
651 * allocated from first region. If the memory extends to the second
652 * region (or the third region if applicable), Management Complex (MC)
653 * memory should be put into the highest region, i.e. the end of DDR
654 * memory. CONFIG_MAX_MEM_MAPPED is set to the size of first region so
655 * U-Boot doesn't relocate itself into higher address. Should DDR be
656 * configured to skip the first region, this function needs to be
659 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
660 ea_size = CONFIG_MAX_MEM_MAPPED;
661 rem = gd->ram_size - ea_size;
663 ea_size = gd->ram_size;
666 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
667 /* Check if we have enough space for secure memory */
668 if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE)
669 ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
671 printf("Error: No enough space for secure memory.\n");
673 /* Check if we have enough memory for MC */
674 if (rem < board_reserve_ram_top(rem)) {
675 /* Not enough memory in high region to reserve */
676 if (ea_size > board_reserve_ram_top(ea_size))
677 ea_size -= board_reserve_ram_top(ea_size);
679 printf("Error: No enough space for reserved memory.\n");
685 int dram_init_banksize(void)
687 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
688 phys_size_t dp_ddr_size;
692 * gd->ram_size has the total size of DDR memory, less reserved secure
693 * memory. The DDR extends from low region to high region(s) presuming
694 * no hole is created with DDR configuration. gd->arch.secure_ram tracks
695 * the location of secure memory. gd->arch.resv_ram tracks the location
696 * of reserved memory for Management Complex (MC). Because gd->ram_size
697 * is reduced by this function if secure memory is reserved, checking
698 * gd->arch.secure_ram should be done to avoid running it repeatedly.
701 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
702 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
703 debug("No need to run again, skip %s\n", __func__);
709 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
710 if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
711 gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
712 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
713 gd->bd->bi_dram[1].size = gd->ram_size -
714 CONFIG_SYS_DDR_BLOCK1_SIZE;
715 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
716 if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
717 gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
718 gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
719 CONFIG_SYS_DDR_BLOCK2_SIZE;
720 gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
724 gd->bd->bi_dram[0].size = gd->ram_size;
726 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
727 if (gd->bd->bi_dram[0].size >
728 CONFIG_SYS_MEM_RESERVE_SECURE) {
729 gd->bd->bi_dram[0].size -=
730 CONFIG_SYS_MEM_RESERVE_SECURE;
731 gd->arch.secure_ram = gd->bd->bi_dram[0].start +
732 gd->bd->bi_dram[0].size;
733 gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
734 gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
736 #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
738 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
739 /* Assign memory for MC */
740 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
741 if (gd->bd->bi_dram[2].size >=
742 board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
743 gd->arch.resv_ram = gd->bd->bi_dram[2].start +
744 gd->bd->bi_dram[2].size -
745 board_reserve_ram_top(gd->bd->bi_dram[2].size);
749 if (gd->bd->bi_dram[1].size >=
750 board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
751 gd->arch.resv_ram = gd->bd->bi_dram[1].start +
752 gd->bd->bi_dram[1].size -
753 board_reserve_ram_top(gd->bd->bi_dram[1].size);
754 } else if (gd->bd->bi_dram[0].size >
755 board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
756 gd->arch.resv_ram = gd->bd->bi_dram[0].start +
757 gd->bd->bi_dram[0].size -
758 board_reserve_ram_top(gd->bd->bi_dram[0].size);
761 #endif /* CONFIG_FSL_MC_ENET */
763 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
764 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
765 #error "This SoC shouldn't have DP DDR"
767 if (soc_has_dp_ddr()) {
768 /* initialize DP-DDR here */
771 * DDR controller use 0 as the base address for binding.
772 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
774 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
776 CONFIG_DP_DDR_NUM_CTRLS,
777 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
780 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
781 gd->bd->bi_dram[2].size = dp_ddr_size;
783 puts("Not detected");
788 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
789 debug("%s is called. gd->ram_size is reduced to %lu\n",
790 __func__, (ulong)gd->ram_size);
796 #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
797 void efi_add_known_memory(void)
800 phys_addr_t ram_start, start;
801 phys_size_t ram_size;
805 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
806 #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
807 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
808 #error "This SoC shouldn't have DP DDR"
811 continue; /* skip DP-DDR */
813 ram_start = gd->bd->bi_dram[i].start;
814 ram_size = gd->bd->bi_dram[i].size;
815 #ifdef CONFIG_RESV_RAM
816 if (gd->arch.resv_ram >= ram_start &&
817 gd->arch.resv_ram < ram_start + ram_size)
818 ram_size = gd->arch.resv_ram - ram_start;
820 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
821 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
823 efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
830 * Before DDR size is known, early MMU table have DDR mapped as device memory
831 * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
832 * needs to be set for these mappings.
833 * If a special case configures DDR with holes in the mapping, the holes need
834 * to be marked as invalid. This is not implemented in this function.
836 void update_early_mmu_table(void)
838 if (!gd->arch.tlb_addr)
841 if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
842 mmu_change_region_attr(
843 CONFIG_SYS_SDRAM_BASE,
845 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
846 PTE_BLOCK_OUTER_SHARE |
850 mmu_change_region_attr(
851 CONFIG_SYS_SDRAM_BASE,
852 CONFIG_SYS_DDR_BLOCK1_SIZE,
853 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
854 PTE_BLOCK_OUTER_SHARE |
857 #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
858 #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
859 #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
861 if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
862 CONFIG_SYS_DDR_BLOCK2_SIZE) {
863 mmu_change_region_attr(
864 CONFIG_SYS_DDR_BLOCK2_BASE,
865 CONFIG_SYS_DDR_BLOCK2_SIZE,
866 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
867 PTE_BLOCK_OUTER_SHARE |
870 mmu_change_region_attr(
871 CONFIG_SYS_DDR_BLOCK3_BASE,
873 CONFIG_SYS_DDR_BLOCK1_SIZE -
874 CONFIG_SYS_DDR_BLOCK2_SIZE,
875 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
876 PTE_BLOCK_OUTER_SHARE |
882 mmu_change_region_attr(
883 CONFIG_SYS_DDR_BLOCK2_BASE,
885 CONFIG_SYS_DDR_BLOCK1_SIZE,
886 PTE_BLOCK_MEMTYPE(MT_NORMAL) |
887 PTE_BLOCK_OUTER_SHARE |
894 __weak int dram_init(void)
897 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
898 /* This will break-before-make MMU for DDR */
899 update_early_mmu_table();