init.c 4.7 KB

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