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/config.h>
16 #include <linux/types.h>
18 #include <asm/addrspace.h>
19 #include <asm/cpu-features.h>
20 #include <asm/ptrace.h>
22 #include <asm/interrupt.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 thiswhere 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)
146 #define set_wmb(var, value) \
147 do { var = value; wmb(); } while (0)
150 * switch_to(n) should switch tasks to task nr n, first
151 * checking that n isn't the current task, in which case it does nothing.
153 extern asmlinkage void *resume(void *last, void *next, void *next_ti);
157 #define switch_to(prev,next,last) \
159 (last) = resume(prev, next, next->thread_info); \
162 #define ROT_IN_PIECES \
163 " .set noreorder \n" \
166 static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
170 if (cpu_has_llsc && R10000_LLSC_WAR) {
173 __asm__ __volatile__(
174 "1: ll %0, %3 # xchg_u32 \n"
182 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
183 : "R" (*m), "Jr" (val)
185 } else if (cpu_has_llsc) {
188 __asm__ __volatile__(
189 "1: ll %0, %3 # xchg_u32 \n"
196 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
197 : "R" (*m), "Jr" (val)
202 local_irq_save(flags);
205 local_irq_restore(flags); /* implies memory barrier */
212 static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
216 if (cpu_has_llsc && R10000_LLSC_WAR) {
219 __asm__ __volatile__(
220 "1: lld %0, %3 # xchg_u64 \n"
228 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
229 : "R" (*m), "Jr" (val)
231 } else if (cpu_has_llsc) {
234 __asm__ __volatile__(
235 "1: lld %0, %3 # xchg_u64 \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 */
257 extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
258 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
261 /* This function doesn't exist, so you'll get a linker error
262 if something tries to do an invalid xchg(). */
263 extern void __xchg_called_with_bad_pointer(void);
265 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
269 return __xchg_u32(ptr, x);
271 return __xchg_u64(ptr, x);
273 __xchg_called_with_bad_pointer();
277 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
278 #define tas(ptr) (xchg((ptr),1))
280 #define __HAVE_ARCH_CMPXCHG 1
282 static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
287 if (cpu_has_llsc && R10000_LLSC_WAR) {
288 __asm__ __volatile__(
290 "1: ll %0, %2 # __cmpxchg_u32 \n"
291 " bne %0, %z3, 2f \n"
301 : "=&r" (retval), "=m" (*m)
302 : "R" (*m), "Jr" (old), "Jr" (new)
304 } else if (cpu_has_llsc) {
305 __asm__ __volatile__(
307 "1: ll %0, %2 # __cmpxchg_u32 \n"
308 " bne %0, %z3, 2f \n"
317 : "=&r" (retval), "=m" (*m)
318 : "R" (*m), "Jr" (old), "Jr" (new)
323 local_irq_save(flags);
327 local_irq_restore(flags); /* implies memory barrier */
334 static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
340 __asm__ __volatile__(
342 "1: lld %0, %2 # __cmpxchg_u64 \n"
343 " bne %0, %z3, 2f \n"
353 : "=&r" (retval), "=m" (*m)
354 : "R" (*m), "Jr" (old), "Jr" (new)
356 } else if (cpu_has_llsc) {
357 __asm__ __volatile__(
359 "1: lld %0, %2 # __cmpxchg_u64 \n"
360 " bne %0, %z3, 2f \n"
369 : "=&r" (retval), "=m" (*m)
370 : "R" (*m), "Jr" (old), "Jr" (new)
375 local_irq_save(flags);
379 local_irq_restore(flags); /* implies memory barrier */
385 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
386 volatile int * m, unsigned long old, unsigned long new);
387 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
390 /* This function doesn't exist, so you'll get a linker error
391 if something tries to do an invalid cmpxchg(). */
392 extern void __cmpxchg_called_with_bad_pointer(void);
394 static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
395 unsigned long new, int size)
399 return __cmpxchg_u32(ptr, old, new);
401 return __cmpxchg_u64(ptr, old, new);
403 __cmpxchg_called_with_bad_pointer();
407 #define cmpxchg(ptr,old,new) ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
409 extern void *set_except_vector(int n, void *addr);
410 extern void per_cpu_trap_init(void);
412 extern NORET_TYPE void __die(const char *, struct pt_regs *, const char *file,
413 const char *func, unsigned long line);
414 extern void __die_if_kernel(const char *, struct pt_regs *, const char *file,
415 const char *func, unsigned long line);
417 #define die(msg, regs) \
418 __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
419 #define die_if_kernel(msg, regs) \
420 __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
422 extern int stop_a_enabled;
425 * See include/asm-ia64/system.h; prevents deadlock on SMP
428 #define __ARCH_WANT_UNLOCKED_CTXSW
430 #define arch_align_stack(x) (x)
432 #endif /* _ASM_SYSTEM_H */