fdt.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <libfdt.h>
  8. #include <fdt_support.h>
  9. #include <phy.h>
  10. #ifdef CONFIG_FSL_LSCH3
  11. #include <asm/arch/fdt.h>
  12. #endif
  13. #ifdef CONFIG_FSL_ESDHC
  14. #include <fsl_esdhc.h>
  15. #endif
  16. #ifdef CONFIG_SYS_DPAA_FMAN
  17. #include <fsl_fman.h>
  18. #endif
  19. #ifdef CONFIG_MP
  20. #include <asm/arch/mp.h>
  21. #endif
  22. int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
  23. {
  24. return fdt_setprop_string(blob, offset, "phy-connection-type",
  25. phy_string_for_interface(phyc));
  26. }
  27. #ifdef CONFIG_MP
  28. void ft_fixup_cpu(void *blob)
  29. {
  30. int off;
  31. __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
  32. fdt32_t *reg;
  33. int addr_cells;
  34. u64 val, core_id;
  35. size_t *boot_code_size = &(__secondary_boot_code_size);
  36. off = fdt_path_offset(blob, "/cpus");
  37. if (off < 0) {
  38. puts("couldn't find /cpus node\n");
  39. return;
  40. }
  41. of_bus_default_count_cells(blob, off, &addr_cells, NULL);
  42. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  43. while (off != -FDT_ERR_NOTFOUND) {
  44. reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
  45. if (reg) {
  46. core_id = of_read_number(reg, addr_cells);
  47. if (core_id == 0 || (is_core_online(core_id))) {
  48. val = spin_tbl_addr;
  49. val += id_to_core(core_id) *
  50. SPIN_TABLE_ELEM_SIZE;
  51. val = cpu_to_fdt64(val);
  52. fdt_setprop_string(blob, off, "enable-method",
  53. "spin-table");
  54. fdt_setprop(blob, off, "cpu-release-addr",
  55. &val, sizeof(val));
  56. } else {
  57. debug("skipping offline core\n");
  58. }
  59. } else {
  60. puts("Warning: found cpu node without reg property\n");
  61. }
  62. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  63. "cpu", 4);
  64. }
  65. fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
  66. *boot_code_size);
  67. }
  68. #endif
  69. /*
  70. * the burden is on the the caller to not request a count
  71. * exceeding the bounds of the stream_ids[] array
  72. */
  73. void alloc_stream_ids(int start_id, int count, u32 *stream_ids, int max_cnt)
  74. {
  75. int i;
  76. if (count > max_cnt) {
  77. printf("\n%s: ERROR: max per-device stream ID count exceed\n",
  78. __func__);
  79. return;
  80. }
  81. for (i = 0; i < count; i++)
  82. stream_ids[i] = start_id++;
  83. }
  84. /*
  85. * This function updates the mmu-masters property on the SMMU
  86. * node as per the SMMU binding-- phandle and list of stream IDs
  87. * for each MMU master.
  88. */
  89. void append_mmu_masters(void *blob, const char *smmu_path,
  90. const char *master_name, u32 *stream_ids, int count)
  91. {
  92. u32 phandle;
  93. int smmu_nodeoffset;
  94. int master_nodeoffset;
  95. int i;
  96. /* get phandle of mmu master device */
  97. master_nodeoffset = fdt_path_offset(blob, master_name);
  98. if (master_nodeoffset < 0) {
  99. printf("\n%s: ERROR: master not found\n", __func__);
  100. return;
  101. }
  102. phandle = fdt_get_phandle(blob, master_nodeoffset);
  103. if (!phandle) { /* if master has no phandle, create one */
  104. phandle = fdt_create_phandle(blob, master_nodeoffset);
  105. if (!phandle) {
  106. printf("\n%s: ERROR: unable to create phandle\n",
  107. __func__);
  108. return;
  109. }
  110. }
  111. /* append it to mmu-masters */
  112. smmu_nodeoffset = fdt_path_offset(blob, smmu_path);
  113. if (fdt_appendprop_u32(blob, smmu_nodeoffset, "mmu-masters",
  114. phandle) < 0) {
  115. printf("\n%s: ERROR: unable to update SMMU node\n", __func__);
  116. return;
  117. }
  118. /* for each stream ID, append to mmu-masters */
  119. for (i = 0; i < count; i++) {
  120. fdt_appendprop_u32(blob, smmu_nodeoffset, "mmu-masters",
  121. stream_ids[i]);
  122. }
  123. /* fix up #stream-id-cells with stream ID count */
  124. if (fdt_setprop_u32(blob, master_nodeoffset, "#stream-id-cells",
  125. count) < 0)
  126. printf("\n%s: ERROR: unable to update #stream-id-cells\n",
  127. __func__);
  128. }
  129. /*
  130. * The info below summarizes how streamID partitioning works
  131. * for ls2080a and how it is conveyed to the OS via the device tree.
  132. *
  133. * -non-PCI legacy, platform devices (USB, SD/MMC, SATA, DMA)
  134. * -all legacy devices get a unique ICID assigned and programmed in
  135. * their AMQR registers by u-boot
  136. * -u-boot updates the hardware device tree with streamID properties
  137. * for each platform/legacy device (smmu-masters property)
  138. *
  139. * -PCIe
  140. * -for each PCI controller that is active (as per RCW settings),
  141. * u-boot will allocate a range of ICID and convey that to Linux via
  142. * the device tree (smmu-masters property)
  143. *
  144. * -DPAA2
  145. * -u-boot will allocate a range of ICIDs to be used by the Management
  146. * Complex for containers and will set these values in the MC DPC image.
  147. * -the MC is responsible for allocating and setting up ICIDs
  148. * for all DPAA2 devices.
  149. *
  150. */
  151. #ifdef CONFIG_FSL_LSCH3
  152. static void fdt_fixup_smmu(void *blob)
  153. {
  154. int nodeoffset;
  155. nodeoffset = fdt_path_offset(blob, "/iommu@5000000");
  156. if (nodeoffset < 0) {
  157. printf("\n%s: WARNING: no SMMU node found\n", __func__);
  158. return;
  159. }
  160. /* fixup for all PCI controllers */
  161. #ifdef CONFIG_PCI
  162. fdt_fixup_smmu_pcie(blob);
  163. #endif
  164. }
  165. #endif
  166. void ft_cpu_setup(void *blob, bd_t *bd)
  167. {
  168. #ifdef CONFIG_MP
  169. ft_fixup_cpu(blob);
  170. #endif
  171. #ifdef CONFIG_SYS_NS16550
  172. do_fixup_by_compat_u32(blob, "fsl,ns16550",
  173. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  174. #endif
  175. do_fixup_by_compat_u32(blob, "fixed-clock",
  176. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  177. #ifdef CONFIG_PCI
  178. ft_pci_setup(blob, bd);
  179. #endif
  180. #ifdef CONFIG_FSL_ESDHC
  181. fdt_fixup_esdhc(blob, bd);
  182. #endif
  183. #ifdef CONFIG_FSL_LSCH3
  184. fdt_fixup_smmu(blob);
  185. #endif
  186. #ifdef CONFIG_SYS_DPAA_FMAN
  187. fdt_fixup_fman_firmware(blob);
  188. #endif
  189. }