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) 2006 by Ralf Baechle (ralf@linux-mips.org)
8 #ifndef __ASM_BARRIER_H
9 #define __ASM_BARRIER_H
12 * read_barrier_depends - Flush all pending reads that subsequents reads
15 * No data-dependent reads from memory-like regions are ever reordered
16 * over this barrier. All reads preceding this primitive are guaranteed
17 * to access memory (but not necessarily other CPUs' caches) before any
18 * reads following this primitive that depend on the data return by
19 * any of the preceding reads. This primitive is much lighter weight than
20 * rmb() on most CPUs, and is never heavier weight than is
23 * These ordering constraints are respected by both the local CPU
26 * Ordering is not guaranteed by anything other than these primitives,
27 * not even by data dependencies. See the documentation for
28 * memory_barrier() for examples and URLs to more information.
30 * For example, the following code would force ordering (the initial
31 * value of "a" is zero, "b" is one, and "p" is "&a"):
39 * read_barrier_depends();
43 * because the read of "*q" depends on the read of "p" and these
44 * two reads are separated by a read_barrier_depends(). However,
45 * the following code, with the same initial values for "a" and "b":
53 * read_barrier_depends();
57 * does not enforce ordering, since there is no data dependency between
58 * the read of "a" and the read of "b". Therefore, on some CPUs, such
59 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
60 * in cases like this where there are no data dependencies.
63 #define read_barrier_depends() do { } while(0)
64 #define smp_read_barrier_depends() do { } while(0)
66 #ifdef CONFIG_CPU_HAS_SYNC
68 __asm__ __volatile__( \
70 ".set noreorder\n\t" \
78 #define __sync() do { } while(0)
81 #define __fast_iob() \
82 __asm__ __volatile__( \
84 ".set noreorder\n\t" \
89 : "m" (*(int *)CKSEG1) \
91 #ifdef CONFIG_CPU_CAVIUM_OCTEON
92 # define OCTEON_SYNCW_STR ".set push\n.set arch=octeon\nsyncw\nsyncw\n.set pop\n"
93 # define __syncw() __asm__ __volatile__(OCTEON_SYNCW_STR : : : "memory")
95 # define fast_wmb() __syncw()
96 # define fast_rmb() barrier()
97 # define fast_mb() __sync()
98 # define fast_iob() do { } while (0)
99 #else /* ! CONFIG_CPU_CAVIUM_OCTEON */
100 # define fast_wmb() __sync()
101 # define fast_rmb() __sync()
102 # define fast_mb() __sync()
103 # ifdef CONFIG_SGI_IP28
104 # define fast_iob() \
105 __asm__ __volatile__( \
107 ".set noreorder\n\t" \
113 : "m" (*(int *)CKSEG1ADDR(0x1fa00004)) \
116 # define fast_iob() \
122 #endif /* CONFIG_CPU_CAVIUM_OCTEON */
124 #ifdef CONFIG_CPU_HAS_WB
126 #include <asm/wbflush.h>
128 #define wmb() fast_wmb()
129 #define rmb() fast_rmb()
130 #define mb() wbflush()
131 #define iob() wbflush()
133 #else /* !CONFIG_CPU_HAS_WB */
135 #define wmb() fast_wmb()
136 #define rmb() fast_rmb()
137 #define mb() fast_mb()
138 #define iob() fast_iob()
140 #endif /* !CONFIG_CPU_HAS_WB */
142 #if defined(CONFIG_WEAK_ORDERING) && defined(CONFIG_SMP)
143 # ifdef CONFIG_CPU_CAVIUM_OCTEON
144 # define smp_mb() __sync()
145 # define smp_rmb() barrier()
146 # define smp_wmb() __syncw()
148 # define smp_mb() __asm__ __volatile__("sync" : : :"memory")
149 # define smp_rmb() __asm__ __volatile__("sync" : : :"memory")
150 # define smp_wmb() __asm__ __volatile__("sync" : : :"memory")
153 #define smp_mb() barrier()
154 #define smp_rmb() barrier()
155 #define smp_wmb() barrier()
158 #if defined(CONFIG_WEAK_REORDERING_BEYOND_LLSC) && defined(CONFIG_SMP)
159 #define __WEAK_LLSC_MB " sync \n"
161 #define __WEAK_LLSC_MB " \n"
164 #define set_mb(var, value) \
165 do { var = value; smp_mb(); } while (0)
167 #define smp_llsc_mb() __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory")
169 #ifdef CONFIG_CPU_CAVIUM_OCTEON
170 #define smp_mb__before_llsc() smp_wmb()
171 /* Cause previous writes to become visible on all CPUs as soon as possible */
172 #define nudge_writes() __asm__ __volatile__(".set push\n\t" \
173 ".set arch=octeon\n\t" \
175 ".set pop" : : : "memory")
177 #define smp_mb__before_llsc() smp_llsc_mb()
178 #define nudge_writes() mb()
181 #endif /* __ASM_BARRIER_H */