init.c 7.6 KB

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