init.c 6.3 KB

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