fdt.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  4. * Copyright 2020 NXP
  5. */
  6. #include <common.h>
  7. #include <clock_legacy.h>
  8. #include <efi_loader.h>
  9. #include <log.h>
  10. #include <asm/cache.h>
  11. #include <linux/libfdt.h>
  12. #include <fdt_support.h>
  13. #include <phy.h>
  14. #ifdef CONFIG_FSL_LSCH3
  15. #include <asm/arch/fdt.h>
  16. #endif
  17. #ifdef CONFIG_FSL_ESDHC
  18. #include <fsl_esdhc.h>
  19. #endif
  20. #ifdef CONFIG_SYS_DPAA_FMAN
  21. #include <fsl_fman.h>
  22. #endif
  23. #ifdef CONFIG_MP
  24. #include <asm/arch/mp.h>
  25. #endif
  26. #include <fsl_sec.h>
  27. #include <asm/arch-fsl-layerscape/soc.h>
  28. #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
  29. #include <asm/armv8/sec_firmware.h>
  30. #endif
  31. #include <asm/arch/speed.h>
  32. #include <fsl_qbman.h>
  33. int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
  34. {
  35. const char *conn;
  36. /* Do NOT apply fixup for backplane modes specified in DT */
  37. if (phyc == PHY_INTERFACE_MODE_XGMII) {
  38. conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
  39. if (is_backplane_mode(conn))
  40. return 0;
  41. }
  42. return fdt_setprop_string(blob, offset, "phy-connection-type",
  43. phy_string_for_interface(phyc));
  44. }
  45. #ifdef CONFIG_MP
  46. void ft_fixup_cpu(void *blob)
  47. {
  48. int off;
  49. __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
  50. fdt32_t *reg;
  51. int addr_cells;
  52. u64 val, core_id;
  53. u32 mask = cpu_pos_mask();
  54. int off_prev = -1;
  55. off = fdt_path_offset(blob, "/cpus");
  56. if (off < 0) {
  57. puts("couldn't find /cpus node\n");
  58. return;
  59. }
  60. fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
  61. off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type",
  62. "cpu", 4);
  63. while (off != -FDT_ERR_NOTFOUND) {
  64. reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
  65. if (reg) {
  66. core_id = fdt_read_number(reg, addr_cells);
  67. if (!test_bit(id_to_core(core_id), &mask)) {
  68. fdt_del_node(blob, off);
  69. off = off_prev;
  70. }
  71. }
  72. off_prev = off;
  73. off = fdt_node_offset_by_prop_value(blob, off_prev,
  74. "device_type", "cpu", 4);
  75. }
  76. #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
  77. defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
  78. int node;
  79. u32 psci_ver;
  80. /* Check the psci version to determine if the psci is supported */
  81. psci_ver = sec_firmware_support_psci_version();
  82. if (psci_ver == 0xffffffff) {
  83. /* remove psci DT node */
  84. node = fdt_path_offset(blob, "/psci");
  85. if (node >= 0)
  86. goto remove_psci_node;
  87. node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
  88. if (node >= 0)
  89. goto remove_psci_node;
  90. node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
  91. if (node >= 0)
  92. goto remove_psci_node;
  93. node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
  94. if (node >= 0)
  95. goto remove_psci_node;
  96. remove_psci_node:
  97. if (node >= 0)
  98. fdt_del_node(blob, node);
  99. } else {
  100. return;
  101. }
  102. #endif
  103. off = fdt_path_offset(blob, "/cpus");
  104. if (off < 0) {
  105. puts("couldn't find /cpus node\n");
  106. return;
  107. }
  108. fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
  109. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  110. while (off != -FDT_ERR_NOTFOUND) {
  111. reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
  112. if (reg) {
  113. core_id = fdt_read_number(reg, addr_cells);
  114. if (core_id == 0 || (is_core_online(core_id))) {
  115. val = spin_tbl_addr;
  116. val += id_to_core(core_id) *
  117. SPIN_TABLE_ELEM_SIZE;
  118. val = cpu_to_fdt64(val);
  119. fdt_setprop_string(blob, off, "enable-method",
  120. "spin-table");
  121. fdt_setprop(blob, off, "cpu-release-addr",
  122. &val, sizeof(val));
  123. } else {
  124. debug("skipping offline core\n");
  125. }
  126. } else {
  127. puts("Warning: found cpu node without reg property\n");
  128. }
  129. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  130. "cpu", 4);
  131. }
  132. fdt_add_mem_rsv(blob, (uintptr_t)secondary_boot_code_start,
  133. secondary_boot_code_size);
  134. #if CONFIG_IS_ENABLED(EFI_LOADER)
  135. efi_add_memory_map((uintptr_t)secondary_boot_code_start,
  136. secondary_boot_code_size, EFI_RESERVED_MEMORY_TYPE);
  137. #endif
  138. }
  139. #endif
  140. void fsl_fdt_disable_usb(void *blob)
  141. {
  142. int off;
  143. /*
  144. * SYSCLK is used as a reference clock for USB. When the USB
  145. * controller is used, SYSCLK must meet the additional requirement
  146. * of 100 MHz.
  147. */
  148. if (CONFIG_SYS_CLK_FREQ != 100000000) {
  149. off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
  150. while (off != -FDT_ERR_NOTFOUND) {
  151. fdt_status_disabled(blob, off);
  152. off = fdt_node_offset_by_compatible(blob, off,
  153. "snps,dwc3");
  154. }
  155. }
  156. }
  157. #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
  158. static void fdt_fixup_gic(void *blob)
  159. {
  160. int offset, err;
  161. u64 reg[8];
  162. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  163. unsigned int val;
  164. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  165. int align_64k = 0;
  166. val = gur_in32(&gur->svr);
  167. if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) {
  168. align_64k = 1;
  169. } else if (SVR_REV(val) != REV1_0) {
  170. val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT);
  171. if (!val)
  172. align_64k = 1;
  173. }
  174. offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000");
  175. if (offset < 0) {
  176. printf("WARNING: fdt_subnode_offset can't find node %s: %s\n",
  177. "interrupt-controller@1400000", fdt_strerror(offset));
  178. return;
  179. }
  180. /* Fixup gic node align with 64K */
  181. if (align_64k) {
  182. reg[0] = cpu_to_fdt64(GICD_BASE_64K);
  183. reg[1] = cpu_to_fdt64(GICD_SIZE_64K);
  184. reg[2] = cpu_to_fdt64(GICC_BASE_64K);
  185. reg[3] = cpu_to_fdt64(GICC_SIZE_64K);
  186. reg[4] = cpu_to_fdt64(GICH_BASE_64K);
  187. reg[5] = cpu_to_fdt64(GICH_SIZE_64K);
  188. reg[6] = cpu_to_fdt64(GICV_BASE_64K);
  189. reg[7] = cpu_to_fdt64(GICV_SIZE_64K);
  190. } else {
  191. /* Fixup gic node align with default */
  192. reg[0] = cpu_to_fdt64(GICD_BASE);
  193. reg[1] = cpu_to_fdt64(GICD_SIZE);
  194. reg[2] = cpu_to_fdt64(GICC_BASE);
  195. reg[3] = cpu_to_fdt64(GICC_SIZE);
  196. reg[4] = cpu_to_fdt64(GICH_BASE);
  197. reg[5] = cpu_to_fdt64(GICH_SIZE);
  198. reg[6] = cpu_to_fdt64(GICV_BASE);
  199. reg[7] = cpu_to_fdt64(GICV_SIZE);
  200. }
  201. err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg));
  202. if (err < 0) {
  203. printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
  204. "reg", "interrupt-controller@1400000",
  205. fdt_strerror(err));
  206. return;
  207. }
  208. return;
  209. }
  210. #endif
  211. #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
  212. static int _fdt_fixup_msi_node(void *blob, const char *name,
  213. int irq_0, int irq_1, int rev)
  214. {
  215. int err, offset, len;
  216. u32 tmp[4][3];
  217. void *p;
  218. offset = fdt_path_offset(blob, name);
  219. if (offset < 0) {
  220. printf("WARNING: fdt_path_offset can't find path %s: %s\n",
  221. name, fdt_strerror(offset));
  222. return 0;
  223. }
  224. /*fixup the property of interrupts*/
  225. tmp[0][0] = cpu_to_fdt32(0x0);
  226. tmp[0][1] = cpu_to_fdt32(irq_0);
  227. tmp[0][2] = cpu_to_fdt32(0x4);
  228. if (rev > REV1_0) {
  229. tmp[1][0] = cpu_to_fdt32(0x0);
  230. tmp[1][1] = cpu_to_fdt32(irq_1);
  231. tmp[1][2] = cpu_to_fdt32(0x4);
  232. tmp[2][0] = cpu_to_fdt32(0x0);
  233. tmp[2][1] = cpu_to_fdt32(irq_1 + 1);
  234. tmp[2][2] = cpu_to_fdt32(0x4);
  235. tmp[3][0] = cpu_to_fdt32(0x0);
  236. tmp[3][1] = cpu_to_fdt32(irq_1 + 2);
  237. tmp[3][2] = cpu_to_fdt32(0x4);
  238. len = sizeof(tmp);
  239. } else {
  240. len = sizeof(tmp[0]);
  241. }
  242. err = fdt_setprop(blob, offset, "interrupts", tmp, len);
  243. if (err < 0) {
  244. printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
  245. "interrupts", name, fdt_strerror(err));
  246. return 0;
  247. }
  248. /*fixup the property of reg*/
  249. p = (char *)fdt_getprop(blob, offset, "reg", &len);
  250. if (!p) {
  251. printf("WARNING: fdt_getprop can't get %s from node %s\n",
  252. "reg", name);
  253. return 0;
  254. }
  255. memcpy((char *)tmp, p, len);
  256. if (rev > REV1_0)
  257. *((u32 *)tmp + 3) = cpu_to_fdt32(0x1000);
  258. else
  259. *((u32 *)tmp + 3) = cpu_to_fdt32(0x8);
  260. err = fdt_setprop(blob, offset, "reg", tmp, len);
  261. if (err < 0) {
  262. printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
  263. "reg", name, fdt_strerror(err));
  264. return 0;
  265. }
  266. /*fixup the property of compatible*/
  267. if (rev > REV1_0)
  268. err = fdt_setprop_string(blob, offset, "compatible",
  269. "fsl,ls1043a-v1.1-msi");
  270. else
  271. err = fdt_setprop_string(blob, offset, "compatible",
  272. "fsl,ls1043a-msi");
  273. if (err < 0) {
  274. printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
  275. "compatible", name, fdt_strerror(err));
  276. return 0;
  277. }
  278. return 1;
  279. }
  280. static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev)
  281. {
  282. int offset, len, err;
  283. void *p;
  284. int val;
  285. u32 tmp[4][8];
  286. offset = fdt_path_offset(blob, name);
  287. if (offset < 0) {
  288. printf("WARNING: fdt_path_offset can't find path %s: %s\n",
  289. name, fdt_strerror(offset));
  290. return 0;
  291. }
  292. p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len);
  293. if (!p || len != sizeof(tmp)) {
  294. printf("WARNING: fdt_getprop can't get %s from node %s\n",
  295. "interrupt-map", name);
  296. return 0;
  297. }
  298. memcpy((char *)tmp, p, len);
  299. val = fdt32_to_cpu(tmp[0][6]);
  300. if (rev == REV1_0) {
  301. tmp[1][6] = cpu_to_fdt32(val + 1);
  302. tmp[2][6] = cpu_to_fdt32(val + 2);
  303. tmp[3][6] = cpu_to_fdt32(val + 3);
  304. } else {
  305. tmp[1][6] = cpu_to_fdt32(val);
  306. tmp[2][6] = cpu_to_fdt32(val);
  307. tmp[3][6] = cpu_to_fdt32(val);
  308. }
  309. err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp));
  310. if (err < 0) {
  311. printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n",
  312. "interrupt-map", name, fdt_strerror(err));
  313. return 0;
  314. }
  315. return 1;
  316. }
  317. /* Fixup msi node for ls1043a rev1.1*/
  318. static void fdt_fixup_msi(void *blob)
  319. {
  320. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  321. unsigned int rev;
  322. rev = gur_in32(&gur->svr);
  323. if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A)))
  324. return;
  325. rev = SVR_REV(rev);
  326. _fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000",
  327. 116, 111, rev);
  328. _fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000",
  329. 126, 121, rev);
  330. _fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000",
  331. 160, 155, rev);
  332. _fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev);
  333. _fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev);
  334. _fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev);
  335. }
  336. #endif
  337. #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
  338. /* Remove JR node used by SEC firmware */
  339. void fdt_fixup_remove_jr(void *blob)
  340. {
  341. int jr_node, addr_cells, len;
  342. int crypto_node = fdt_path_offset(blob, "crypto");
  343. u64 jr_offset, used_jr;
  344. fdt32_t *reg;
  345. used_jr = sec_firmware_used_jobring_offset();
  346. fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL);
  347. jr_node = fdt_node_offset_by_compatible(blob, crypto_node,
  348. "fsl,sec-v4.0-job-ring");
  349. while (jr_node != -FDT_ERR_NOTFOUND) {
  350. reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len);
  351. jr_offset = fdt_read_number(reg, addr_cells);
  352. if (jr_offset == used_jr) {
  353. fdt_del_node(blob, jr_node);
  354. break;
  355. }
  356. jr_node = fdt_node_offset_by_compatible(blob, jr_node,
  357. "fsl,sec-v4.0-job-ring");
  358. }
  359. }
  360. #endif
  361. #ifdef CONFIG_ARCH_LS1028A
  362. static void fdt_disable_multimedia(void *blob, unsigned int svr)
  363. {
  364. int off;
  365. if (IS_MULTIMEDIA_EN(svr))
  366. return;
  367. /* Disable eDP/LCD node */
  368. off = fdt_node_offset_by_compatible(blob, -1, "arm,mali-dp500");
  369. if (off != -FDT_ERR_NOTFOUND)
  370. fdt_status_disabled(blob, off);
  371. /* Disable GPU node */
  372. off = fdt_node_offset_by_compatible(blob, -1, "fsl,ls1028a-gpu");
  373. if (off != -FDT_ERR_NOTFOUND)
  374. fdt_status_disabled(blob, off);
  375. }
  376. #endif
  377. #ifdef CONFIG_PCIE_ECAM_GENERIC
  378. __weak void fdt_fixup_ecam(void *blob)
  379. {
  380. }
  381. #endif
  382. void ft_cpu_setup(void *blob, struct bd_info *bd)
  383. {
  384. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  385. unsigned int svr = gur_in32(&gur->svr);
  386. /* delete crypto node if not on an E-processor */
  387. if (!IS_E_PROCESSOR(svr))
  388. fdt_fixup_crypto_node(blob, 0);
  389. #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
  390. else {
  391. ccsr_sec_t __iomem *sec;
  392. #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
  393. fdt_fixup_remove_jr(blob);
  394. fdt_fixup_kaslr(blob);
  395. #endif
  396. sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  397. fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
  398. }
  399. #endif
  400. #ifdef CONFIG_MP
  401. ft_fixup_cpu(blob);
  402. #endif
  403. #ifdef CONFIG_SYS_NS16550
  404. do_fixup_by_compat_u32(blob, "fsl,ns16550",
  405. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  406. #endif
  407. do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency",
  408. CONFIG_SYS_CLK_FREQ, 1);
  409. #ifdef CONFIG_GIC_V3_ITS
  410. ls_gic_rd_tables_init(blob);
  411. #endif
  412. #if defined(CONFIG_PCIE_LAYERSCAPE) || defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
  413. ft_pci_setup(blob, bd);
  414. #endif
  415. #ifdef CONFIG_FSL_ESDHC
  416. fdt_fixup_esdhc(blob, bd);
  417. #endif
  418. #ifdef CONFIG_SYS_DPAA_QBMAN
  419. fdt_fixup_bportals(blob);
  420. fdt_fixup_qportals(blob);
  421. do_fixup_by_compat_u32(blob, "fsl,qman",
  422. "clock-frequency", get_qman_freq(), 1);
  423. #endif
  424. #ifdef CONFIG_SYS_DPAA_FMAN
  425. fdt_fixup_fman_firmware(blob);
  426. #endif
  427. #ifndef CONFIG_ARCH_LS1012A
  428. fsl_fdt_disable_usb(blob);
  429. #endif
  430. #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
  431. fdt_fixup_gic(blob);
  432. #endif
  433. #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
  434. fdt_fixup_msi(blob);
  435. #endif
  436. #ifdef CONFIG_ARCH_LS1028A
  437. fdt_disable_multimedia(blob, svr);
  438. #endif
  439. #ifdef CONFIG_PCIE_ECAM_GENERIC
  440. fdt_fixup_ecam(blob);
  441. #endif
  442. }