fdt.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2000
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <libfdt.h>
  27. #include <fdt_support.h>
  28. #include <asm/processor.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. extern void ft_qe_setup(void *blob);
  31. #ifdef CONFIG_MP
  32. #include "mp.h"
  33. void ft_fixup_cpu(void *blob, u64 memory_limit)
  34. {
  35. int off;
  36. ulong spin_tbl_addr = get_spin_addr();
  37. u32 bootpg, id = get_my_id();
  38. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  39. if ((u64)gd->ram_size > 0xfffff000)
  40. bootpg = 0xfffff000;
  41. else
  42. bootpg = gd->ram_size - 4096;
  43. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  44. while (off != -FDT_ERR_NOTFOUND) {
  45. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  46. if (reg) {
  47. if (*reg == id) {
  48. fdt_setprop_string(blob, off, "status", "okay");
  49. } else {
  50. u64 val = *reg * SIZE_BOOT_ENTRY + spin_tbl_addr;
  51. val = cpu_to_fdt32(val);
  52. fdt_setprop_string(blob, off, "status",
  53. "disabled");
  54. fdt_setprop_string(blob, off, "enable-method",
  55. "spin-table");
  56. fdt_setprop(blob, off, "cpu-release-addr",
  57. &val, sizeof(val));
  58. }
  59. } else {
  60. printf ("cpu NULL\n");
  61. }
  62. off = fdt_node_offset_by_prop_value(blob, off,
  63. "device_type", "cpu", 4);
  64. }
  65. /* Reserve the boot page so OSes dont use it */
  66. if ((u64)bootpg < memory_limit) {
  67. off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
  68. if (off < 0)
  69. printf("%s: %s\n", __FUNCTION__, fdt_strerror(off));
  70. }
  71. }
  72. #endif
  73. #ifdef CONFIG_L2_CACHE
  74. /* return size in kilobytes */
  75. static inline u32 l2cache_size(void)
  76. {
  77. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  78. volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
  79. u32 ver = SVR_SOC_VER(get_svr());
  80. switch (l2siz_field) {
  81. case 0x0:
  82. break;
  83. case 0x1:
  84. if (ver == SVR_8540 || ver == SVR_8560 ||
  85. ver == SVR_8541 || ver == SVR_8541_E ||
  86. ver == SVR_8555 || ver == SVR_8555_E)
  87. return 128;
  88. else
  89. return 256;
  90. break;
  91. case 0x2:
  92. if (ver == SVR_8540 || ver == SVR_8560 ||
  93. ver == SVR_8541 || ver == SVR_8541_E ||
  94. ver == SVR_8555 || ver == SVR_8555_E)
  95. return 256;
  96. else
  97. return 512;
  98. break;
  99. case 0x3:
  100. return 1024;
  101. break;
  102. }
  103. return 0;
  104. }
  105. static inline void ft_fixup_l2cache(void *blob)
  106. {
  107. int len, off;
  108. u32 *ph;
  109. struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
  110. char compat_buf[38];
  111. const u32 line_size = 32;
  112. const u32 num_ways = 8;
  113. const u32 size = l2cache_size() * 1024;
  114. const u32 num_sets = size / (line_size * num_ways);
  115. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  116. if (off < 0) {
  117. debug("no cpu node fount\n");
  118. return;
  119. }
  120. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  121. if (ph == NULL) {
  122. debug("no next-level-cache property\n");
  123. return ;
  124. }
  125. off = fdt_node_offset_by_phandle(blob, *ph);
  126. if (off < 0) {
  127. printf("%s: %s\n", __func__, fdt_strerror(off));
  128. return ;
  129. }
  130. if (cpu) {
  131. len = sprintf(compat_buf, "fsl,mpc%s-l2-cache-controller",
  132. cpu->name);
  133. sprintf(&compat_buf[len + 1], "cache");
  134. }
  135. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  136. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  137. fdt_setprop_cell(blob, off, "cache-size", size);
  138. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  139. fdt_setprop_cell(blob, off, "cache-level", 2);
  140. fdt_setprop(blob, off, "compatible", compat_buf, sizeof(compat_buf));
  141. }
  142. #else
  143. #define ft_fixup_l2cache(x)
  144. #endif
  145. static inline void ft_fixup_cache(void *blob)
  146. {
  147. int off;
  148. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  149. while (off != -FDT_ERR_NOTFOUND) {
  150. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  151. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  152. u32 isize, iline_size, inum_sets, inum_ways;
  153. u32 dsize, dline_size, dnum_sets, dnum_ways;
  154. /* d-side config */
  155. dsize = (l1cfg0 & 0x7ff) * 1024;
  156. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  157. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  158. dnum_sets = dsize / (dline_size * dnum_ways);
  159. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  160. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  161. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  162. /* i-side config */
  163. isize = (l1cfg1 & 0x7ff) * 1024;
  164. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  165. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  166. inum_sets = isize / (iline_size * inum_ways);
  167. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  168. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  169. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  170. off = fdt_node_offset_by_prop_value(blob, off,
  171. "device_type", "cpu", 4);
  172. }
  173. ft_fixup_l2cache(blob);
  174. }
  175. void fdt_add_enet_stashing(void *fdt)
  176. {
  177. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  178. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  179. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  180. }
  181. void ft_cpu_setup(void *blob, bd_t *bd)
  182. {
  183. /* delete crypto node if not on an E-processor */
  184. if (!IS_E_PROCESSOR(get_svr()))
  185. fdt_fixup_crypto_node(blob, 0);
  186. #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
  187. defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
  188. fdt_fixup_ethernet(blob);
  189. fdt_add_enet_stashing(blob);
  190. #endif
  191. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  192. "timebase-frequency", bd->bi_busfreq / 8, 1);
  193. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  194. "bus-frequency", bd->bi_busfreq, 1);
  195. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  196. "clock-frequency", bd->bi_intfreq, 1);
  197. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  198. "bus-frequency", bd->bi_busfreq, 1);
  199. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  200. "bus-frequency", gd->lbc_clk, 1);
  201. do_fixup_by_compat_u32(blob, "fsl,elbc",
  202. "bus-frequency", gd->lbc_clk, 1);
  203. #ifdef CONFIG_QE
  204. ft_qe_setup(blob);
  205. #endif
  206. #ifdef CONFIG_SYS_NS16550
  207. do_fixup_by_compat_u32(blob, "ns16550",
  208. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  209. #endif
  210. #ifdef CONFIG_CPM2
  211. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  212. "current-speed", bd->bi_baudrate, 1);
  213. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  214. "clock-frequency", bd->bi_brgfreq, 1);
  215. #endif
  216. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  217. #ifdef CONFIG_MP
  218. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  219. #endif
  220. ft_fixup_cache(blob);
  221. }