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 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/cpu-features.h>
21 #include <asm/ptrace.h>
25 * read_barrier_depends - Flush all pending reads that subsequents reads
28 * No data-dependent reads from memory-like regions are ever reordered
29 * over this barrier. All reads preceding this primitive are guaranteed
30 * to access memory (but not necessarily other CPUs' caches) before any
31 * reads following this primitive that depend on the data return by
32 * any of the preceding reads. This primitive is much lighter weight than
33 * rmb() on most CPUs, and is never heavier weight than is
36 * These ordering constraints are respected by both the local CPU
39 * Ordering is not guaranteed by anything other than these primitives,
40 * not even by data dependencies. See the documentation for
41 * memory_barrier() for examples and URLs to more information.
43 * For example, the following code would force ordering (the initial
44 * value of "a" is zero, "b" is one, and "p" is "&a"):
52 * read_barrier_depends();
56 * because the read of "*q" depends on the read of "p" and these
57 * two reads are separated by a read_barrier_depends(). However,
58 * the following code, with the same initial values for "a" and "b":
66 * read_barrier_depends();
70 * does not enforce ordering, since there is no data dependency between
71 * the read of "a" and the read of "b". Therefore, on some CPUs, such
72 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
73 * in cases like this where there are no data dependencies.
76 #define read_barrier_depends() do { } while(0)
78 #ifdef CONFIG_CPU_HAS_SYNC
80 __asm__ __volatile__( \
82 ".set noreorder\n\t" \
90 #define __sync() do { } while(0)
93 #define __fast_iob() \
94 __asm__ __volatile__( \
96 ".set noreorder\n\t" \
101 : "m" (*(int *)CKSEG1) \
104 #define fast_wmb() __sync()
105 #define fast_rmb() __sync()
106 #define fast_mb() __sync()
113 #ifdef CONFIG_CPU_HAS_WB
115 #include <asm/wbflush.h>
117 #define wmb() fast_wmb()
118 #define rmb() fast_rmb()
119 #define mb() wbflush()
120 #define iob() wbflush()
122 #else /* !CONFIG_CPU_HAS_WB */
124 #define wmb() fast_wmb()
125 #define rmb() fast_rmb()
126 #define mb() fast_mb()
127 #define iob() fast_iob()
129 #endif /* !CONFIG_CPU_HAS_WB */
132 #define smp_mb() mb()
133 #define smp_rmb() rmb()
134 #define smp_wmb() wmb()
135 #define smp_read_barrier_depends() read_barrier_depends()
137 #define smp_mb() barrier()
138 #define smp_rmb() barrier()
139 #define smp_wmb() barrier()
140 #define smp_read_barrier_depends() do { } while(0)
143 #define set_mb(var, value) \
144 do { var = value; mb(); } while (0)
147 * switch_to(n) should switch tasks to task nr n, first
148 * checking that n isn't the current task, in which case it does nothing.
150 extern asmlinkage void *resume(void *last, void *next, void *next_ti);
154 #ifdef CONFIG_MIPS_MT_FPAFF
157 * Handle the scheduler resume end of FPU affinity management. We do this
158 * inline to try to keep the overhead down. If we have been forced to run on
159 * a "CPU" with an FPU because of a previous high level of FP computation,
160 * but did not actually use the FPU during the most recent time-slice (CU1
161 * isn't set), we undo the restriction on cpus_allowed.
163 * We're not calling set_cpus_allowed() here, because we have no need to
164 * force prompt migration - we're already switching the current CPU to a
168 #define switch_to(prev,next,last) \
171 (prev->thread.mflags & MF_FPUBOUND) && \
172 (!(KSTK_STATUS(prev) & ST0_CU1))) { \
173 prev->thread.mflags &= ~MF_FPUBOUND; \
174 prev->cpus_allowed = prev->thread.user_cpus_allowed; \
178 next->thread.emulated_fp = 0; \
179 (last) = resume(prev, next, next->thread_info); \
181 __restore_dsp(current); \
185 #define switch_to(prev,next,last) \
189 (last) = resume(prev, next, task_thread_info(next)); \
191 __restore_dsp(current); \
196 * On SMP systems, when the scheduler does migration-cost autodetection,
197 * it needs a way to flush as much of the CPU's caches as possible.
199 * TODO: fill this in!
201 static inline void sched_cacheflush(void)
205 static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
209 if (cpu_has_llsc && R10000_LLSC_WAR) {
212 __asm__ __volatile__(
214 "1: ll %0, %3 # xchg_u32 \n"
224 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
225 : "R" (*m), "Jr" (val)
227 } else if (cpu_has_llsc) {
230 __asm__ __volatile__(
232 "1: ll %0, %3 # xchg_u32 \n"
242 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
243 : "R" (*m), "Jr" (val)
248 local_irq_save(flags);
251 local_irq_restore(flags); /* implies memory barrier */
258 static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
262 if (cpu_has_llsc && R10000_LLSC_WAR) {
265 __asm__ __volatile__(
267 "1: lld %0, %3 # xchg_u64 \n"
275 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
276 : "R" (*m), "Jr" (val)
278 } else if (cpu_has_llsc) {
281 __asm__ __volatile__(
283 "1: lld %0, %3 # xchg_u64 \n"
291 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
292 : "R" (*m), "Jr" (val)
297 local_irq_save(flags);
300 local_irq_restore(flags); /* implies memory barrier */
306 extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
307 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
310 /* This function doesn't exist, so you'll get a linker error
311 if something tries to do an invalid xchg(). */
312 extern void __xchg_called_with_bad_pointer(void);
314 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
318 return __xchg_u32(ptr, x);
320 return __xchg_u64(ptr, x);
322 __xchg_called_with_bad_pointer();
326 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
327 #define tas(ptr) (xchg((ptr),1))
329 #define __HAVE_ARCH_CMPXCHG 1
331 static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
336 if (cpu_has_llsc && R10000_LLSC_WAR) {
337 __asm__ __volatile__(
341 "1: ll %0, %2 # __cmpxchg_u32 \n"
342 " bne %0, %z3, 2f \n"
353 : "=&r" (retval), "=R" (*m)
354 : "R" (*m), "Jr" (old), "Jr" (new)
356 } else if (cpu_has_llsc) {
357 __asm__ __volatile__(
361 "1: ll %0, %2 # __cmpxchg_u32 \n"
362 " bne %0, %z3, 2f \n"
373 : "=&r" (retval), "=R" (*m)
374 : "R" (*m), "Jr" (old), "Jr" (new)
379 local_irq_save(flags);
383 local_irq_restore(flags); /* implies memory barrier */
390 static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
396 __asm__ __volatile__(
400 "1: lld %0, %2 # __cmpxchg_u64 \n"
401 " bne %0, %z3, 2f \n"
410 : "=&r" (retval), "=R" (*m)
411 : "R" (*m), "Jr" (old), "Jr" (new)
413 } else if (cpu_has_llsc) {
414 __asm__ __volatile__(
418 "1: lld %0, %2 # __cmpxchg_u64 \n"
419 " bne %0, %z3, 2f \n"
428 : "=&r" (retval), "=R" (*m)
429 : "R" (*m), "Jr" (old), "Jr" (new)
434 local_irq_save(flags);
438 local_irq_restore(flags); /* implies memory barrier */
444 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
445 volatile int * m, unsigned long old, unsigned long new);
446 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
449 /* This function doesn't exist, so you'll get a linker error
450 if something tries to do an invalid cmpxchg(). */
451 extern void __cmpxchg_called_with_bad_pointer(void);
453 static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
454 unsigned long new, int size)
458 return __cmpxchg_u32(ptr, old, new);
460 return __cmpxchg_u64(ptr, old, new);
462 __cmpxchg_called_with_bad_pointer();
466 #define cmpxchg(ptr,old,new) ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
468 extern void set_handler (unsigned long offset, void *addr, unsigned long len);
469 extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len);
470 extern void *set_vi_handler (int n, void *addr);
471 extern void *set_except_vector(int n, void *addr);
472 extern unsigned long ebase;
473 extern void per_cpu_trap_init(void);
475 extern NORET_TYPE void die(const char *, struct pt_regs *);
477 static inline void die_if_kernel(const char *str, struct pt_regs *regs)
479 if (unlikely(!user_mode(regs)))
483 extern int stop_a_enabled;
486 * See include/asm-ia64/system.h; prevents deadlock on SMP
489 #define __ARCH_WANT_UNLOCKED_CTXSW
491 #define arch_align_stack(x) (x)
493 #endif /* _ASM_SYSTEM_H */