local_t: mips extension
[linux-2.6/pdupreez.git] / include / asm-mips / system.h
blobd53dd72455615dc7ae443e74cb7d5216f9a4fb27
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle
7 * Copyright (C) 1996 by Paul M. Antoine
8 * Copyright (C) 1999 Silicon Graphics
9 * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
10 * Copyright (C) 2000 MIPS Technologies, Inc.
12 #ifndef _ASM_SYSTEM_H
13 #define _ASM_SYSTEM_H
15 #include <linux/types.h>
16 #include <linux/irqflags.h>
18 #include <asm/addrspace.h>
19 #include <asm/barrier.h>
20 #include <asm/cpu-features.h>
21 #include <asm/dsp.h>
22 #include <asm/war.h>
26 * switch_to(n) should switch tasks to task nr n, first
27 * checking that n isn't the current task, in which case it does nothing.
29 extern asmlinkage void *resume(void *last, void *next, void *next_ti);
31 struct task_struct;
33 #ifdef CONFIG_MIPS_MT_FPAFF
36 * Handle the scheduler resume end of FPU affinity management. We do this
37 * inline to try to keep the overhead down. If we have been forced to run on
38 * a "CPU" with an FPU because of a previous high level of FP computation,
39 * but did not actually use the FPU during the most recent time-slice (CU1
40 * isn't set), we undo the restriction on cpus_allowed.
42 * We're not calling set_cpus_allowed() here, because we have no need to
43 * force prompt migration - we're already switching the current CPU to a
44 * different thread.
47 #define switch_to(prev,next,last) \
48 do { \
49 if (cpu_has_fpu && \
50 (prev->thread.mflags & MF_FPUBOUND) && \
51 (!(KSTK_STATUS(prev) & ST0_CU1))) { \
52 prev->thread.mflags &= ~MF_FPUBOUND; \
53 prev->cpus_allowed = prev->thread.user_cpus_allowed; \
54 } \
55 if (cpu_has_dsp) \
56 __save_dsp(prev); \
57 next->thread.emulated_fp = 0; \
58 (last) = resume(prev, next, next->thread_info); \
59 if (cpu_has_dsp) \
60 __restore_dsp(current); \
61 } while(0)
63 #else
64 #define switch_to(prev,next,last) \
65 do { \
66 if (cpu_has_dsp) \
67 __save_dsp(prev); \
68 (last) = resume(prev, next, task_thread_info(next)); \
69 if (cpu_has_dsp) \
70 __restore_dsp(current); \
71 } while(0)
72 #endif
75 * On SMP systems, when the scheduler does migration-cost autodetection,
76 * it needs a way to flush as much of the CPU's caches as possible.
78 * TODO: fill this in!
80 static inline void sched_cacheflush(void)
84 static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
86 __u32 retval;
88 if (cpu_has_llsc && R10000_LLSC_WAR) {
89 unsigned long dummy;
91 __asm__ __volatile__(
92 " .set mips3 \n"
93 "1: ll %0, %3 # xchg_u32 \n"
94 " .set mips0 \n"
95 " move %2, %z4 \n"
96 " .set mips3 \n"
97 " sc %2, %1 \n"
98 " beqzl %2, 1b \n"
99 " .set mips0 \n"
100 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
101 : "R" (*m), "Jr" (val)
102 : "memory");
103 } else if (cpu_has_llsc) {
104 unsigned long dummy;
106 __asm__ __volatile__(
107 " .set mips3 \n"
108 "1: ll %0, %3 # xchg_u32 \n"
109 " .set mips0 \n"
110 " move %2, %z4 \n"
111 " .set mips3 \n"
112 " sc %2, %1 \n"
113 " beqz %2, 2f \n"
114 " .subsection 2 \n"
115 "2: b 1b \n"
116 " .previous \n"
117 " .set mips0 \n"
118 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
119 : "R" (*m), "Jr" (val)
120 : "memory");
121 } else {
122 unsigned long flags;
124 raw_local_irq_save(flags);
125 retval = *m;
126 *m = val;
127 raw_local_irq_restore(flags); /* implies memory barrier */
130 smp_mb();
132 return retval;
135 #ifdef CONFIG_64BIT
136 static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
138 __u64 retval;
140 if (cpu_has_llsc && R10000_LLSC_WAR) {
141 unsigned long dummy;
143 __asm__ __volatile__(
144 " .set mips3 \n"
145 "1: lld %0, %3 # xchg_u64 \n"
146 " move %2, %z4 \n"
147 " scd %2, %1 \n"
148 " beqzl %2, 1b \n"
149 " .set mips0 \n"
150 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
151 : "R" (*m), "Jr" (val)
152 : "memory");
153 } else if (cpu_has_llsc) {
154 unsigned long dummy;
156 __asm__ __volatile__(
157 " .set mips3 \n"
158 "1: lld %0, %3 # xchg_u64 \n"
159 " move %2, %z4 \n"
160 " scd %2, %1 \n"
161 " beqz %2, 2f \n"
162 " .subsection 2 \n"
163 "2: b 1b \n"
164 " .previous \n"
165 " .set mips0 \n"
166 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
167 : "R" (*m), "Jr" (val)
168 : "memory");
169 } else {
170 unsigned long flags;
172 raw_local_irq_save(flags);
173 retval = *m;
174 *m = val;
175 raw_local_irq_restore(flags); /* implies memory barrier */
178 smp_mb();
180 return retval;
182 #else
183 extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
184 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
185 #endif
187 /* This function doesn't exist, so you'll get a linker error
188 if something tries to do an invalid xchg(). */
189 extern void __xchg_called_with_bad_pointer(void);
191 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
193 switch (size) {
194 case 4:
195 return __xchg_u32(ptr, x);
196 case 8:
197 return __xchg_u64(ptr, x);
199 __xchg_called_with_bad_pointer();
200 return x;
203 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
204 #define tas(ptr) (xchg((ptr),1))
206 #define __HAVE_ARCH_CMPXCHG 1
208 static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
209 unsigned long new)
211 __u32 retval;
213 if (cpu_has_llsc && R10000_LLSC_WAR) {
214 __asm__ __volatile__(
215 " .set push \n"
216 " .set noat \n"
217 " .set mips3 \n"
218 "1: ll %0, %2 # __cmpxchg_u32 \n"
219 " bne %0, %z3, 2f \n"
220 " .set mips0 \n"
221 " move $1, %z4 \n"
222 " .set mips3 \n"
223 " sc $1, %1 \n"
224 " beqzl $1, 1b \n"
225 "2: \n"
226 " .set pop \n"
227 : "=&r" (retval), "=R" (*m)
228 : "R" (*m), "Jr" (old), "Jr" (new)
229 : "memory");
230 } else if (cpu_has_llsc) {
231 __asm__ __volatile__(
232 " .set push \n"
233 " .set noat \n"
234 " .set mips3 \n"
235 "1: ll %0, %2 # __cmpxchg_u32 \n"
236 " bne %0, %z3, 2f \n"
237 " .set mips0 \n"
238 " move $1, %z4 \n"
239 " .set mips3 \n"
240 " sc $1, %1 \n"
241 " beqz $1, 3f \n"
242 "2: \n"
243 " .subsection 2 \n"
244 "3: b 1b \n"
245 " .previous \n"
246 " .set pop \n"
247 : "=&r" (retval), "=R" (*m)
248 : "R" (*m), "Jr" (old), "Jr" (new)
249 : "memory");
250 } else {
251 unsigned long flags;
253 raw_local_irq_save(flags);
254 retval = *m;
255 if (retval == old)
256 *m = new;
257 raw_local_irq_restore(flags); /* implies memory barrier */
260 smp_mb();
262 return retval;
265 static inline unsigned long __cmpxchg_u32_local(volatile int * m,
266 unsigned long old, unsigned long new)
268 __u32 retval;
270 if (cpu_has_llsc && R10000_LLSC_WAR) {
271 __asm__ __volatile__(
272 " .set push \n"
273 " .set noat \n"
274 " .set mips3 \n"
275 "1: ll %0, %2 # __cmpxchg_u32 \n"
276 " bne %0, %z3, 2f \n"
277 " .set mips0 \n"
278 " move $1, %z4 \n"
279 " .set mips3 \n"
280 " sc $1, %1 \n"
281 " beqzl $1, 1b \n"
282 "2: \n"
283 " .set pop \n"
284 : "=&r" (retval), "=R" (*m)
285 : "R" (*m), "Jr" (old), "Jr" (new)
286 : "memory");
287 } else if (cpu_has_llsc) {
288 __asm__ __volatile__(
289 " .set push \n"
290 " .set noat \n"
291 " .set mips3 \n"
292 "1: ll %0, %2 # __cmpxchg_u32 \n"
293 " bne %0, %z3, 2f \n"
294 " .set mips0 \n"
295 " move $1, %z4 \n"
296 " .set mips3 \n"
297 " sc $1, %1 \n"
298 " beqz $1, 1b \n"
299 "2: \n"
300 " .set pop \n"
301 : "=&r" (retval), "=R" (*m)
302 : "R" (*m), "Jr" (old), "Jr" (new)
303 : "memory");
304 } else {
305 unsigned long flags;
307 local_irq_save(flags);
308 retval = *m;
309 if (retval == old)
310 *m = new;
311 local_irq_restore(flags); /* implies memory barrier */
314 return retval;
317 #ifdef CONFIG_64BIT
318 static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
319 unsigned long new)
321 __u64 retval;
323 if (cpu_has_llsc && R10000_LLSC_WAR) {
324 __asm__ __volatile__(
325 " .set push \n"
326 " .set noat \n"
327 " .set mips3 \n"
328 "1: lld %0, %2 # __cmpxchg_u64 \n"
329 " bne %0, %z3, 2f \n"
330 " move $1, %z4 \n"
331 " scd $1, %1 \n"
332 " beqzl $1, 1b \n"
333 "2: \n"
334 " .set pop \n"
335 : "=&r" (retval), "=R" (*m)
336 : "R" (*m), "Jr" (old), "Jr" (new)
337 : "memory");
338 } else if (cpu_has_llsc) {
339 __asm__ __volatile__(
340 " .set push \n"
341 " .set noat \n"
342 " .set mips3 \n"
343 "1: lld %0, %2 # __cmpxchg_u64 \n"
344 " bne %0, %z3, 2f \n"
345 " move $1, %z4 \n"
346 " scd $1, %1 \n"
347 " beqz $1, 3f \n"
348 "2: \n"
349 " .subsection 2 \n"
350 "3: b 1b \n"
351 " .previous \n"
352 " .set pop \n"
353 : "=&r" (retval), "=R" (*m)
354 : "R" (*m), "Jr" (old), "Jr" (new)
355 : "memory");
356 } else {
357 unsigned long flags;
359 raw_local_irq_save(flags);
360 retval = *m;
361 if (retval == old)
362 *m = new;
363 raw_local_irq_restore(flags); /* implies memory barrier */
366 smp_mb();
368 return retval;
371 static inline unsigned long __cmpxchg_u64_local(volatile int * m,
372 unsigned long old, unsigned long new)
374 __u64 retval;
376 if (cpu_has_llsc && R10000_LLSC_WAR) {
377 __asm__ __volatile__(
378 " .set push \n"
379 " .set noat \n"
380 " .set mips3 \n"
381 "1: lld %0, %2 # __cmpxchg_u64 \n"
382 " bne %0, %z3, 2f \n"
383 " move $1, %z4 \n"
384 " scd $1, %1 \n"
385 " beqzl $1, 1b \n"
386 "2: \n"
387 " .set pop \n"
388 : "=&r" (retval), "=R" (*m)
389 : "R" (*m), "Jr" (old), "Jr" (new)
390 : "memory");
391 } else if (cpu_has_llsc) {
392 __asm__ __volatile__(
393 " .set push \n"
394 " .set noat \n"
395 " .set mips3 \n"
396 "1: lld %0, %2 # __cmpxchg_u64 \n"
397 " bne %0, %z3, 2f \n"
398 " move $1, %z4 \n"
399 " scd $1, %1 \n"
400 " beqz $1, 1b \n"
401 "2: \n"
402 " .set pop \n"
403 : "=&r" (retval), "=R" (*m)
404 : "R" (*m), "Jr" (old), "Jr" (new)
405 : "memory");
406 } else {
407 unsigned long flags;
409 local_irq_save(flags);
410 retval = *m;
411 if (retval == old)
412 *m = new;
413 local_irq_restore(flags); /* implies memory barrier */
416 return retval;
419 #else
420 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
421 volatile int * m, unsigned long old, unsigned long new);
422 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
423 extern unsigned long __cmpxchg_u64_local_unsupported_on_32bit_kernels(
424 volatile int * m, unsigned long old, unsigned long new);
425 #define __cmpxchg_u64_local __cmpxchg_u64_local_unsupported_on_32bit_kernels
426 #endif
428 /* This function doesn't exist, so you'll get a linker error
429 if something tries to do an invalid cmpxchg(). */
430 extern void __cmpxchg_called_with_bad_pointer(void);
432 static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
433 unsigned long new, int size)
435 switch (size) {
436 case 4:
437 return __cmpxchg_u32(ptr, old, new);
438 case 8:
439 return __cmpxchg_u64(ptr, old, new);
441 __cmpxchg_called_with_bad_pointer();
442 return old;
445 static inline unsigned long __cmpxchg_local(volatile void * ptr,
446 unsigned long old, unsigned long new, int size)
448 switch (size) {
449 case 4:
450 return __cmpxchg_u32_local(ptr, old, new);
451 case 8:
452 return __cmpxchg_u64_local(ptr, old, new);
454 __cmpxchg_called_with_bad_pointer();
455 return old;
458 #define cmpxchg(ptr,old,new) \
459 ((__typeof__(*(ptr)))__cmpxchg((ptr), \
460 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
462 #define cmpxchg_local(ptr,old,new) \
463 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
464 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
466 extern void set_handler (unsigned long offset, void *addr, unsigned long len);
467 extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len);
468 extern void *set_vi_handler (int n, void *addr);
469 extern void *set_except_vector(int n, void *addr);
470 extern unsigned long ebase;
471 extern void per_cpu_trap_init(void);
473 extern int stop_a_enabled;
476 * See include/asm-ia64/system.h; prevents deadlock on SMP
477 * systems.
479 #define __ARCH_WANT_UNLOCKED_CTXSW
481 #define arch_align_stack(x) (x)
483 #endif /* _ASM_SYSTEM_H */