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
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.
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>
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
);
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
47 #define switch_to(prev,next,last) \
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; \
57 next->thread.emulated_fp = 0; \
58 (last) = resume(prev, next, task_thread_info(next)); \
60 __restore_dsp(current); \
64 #define switch_to(prev,next,last) \
68 (last) = resume(prev, next, task_thread_info(next)); \
70 __restore_dsp(current); \
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.
80 static inline void sched_cacheflush(void)
84 static inline unsigned long __xchg_u32(volatile int * m
, unsigned int val
)
88 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
93 "1: ll %0, %3 # xchg_u32 \n"
100 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
101 : "R" (*m
), "Jr" (val
)
103 } else if (cpu_has_llsc
) {
106 __asm__
__volatile__(
108 "1: ll %0, %3 # xchg_u32 \n"
118 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
119 : "R" (*m
), "Jr" (val
)
124 raw_local_irq_save(flags
);
127 raw_local_irq_restore(flags
); /* implies memory barrier */
136 static inline __u64
__xchg_u64(volatile __u64
* m
, __u64 val
)
140 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
143 __asm__
__volatile__(
145 "1: lld %0, %3 # xchg_u64 \n"
150 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
151 : "R" (*m
), "Jr" (val
)
153 } else if (cpu_has_llsc
) {
156 __asm__
__volatile__(
158 "1: lld %0, %3 # xchg_u64 \n"
166 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
167 : "R" (*m
), "Jr" (val
)
172 raw_local_irq_save(flags
);
175 raw_local_irq_restore(flags
); /* implies memory barrier */
183 extern __u64
__xchg_u64_unsupported_on_32bit_kernels(volatile __u64
* m
, __u64 val
);
184 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
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
)
195 return __xchg_u32(ptr
, x
);
197 return __xchg_u64(ptr
, x
);
199 __xchg_called_with_bad_pointer();
203 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
205 #define __HAVE_ARCH_CMPXCHG 1
207 static inline unsigned long __cmpxchg_u32(volatile int * m
, unsigned long old
,
212 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
213 __asm__
__volatile__(
217 "1: ll %0, %2 # __cmpxchg_u32 \n"
218 " bne %0, %z3, 2f \n"
226 : "=&r" (retval
), "=R" (*m
)
227 : "R" (*m
), "Jr" (old
), "Jr" (new)
229 } else if (cpu_has_llsc
) {
230 __asm__
__volatile__(
234 "1: ll %0, %2 # __cmpxchg_u32 \n"
235 " bne %0, %z3, 2f \n"
246 : "=&r" (retval
), "=R" (*m
)
247 : "R" (*m
), "Jr" (old
), "Jr" (new)
252 raw_local_irq_save(flags
);
256 raw_local_irq_restore(flags
); /* implies memory barrier */
264 static inline unsigned long __cmpxchg_u32_local(volatile int * m
,
265 unsigned long old
, unsigned long new)
269 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
270 __asm__
__volatile__(
274 "1: ll %0, %2 # __cmpxchg_u32 \n"
275 " bne %0, %z3, 2f \n"
283 : "=&r" (retval
), "=R" (*m
)
284 : "R" (*m
), "Jr" (old
), "Jr" (new)
286 } else if (cpu_has_llsc
) {
287 __asm__
__volatile__(
291 "1: ll %0, %2 # __cmpxchg_u32 \n"
292 " bne %0, %z3, 2f \n"
300 : "=&r" (retval
), "=R" (*m
)
301 : "R" (*m
), "Jr" (old
), "Jr" (new)
306 local_irq_save(flags
);
310 local_irq_restore(flags
); /* implies memory barrier */
317 static inline unsigned long __cmpxchg_u64(volatile int * m
, unsigned long old
,
322 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
323 __asm__
__volatile__(
327 "1: lld %0, %2 # __cmpxchg_u64 \n"
328 " bne %0, %z3, 2f \n"
334 : "=&r" (retval
), "=R" (*m
)
335 : "R" (*m
), "Jr" (old
), "Jr" (new)
337 } else if (cpu_has_llsc
) {
338 __asm__
__volatile__(
342 "1: lld %0, %2 # __cmpxchg_u64 \n"
343 " bne %0, %z3, 2f \n"
352 : "=&r" (retval
), "=R" (*m
)
353 : "R" (*m
), "Jr" (old
), "Jr" (new)
358 raw_local_irq_save(flags
);
362 raw_local_irq_restore(flags
); /* implies memory barrier */
370 static inline unsigned long __cmpxchg_u64_local(volatile int * m
,
371 unsigned long old
, unsigned long new)
375 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
376 __asm__
__volatile__(
380 "1: lld %0, %2 # __cmpxchg_u64 \n"
381 " bne %0, %z3, 2f \n"
387 : "=&r" (retval
), "=R" (*m
)
388 : "R" (*m
), "Jr" (old
), "Jr" (new)
390 } else if (cpu_has_llsc
) {
391 __asm__
__volatile__(
395 "1: lld %0, %2 # __cmpxchg_u64 \n"
396 " bne %0, %z3, 2f \n"
402 : "=&r" (retval
), "=R" (*m
)
403 : "R" (*m
), "Jr" (old
), "Jr" (new)
408 local_irq_save(flags
);
412 local_irq_restore(flags
); /* implies memory barrier */
419 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
420 volatile int * m
, unsigned long old
, unsigned long new);
421 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
422 extern unsigned long __cmpxchg_u64_local_unsupported_on_32bit_kernels(
423 volatile int * m
, unsigned long old
, unsigned long new);
424 #define __cmpxchg_u64_local __cmpxchg_u64_local_unsupported_on_32bit_kernels
427 /* This function doesn't exist, so you'll get a linker error
428 if something tries to do an invalid cmpxchg(). */
429 extern void __cmpxchg_called_with_bad_pointer(void);
431 static inline unsigned long __cmpxchg(volatile void * ptr
, unsigned long old
,
432 unsigned long new, int size
)
436 return __cmpxchg_u32(ptr
, old
, new);
438 return __cmpxchg_u64(ptr
, old
, new);
440 __cmpxchg_called_with_bad_pointer();
444 static inline unsigned long __cmpxchg_local(volatile void * ptr
,
445 unsigned long old
, unsigned long new, int size
)
449 return __cmpxchg_u32_local(ptr
, old
, new);
451 return __cmpxchg_u64_local(ptr
, old
, new);
453 __cmpxchg_called_with_bad_pointer();
457 #define cmpxchg(ptr,old,new) \
458 ((__typeof__(*(ptr)))__cmpxchg((ptr), \
459 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
461 #define cmpxchg_local(ptr,old,new) \
462 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
463 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
465 extern void set_handler (unsigned long offset
, void *addr
, unsigned long len
);
466 extern void set_uncached_handler (unsigned long offset
, void *addr
, unsigned long len
);
467 extern void *set_vi_handler (int n
, void *addr
);
468 extern void *set_except_vector(int n
, void *addr
);
469 extern unsigned long ebase
;
470 extern void per_cpu_trap_init(void);
472 extern int stop_a_enabled
;
475 * See include/asm-ia64/system.h; prevents deadlock on SMP
478 #define __ARCH_WANT_UNLOCKED_CTXSW
480 #define arch_align_stack(x) (x)
482 #endif /* _ASM_SYSTEM_H */