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 __mips_mt_fpaff_switch_to(prev) \
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; \
55 next->thread.emulated_fp = 0; \
59 #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
62 #define switch_to(prev,next,last) \
64 __mips_mt_fpaff_switch_to(prev); \
67 (last) = resume(prev, next, task_thread_info(next)); \
69 __restore_dsp(current); \
70 if (cpu_has_userlocal) \
71 write_c0_userlocal(task_thread_info(current)->tp_value);\
74 static inline unsigned long __xchg_u32(volatile int * m
, unsigned int val
)
78 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
83 "1: ll %0, %3 # xchg_u32 \n"
90 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
91 : "R" (*m
), "Jr" (val
)
93 } else if (cpu_has_llsc
) {
98 "1: ll %0, %3 # xchg_u32 \n"
108 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
109 : "R" (*m
), "Jr" (val
)
114 raw_local_irq_save(flags
);
117 raw_local_irq_restore(flags
); /* implies memory barrier */
126 static inline __u64
__xchg_u64(volatile __u64
* m
, __u64 val
)
130 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
133 __asm__
__volatile__(
135 "1: lld %0, %3 # xchg_u64 \n"
140 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
141 : "R" (*m
), "Jr" (val
)
143 } else if (cpu_has_llsc
) {
146 __asm__
__volatile__(
148 "1: lld %0, %3 # xchg_u64 \n"
156 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
157 : "R" (*m
), "Jr" (val
)
162 raw_local_irq_save(flags
);
165 raw_local_irq_restore(flags
); /* implies memory barrier */
173 extern __u64
__xchg_u64_unsupported_on_32bit_kernels(volatile __u64
* m
, __u64 val
);
174 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
177 /* This function doesn't exist, so you'll get a linker error
178 if something tries to do an invalid xchg(). */
179 extern void __xchg_called_with_bad_pointer(void);
181 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
185 return __xchg_u32(ptr
, x
);
187 return __xchg_u64(ptr
, x
);
189 __xchg_called_with_bad_pointer();
193 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
195 #define __HAVE_ARCH_CMPXCHG 1
197 static inline unsigned long __cmpxchg_u32(volatile int * m
, unsigned long old
,
202 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
203 __asm__
__volatile__(
207 "1: ll %0, %2 # __cmpxchg_u32 \n"
208 " bne %0, %z3, 2f \n"
216 : "=&r" (retval
), "=R" (*m
)
217 : "R" (*m
), "Jr" (old
), "Jr" (new)
219 } else if (cpu_has_llsc
) {
220 __asm__
__volatile__(
224 "1: ll %0, %2 # __cmpxchg_u32 \n"
225 " bne %0, %z3, 2f \n"
236 : "=&r" (retval
), "=R" (*m
)
237 : "R" (*m
), "Jr" (old
), "Jr" (new)
242 raw_local_irq_save(flags
);
246 raw_local_irq_restore(flags
); /* implies memory barrier */
254 static inline unsigned long __cmpxchg_u32_local(volatile int * m
,
255 unsigned long old
, unsigned long new)
259 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
260 __asm__
__volatile__(
264 "1: ll %0, %2 # __cmpxchg_u32 \n"
265 " bne %0, %z3, 2f \n"
273 : "=&r" (retval
), "=R" (*m
)
274 : "R" (*m
), "Jr" (old
), "Jr" (new)
276 } else if (cpu_has_llsc
) {
277 __asm__
__volatile__(
281 "1: ll %0, %2 # __cmpxchg_u32 \n"
282 " bne %0, %z3, 2f \n"
290 : "=&r" (retval
), "=R" (*m
)
291 : "R" (*m
), "Jr" (old
), "Jr" (new)
296 local_irq_save(flags
);
300 local_irq_restore(flags
); /* implies memory barrier */
307 static inline unsigned long __cmpxchg_u64(volatile int * m
, unsigned long old
,
312 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
313 __asm__
__volatile__(
317 "1: lld %0, %2 # __cmpxchg_u64 \n"
318 " bne %0, %z3, 2f \n"
324 : "=&r" (retval
), "=R" (*m
)
325 : "R" (*m
), "Jr" (old
), "Jr" (new)
327 } else if (cpu_has_llsc
) {
328 __asm__
__volatile__(
332 "1: lld %0, %2 # __cmpxchg_u64 \n"
333 " bne %0, %z3, 2f \n"
342 : "=&r" (retval
), "=R" (*m
)
343 : "R" (*m
), "Jr" (old
), "Jr" (new)
348 raw_local_irq_save(flags
);
352 raw_local_irq_restore(flags
); /* implies memory barrier */
360 static inline unsigned long __cmpxchg_u64_local(volatile int * m
,
361 unsigned long old
, unsigned long new)
365 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
366 __asm__
__volatile__(
370 "1: lld %0, %2 # __cmpxchg_u64 \n"
371 " bne %0, %z3, 2f \n"
377 : "=&r" (retval
), "=R" (*m
)
378 : "R" (*m
), "Jr" (old
), "Jr" (new)
380 } else if (cpu_has_llsc
) {
381 __asm__
__volatile__(
385 "1: lld %0, %2 # __cmpxchg_u64 \n"
386 " bne %0, %z3, 2f \n"
392 : "=&r" (retval
), "=R" (*m
)
393 : "R" (*m
), "Jr" (old
), "Jr" (new)
398 local_irq_save(flags
);
402 local_irq_restore(flags
); /* implies memory barrier */
409 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
410 volatile int * m
, unsigned long old
, unsigned long new);
411 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
412 extern unsigned long __cmpxchg_u64_local_unsupported_on_32bit_kernels(
413 volatile int * m
, unsigned long old
, unsigned long new);
414 #define __cmpxchg_u64_local __cmpxchg_u64_local_unsupported_on_32bit_kernels
417 /* This function doesn't exist, so you'll get a linker error
418 if something tries to do an invalid cmpxchg(). */
419 extern void __cmpxchg_called_with_bad_pointer(void);
421 static inline unsigned long __cmpxchg(volatile void * ptr
, unsigned long old
,
422 unsigned long new, int size
)
426 return __cmpxchg_u32(ptr
, old
, new);
428 return __cmpxchg_u64(ptr
, old
, new);
430 __cmpxchg_called_with_bad_pointer();
434 static inline unsigned long __cmpxchg_local(volatile void * ptr
,
435 unsigned long old
, unsigned long new, int size
)
439 return __cmpxchg_u32_local(ptr
, old
, new);
441 return __cmpxchg_u64_local(ptr
, old
, new);
443 __cmpxchg_called_with_bad_pointer();
447 #define cmpxchg(ptr,old,new) \
448 ((__typeof__(*(ptr)))__cmpxchg((ptr), \
449 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
451 #define cmpxchg_local(ptr,old,new) \
452 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
453 (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
455 extern void set_handler (unsigned long offset
, void *addr
, unsigned long len
);
456 extern void set_uncached_handler (unsigned long offset
, void *addr
, unsigned long len
);
458 typedef void (*vi_handler_t
)(void);
459 extern void *set_vi_handler (int n
, vi_handler_t addr
);
461 extern void *set_except_vector(int n
, void *addr
);
462 extern unsigned long ebase
;
463 extern void per_cpu_trap_init(void);
465 extern int stop_a_enabled
;
468 * See include/asm-ia64/system.h; prevents deadlock on SMP
471 #define __ARCH_WANT_UNLOCKED_CTXSW
473 #define arch_align_stack(x) (x)
475 #endif /* _ASM_SYSTEM_H */