cpu.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /*
  2. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <linux/errno.h>
  9. #include <asm/system.h>
  10. #include <asm/armv8/mmu.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/fsl_serdes.h>
  13. #include <asm/arch/soc.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/speed.h>
  16. #ifdef CONFIG_MP
  17. #include <asm/arch/mp.h>
  18. #endif
  19. #include <efi_loader.h>
  20. #include <fm_eth.h>
  21. #include <fsl-mc/fsl_mc.h>
  22. #ifdef CONFIG_FSL_ESDHC
  23. #include <fsl_esdhc.h>
  24. #endif
  25. #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
  26. #include <asm/armv8/sec_firmware.h>
  27. #endif
  28. #ifdef CONFIG_SYS_FSL_DDR
  29. #include <fsl_ddr.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. struct mm_region *mem_map = early_map;
  33. void cpu_name(char *name)
  34. {
  35. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  36. unsigned int i, svr, ver;
  37. svr = gur_in32(&gur->svr);
  38. ver = SVR_SOC_VER(svr);
  39. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  40. if ((cpu_type_list[i].soc_ver & SVR_WO_E) == ver) {
  41. strcpy(name, cpu_type_list[i].name);
  42. if (IS_E_PROCESSOR(svr))
  43. strcat(name, "E");
  44. sprintf(name + strlen(name), " Rev%d.%d",
  45. SVR_MAJ(svr), SVR_MIN(svr));
  46. break;
  47. }
  48. if (i == ARRAY_SIZE(cpu_type_list))
  49. strcpy(name, "unknown");
  50. }
  51. #ifndef CONFIG_SYS_DCACHE_OFF
  52. /*
  53. * To start MMU before DDR is available, we create MMU table in SRAM.
  54. * The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three
  55. * levels of translation tables here to cover 40-bit address space.
  56. * We use 4KB granule size, with 40 bits physical address, T0SZ=24
  57. * Address above EARLY_PGTABLE_SIZE (0x5000) is free for other purpose.
  58. * Note, the debug print in cache_v8.c is not usable for debugging
  59. * these early MMU tables because UART is not yet available.
  60. */
  61. static inline void early_mmu_setup(void)
  62. {
  63. unsigned int el = current_el();
  64. /* global data is already setup, no allocation yet */
  65. gd->arch.tlb_addr = CONFIG_SYS_FSL_OCRAM_BASE;
  66. gd->arch.tlb_fillptr = gd->arch.tlb_addr;
  67. gd->arch.tlb_size = EARLY_PGTABLE_SIZE;
  68. /* Create early page tables */
  69. setup_pgtables();
  70. /* point TTBR to the new table */
  71. set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
  72. get_tcr(el, NULL, NULL) &
  73. ~(TCR_ORGN_MASK | TCR_IRGN_MASK),
  74. MEMORY_ATTRIBUTES);
  75. set_sctlr(get_sctlr() | CR_M);
  76. }
  77. /*
  78. * The final tables look similar to early tables, but different in detail.
  79. * These tables are in DRAM. Sub tables are added to enable cache for
  80. * QBMan and OCRAM.
  81. *
  82. * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
  83. * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
  84. */
  85. static inline void final_mmu_setup(void)
  86. {
  87. u64 tlb_addr_save = gd->arch.tlb_addr;
  88. unsigned int el = current_el();
  89. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  90. int index;
  91. #endif
  92. mem_map = final_map;
  93. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  94. if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
  95. if (el == 3) {
  96. /*
  97. * Only use gd->arch.secure_ram if the address is
  98. * recalculated. Align to 4KB for MMU table.
  99. */
  100. /* put page tables in secure ram */
  101. index = ARRAY_SIZE(final_map) - 2;
  102. gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
  103. final_map[index].virt = gd->arch.secure_ram & ~0x3;
  104. final_map[index].phys = final_map[index].virt;
  105. final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
  106. final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
  107. gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
  108. tlb_addr_save = gd->arch.tlb_addr;
  109. } else {
  110. /* Use allocated (board_f.c) memory for TLB */
  111. tlb_addr_save = gd->arch.tlb_allocated;
  112. gd->arch.tlb_addr = tlb_addr_save;
  113. }
  114. }
  115. #endif
  116. /* Reset the fill ptr */
  117. gd->arch.tlb_fillptr = tlb_addr_save;
  118. /* Create normal system page tables */
  119. setup_pgtables();
  120. /* Create emergency page tables */
  121. gd->arch.tlb_addr = gd->arch.tlb_fillptr;
  122. gd->arch.tlb_emerg = gd->arch.tlb_addr;
  123. setup_pgtables();
  124. gd->arch.tlb_addr = tlb_addr_save;
  125. /* flush new MMU table */
  126. flush_dcache_range(gd->arch.tlb_addr,
  127. gd->arch.tlb_addr + gd->arch.tlb_size);
  128. /* point TTBR to the new table */
  129. set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
  130. MEMORY_ATTRIBUTES);
  131. /*
  132. * EL3 MMU is already enabled, just need to invalidate TLB to load the
  133. * new table. The new table is compatible with the current table, if
  134. * MMU somehow walks through the new table before invalidation TLB,
  135. * it still works. So we don't need to turn off MMU here.
  136. * When EL2 MMU table is created by calling this function, MMU needs
  137. * to be enabled.
  138. */
  139. set_sctlr(get_sctlr() | CR_M);
  140. }
  141. u64 get_page_table_size(void)
  142. {
  143. return 0x10000;
  144. }
  145. int arch_cpu_init(void)
  146. {
  147. icache_enable();
  148. __asm_invalidate_dcache_all();
  149. __asm_invalidate_tlb_all();
  150. early_mmu_setup();
  151. set_sctlr(get_sctlr() | CR_C);
  152. return 0;
  153. }
  154. void mmu_setup(void)
  155. {
  156. final_mmu_setup();
  157. }
  158. /*
  159. * This function is called from common/board_r.c.
  160. * It recreates MMU table in main memory.
  161. */
  162. void enable_caches(void)
  163. {
  164. mmu_setup();
  165. __asm_invalidate_tlb_all();
  166. icache_enable();
  167. dcache_enable();
  168. }
  169. #endif
  170. u32 initiator_type(u32 cluster, int init_id)
  171. {
  172. struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  173. u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
  174. u32 type = 0;
  175. type = gur_in32(&gur->tp_ityp[idx]);
  176. if (type & TP_ITYP_AV)
  177. return type;
  178. return 0;
  179. }
  180. u32 cpu_pos_mask(void)
  181. {
  182. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  183. int i = 0;
  184. u32 cluster, type, mask = 0;
  185. do {
  186. int j;
  187. cluster = gur_in32(&gur->tp_cluster[i].lower);
  188. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  189. type = initiator_type(cluster, j);
  190. if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
  191. mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
  192. }
  193. i++;
  194. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  195. return mask;
  196. }
  197. u32 cpu_mask(void)
  198. {
  199. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  200. int i = 0, count = 0;
  201. u32 cluster, type, mask = 0;
  202. do {
  203. int j;
  204. cluster = gur_in32(&gur->tp_cluster[i].lower);
  205. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  206. type = initiator_type(cluster, j);
  207. if (type) {
  208. if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
  209. mask |= 1 << count;
  210. count++;
  211. }
  212. }
  213. i++;
  214. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  215. return mask;
  216. }
  217. /*
  218. * Return the number of cores on this SOC.
  219. */
  220. int cpu_numcores(void)
  221. {
  222. return hweight32(cpu_mask());
  223. }
  224. int fsl_qoriq_core_to_cluster(unsigned int core)
  225. {
  226. struct ccsr_gur __iomem *gur =
  227. (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
  228. int i = 0, count = 0;
  229. u32 cluster;
  230. do {
  231. int j;
  232. cluster = gur_in32(&gur->tp_cluster[i].lower);
  233. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  234. if (initiator_type(cluster, j)) {
  235. if (count == core)
  236. return i;
  237. count++;
  238. }
  239. }
  240. i++;
  241. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  242. return -1; /* cannot identify the cluster */
  243. }
  244. u32 fsl_qoriq_core_to_type(unsigned int core)
  245. {
  246. struct ccsr_gur __iomem *gur =
  247. (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
  248. int i = 0, count = 0;
  249. u32 cluster, type;
  250. do {
  251. int j;
  252. cluster = gur_in32(&gur->tp_cluster[i].lower);
  253. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  254. type = initiator_type(cluster, j);
  255. if (type) {
  256. if (count == core)
  257. return type;
  258. count++;
  259. }
  260. }
  261. i++;
  262. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  263. return -1; /* cannot identify the cluster */
  264. }
  265. #ifndef CONFIG_FSL_LSCH3
  266. uint get_svr(void)
  267. {
  268. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  269. return gur_in32(&gur->svr);
  270. }
  271. #endif
  272. #ifdef CONFIG_DISPLAY_CPUINFO
  273. int print_cpuinfo(void)
  274. {
  275. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  276. struct sys_info sysinfo;
  277. char buf[32];
  278. unsigned int i, core;
  279. u32 type, rcw, svr = gur_in32(&gur->svr);
  280. puts("SoC: ");
  281. cpu_name(buf);
  282. printf(" %s (0x%x)\n", buf, svr);
  283. memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
  284. get_sys_info(&sysinfo);
  285. puts("Clock Configuration:");
  286. for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
  287. if (!(i % 3))
  288. puts("\n ");
  289. type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
  290. printf("CPU%d(%s):%-4s MHz ", core,
  291. type == TY_ITYP_VER_A7 ? "A7 " :
  292. (type == TY_ITYP_VER_A53 ? "A53" :
  293. (type == TY_ITYP_VER_A57 ? "A57" :
  294. (type == TY_ITYP_VER_A72 ? "A72" : " "))),
  295. strmhz(buf, sysinfo.freq_processor[core]));
  296. }
  297. /* Display platform clock as Bus frequency. */
  298. printf("\n Bus: %-4s MHz ",
  299. strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
  300. printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
  301. #ifdef CONFIG_SYS_DPAA_FMAN
  302. printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
  303. #endif
  304. #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
  305. if (soc_has_dp_ddr()) {
  306. printf(" DP-DDR: %-4s MT/s",
  307. strmhz(buf, sysinfo.freq_ddrbus2));
  308. }
  309. #endif
  310. puts("\n");
  311. /*
  312. * Display the RCW, so that no one gets confused as to what RCW
  313. * we're actually using for this boot.
  314. */
  315. puts("Reset Configuration Word (RCW):");
  316. for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
  317. rcw = gur_in32(&gur->rcwsr[i]);
  318. if ((i % 4) == 0)
  319. printf("\n %08x:", i * 4);
  320. printf(" %08x", rcw);
  321. }
  322. puts("\n");
  323. return 0;
  324. }
  325. #endif
  326. #ifdef CONFIG_FSL_ESDHC
  327. int cpu_mmc_init(bd_t *bis)
  328. {
  329. return fsl_esdhc_mmc_init(bis);
  330. }
  331. #endif
  332. int cpu_eth_init(bd_t *bis)
  333. {
  334. int error = 0;
  335. #ifdef CONFIG_FSL_MC_ENET
  336. error = fsl_mc_ldpaa_init(bis);
  337. #endif
  338. #ifdef CONFIG_FMAN_ENET
  339. fm_standard_init(bis);
  340. #endif
  341. return error;
  342. }
  343. int arch_early_init_r(void)
  344. {
  345. #ifdef CONFIG_MP
  346. int rv = 1;
  347. u32 psci_ver = 0xffffffff;
  348. #endif
  349. #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
  350. erratum_a009635();
  351. #endif
  352. #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
  353. erratum_a009942_check_cpo();
  354. #endif
  355. #ifdef CONFIG_MP
  356. #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
  357. defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
  358. /* Check the psci version to determine if the psci is supported */
  359. psci_ver = sec_firmware_support_psci_version();
  360. #endif
  361. if (psci_ver == 0xffffffff) {
  362. rv = fsl_layerscape_wake_seconday_cores();
  363. if (rv)
  364. printf("Did not wake secondary cores\n");
  365. }
  366. #endif
  367. #ifdef CONFIG_SYS_HAS_SERDES
  368. fsl_serdes_init();
  369. #endif
  370. #ifdef CONFIG_FMAN_ENET
  371. fman_enet_init();
  372. #endif
  373. return 0;
  374. }
  375. int timer_init(void)
  376. {
  377. u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
  378. #ifdef CONFIG_FSL_LSCH3
  379. u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
  380. #endif
  381. #ifdef CONFIG_LS2080A
  382. u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
  383. u32 svr_dev_id;
  384. #endif
  385. #ifdef COUNTER_FREQUENCY_REAL
  386. unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
  387. /* Update with accurate clock frequency */
  388. asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
  389. #endif
  390. #ifdef CONFIG_FSL_LSCH3
  391. /* Enable timebase for all clusters.
  392. * It is safe to do so even some clusters are not enabled.
  393. */
  394. out_le32(cltbenr, 0xf);
  395. #endif
  396. #ifdef CONFIG_LS2080A
  397. /*
  398. * In certain Layerscape SoCs, the clock for each core's
  399. * has an enable bit in the PMU Physical Core Time Base Enable
  400. * Register (PCTBENR), which allows the watchdog to operate.
  401. */
  402. setbits_le32(pctbenr, 0xff);
  403. /*
  404. * For LS2080A SoC and its personalities, timer controller
  405. * offset is different
  406. */
  407. svr_dev_id = get_svr() >> 16;
  408. if (svr_dev_id == SVR_DEV_LS2080A)
  409. cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
  410. #endif
  411. /* Enable clock for timer
  412. * This is a global setting.
  413. */
  414. out_le32(cntcr, 0x1);
  415. return 0;
  416. }
  417. __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
  418. void __efi_runtime reset_cpu(ulong addr)
  419. {
  420. u32 val;
  421. /* Raise RESET_REQ_B */
  422. val = scfg_in32(rstcr);
  423. val |= 0x02;
  424. scfg_out32(rstcr, val);
  425. }
  426. #ifdef CONFIG_EFI_LOADER
  427. void __efi_runtime EFIAPI efi_reset_system(
  428. enum efi_reset_type reset_type,
  429. efi_status_t reset_status,
  430. unsigned long data_size, void *reset_data)
  431. {
  432. switch (reset_type) {
  433. case EFI_RESET_COLD:
  434. case EFI_RESET_WARM:
  435. reset_cpu(0);
  436. break;
  437. case EFI_RESET_SHUTDOWN:
  438. /* Nothing we can do */
  439. break;
  440. }
  441. while (1) { }
  442. }
  443. void efi_reset_system_init(void)
  444. {
  445. efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
  446. }
  447. #endif
  448. phys_size_t board_reserve_ram_top(phys_size_t ram_size)
  449. {
  450. phys_size_t ram_top = ram_size;
  451. #ifdef CONFIG_FSL_MC_ENET
  452. /* The start address of MC reserved memory needs to be aligned. */
  453. ram_top -= mc_get_dram_block_size();
  454. ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
  455. #endif
  456. return ram_size - ram_top;
  457. }
  458. phys_size_t get_effective_memsize(void)
  459. {
  460. phys_size_t ea_size, rem = 0;
  461. /*
  462. * For ARMv8 SoCs, DDR memory is split into two or three regions. The
  463. * first region is 2GB space at 0x8000_0000. If the memory extends to
  464. * the second region (or the third region if applicable), the secure
  465. * memory and Management Complex (MC) memory should be put into the
  466. * highest region, i.e. the end of DDR memory. CONFIG_MAX_MEM_MAPPED
  467. * is set to the size of first region so U-Boot doesn't relocate itself
  468. * into higher address. Should DDR be configured to skip the first
  469. * region, this function needs to be adjusted.
  470. */
  471. if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
  472. ea_size = CONFIG_MAX_MEM_MAPPED;
  473. rem = gd->ram_size - ea_size;
  474. } else {
  475. ea_size = gd->ram_size;
  476. }
  477. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  478. /* Check if we have enough space for secure memory */
  479. if (rem > CONFIG_SYS_MEM_RESERVE_SECURE) {
  480. rem -= CONFIG_SYS_MEM_RESERVE_SECURE;
  481. } else {
  482. if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE) {
  483. ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  484. rem = 0; /* Presume MC requires more memory */
  485. } else {
  486. printf("Error: No enough space for secure memory.\n");
  487. }
  488. }
  489. #endif
  490. /* Check if we have enough memory for MC */
  491. if (rem < board_reserve_ram_top(rem)) {
  492. /* Not enough memory in high region to reserve */
  493. if (ea_size > board_reserve_ram_top(rem))
  494. ea_size -= board_reserve_ram_top(rem);
  495. else
  496. printf("Error: No enough space for reserved memory.\n");
  497. }
  498. return ea_size;
  499. }
  500. void dram_init_banksize(void)
  501. {
  502. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  503. phys_size_t dp_ddr_size;
  504. #endif
  505. /*
  506. * gd->ram_size has the total size of DDR memory, less reserved secure
  507. * memory. The DDR extends from low region to high region(s) presuming
  508. * no hole is created with DDR configuration. gd->arch.secure_ram tracks
  509. * the location of secure memory. gd->arch.resv_ram tracks the location
  510. * of reserved memory for Management Complex (MC).
  511. */
  512. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  513. if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
  514. gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
  515. gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
  516. gd->bd->bi_dram[1].size = gd->ram_size -
  517. CONFIG_SYS_DDR_BLOCK1_SIZE;
  518. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  519. if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
  520. gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
  521. gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
  522. CONFIG_SYS_DDR_BLOCK2_SIZE;
  523. gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
  524. }
  525. #endif
  526. } else {
  527. gd->bd->bi_dram[0].size = gd->ram_size;
  528. }
  529. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  530. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  531. if (gd->bd->bi_dram[2].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
  532. gd->bd->bi_dram[2].size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  533. gd->arch.secure_ram = gd->bd->bi_dram[2].start +
  534. gd->bd->bi_dram[2].size;
  535. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  536. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  537. } else
  538. #endif
  539. {
  540. if (gd->bd->bi_dram[1].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
  541. gd->bd->bi_dram[1].size -=
  542. CONFIG_SYS_MEM_RESERVE_SECURE;
  543. gd->arch.secure_ram = gd->bd->bi_dram[1].start +
  544. gd->bd->bi_dram[1].size;
  545. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  546. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  547. } else if (gd->bd->bi_dram[0].size >
  548. CONFIG_SYS_MEM_RESERVE_SECURE) {
  549. gd->bd->bi_dram[0].size -=
  550. CONFIG_SYS_MEM_RESERVE_SECURE;
  551. gd->arch.secure_ram = gd->bd->bi_dram[0].start +
  552. gd->bd->bi_dram[0].size;
  553. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  554. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  555. }
  556. }
  557. #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
  558. #ifdef CONFIG_FSL_MC_ENET
  559. /* Assign memory for MC */
  560. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  561. if (gd->bd->bi_dram[2].size >=
  562. board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
  563. gd->arch.resv_ram = gd->bd->bi_dram[2].start +
  564. gd->bd->bi_dram[2].size -
  565. board_reserve_ram_top(gd->bd->bi_dram[2].size);
  566. } else
  567. #endif
  568. {
  569. if (gd->bd->bi_dram[1].size >=
  570. board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
  571. gd->arch.resv_ram = gd->bd->bi_dram[1].start +
  572. gd->bd->bi_dram[1].size -
  573. board_reserve_ram_top(gd->bd->bi_dram[1].size);
  574. } else if (gd->bd->bi_dram[0].size >
  575. board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
  576. gd->arch.resv_ram = gd->bd->bi_dram[0].start +
  577. gd->bd->bi_dram[0].size -
  578. board_reserve_ram_top(gd->bd->bi_dram[0].size);
  579. }
  580. }
  581. #endif /* CONFIG_FSL_MC_ENET */
  582. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  583. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  584. #error "This SoC shouldn't have DP DDR"
  585. #endif
  586. if (soc_has_dp_ddr()) {
  587. /* initialize DP-DDR here */
  588. puts("DP-DDR: ");
  589. /*
  590. * DDR controller use 0 as the base address for binding.
  591. * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
  592. */
  593. dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
  594. CONFIG_DP_DDR_CTRL,
  595. CONFIG_DP_DDR_NUM_CTRLS,
  596. CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
  597. NULL, NULL, NULL);
  598. if (dp_ddr_size) {
  599. gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
  600. gd->bd->bi_dram[2].size = dp_ddr_size;
  601. } else {
  602. puts("Not detected");
  603. }
  604. }
  605. #endif
  606. }
  607. #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
  608. void efi_add_known_memory(void)
  609. {
  610. int i;
  611. phys_addr_t ram_start, start;
  612. phys_size_t ram_size;
  613. u64 pages;
  614. /* Add RAM */
  615. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  616. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  617. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  618. #error "This SoC shouldn't have DP DDR"
  619. #endif
  620. if (i == 2)
  621. continue; /* skip DP-DDR */
  622. #endif
  623. ram_start = gd->bd->bi_dram[i].start;
  624. ram_size = gd->bd->bi_dram[i].size;
  625. #ifdef CONFIG_RESV_RAM
  626. if (gd->arch.resv_ram >= ram_start &&
  627. gd->arch.resv_ram < ram_start + ram_size)
  628. ram_size = gd->arch.resv_ram - ram_start;
  629. #endif
  630. start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
  631. pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
  632. efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
  633. false);
  634. }
  635. }
  636. #endif