idle.c 5.3 KB

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