]>
Commit | Line | Data |
---|---|---|
49f2ec91 RB |
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 | /* | |
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 | ||
33 | static void r3081_wait(void) | |
34 | { | |
35 | unsigned long cfg = read_c0_conf(); | |
36 | write_c0_conf(cfg | R30XX_CONF_HALT); | |
fb40bc3e | 37 | local_irq_enable(); |
49f2ec91 RB |
38 | } |
39 | ||
40 | static void r39xx_wait(void) | |
41 | { | |
49f2ec91 RB |
42 | if (!need_resched()) |
43 | write_c0_conf(read_c0_conf() | TX39_CONF_HALT); | |
44 | local_irq_enable(); | |
45 | } | |
46 | ||
47 | extern void r4k_wait(void); | |
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 | { | |
49f2ec91 | 58 | if (!need_resched()) |
f91a148a RB |
59 | __asm__( |
60 | " .set push \n" | |
61 | " .set mips3 \n" | |
62 | " wait \n" | |
63 | " .set pop \n"); | |
49f2ec91 | 64 | local_irq_enable(); |
f91a148a RB |
65 | __asm__( |
66 | " .globl __pastwait \n" | |
67 | "__pastwait: \n"); | |
49f2ec91 RB |
68 | } |
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 | { | |
49f2ec91 RB |
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 | /* | |
91 | * The Au1xxx wait is available only if using 32khz counter or | |
92 | * external timer source, but specifically not CP0 Counter. | |
93 | * alchemy/common/time.c may override cpu_wait! | |
94 | */ | |
95 | static void au1k_wait(void) | |
96 | { | |
f91a148a RB |
97 | __asm__( |
98 | " .set mips3 \n" | |
99 | " cache 0x14, 0(%0) \n" | |
100 | " cache 0x14, 32(%0) \n" | |
101 | " sync \n" | |
102 | " nop \n" | |
103 | " wait \n" | |
104 | " nop \n" | |
105 | " nop \n" | |
106 | " nop \n" | |
107 | " nop \n" | |
108 | " .set mips0 \n" | |
109 | : : "r" (au1k_wait)); | |
fb40bc3e | 110 | local_irq_enable(); |
49f2ec91 RB |
111 | } |
112 | ||
113 | static int __initdata nowait; | |
114 | ||
115 | static int __init wait_disable(char *s) | |
116 | { | |
117 | nowait = 1; | |
118 | ||
119 | return 1; | |
120 | } | |
121 | ||
122 | __setup("nowait", wait_disable); | |
123 | ||
124 | void __init check_wait(void) | |
125 | { | |
126 | struct cpuinfo_mips *c = ¤t_cpu_data; | |
127 | ||
128 | if (nowait) { | |
129 | printk("Wait instruction disabled.\n"); | |
130 | return; | |
131 | } | |
132 | ||
133 | switch (c->cputype) { | |
134 | case CPU_R3081: | |
135 | case CPU_R3081E: | |
136 | cpu_wait = r3081_wait; | |
137 | break; | |
138 | case CPU_TX3927: | |
139 | cpu_wait = r39xx_wait; | |
140 | break; | |
141 | case CPU_R4200: | |
142 | /* case CPU_R4300: */ | |
143 | case CPU_R4600: | |
144 | case CPU_R4640: | |
145 | case CPU_R4650: | |
146 | case CPU_R4700: | |
147 | case CPU_R5000: | |
148 | case CPU_R5500: | |
149 | case CPU_NEVADA: | |
150 | case CPU_4KC: | |
151 | case CPU_4KEC: | |
152 | case CPU_4KSC: | |
153 | case CPU_5KC: | |
154 | case CPU_25KF: | |
155 | case CPU_PR4450: | |
156 | case CPU_BMIPS3300: | |
157 | case CPU_BMIPS4350: | |
158 | case CPU_BMIPS4380: | |
159 | case CPU_BMIPS5000: | |
160 | case CPU_CAVIUM_OCTEON: | |
161 | case CPU_CAVIUM_OCTEON_PLUS: | |
162 | case CPU_CAVIUM_OCTEON2: | |
163 | case CPU_JZRISC: | |
164 | case CPU_LOONGSON1: | |
165 | case CPU_XLR: | |
166 | case CPU_XLP: | |
167 | cpu_wait = r4k_wait; | |
168 | break; | |
169 | ||
170 | case CPU_RM7000: | |
171 | cpu_wait = rm7k_wait_irqoff; | |
172 | break; | |
173 | ||
174 | case CPU_M14KC: | |
175 | case CPU_M14KEC: | |
176 | case CPU_24K: | |
177 | case CPU_34K: | |
178 | case CPU_1004K: | |
179 | cpu_wait = r4k_wait; | |
180 | if (read_c0_config7() & MIPS_CONF7_WII) | |
181 | cpu_wait = r4k_wait_irqoff; | |
182 | break; | |
183 | ||
184 | case CPU_74K: | |
185 | cpu_wait = r4k_wait; | |
186 | if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0)) | |
187 | cpu_wait = r4k_wait_irqoff; | |
188 | break; | |
189 | ||
190 | case CPU_TX49XX: | |
191 | cpu_wait = r4k_wait_irqoff; | |
192 | break; | |
193 | case CPU_ALCHEMY: | |
194 | cpu_wait = au1k_wait; | |
195 | break; | |
196 | case CPU_20KC: | |
197 | /* | |
198 | * WAIT on Rev1.0 has E1, E2, E3 and E16. | |
199 | * WAIT on Rev2.0 and Rev3.0 has E16. | |
200 | * Rev3.1 WAIT is nop, why bother | |
201 | */ | |
202 | if ((c->processor_id & 0xff) <= 0x64) | |
203 | break; | |
204 | ||
205 | /* | |
206 | * Another rev is incremeting c0_count at a reduced clock | |
207 | * rate while in WAIT mode. So we basically have the choice | |
208 | * between using the cp0 timer as clocksource or avoiding | |
209 | * the WAIT instruction. Until more details are known, | |
210 | * disable the use of WAIT for 20Kc entirely. | |
211 | cpu_wait = r4k_wait; | |
212 | */ | |
213 | break; | |
214 | case CPU_RM9000: | |
215 | if ((c->processor_id & 0x00ff) >= 0x40) | |
216 | cpu_wait = r4k_wait; | |
217 | break; | |
218 | default: | |
219 | break; | |
220 | } | |
221 | } | |
222 | ||
00baf857 | 223 | static void smtc_idle_hook(void) |
49f2ec91 RB |
224 | { |
225 | #ifdef CONFIG_MIPS_MT_SMTC | |
00baf857 | 226 | void smtc_idle_loop_hook(void); |
49f2ec91 RB |
227 | |
228 | smtc_idle_loop_hook(); | |
229 | #endif | |
00baf857 RB |
230 | } |
231 | ||
232 | void arch_cpu_idle(void) | |
233 | { | |
234 | smtc_idle_hook(); | |
49f2ec91 | 235 | if (cpu_wait) |
c9b6869d | 236 | cpu_wait(); |
49f2ec91 RB |
237 | else |
238 | local_irq_enable(); | |
239 | } |