init.c 7.9 KB

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