init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. /*
  63. * If the OC is already in RAM mode, we only have
  64. * half of the entries to flush..
  65. */
  66. if (ccr & CCR_CACHE_ORA)
  67. waysize >>= 1;
  68. waysize <<= cpu_data->dcache.entry_shift;
  69. #ifdef CCR_CACHE_EMODE
  70. /* If EMODE is not set, we only have 1 way to flush. */
  71. if (!(ccr & CCR_CACHE_EMODE))
  72. ways = 1;
  73. else
  74. #endif
  75. ways = cpu_data->dcache.ways;
  76. addrstart = CACHE_OC_ADDRESS_ARRAY;
  77. do {
  78. unsigned long addr;
  79. for (addr = addrstart;
  80. addr < addrstart + waysize;
  81. addr += cpu_data->dcache.linesz)
  82. ctrl_outl(0, addr);
  83. addrstart += cpu_data->dcache.way_incr;
  84. } while (--ways);
  85. }
  86. /*
  87. * Default CCR values .. enable the caches
  88. * and invalidate them immediately..
  89. */
  90. flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
  91. #ifdef CCR_CACHE_EMODE
  92. /* Force EMODE if possible */
  93. if (cpu_data->dcache.ways > 1)
  94. flags |= CCR_CACHE_EMODE;
  95. else
  96. flags &= ~CCR_CACHE_EMODE;
  97. #endif
  98. #ifdef CONFIG_SH_WRITETHROUGH
  99. /* Turn on Write-through caching */
  100. flags |= CCR_CACHE_WT;
  101. #else
  102. /* .. or default to Write-back */
  103. flags |= CCR_CACHE_CB;
  104. #endif
  105. #ifdef CONFIG_SH_OCRAM
  106. /* Turn on OCRAM -- halve the OC */
  107. flags |= CCR_CACHE_ORA;
  108. cpu_data->dcache.sets >>= 1;
  109. cpu_data->dcache.way_size = cpu_data->dcache.sets *
  110. cpu_data->dcache.linesz;
  111. #endif
  112. ctrl_outl(flags, CCR);
  113. back_to_P1();
  114. }
  115. #ifdef CONFIG_SH_DSP
  116. static void __init release_dsp(void)
  117. {
  118. unsigned long sr;
  119. /* Clear SR.DSP bit */
  120. __asm__ __volatile__ (
  121. "stc\tsr, %0\n\t"
  122. "and\t%1, %0\n\t"
  123. "ldc\t%0, sr\n\t"
  124. : "=&r" (sr)
  125. : "r" (~SR_DSP)
  126. );
  127. }
  128. static void __init dsp_init(void)
  129. {
  130. unsigned long sr;
  131. /*
  132. * Set the SR.DSP bit, wait for one instruction, and then read
  133. * back the SR value.
  134. */
  135. __asm__ __volatile__ (
  136. "stc\tsr, %0\n\t"
  137. "or\t%1, %0\n\t"
  138. "ldc\t%0, sr\n\t"
  139. "nop\n\t"
  140. "stc\tsr, %0\n\t"
  141. : "=&r" (sr)
  142. : "r" (SR_DSP)
  143. );
  144. /* If the DSP bit is still set, this CPU has a DSP */
  145. if (sr & SR_DSP)
  146. cpu_data->flags |= CPU_HAS_DSP;
  147. /* Now that we've determined the DSP status, clear the DSP bit. */
  148. release_dsp();
  149. }
  150. #endif /* CONFIG_SH_DSP */
  151. /**
  152. * sh_cpu_init
  153. *
  154. * This is our initial entry point for each CPU, and is invoked on the boot
  155. * CPU prior to calling start_kernel(). For SMP, a combination of this and
  156. * start_secondary() will bring up each processor to a ready state prior
  157. * to hand forking the idle loop.
  158. *
  159. * We do all of the basic processor init here, including setting up the
  160. * caches, FPU, DSP, kicking the UBC, etc. By the time start_kernel() is
  161. * hit (and subsequently platform_setup()) things like determining the
  162. * CPU subtype and initial configuration will all be done.
  163. *
  164. * Each processor family is still responsible for doing its own probing
  165. * and cache configuration in detect_cpu_and_cache_system().
  166. */
  167. asmlinkage void __init sh_cpu_init(void)
  168. {
  169. /* First, probe the CPU */
  170. detect_cpu_and_cache_system();
  171. /* Init the cache */
  172. cache_init();
  173. shm_align_mask = max_t(unsigned long,
  174. cpu_data->dcache.way_size - 1,
  175. PAGE_SIZE - 1);
  176. /* Disable the FPU */
  177. if (fpu_disabled) {
  178. printk("FPU Disabled\n");
  179. cpu_data->flags &= ~CPU_HAS_FPU;
  180. disable_fpu();
  181. }
  182. /* FPU initialization */
  183. if ((cpu_data->flags & CPU_HAS_FPU)) {
  184. clear_thread_flag(TIF_USEDFPU);
  185. clear_used_math();
  186. }
  187. #ifdef CONFIG_SH_DSP
  188. /* Probe for DSP */
  189. dsp_init();
  190. /* Disable the DSP */
  191. if (dsp_disabled) {
  192. printk("DSP Disabled\n");
  193. cpu_data->flags &= ~CPU_HAS_DSP;
  194. release_dsp();
  195. }
  196. #endif
  197. #ifdef CONFIG_UBC_WAKEUP
  198. /*
  199. * Some brain-damaged loaders decided it would be a good idea to put
  200. * the UBC to sleep. This causes some issues when it comes to things
  201. * like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB. So ..
  202. * we wake it up and hope that all is well.
  203. */
  204. ubc_wakeup();
  205. #endif
  206. }