fdt.c 5.1 KB

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