idle.c 5.1 KB

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