idle.c 5.1 KB

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