init.c 5.5 KB

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