fdt.c 11 KB

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