init.c 8.3 KB

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