init.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * arch/sh/kernel/cpu/init.c
  3. *
  4. * CPU init code
  5. *
  6. * Copyright (C) 2002 - 2009 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/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/log2.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/processor.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/page.h>
  21. #include <asm/system.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/cache.h>
  24. #include <asm/elf.h>
  25. #include <asm/io.h>
  26. #include <asm/smp.h>
  27. #ifdef CONFIG_SH_FPU
  28. #define cpu_has_fpu 1
  29. #else
  30. #define cpu_has_fpu 0
  31. #endif
  32. #ifdef CONFIG_SH_DSP
  33. #define cpu_has_dsp 1
  34. #else
  35. #define cpu_has_dsp 0
  36. #endif
  37. /*
  38. * Generic wrapper for command line arguments to disable on-chip
  39. * peripherals (nofpu, nodsp, and so forth).
  40. */
  41. #define onchip_setup(x) \
  42. static int x##_disabled __initdata = !cpu_has_##x; \
  43. \
  44. static int __init x##_setup(char *opts) \
  45. { \
  46. x##_disabled = 1; \
  47. return 1; \
  48. } \
  49. __setup("no" __stringify(x), x##_setup);
  50. onchip_setup(fpu);
  51. onchip_setup(dsp);
  52. #ifdef CONFIG_SPECULATIVE_EXECUTION
  53. #define CPUOPM 0xff2f0000
  54. #define CPUOPM_RABD (1 << 5)
  55. static void __init speculative_execution_init(void)
  56. {
  57. /* Clear RABD */
  58. ctrl_outl(ctrl_inl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
  59. /* Flush the update */
  60. (void)ctrl_inl(CPUOPM);
  61. ctrl_barrier();
  62. }
  63. #else
  64. #define speculative_execution_init() do { } while (0)
  65. #endif
  66. #ifdef CONFIG_CPU_SH4A
  67. #define EXPMASK 0xff2f0004
  68. #define EXPMASK_RTEDS (1 << 0)
  69. #define EXPMASK_BRDSSLP (1 << 1)
  70. #define EXPMASK_MMCAW (1 << 4)
  71. static void __init expmask_init(void)
  72. {
  73. unsigned long expmask = __raw_readl(EXPMASK);
  74. /*
  75. * Future proofing.
  76. *
  77. * Disable support for slottable sleep instruction, non-nop
  78. * instructions in the rte delay slot, and associative writes to
  79. * the memory-mapped cache array.
  80. */
  81. expmask &= ~(EXPMASK_RTEDS | EXPMASK_BRDSSLP | EXPMASK_MMCAW);
  82. __raw_writel(expmask, EXPMASK);
  83. ctrl_barrier();
  84. }
  85. #else
  86. #define expmask_init() do { } while (0)
  87. #endif
  88. /* 2nd-level cache init */
  89. void __attribute__ ((weak)) l2_cache_init(void)
  90. {
  91. }
  92. /*
  93. * Generic first-level cache init
  94. */
  95. #ifdef CONFIG_SUPERH32
  96. static void cache_init(void)
  97. {
  98. unsigned long ccr, flags;
  99. jump_to_uncached();
  100. ccr = ctrl_inl(CCR);
  101. /*
  102. * At this point we don't know whether the cache is enabled or not - a
  103. * bootloader may have enabled it. There are at least 2 things that
  104. * could be dirty in the cache at this point:
  105. * 1. kernel command line set up by boot loader
  106. * 2. spilled registers from the prolog of this function
  107. * => before re-initialising the cache, we must do a purge of the whole
  108. * cache out to memory for safety. As long as nothing is spilled
  109. * during the loop to lines that have already been done, this is safe.
  110. * - RPC
  111. */
  112. if (ccr & CCR_CACHE_ENABLE) {
  113. unsigned long ways, waysize, addrstart;
  114. waysize = current_cpu_data.dcache.sets;
  115. #ifdef CCR_CACHE_ORA
  116. /*
  117. * If the OC is already in RAM mode, we only have
  118. * half of the entries to flush..
  119. */
  120. if (ccr & CCR_CACHE_ORA)
  121. waysize >>= 1;
  122. #endif
  123. waysize <<= current_cpu_data.dcache.entry_shift;
  124. #ifdef CCR_CACHE_EMODE
  125. /* If EMODE is not set, we only have 1 way to flush. */
  126. if (!(ccr & CCR_CACHE_EMODE))
  127. ways = 1;
  128. else
  129. #endif
  130. ways = current_cpu_data.dcache.ways;
  131. addrstart = CACHE_OC_ADDRESS_ARRAY;
  132. do {
  133. unsigned long addr;
  134. for (addr = addrstart;
  135. addr < addrstart + waysize;
  136. addr += current_cpu_data.dcache.linesz)
  137. ctrl_outl(0, addr);
  138. addrstart += current_cpu_data.dcache.way_incr;
  139. } while (--ways);
  140. }
  141. /*
  142. * Default CCR values .. enable the caches
  143. * and invalidate them immediately..
  144. */
  145. flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
  146. #ifdef CCR_CACHE_EMODE
  147. /* Force EMODE if possible */
  148. if (current_cpu_data.dcache.ways > 1)
  149. flags |= CCR_CACHE_EMODE;
  150. else
  151. flags &= ~CCR_CACHE_EMODE;
  152. #endif
  153. #if defined(CONFIG_CACHE_WRITETHROUGH)
  154. /* Write-through */
  155. flags |= CCR_CACHE_WT;
  156. #elif defined(CONFIG_CACHE_WRITEBACK)
  157. /* Write-back */
  158. flags |= CCR_CACHE_CB;
  159. #else
  160. /* Off */
  161. flags &= ~CCR_CACHE_ENABLE;
  162. #endif
  163. l2_cache_init();
  164. ctrl_outl(flags, CCR);
  165. back_to_cached();
  166. }
  167. #else
  168. #define cache_init() do { } while (0)
  169. #endif
  170. #define CSHAPE(totalsize, linesize, assoc) \
  171. ((totalsize & ~0xff) | (linesize << 4) | assoc)
  172. #define CACHE_DESC_SHAPE(desc) \
  173. CSHAPE((desc).way_size * (desc).ways, ilog2((desc).linesz), (desc).ways)
  174. static void detect_cache_shape(void)
  175. {
  176. l1d_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.dcache);
  177. if (current_cpu_data.dcache.flags & SH_CACHE_COMBINED)
  178. l1i_cache_shape = l1d_cache_shape;
  179. else
  180. l1i_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.icache);
  181. if (current_cpu_data.flags & CPU_HAS_L2_CACHE)
  182. l2_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.scache);
  183. else
  184. l2_cache_shape = -1; /* No S-cache */
  185. }
  186. static void __init fpu_init(void)
  187. {
  188. /* Disable the FPU */
  189. if (fpu_disabled && (current_cpu_data.flags & CPU_HAS_FPU)) {
  190. printk("FPU Disabled\n");
  191. current_cpu_data.flags &= ~CPU_HAS_FPU;
  192. }
  193. disable_fpu();
  194. clear_used_math();
  195. }
  196. #ifdef CONFIG_SH_DSP
  197. static void __init release_dsp(void)
  198. {
  199. unsigned long sr;
  200. /* Clear SR.DSP bit */
  201. __asm__ __volatile__ (
  202. "stc\tsr, %0\n\t"
  203. "and\t%1, %0\n\t"
  204. "ldc\t%0, sr\n\t"
  205. : "=&r" (sr)
  206. : "r" (~SR_DSP)
  207. );
  208. }
  209. static void __init dsp_init(void)
  210. {
  211. unsigned long sr;
  212. /*
  213. * Set the SR.DSP bit, wait for one instruction, and then read
  214. * back the SR value.
  215. */
  216. __asm__ __volatile__ (
  217. "stc\tsr, %0\n\t"
  218. "or\t%1, %0\n\t"
  219. "ldc\t%0, sr\n\t"
  220. "nop\n\t"
  221. "stc\tsr, %0\n\t"
  222. : "=&r" (sr)
  223. : "r" (SR_DSP)
  224. );
  225. /* If the DSP bit is still set, this CPU has a DSP */
  226. if (sr & SR_DSP)
  227. current_cpu_data.flags |= CPU_HAS_DSP;
  228. /* Disable the DSP */
  229. if (dsp_disabled && (current_cpu_data.flags & CPU_HAS_DSP)) {
  230. printk("DSP Disabled\n");
  231. current_cpu_data.flags &= ~CPU_HAS_DSP;
  232. }
  233. /* Now that we've determined the DSP status, clear the DSP bit. */
  234. release_dsp();
  235. }
  236. #else
  237. static inline void __init dsp_init(void) { }
  238. #endif /* CONFIG_SH_DSP */
  239. /**
  240. * sh_cpu_init
  241. *
  242. * This is our initial entry point for each CPU, and is invoked on the
  243. * boot CPU prior to calling start_kernel(). For SMP, a combination of
  244. * this and start_secondary() will bring up each processor to a ready
  245. * state prior to hand forking the idle loop.
  246. *
  247. * We do all of the basic processor init here, including setting up
  248. * the caches, FPU, DSP, etc. By the time start_kernel() is hit (and
  249. * subsequently platform_setup()) things like determining the CPU
  250. * subtype and initial configuration will all be done.
  251. *
  252. * Each processor family is still responsible for doing its own probing
  253. * and cache configuration in detect_cpu_and_cache_system().
  254. */
  255. asmlinkage void __init sh_cpu_init(void)
  256. {
  257. current_thread_info()->cpu = hard_smp_processor_id();
  258. /* First, probe the CPU */
  259. detect_cpu_and_cache_system();
  260. if (current_cpu_data.type == CPU_SH_NONE)
  261. panic("Unknown CPU");
  262. /* First setup the rest of the I-cache info */
  263. current_cpu_data.icache.entry_mask = current_cpu_data.icache.way_incr -
  264. current_cpu_data.icache.linesz;
  265. current_cpu_data.icache.way_size = current_cpu_data.icache.sets *
  266. current_cpu_data.icache.linesz;
  267. /* And the D-cache too */
  268. current_cpu_data.dcache.entry_mask = current_cpu_data.dcache.way_incr -
  269. current_cpu_data.dcache.linesz;
  270. current_cpu_data.dcache.way_size = current_cpu_data.dcache.sets *
  271. current_cpu_data.dcache.linesz;
  272. /* Init the cache */
  273. cache_init();
  274. if (raw_smp_processor_id() == 0) {
  275. shm_align_mask = max_t(unsigned long,
  276. current_cpu_data.dcache.way_size - 1,
  277. PAGE_SIZE - 1);
  278. /* Boot CPU sets the cache shape */
  279. detect_cache_shape();
  280. }
  281. fpu_init();
  282. dsp_init();
  283. /*
  284. * Initialize the per-CPU ASID cache very early, since the
  285. * TLB flushing routines depend on this being setup.
  286. */
  287. current_cpu_data.asid_cache = NO_CONTEXT;
  288. speculative_execution_init();
  289. expmask_init();
  290. /*
  291. * Boot processor to setup the FP and extended state context info.
  292. */
  293. if (raw_smp_processor_id() == 0)
  294. init_thread_xstate();
  295. }