cpu.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. /*
  2. * Copyright 2017 NXP
  3. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <fsl_ddr_sdram.h>
  9. #include <asm/io.h>
  10. #include <linux/errno.h>
  11. #include <asm/system.h>
  12. #include <asm/armv8/mmu.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/fsl_serdes.h>
  15. #include <asm/arch/soc.h>
  16. #include <asm/arch/cpu.h>
  17. #include <asm/arch/speed.h>
  18. #include <fsl_immap.h>
  19. #include <asm/arch/mp.h>
  20. #include <efi_loader.h>
  21. #include <fm_eth.h>
  22. #include <fsl-mc/fsl_mc.h>
  23. #ifdef CONFIG_FSL_ESDHC
  24. #include <fsl_esdhc.h>
  25. #endif
  26. #include <asm/armv8/sec_firmware.h>
  27. #ifdef CONFIG_SYS_FSL_DDR
  28. #include <fsl_ddr.h>
  29. #endif
  30. #include <asm/arch/clock.h>
  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. static void fix_pcie_mmu_map(void)
  78. {
  79. #ifdef CONFIG_ARCH_LS2080A
  80. unsigned int i;
  81. u32 svr, ver;
  82. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  83. svr = gur_in32(&gur->svr);
  84. ver = SVR_SOC_VER(svr);
  85. /* Fix PCIE base and size for LS2088A */
  86. if ((ver == SVR_LS2088A) || (ver == SVR_LS2084A) ||
  87. (ver == SVR_LS2048A) || (ver == SVR_LS2044A) ||
  88. (ver == SVR_LS2081A) || (ver == SVR_LS2041A)) {
  89. for (i = 0; i < ARRAY_SIZE(final_map); i++) {
  90. switch (final_map[i].phys) {
  91. case CONFIG_SYS_PCIE1_PHYS_ADDR:
  92. final_map[i].phys = 0x2000000000ULL;
  93. final_map[i].virt = 0x2000000000ULL;
  94. final_map[i].size = 0x800000000ULL;
  95. break;
  96. case CONFIG_SYS_PCIE2_PHYS_ADDR:
  97. final_map[i].phys = 0x2800000000ULL;
  98. final_map[i].virt = 0x2800000000ULL;
  99. final_map[i].size = 0x800000000ULL;
  100. break;
  101. case CONFIG_SYS_PCIE3_PHYS_ADDR:
  102. final_map[i].phys = 0x3000000000ULL;
  103. final_map[i].virt = 0x3000000000ULL;
  104. final_map[i].size = 0x800000000ULL;
  105. break;
  106. case CONFIG_SYS_PCIE4_PHYS_ADDR:
  107. final_map[i].phys = 0x3800000000ULL;
  108. final_map[i].virt = 0x3800000000ULL;
  109. final_map[i].size = 0x800000000ULL;
  110. break;
  111. default:
  112. break;
  113. }
  114. }
  115. }
  116. #endif
  117. }
  118. /*
  119. * The final tables look similar to early tables, but different in detail.
  120. * These tables are in DRAM. Sub tables are added to enable cache for
  121. * QBMan and OCRAM.
  122. *
  123. * Put the MMU table in secure memory if gd->arch.secure_ram is valid.
  124. * OCRAM will be not used for this purpose so gd->arch.secure_ram can't be 0.
  125. */
  126. static inline void final_mmu_setup(void)
  127. {
  128. u64 tlb_addr_save = gd->arch.tlb_addr;
  129. unsigned int el = current_el();
  130. int index;
  131. /* fix the final_map before filling in the block entries */
  132. fix_pcie_mmu_map();
  133. mem_map = final_map;
  134. /* Update mapping for DDR to actual size */
  135. for (index = 0; index < ARRAY_SIZE(final_map) - 2; index++) {
  136. /*
  137. * Find the entry for DDR mapping and update the address and
  138. * size. Zero-sized mapping will be skipped when creating MMU
  139. * table.
  140. */
  141. switch (final_map[index].virt) {
  142. case CONFIG_SYS_FSL_DRAM_BASE1:
  143. final_map[index].virt = gd->bd->bi_dram[0].start;
  144. final_map[index].phys = gd->bd->bi_dram[0].start;
  145. final_map[index].size = gd->bd->bi_dram[0].size;
  146. break;
  147. #ifdef CONFIG_SYS_FSL_DRAM_BASE2
  148. case CONFIG_SYS_FSL_DRAM_BASE2:
  149. #if (CONFIG_NR_DRAM_BANKS >= 2)
  150. final_map[index].virt = gd->bd->bi_dram[1].start;
  151. final_map[index].phys = gd->bd->bi_dram[1].start;
  152. final_map[index].size = gd->bd->bi_dram[1].size;
  153. #else
  154. final_map[index].size = 0;
  155. #endif
  156. break;
  157. #endif
  158. #ifdef CONFIG_SYS_FSL_DRAM_BASE3
  159. case CONFIG_SYS_FSL_DRAM_BASE3:
  160. #if (CONFIG_NR_DRAM_BANKS >= 3)
  161. final_map[index].virt = gd->bd->bi_dram[2].start;
  162. final_map[index].phys = gd->bd->bi_dram[2].start;
  163. final_map[index].size = gd->bd->bi_dram[2].size;
  164. #else
  165. final_map[index].size = 0;
  166. #endif
  167. break;
  168. #endif
  169. default:
  170. break;
  171. }
  172. }
  173. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  174. if (gd->arch.secure_ram & MEM_RESERVE_SECURE_MAINTAINED) {
  175. if (el == 3) {
  176. /*
  177. * Only use gd->arch.secure_ram if the address is
  178. * recalculated. Align to 4KB for MMU table.
  179. */
  180. /* put page tables in secure ram */
  181. index = ARRAY_SIZE(final_map) - 2;
  182. gd->arch.tlb_addr = gd->arch.secure_ram & ~0xfff;
  183. final_map[index].virt = gd->arch.secure_ram & ~0x3;
  184. final_map[index].phys = final_map[index].virt;
  185. final_map[index].size = CONFIG_SYS_MEM_RESERVE_SECURE;
  186. final_map[index].attrs = PTE_BLOCK_OUTER_SHARE;
  187. gd->arch.secure_ram |= MEM_RESERVE_SECURE_SECURED;
  188. tlb_addr_save = gd->arch.tlb_addr;
  189. } else {
  190. /* Use allocated (board_f.c) memory for TLB */
  191. tlb_addr_save = gd->arch.tlb_allocated;
  192. gd->arch.tlb_addr = tlb_addr_save;
  193. }
  194. }
  195. #endif
  196. /* Reset the fill ptr */
  197. gd->arch.tlb_fillptr = tlb_addr_save;
  198. /* Create normal system page tables */
  199. setup_pgtables();
  200. /* Create emergency page tables */
  201. gd->arch.tlb_addr = gd->arch.tlb_fillptr;
  202. gd->arch.tlb_emerg = gd->arch.tlb_addr;
  203. setup_pgtables();
  204. gd->arch.tlb_addr = tlb_addr_save;
  205. /* Disable cache and MMU */
  206. dcache_disable(); /* TLBs are invalidated */
  207. invalidate_icache_all();
  208. /* point TTBR to the new table */
  209. set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
  210. MEMORY_ATTRIBUTES);
  211. set_sctlr(get_sctlr() | CR_M);
  212. }
  213. u64 get_page_table_size(void)
  214. {
  215. return 0x10000;
  216. }
  217. int arch_cpu_init(void)
  218. {
  219. /*
  220. * This function is called before U-Boot relocates itself to speed up
  221. * on system running. It is not necessary to run if performance is not
  222. * critical. Skip if MMU is already enabled by SPL or other means.
  223. */
  224. if (get_sctlr() & CR_M)
  225. return 0;
  226. icache_enable();
  227. __asm_invalidate_dcache_all();
  228. __asm_invalidate_tlb_all();
  229. early_mmu_setup();
  230. set_sctlr(get_sctlr() | CR_C);
  231. return 0;
  232. }
  233. void mmu_setup(void)
  234. {
  235. final_mmu_setup();
  236. }
  237. /*
  238. * This function is called from common/board_r.c.
  239. * It recreates MMU table in main memory.
  240. */
  241. void enable_caches(void)
  242. {
  243. mmu_setup();
  244. __asm_invalidate_tlb_all();
  245. icache_enable();
  246. dcache_enable();
  247. }
  248. #endif
  249. u32 initiator_type(u32 cluster, int init_id)
  250. {
  251. struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  252. u32 idx = (cluster >> (init_id * 8)) & TP_CLUSTER_INIT_MASK;
  253. u32 type = 0;
  254. type = gur_in32(&gur->tp_ityp[idx]);
  255. if (type & TP_ITYP_AV)
  256. return type;
  257. return 0;
  258. }
  259. u32 cpu_pos_mask(void)
  260. {
  261. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  262. int i = 0;
  263. u32 cluster, type, mask = 0;
  264. do {
  265. int j;
  266. cluster = gur_in32(&gur->tp_cluster[i].lower);
  267. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  268. type = initiator_type(cluster, j);
  269. if (type && (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM))
  270. mask |= 1 << (i * TP_INIT_PER_CLUSTER + j);
  271. }
  272. i++;
  273. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  274. return mask;
  275. }
  276. u32 cpu_mask(void)
  277. {
  278. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  279. int i = 0, count = 0;
  280. u32 cluster, type, mask = 0;
  281. do {
  282. int j;
  283. cluster = gur_in32(&gur->tp_cluster[i].lower);
  284. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  285. type = initiator_type(cluster, j);
  286. if (type) {
  287. if (TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
  288. mask |= 1 << count;
  289. count++;
  290. }
  291. }
  292. i++;
  293. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  294. return mask;
  295. }
  296. /*
  297. * Return the number of cores on this SOC.
  298. */
  299. int cpu_numcores(void)
  300. {
  301. return hweight32(cpu_mask());
  302. }
  303. int fsl_qoriq_core_to_cluster(unsigned int core)
  304. {
  305. struct ccsr_gur __iomem *gur =
  306. (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
  307. int i = 0, count = 0;
  308. u32 cluster;
  309. do {
  310. int j;
  311. cluster = gur_in32(&gur->tp_cluster[i].lower);
  312. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  313. if (initiator_type(cluster, j)) {
  314. if (count == core)
  315. return i;
  316. count++;
  317. }
  318. }
  319. i++;
  320. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  321. return -1; /* cannot identify the cluster */
  322. }
  323. u32 fsl_qoriq_core_to_type(unsigned int core)
  324. {
  325. struct ccsr_gur __iomem *gur =
  326. (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR);
  327. int i = 0, count = 0;
  328. u32 cluster, type;
  329. do {
  330. int j;
  331. cluster = gur_in32(&gur->tp_cluster[i].lower);
  332. for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
  333. type = initiator_type(cluster, j);
  334. if (type) {
  335. if (count == core)
  336. return type;
  337. count++;
  338. }
  339. }
  340. i++;
  341. } while ((cluster & TP_CLUSTER_EOC) == 0x0);
  342. return -1; /* cannot identify the cluster */
  343. }
  344. #ifndef CONFIG_FSL_LSCH3
  345. uint get_svr(void)
  346. {
  347. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  348. return gur_in32(&gur->svr);
  349. }
  350. #endif
  351. #ifdef CONFIG_DISPLAY_CPUINFO
  352. int print_cpuinfo(void)
  353. {
  354. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  355. struct sys_info sysinfo;
  356. char buf[32];
  357. unsigned int i, core;
  358. u32 type, rcw, svr = gur_in32(&gur->svr);
  359. puts("SoC: ");
  360. cpu_name(buf);
  361. printf(" %s (0x%x)\n", buf, svr);
  362. memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
  363. get_sys_info(&sysinfo);
  364. puts("Clock Configuration:");
  365. for_each_cpu(i, core, cpu_numcores(), cpu_mask()) {
  366. if (!(i % 3))
  367. puts("\n ");
  368. type = TP_ITYP_VER(fsl_qoriq_core_to_type(core));
  369. printf("CPU%d(%s):%-4s MHz ", core,
  370. type == TY_ITYP_VER_A7 ? "A7 " :
  371. (type == TY_ITYP_VER_A53 ? "A53" :
  372. (type == TY_ITYP_VER_A57 ? "A57" :
  373. (type == TY_ITYP_VER_A72 ? "A72" : " "))),
  374. strmhz(buf, sysinfo.freq_processor[core]));
  375. }
  376. /* Display platform clock as Bus frequency. */
  377. printf("\n Bus: %-4s MHz ",
  378. strmhz(buf, sysinfo.freq_systembus / CONFIG_SYS_FSL_PCLK_DIV));
  379. printf("DDR: %-4s MT/s", strmhz(buf, sysinfo.freq_ddrbus));
  380. #ifdef CONFIG_SYS_DPAA_FMAN
  381. printf(" FMAN: %-4s MHz", strmhz(buf, sysinfo.freq_fman[0]));
  382. #endif
  383. #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
  384. if (soc_has_dp_ddr()) {
  385. printf(" DP-DDR: %-4s MT/s",
  386. strmhz(buf, sysinfo.freq_ddrbus2));
  387. }
  388. #endif
  389. puts("\n");
  390. /*
  391. * Display the RCW, so that no one gets confused as to what RCW
  392. * we're actually using for this boot.
  393. */
  394. puts("Reset Configuration Word (RCW):");
  395. for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
  396. rcw = gur_in32(&gur->rcwsr[i]);
  397. if ((i % 4) == 0)
  398. printf("\n %08x:", i * 4);
  399. printf(" %08x", rcw);
  400. }
  401. puts("\n");
  402. return 0;
  403. }
  404. #endif
  405. #ifdef CONFIG_FSL_ESDHC
  406. int cpu_mmc_init(bd_t *bis)
  407. {
  408. return fsl_esdhc_mmc_init(bis);
  409. }
  410. #endif
  411. int cpu_eth_init(bd_t *bis)
  412. {
  413. int error = 0;
  414. #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
  415. error = fsl_mc_ldpaa_init(bis);
  416. #endif
  417. #ifdef CONFIG_FMAN_ENET
  418. fm_standard_init(bis);
  419. #endif
  420. return error;
  421. }
  422. static inline int check_psci(void)
  423. {
  424. unsigned int psci_ver;
  425. psci_ver = sec_firmware_support_psci_version();
  426. if (psci_ver == PSCI_INVALID_VER)
  427. return 1;
  428. return 0;
  429. }
  430. int arch_early_init_r(void)
  431. {
  432. #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
  433. u32 svr_dev_id;
  434. /*
  435. * erratum A009635 is valid only for LS2080A SoC and
  436. * its personalitiesi
  437. */
  438. svr_dev_id = get_svr() >> 16;
  439. if (svr_dev_id == SVR_DEV_LS2080A)
  440. erratum_a009635();
  441. #endif
  442. #if defined(CONFIG_SYS_FSL_ERRATUM_A009942) && defined(CONFIG_SYS_FSL_DDR)
  443. erratum_a009942_check_cpo();
  444. #endif
  445. if (check_psci()) {
  446. debug("PSCI: PSCI does not exist.\n");
  447. /* if PSCI does not exist, boot secondary cores here */
  448. if (fsl_layerscape_wake_seconday_cores())
  449. printf("Did not wake secondary cores\n");
  450. }
  451. #ifdef CONFIG_SYS_HAS_SERDES
  452. fsl_serdes_init();
  453. #endif
  454. #ifdef CONFIG_FMAN_ENET
  455. fman_enet_init();
  456. #endif
  457. return 0;
  458. }
  459. int timer_init(void)
  460. {
  461. u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
  462. #ifdef CONFIG_FSL_LSCH3
  463. u32 __iomem *cltbenr = (u32 *)CONFIG_SYS_FSL_PMU_CLTBENR;
  464. #endif
  465. #ifdef CONFIG_ARCH_LS2080A
  466. u32 __iomem *pctbenr = (u32 *)FSL_PMU_PCTBENR_OFFSET;
  467. u32 svr_dev_id;
  468. #endif
  469. #ifdef COUNTER_FREQUENCY_REAL
  470. unsigned long cntfrq = COUNTER_FREQUENCY_REAL;
  471. /* Update with accurate clock frequency */
  472. if (current_el() == 3)
  473. asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
  474. #endif
  475. #ifdef CONFIG_FSL_LSCH3
  476. /* Enable timebase for all clusters.
  477. * It is safe to do so even some clusters are not enabled.
  478. */
  479. out_le32(cltbenr, 0xf);
  480. #endif
  481. #ifdef CONFIG_ARCH_LS2080A
  482. /*
  483. * In certain Layerscape SoCs, the clock for each core's
  484. * has an enable bit in the PMU Physical Core Time Base Enable
  485. * Register (PCTBENR), which allows the watchdog to operate.
  486. */
  487. setbits_le32(pctbenr, 0xff);
  488. /*
  489. * For LS2080A SoC and its personalities, timer controller
  490. * offset is different
  491. */
  492. svr_dev_id = get_svr() >> 16;
  493. if (svr_dev_id == SVR_DEV_LS2080A)
  494. cntcr = (u32 *)SYS_FSL_LS2080A_LS2085A_TIMER_ADDR;
  495. #endif
  496. /* Enable clock for timer
  497. * This is a global setting.
  498. */
  499. out_le32(cntcr, 0x1);
  500. return 0;
  501. }
  502. __efi_runtime_data u32 __iomem *rstcr = (u32 *)CONFIG_SYS_FSL_RST_ADDR;
  503. void __efi_runtime reset_cpu(ulong addr)
  504. {
  505. u32 val;
  506. /* Raise RESET_REQ_B */
  507. val = scfg_in32(rstcr);
  508. val |= 0x02;
  509. scfg_out32(rstcr, val);
  510. }
  511. #ifdef CONFIG_EFI_LOADER
  512. void __efi_runtime EFIAPI efi_reset_system(
  513. enum efi_reset_type reset_type,
  514. efi_status_t reset_status,
  515. unsigned long data_size, void *reset_data)
  516. {
  517. switch (reset_type) {
  518. case EFI_RESET_COLD:
  519. case EFI_RESET_WARM:
  520. reset_cpu(0);
  521. break;
  522. case EFI_RESET_SHUTDOWN:
  523. /* Nothing we can do */
  524. break;
  525. }
  526. while (1) { }
  527. }
  528. void efi_reset_system_init(void)
  529. {
  530. efi_add_runtime_mmio(&rstcr, sizeof(*rstcr));
  531. }
  532. #endif
  533. phys_size_t board_reserve_ram_top(phys_size_t ram_size)
  534. {
  535. phys_size_t ram_top = ram_size;
  536. #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
  537. /* The start address of MC reserved memory needs to be aligned. */
  538. ram_top -= mc_get_dram_block_size();
  539. ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
  540. #endif
  541. return ram_size - ram_top;
  542. }
  543. phys_size_t get_effective_memsize(void)
  544. {
  545. phys_size_t ea_size, rem = 0;
  546. /*
  547. * For ARMv8 SoCs, DDR memory is split into two or three regions. The
  548. * first region is 2GB space at 0x8000_0000. If the memory extends to
  549. * the second region (or the third region if applicable), the secure
  550. * memory and Management Complex (MC) memory should be put into the
  551. * highest region, i.e. the end of DDR memory. CONFIG_MAX_MEM_MAPPED
  552. * is set to the size of first region so U-Boot doesn't relocate itself
  553. * into higher address. Should DDR be configured to skip the first
  554. * region, this function needs to be adjusted.
  555. */
  556. if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
  557. ea_size = CONFIG_MAX_MEM_MAPPED;
  558. rem = gd->ram_size - ea_size;
  559. } else {
  560. ea_size = gd->ram_size;
  561. }
  562. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  563. /* Check if we have enough space for secure memory */
  564. if (rem > CONFIG_SYS_MEM_RESERVE_SECURE) {
  565. rem -= CONFIG_SYS_MEM_RESERVE_SECURE;
  566. } else {
  567. if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE) {
  568. ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  569. rem = 0; /* Presume MC requires more memory */
  570. } else {
  571. printf("Error: No enough space for secure memory.\n");
  572. }
  573. }
  574. #endif
  575. /* Check if we have enough memory for MC */
  576. if (rem < board_reserve_ram_top(rem)) {
  577. /* Not enough memory in high region to reserve */
  578. if (ea_size > board_reserve_ram_top(rem))
  579. ea_size -= board_reserve_ram_top(rem);
  580. else
  581. printf("Error: No enough space for reserved memory.\n");
  582. }
  583. return ea_size;
  584. }
  585. int dram_init_banksize(void)
  586. {
  587. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  588. phys_size_t dp_ddr_size;
  589. #endif
  590. /*
  591. * gd->ram_size has the total size of DDR memory, less reserved secure
  592. * memory. The DDR extends from low region to high region(s) presuming
  593. * no hole is created with DDR configuration. gd->arch.secure_ram tracks
  594. * the location of secure memory. gd->arch.resv_ram tracks the location
  595. * of reserved memory for Management Complex (MC).
  596. */
  597. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  598. if (gd->ram_size > CONFIG_SYS_DDR_BLOCK1_SIZE) {
  599. gd->bd->bi_dram[0].size = CONFIG_SYS_DDR_BLOCK1_SIZE;
  600. gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
  601. gd->bd->bi_dram[1].size = gd->ram_size -
  602. CONFIG_SYS_DDR_BLOCK1_SIZE;
  603. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  604. if (gd->bi_dram[1].size > CONFIG_SYS_DDR_BLOCK2_SIZE) {
  605. gd->bd->bi_dram[2].start = CONFIG_SYS_DDR_BLOCK3_BASE;
  606. gd->bd->bi_dram[2].size = gd->bd->bi_dram[1].size -
  607. CONFIG_SYS_DDR_BLOCK2_SIZE;
  608. gd->bd->bi_dram[1].size = CONFIG_SYS_DDR_BLOCK2_SIZE;
  609. }
  610. #endif
  611. } else {
  612. gd->bd->bi_dram[0].size = gd->ram_size;
  613. }
  614. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  615. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  616. if (gd->bd->bi_dram[2].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
  617. gd->bd->bi_dram[2].size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  618. gd->arch.secure_ram = gd->bd->bi_dram[2].start +
  619. gd->bd->bi_dram[2].size;
  620. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  621. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  622. } else
  623. #endif
  624. {
  625. if (gd->bd->bi_dram[1].size >= CONFIG_SYS_MEM_RESERVE_SECURE) {
  626. gd->bd->bi_dram[1].size -=
  627. CONFIG_SYS_MEM_RESERVE_SECURE;
  628. gd->arch.secure_ram = gd->bd->bi_dram[1].start +
  629. gd->bd->bi_dram[1].size;
  630. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  631. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  632. } else if (gd->bd->bi_dram[0].size >
  633. CONFIG_SYS_MEM_RESERVE_SECURE) {
  634. gd->bd->bi_dram[0].size -=
  635. CONFIG_SYS_MEM_RESERVE_SECURE;
  636. gd->arch.secure_ram = gd->bd->bi_dram[0].start +
  637. gd->bd->bi_dram[0].size;
  638. gd->arch.secure_ram |= MEM_RESERVE_SECURE_MAINTAINED;
  639. gd->ram_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
  640. }
  641. }
  642. #endif /* CONFIG_SYS_MEM_RESERVE_SECURE */
  643. #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
  644. /* Assign memory for MC */
  645. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  646. if (gd->bd->bi_dram[2].size >=
  647. board_reserve_ram_top(gd->bd->bi_dram[2].size)) {
  648. gd->arch.resv_ram = gd->bd->bi_dram[2].start +
  649. gd->bd->bi_dram[2].size -
  650. board_reserve_ram_top(gd->bd->bi_dram[2].size);
  651. } else
  652. #endif
  653. {
  654. if (gd->bd->bi_dram[1].size >=
  655. board_reserve_ram_top(gd->bd->bi_dram[1].size)) {
  656. gd->arch.resv_ram = gd->bd->bi_dram[1].start +
  657. gd->bd->bi_dram[1].size -
  658. board_reserve_ram_top(gd->bd->bi_dram[1].size);
  659. } else if (gd->bd->bi_dram[0].size >
  660. board_reserve_ram_top(gd->bd->bi_dram[0].size)) {
  661. gd->arch.resv_ram = gd->bd->bi_dram[0].start +
  662. gd->bd->bi_dram[0].size -
  663. board_reserve_ram_top(gd->bd->bi_dram[0].size);
  664. }
  665. }
  666. #endif /* CONFIG_FSL_MC_ENET */
  667. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  668. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  669. #error "This SoC shouldn't have DP DDR"
  670. #endif
  671. if (soc_has_dp_ddr()) {
  672. /* initialize DP-DDR here */
  673. puts("DP-DDR: ");
  674. /*
  675. * DDR controller use 0 as the base address for binding.
  676. * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
  677. */
  678. dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
  679. CONFIG_DP_DDR_CTRL,
  680. CONFIG_DP_DDR_NUM_CTRLS,
  681. CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
  682. NULL, NULL, NULL);
  683. if (dp_ddr_size) {
  684. gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
  685. gd->bd->bi_dram[2].size = dp_ddr_size;
  686. } else {
  687. puts("Not detected");
  688. }
  689. }
  690. #endif
  691. return 0;
  692. }
  693. #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
  694. void efi_add_known_memory(void)
  695. {
  696. int i;
  697. phys_addr_t ram_start, start;
  698. phys_size_t ram_size;
  699. u64 pages;
  700. /* Add RAM */
  701. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  702. #ifdef CONFIG_SYS_DP_DDR_BASE_PHY
  703. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  704. #error "This SoC shouldn't have DP DDR"
  705. #endif
  706. if (i == 2)
  707. continue; /* skip DP-DDR */
  708. #endif
  709. ram_start = gd->bd->bi_dram[i].start;
  710. ram_size = gd->bd->bi_dram[i].size;
  711. #ifdef CONFIG_RESV_RAM
  712. if (gd->arch.resv_ram >= ram_start &&
  713. gd->arch.resv_ram < ram_start + ram_size)
  714. ram_size = gd->arch.resv_ram - ram_start;
  715. #endif
  716. start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
  717. pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
  718. efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
  719. false);
  720. }
  721. }
  722. #endif
  723. /*
  724. * Before DDR size is known, early MMU table have DDR mapped as device memory
  725. * to avoid speculative access. To relocate U-Boot to DDR, "normal memory"
  726. * needs to be set for these mappings.
  727. * If a special case configures DDR with holes in the mapping, the holes need
  728. * to be marked as invalid. This is not implemented in this function.
  729. */
  730. void update_early_mmu_table(void)
  731. {
  732. if (!gd->arch.tlb_addr)
  733. return;
  734. if (gd->ram_size <= CONFIG_SYS_FSL_DRAM_SIZE1) {
  735. mmu_change_region_attr(
  736. CONFIG_SYS_SDRAM_BASE,
  737. gd->ram_size,
  738. PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  739. PTE_BLOCK_OUTER_SHARE |
  740. PTE_BLOCK_NS |
  741. PTE_TYPE_VALID);
  742. } else {
  743. mmu_change_region_attr(
  744. CONFIG_SYS_SDRAM_BASE,
  745. CONFIG_SYS_DDR_BLOCK1_SIZE,
  746. PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  747. PTE_BLOCK_OUTER_SHARE |
  748. PTE_BLOCK_NS |
  749. PTE_TYPE_VALID);
  750. #ifdef CONFIG_SYS_DDR_BLOCK3_BASE
  751. #ifndef CONFIG_SYS_DDR_BLOCK2_SIZE
  752. #error "Missing CONFIG_SYS_DDR_BLOCK2_SIZE"
  753. #endif
  754. if (gd->ram_size - CONFIG_SYS_DDR_BLOCK1_SIZE >
  755. CONFIG_SYS_DDR_BLOCK2_SIZE) {
  756. mmu_change_region_attr(
  757. CONFIG_SYS_DDR_BLOCK2_BASE,
  758. CONFIG_SYS_DDR_BLOCK2_SIZE,
  759. PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  760. PTE_BLOCK_OUTER_SHARE |
  761. PTE_BLOCK_NS |
  762. PTE_TYPE_VALID);
  763. mmu_change_region_attr(
  764. CONFIG_SYS_DDR_BLOCK3_BASE,
  765. gd->ram_size -
  766. CONFIG_SYS_DDR_BLOCK1_SIZE -
  767. CONFIG_SYS_DDR_BLOCK2_SIZE,
  768. PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  769. PTE_BLOCK_OUTER_SHARE |
  770. PTE_BLOCK_NS |
  771. PTE_TYPE_VALID);
  772. } else
  773. #endif
  774. {
  775. mmu_change_region_attr(
  776. CONFIG_SYS_DDR_BLOCK2_BASE,
  777. gd->ram_size -
  778. CONFIG_SYS_DDR_BLOCK1_SIZE,
  779. PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  780. PTE_BLOCK_OUTER_SHARE |
  781. PTE_BLOCK_NS |
  782. PTE_TYPE_VALID);
  783. }
  784. }
  785. }
  786. __weak int dram_init(void)
  787. {
  788. fsl_initdram();
  789. #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
  790. /* This will break-before-make MMU for DDR */
  791. update_early_mmu_table();
  792. #endif
  793. return 0;
  794. }