fdt.c 5.0 KB

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