init.c 6.8 KB

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