fdt.c 9.0 KB

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