idle.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. local_irq_enable();
  36. }
  37. static void r39xx_wait(void)
  38. {
  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. if (!need_resched())
  54. __asm__(
  55. " .set push \n"
  56. " .set mips3 \n"
  57. " wait \n"
  58. " .set pop \n");
  59. local_irq_enable();
  60. __asm__(
  61. " .globl __pastwait \n"
  62. "__pastwait: \n");
  63. }
  64. /*
  65. * The RM7000 variant has to handle erratum 38. The workaround is to not
  66. * have any pending stores when the WAIT instruction is executed.
  67. */
  68. static void rm7k_wait_irqoff(void)
  69. {
  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__(
  91. " .set mips3 \n"
  92. " cache 0x14, 0(%0) \n"
  93. " cache 0x14, 32(%0) \n"
  94. " sync \n"
  95. " nop \n"
  96. " wait \n"
  97. " nop \n"
  98. " nop \n"
  99. " nop \n"
  100. " nop \n"
  101. " .set mips0 \n"
  102. : : "r" (au1k_wait));
  103. local_irq_enable();
  104. }
  105. static int __initdata nowait;
  106. static int __init wait_disable(char *s)
  107. {
  108. nowait = 1;
  109. return 1;
  110. }
  111. __setup("nowait", wait_disable);
  112. void __init check_wait(void)
  113. {
  114. struct cpuinfo_mips *c = &current_cpu_data;
  115. if (nowait) {
  116. printk("Wait instruction disabled.\n");
  117. return;
  118. }
  119. switch (c->cputype) {
  120. case CPU_R3081:
  121. case CPU_R3081E:
  122. cpu_wait = r3081_wait;
  123. break;
  124. case CPU_TX3927:
  125. cpu_wait = r39xx_wait;
  126. break;
  127. case CPU_R4200:
  128. /* case CPU_R4300: */
  129. case CPU_R4600:
  130. case CPU_R4640:
  131. case CPU_R4650:
  132. case CPU_R4700:
  133. case CPU_R5000:
  134. case CPU_R5500:
  135. case CPU_NEVADA:
  136. case CPU_4KC:
  137. case CPU_4KEC:
  138. case CPU_4KSC:
  139. case CPU_5KC:
  140. case CPU_25KF:
  141. case CPU_PR4450:
  142. case CPU_BMIPS3300:
  143. case CPU_BMIPS4350:
  144. case CPU_BMIPS4380:
  145. case CPU_BMIPS5000:
  146. case CPU_CAVIUM_OCTEON:
  147. case CPU_CAVIUM_OCTEON_PLUS:
  148. case CPU_CAVIUM_OCTEON2:
  149. case CPU_JZRISC:
  150. case CPU_LOONGSON1:
  151. case CPU_XLR:
  152. case CPU_XLP:
  153. cpu_wait = r4k_wait;
  154. break;
  155. case CPU_RM7000:
  156. cpu_wait = rm7k_wait_irqoff;
  157. break;
  158. case CPU_M14KC:
  159. case CPU_M14KEC:
  160. case CPU_24K:
  161. case CPU_34K:
  162. case CPU_1004K:
  163. cpu_wait = r4k_wait;
  164. if (read_c0_config7() & MIPS_CONF7_WII)
  165. cpu_wait = r4k_wait_irqoff;
  166. break;
  167. case CPU_74K:
  168. cpu_wait = r4k_wait;
  169. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  170. cpu_wait = r4k_wait_irqoff;
  171. break;
  172. case CPU_TX49XX:
  173. cpu_wait = r4k_wait_irqoff;
  174. break;
  175. case CPU_ALCHEMY:
  176. cpu_wait = au1k_wait;
  177. break;
  178. case CPU_20KC:
  179. /*
  180. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  181. * WAIT on Rev2.0 and Rev3.0 has E16.
  182. * Rev3.1 WAIT is nop, why bother
  183. */
  184. if ((c->processor_id & 0xff) <= 0x64)
  185. break;
  186. /*
  187. * Another rev is incremeting c0_count at a reduced clock
  188. * rate while in WAIT mode. So we basically have the choice
  189. * between using the cp0 timer as clocksource or avoiding
  190. * the WAIT instruction. Until more details are known,
  191. * disable the use of WAIT for 20Kc entirely.
  192. cpu_wait = r4k_wait;
  193. */
  194. break;
  195. case CPU_RM9000:
  196. if ((c->processor_id & 0x00ff) >= 0x40)
  197. cpu_wait = r4k_wait;
  198. break;
  199. default:
  200. break;
  201. }
  202. }
  203. static void smtc_idle_hook(void)
  204. {
  205. #ifdef CONFIG_MIPS_MT_SMTC
  206. void smtc_idle_loop_hook(void);
  207. smtc_idle_loop_hook();
  208. #endif
  209. }
  210. void arch_cpu_idle(void)
  211. {
  212. smtc_idle_hook();
  213. if (cpu_wait)
  214. cpu_wait();
  215. else
  216. local_irq_enable();
  217. }