fdt.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 = determine_mp_bootpg();
  38. u32 id = get_my_id();
  39. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  40. while (off != -FDT_ERR_NOTFOUND) {
  41. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  42. if (reg) {
  43. if (*reg == id) {
  44. fdt_setprop_string(blob, off, "status", "okay");
  45. } else {
  46. u64 val = *reg * SIZE_BOOT_ENTRY + spin_tbl_addr;
  47. val = cpu_to_fdt32(val);
  48. fdt_setprop_string(blob, off, "status",
  49. "disabled");
  50. fdt_setprop_string(blob, off, "enable-method",
  51. "spin-table");
  52. fdt_setprop(blob, off, "cpu-release-addr",
  53. &val, sizeof(val));
  54. }
  55. } else {
  56. printf ("cpu NULL\n");
  57. }
  58. off = fdt_node_offset_by_prop_value(blob, off,
  59. "device_type", "cpu", 4);
  60. }
  61. /* Reserve the boot page so OSes dont use it */
  62. if ((u64)bootpg < memory_limit) {
  63. off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
  64. if (off < 0)
  65. printf("%s: %s\n", __FUNCTION__, fdt_strerror(off));
  66. }
  67. }
  68. #endif
  69. #define ft_fixup_l3cache(x, y)
  70. #if defined(CONFIG_L2_CACHE)
  71. /* return size in kilobytes */
  72. static inline u32 l2cache_size(void)
  73. {
  74. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  75. volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
  76. u32 ver = SVR_SOC_VER(get_svr());
  77. switch (l2siz_field) {
  78. case 0x0:
  79. break;
  80. case 0x1:
  81. if (ver == SVR_8540 || ver == SVR_8560 ||
  82. ver == SVR_8541 || ver == SVR_8541_E ||
  83. ver == SVR_8555 || ver == SVR_8555_E)
  84. return 128;
  85. else
  86. return 256;
  87. break;
  88. case 0x2:
  89. if (ver == SVR_8540 || ver == SVR_8560 ||
  90. ver == SVR_8541 || ver == SVR_8541_E ||
  91. ver == SVR_8555 || ver == SVR_8555_E)
  92. return 256;
  93. else
  94. return 512;
  95. break;
  96. case 0x3:
  97. return 1024;
  98. break;
  99. }
  100. return 0;
  101. }
  102. static inline void ft_fixup_l2cache(void *blob)
  103. {
  104. int len, off;
  105. u32 *ph;
  106. struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
  107. char compat_buf[38];
  108. const u32 line_size = 32;
  109. const u32 num_ways = 8;
  110. const u32 size = l2cache_size() * 1024;
  111. const u32 num_sets = size / (line_size * num_ways);
  112. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  113. if (off < 0) {
  114. debug("no cpu node fount\n");
  115. return;
  116. }
  117. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  118. if (ph == NULL) {
  119. debug("no next-level-cache property\n");
  120. return ;
  121. }
  122. off = fdt_node_offset_by_phandle(blob, *ph);
  123. if (off < 0) {
  124. printf("%s: %s\n", __func__, fdt_strerror(off));
  125. return ;
  126. }
  127. if (cpu) {
  128. len = sprintf(compat_buf, "fsl,mpc%s-l2-cache-controller",
  129. cpu->name);
  130. sprintf(&compat_buf[len + 1], "cache");
  131. }
  132. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  133. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  134. fdt_setprop_cell(blob, off, "cache-size", size);
  135. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  136. fdt_setprop_cell(blob, off, "cache-level", 2);
  137. fdt_setprop(blob, off, "compatible", compat_buf, sizeof(compat_buf));
  138. /* we dont bother w/L3 since no platform of this type has one */
  139. }
  140. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  141. static inline void ft_fixup_l2cache(void *blob)
  142. {
  143. int off, l2_off, l3_off = -1;
  144. u32 *ph;
  145. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  146. u32 size, line_size, num_ways, num_sets;
  147. size = (l2cfg0 & 0x3fff) * 64 * 1024;
  148. num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
  149. line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
  150. num_sets = size / (line_size * num_ways);
  151. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  152. while (off != -FDT_ERR_NOTFOUND) {
  153. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  154. if (ph == NULL) {
  155. debug("no next-level-cache property\n");
  156. goto next;
  157. }
  158. l2_off = fdt_node_offset_by_phandle(blob, *ph);
  159. if (l2_off < 0) {
  160. printf("%s: %s\n", __func__, fdt_strerror(off));
  161. goto next;
  162. }
  163. fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
  164. fdt_setprop_cell(blob, l2_off, "cache-block-size", line_size);
  165. fdt_setprop_cell(blob, l2_off, "cache-size", size);
  166. fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
  167. fdt_setprop_cell(blob, l2_off, "cache-level", 2);
  168. fdt_setprop(blob, l2_off, "compatible", "cache", 6);
  169. if (l3_off < 0) {
  170. ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
  171. if (ph == NULL) {
  172. debug("no next-level-cache property\n");
  173. goto next;
  174. }
  175. l3_off = *ph;
  176. }
  177. next:
  178. off = fdt_node_offset_by_prop_value(blob, off,
  179. "device_type", "cpu", 4);
  180. }
  181. if (l3_off > 0) {
  182. l3_off = fdt_node_offset_by_phandle(blob, l3_off);
  183. if (l3_off < 0) {
  184. printf("%s: %s\n", __func__, fdt_strerror(off));
  185. return ;
  186. }
  187. ft_fixup_l3cache(blob, l3_off);
  188. }
  189. }
  190. #else
  191. #define ft_fixup_l2cache(x)
  192. #endif
  193. static inline void ft_fixup_cache(void *blob)
  194. {
  195. int off;
  196. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  197. while (off != -FDT_ERR_NOTFOUND) {
  198. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  199. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  200. u32 isize, iline_size, inum_sets, inum_ways;
  201. u32 dsize, dline_size, dnum_sets, dnum_ways;
  202. /* d-side config */
  203. dsize = (l1cfg0 & 0x7ff) * 1024;
  204. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  205. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  206. dnum_sets = dsize / (dline_size * dnum_ways);
  207. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  208. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  209. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  210. /* i-side config */
  211. isize = (l1cfg1 & 0x7ff) * 1024;
  212. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  213. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  214. inum_sets = isize / (iline_size * inum_ways);
  215. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  216. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  217. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  218. off = fdt_node_offset_by_prop_value(blob, off,
  219. "device_type", "cpu", 4);
  220. }
  221. ft_fixup_l2cache(blob);
  222. }
  223. void fdt_add_enet_stashing(void *fdt)
  224. {
  225. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  226. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  227. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  228. }
  229. void ft_cpu_setup(void *blob, bd_t *bd)
  230. {
  231. int off;
  232. int val;
  233. sys_info_t sysinfo;
  234. /* delete crypto node if not on an E-processor */
  235. if (!IS_E_PROCESSOR(get_svr()))
  236. fdt_fixup_crypto_node(blob, 0);
  237. fdt_fixup_ethernet(blob);
  238. fdt_add_enet_stashing(blob);
  239. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  240. "timebase-frequency", bd->bi_busfreq / 8, 1);
  241. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  242. "bus-frequency", bd->bi_busfreq, 1);
  243. get_sys_info(&sysinfo);
  244. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  245. while (off != -FDT_ERR_NOTFOUND) {
  246. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  247. val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]);
  248. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  249. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  250. "cpu", 4);
  251. }
  252. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  253. "bus-frequency", bd->bi_busfreq, 1);
  254. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  255. "bus-frequency", gd->lbc_clk, 1);
  256. do_fixup_by_compat_u32(blob, "fsl,elbc",
  257. "bus-frequency", gd->lbc_clk, 1);
  258. #ifdef CONFIG_QE
  259. ft_qe_setup(blob);
  260. #endif
  261. #ifdef CONFIG_SYS_NS16550
  262. do_fixup_by_compat_u32(blob, "ns16550",
  263. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  264. #endif
  265. #ifdef CONFIG_CPM2
  266. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  267. "current-speed", bd->bi_baudrate, 1);
  268. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  269. "clock-frequency", bd->bi_brgfreq, 1);
  270. #endif
  271. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  272. #ifdef CONFIG_MP
  273. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  274. #endif
  275. ft_fixup_cache(blob);
  276. }