init.c 8.3 KB

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