probe.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * arch/sh/kernel/cpu/sh4/probe.c
  3. *
  4. * CPU Subtype Probing for SH-4.
  5. *
  6. * Copyright (C) 2001 - 2007 Paul Mundt
  7. * Copyright (C) 2003 Richard Curnow
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <asm/processor.h>
  16. #include <asm/cache.h>
  17. int __init detect_cpu_and_cache_system(void)
  18. {
  19. unsigned long pvr, prr, cvr;
  20. unsigned long size;
  21. static unsigned long sizes[16] = {
  22. [1] = (1 << 12),
  23. [2] = (1 << 13),
  24. [4] = (1 << 14),
  25. [8] = (1 << 15),
  26. [9] = (1 << 16)
  27. };
  28. pvr = (ctrl_inl(CCN_PVR) >> 8) & 0xffffff;
  29. prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
  30. cvr = (ctrl_inl(CCN_CVR));
  31. /*
  32. * Setup some sane SH-4 defaults for the icache
  33. */
  34. boot_cpu_data.icache.way_incr = (1 << 13);
  35. boot_cpu_data.icache.entry_shift = 5;
  36. boot_cpu_data.icache.sets = 256;
  37. boot_cpu_data.icache.ways = 1;
  38. boot_cpu_data.icache.linesz = L1_CACHE_BYTES;
  39. /*
  40. * And again for the dcache ..
  41. */
  42. boot_cpu_data.dcache.way_incr = (1 << 14);
  43. boot_cpu_data.dcache.entry_shift = 5;
  44. boot_cpu_data.dcache.sets = 512;
  45. boot_cpu_data.dcache.ways = 1;
  46. boot_cpu_data.dcache.linesz = L1_CACHE_BYTES;
  47. /*
  48. * Setup some generic flags we can probe on SH-4A parts
  49. */
  50. if (((pvr >> 16) & 0xff) == 0x10) {
  51. if ((cvr & 0x10000000) == 0)
  52. boot_cpu_data.flags |= CPU_HAS_DSP;
  53. boot_cpu_data.flags |= CPU_HAS_LLSC;
  54. }
  55. /* FPU detection works for everyone */
  56. if ((cvr & 0x20000000) == 1)
  57. boot_cpu_data.flags |= CPU_HAS_FPU;
  58. /* Mask off the upper chip ID */
  59. pvr &= 0xffff;
  60. /*
  61. * Probe the underlying processor version/revision and
  62. * adjust cpu_data setup accordingly.
  63. */
  64. switch (pvr) {
  65. case 0x205:
  66. boot_cpu_data.type = CPU_SH7750;
  67. boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
  68. CPU_HAS_PERF_COUNTER;
  69. break;
  70. case 0x206:
  71. boot_cpu_data.type = CPU_SH7750S;
  72. boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
  73. CPU_HAS_PERF_COUNTER;
  74. break;
  75. case 0x1100:
  76. boot_cpu_data.type = CPU_SH7751;
  77. boot_cpu_data.flags |= CPU_HAS_FPU;
  78. break;
  79. case 0x2001:
  80. case 0x2004:
  81. boot_cpu_data.type = CPU_SH7770;
  82. boot_cpu_data.icache.ways = 4;
  83. boot_cpu_data.dcache.ways = 4;
  84. boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
  85. break;
  86. case 0x2006:
  87. case 0x200A:
  88. if (prr == 0x61)
  89. boot_cpu_data.type = CPU_SH7781;
  90. else if (prr == 0xa1)
  91. boot_cpu_data.type = CPU_SH7763;
  92. else
  93. boot_cpu_data.type = CPU_SH7780;
  94. boot_cpu_data.icache.ways = 4;
  95. boot_cpu_data.dcache.ways = 4;
  96. boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
  97. CPU_HAS_LLSC;
  98. break;
  99. case 0x3000:
  100. case 0x3003:
  101. case 0x3009:
  102. boot_cpu_data.type = CPU_SH7343;
  103. boot_cpu_data.icache.ways = 4;
  104. boot_cpu_data.dcache.ways = 4;
  105. boot_cpu_data.flags |= CPU_HAS_LLSC;
  106. break;
  107. case 0x3004:
  108. case 0x3007:
  109. boot_cpu_data.type = CPU_SH7785;
  110. boot_cpu_data.icache.ways = 4;
  111. boot_cpu_data.dcache.ways = 4;
  112. boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
  113. CPU_HAS_LLSC;
  114. break;
  115. case 0x3008:
  116. if (prr == 0xa0 || prr == 0xa1) {
  117. boot_cpu_data.type = CPU_SH7722;
  118. boot_cpu_data.icache.ways = 4;
  119. boot_cpu_data.dcache.ways = 4;
  120. boot_cpu_data.flags |= CPU_HAS_LLSC;
  121. }
  122. else if (prr == 0x70) {
  123. boot_cpu_data.type = CPU_SH7366;
  124. boot_cpu_data.icache.ways = 4;
  125. boot_cpu_data.dcache.ways = 4;
  126. boot_cpu_data.flags |= CPU_HAS_LLSC;
  127. }
  128. break;
  129. case 0x4000: /* 1st cut */
  130. case 0x4001: /* 2nd cut */
  131. boot_cpu_data.type = CPU_SHX3;
  132. boot_cpu_data.icache.ways = 4;
  133. boot_cpu_data.dcache.ways = 4;
  134. boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
  135. CPU_HAS_LLSC;
  136. break;
  137. case 0x700:
  138. boot_cpu_data.type = CPU_SH4_501;
  139. boot_cpu_data.icache.ways = 2;
  140. boot_cpu_data.dcache.ways = 2;
  141. break;
  142. case 0x600:
  143. boot_cpu_data.type = CPU_SH4_202;
  144. boot_cpu_data.icache.ways = 2;
  145. boot_cpu_data.dcache.ways = 2;
  146. boot_cpu_data.flags |= CPU_HAS_FPU;
  147. break;
  148. case 0x500 ... 0x501:
  149. switch (prr) {
  150. case 0x10:
  151. boot_cpu_data.type = CPU_SH7750R;
  152. break;
  153. case 0x11:
  154. boot_cpu_data.type = CPU_SH7751R;
  155. break;
  156. case 0x50 ... 0x5f:
  157. boot_cpu_data.type = CPU_SH7760;
  158. break;
  159. }
  160. boot_cpu_data.icache.ways = 2;
  161. boot_cpu_data.dcache.ways = 2;
  162. boot_cpu_data.flags |= CPU_HAS_FPU;
  163. break;
  164. default:
  165. boot_cpu_data.type = CPU_SH_NONE;
  166. break;
  167. }
  168. #ifdef CONFIG_SH_DIRECT_MAPPED
  169. boot_cpu_data.icache.ways = 1;
  170. boot_cpu_data.dcache.ways = 1;
  171. #endif
  172. #ifdef CONFIG_CPU_HAS_PTEA
  173. boot_cpu_data.flags |= CPU_HAS_PTEA;
  174. #endif
  175. /*
  176. * On anything that's not a direct-mapped cache, look to the CVR
  177. * for I/D-cache specifics.
  178. */
  179. if (boot_cpu_data.icache.ways > 1) {
  180. size = sizes[(cvr >> 20) & 0xf];
  181. boot_cpu_data.icache.way_incr = (size >> 1);
  182. boot_cpu_data.icache.sets = (size >> 6);
  183. }
  184. /* And the rest of the D-cache */
  185. if (boot_cpu_data.dcache.ways > 1) {
  186. size = sizes[(cvr >> 16) & 0xf];
  187. boot_cpu_data.dcache.way_incr = (size >> 1);
  188. boot_cpu_data.dcache.sets = (size >> 6);
  189. }
  190. /*
  191. * Setup the L2 cache desc
  192. *
  193. * SH-4A's have an optional PIPT L2.
  194. */
  195. if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) {
  196. /*
  197. * Size calculation is much more sensible
  198. * than it is for the L1.
  199. *
  200. * Sizes are 128KB, 258KB, 512KB, and 1MB.
  201. */
  202. size = (cvr & 0xf) << 17;
  203. BUG_ON(!size);
  204. boot_cpu_data.scache.way_incr = (1 << 16);
  205. boot_cpu_data.scache.entry_shift = 5;
  206. boot_cpu_data.scache.ways = 4;
  207. boot_cpu_data.scache.linesz = L1_CACHE_BYTES;
  208. boot_cpu_data.scache.entry_mask =
  209. (boot_cpu_data.scache.way_incr -
  210. boot_cpu_data.scache.linesz);
  211. boot_cpu_data.scache.sets = size /
  212. (boot_cpu_data.scache.linesz *
  213. boot_cpu_data.scache.ways);
  214. boot_cpu_data.scache.way_size =
  215. (boot_cpu_data.scache.sets *
  216. boot_cpu_data.scache.linesz);
  217. }
  218. return 0;
  219. }