init.c 6.6 KB

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