idle.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * MIPS idle loop and WAIT instruction support.
  3. *
  4. * Copyright (C) xxxx the Anonymous
  5. * Copyright (C) 1994 - 2006 Ralf Baechle
  6. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  7. * Copyright (C) 2001, 2004, 2011, 2012 MIPS Technologies, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/export.h>
  15. #include <linux/init.h>
  16. #include <linux/irqflags.h>
  17. #include <linux/printk.h>
  18. #include <linux/sched.h>
  19. #include <asm/cpu.h>
  20. #include <asm/cpu-info.h>
  21. #include <asm/cpu-type.h>
  22. #include <asm/idle.h>
  23. #include <asm/mipsregs.h>
  24. /*
  25. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  26. * the implementation of the "wait" feature differs between CPU families. This
  27. * points to the function that implements CPU specific wait.
  28. * The wait instruction stops the pipeline and reduces the power consumption of
  29. * the CPU very much.
  30. */
  31. void (*cpu_wait)(void);
  32. EXPORT_SYMBOL(cpu_wait);
  33. static void r3081_wait(void)
  34. {
  35. unsigned long cfg = read_c0_conf();
  36. write_c0_conf(cfg | R30XX_CONF_HALT);
  37. local_irq_enable();
  38. }
  39. static void r39xx_wait(void)
  40. {
  41. if (!need_resched())
  42. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  43. local_irq_enable();
  44. }
  45. void r4k_wait(void)
  46. {
  47. local_irq_enable();
  48. __r4k_wait();
  49. }
  50. /*
  51. * This variant is preferable as it allows testing need_resched and going to
  52. * sleep depending on the outcome atomically. Unfortunately the "It is
  53. * implementation-dependent whether the pipeline restarts when a non-enabled
  54. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  55. * using this version a gamble.
  56. */
  57. void r4k_wait_irqoff(void)
  58. {
  59. if (!need_resched())
  60. __asm__(
  61. " .set push \n"
  62. " .set mips3 \n"
  63. " wait \n"
  64. " .set pop \n");
  65. local_irq_enable();
  66. __asm__(
  67. " .globl __pastwait \n"
  68. "__pastwait: \n");
  69. }
  70. /*
  71. * The RM7000 variant has to handle erratum 38. The workaround is to not
  72. * have any pending stores when the WAIT instruction is executed.
  73. */
  74. static void rm7k_wait_irqoff(void)
  75. {
  76. if (!need_resched())
  77. __asm__(
  78. " .set push \n"
  79. " .set mips3 \n"
  80. " .set noat \n"
  81. " mfc0 $1, $12 \n"
  82. " sync \n"
  83. " mtc0 $1, $12 # stalls until W stage \n"
  84. " wait \n"
  85. " mtc0 $1, $12 # stalls until W stage \n"
  86. " .set pop \n");
  87. local_irq_enable();
  88. }
  89. /*
  90. * Au1 'wait' is only useful when the 32kHz counter is used as timer,
  91. * since coreclock (and the cp0 counter) stops upon executing it. Only an
  92. * interrupt can wake it, so they must be enabled before entering idle modes.
  93. */
  94. static void au1k_wait(void)
  95. {
  96. unsigned long c0status = read_c0_status() | 1; /* irqs on */
  97. __asm__(
  98. " .set mips3 \n"
  99. " cache 0x14, 0(%0) \n"
  100. " cache 0x14, 32(%0) \n"
  101. " sync \n"
  102. " mtc0 %1, $12 \n" /* wr c0status */
  103. " wait \n"
  104. " nop \n"
  105. " nop \n"
  106. " nop \n"
  107. " nop \n"
  108. " .set mips0 \n"
  109. : : "r" (au1k_wait), "r" (c0status));
  110. }
  111. static int __initdata nowait;
  112. static int __init wait_disable(char *s)
  113. {
  114. nowait = 1;
  115. return 1;
  116. }
  117. __setup("nowait", wait_disable);
  118. void __init check_wait(void)
  119. {
  120. struct cpuinfo_mips *c = &current_cpu_data;
  121. if (nowait) {
  122. printk("Wait instruction disabled.\n");
  123. return;
  124. }
  125. switch (current_cpu_type()) {
  126. case CPU_R3081:
  127. case CPU_R3081E:
  128. cpu_wait = r3081_wait;
  129. break;
  130. case CPU_TX3927:
  131. cpu_wait = r39xx_wait;
  132. break;
  133. case CPU_R4200:
  134. /* case CPU_R4300: */
  135. case CPU_R4600:
  136. case CPU_R4640:
  137. case CPU_R4650:
  138. case CPU_R4700:
  139. case CPU_R5000:
  140. case CPU_R5500:
  141. case CPU_NEVADA:
  142. case CPU_4KC:
  143. case CPU_4KEC:
  144. case CPU_4KSC:
  145. case CPU_5KC:
  146. case CPU_25KF:
  147. case CPU_PR4450:
  148. case CPU_BMIPS3300:
  149. case CPU_BMIPS4350:
  150. case CPU_BMIPS4380:
  151. case CPU_BMIPS5000:
  152. case CPU_CAVIUM_OCTEON:
  153. case CPU_CAVIUM_OCTEON_PLUS:
  154. case CPU_CAVIUM_OCTEON2:
  155. case CPU_CAVIUM_OCTEON3:
  156. case CPU_JZRISC:
  157. case CPU_LOONGSON1:
  158. case CPU_XLR:
  159. case CPU_XLP:
  160. cpu_wait = r4k_wait;
  161. break;
  162. case CPU_RM7000:
  163. cpu_wait = rm7k_wait_irqoff;
  164. break;
  165. case CPU_M14KC:
  166. case CPU_M14KEC:
  167. case CPU_24K:
  168. case CPU_34K:
  169. case CPU_1004K:
  170. cpu_wait = r4k_wait;
  171. if (read_c0_config7() & MIPS_CONF7_WII)
  172. cpu_wait = r4k_wait_irqoff;
  173. break;
  174. case CPU_74K:
  175. cpu_wait = r4k_wait;
  176. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  177. cpu_wait = r4k_wait_irqoff;
  178. break;
  179. case CPU_TX49XX:
  180. cpu_wait = r4k_wait_irqoff;
  181. break;
  182. case CPU_ALCHEMY:
  183. cpu_wait = au1k_wait;
  184. break;
  185. case CPU_20KC:
  186. /*
  187. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  188. * WAIT on Rev2.0 and Rev3.0 has E16.
  189. * Rev3.1 WAIT is nop, why bother
  190. */
  191. if ((c->processor_id & 0xff) <= 0x64)
  192. break;
  193. /*
  194. * Another rev is incremeting c0_count at a reduced clock
  195. * rate while in WAIT mode. So we basically have the choice
  196. * between using the cp0 timer as clocksource or avoiding
  197. * the WAIT instruction. Until more details are known,
  198. * disable the use of WAIT for 20Kc entirely.
  199. cpu_wait = r4k_wait;
  200. */
  201. break;
  202. case CPU_RM9000:
  203. if ((c->processor_id & 0x00ff) >= 0x40)
  204. cpu_wait = r4k_wait;
  205. break;
  206. default:
  207. break;
  208. }
  209. }
  210. static void smtc_idle_hook(void)
  211. {
  212. #ifdef CONFIG_MIPS_MT_SMTC
  213. void smtc_idle_loop_hook(void);
  214. smtc_idle_loop_hook();
  215. #endif
  216. }
  217. void arch_cpu_idle(void)
  218. {
  219. smtc_idle_hook();
  220. if (cpu_wait)
  221. cpu_wait();
  222. else
  223. local_irq_enable();
  224. }