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
11 #include <asm/addrspace.h>
13 #define read_barrier_depends() do { } while(0)
14 #define smp_read_barrier_depends() do { } while(0)
16 #ifdef CONFIG_CPU_HAS_SYNC
18 __asm__ __volatile__( \
20 ".set noreorder\n\t" \
28 #define __sync() do { } while(0)
31 #define __fast_iob() \
32 __asm__ __volatile__( \
34 ".set noreorder\n\t" \
39 : "m" (*(int *)CKSEG1) \
41 #ifdef CONFIG_CPU_CAVIUM_OCTEON
42 # define OCTEON_SYNCW_STR ".set push\n.set arch=octeon\nsyncw\nsyncw\n.set pop\n"
43 # define __syncw() __asm__ __volatile__(OCTEON_SYNCW_STR : : : "memory")
45 # define fast_wmb() __syncw()
46 # define fast_rmb() barrier()
47 # define fast_mb() __sync()
48 # define fast_iob() do { } while (0)
49 #else /* ! CONFIG_CPU_CAVIUM_OCTEON */
50 # define fast_wmb() __sync()
51 # define fast_rmb() __sync()
52 # define fast_mb() __sync()
53 # ifdef CONFIG_SGI_IP28
55 __asm__ __volatile__( \
57 ".set noreorder\n\t" \
63 : "m" (*(int *)CKSEG1ADDR(0x1fa00004)) \
72 #endif /* CONFIG_CPU_CAVIUM_OCTEON */
74 #ifdef CONFIG_CPU_HAS_WB
76 #include <asm/wbflush.h>
78 #define mb() wbflush()
79 #define iob() wbflush()
81 #else /* !CONFIG_CPU_HAS_WB */
83 #define mb() fast_mb()
84 #define iob() fast_iob()
86 #endif /* !CONFIG_CPU_HAS_WB */
88 #define wmb() fast_wmb()
89 #define rmb() fast_rmb()
90 #define dma_wmb() fast_wmb()
91 #define dma_rmb() fast_rmb()
93 #if defined(CONFIG_WEAK_ORDERING) && defined(CONFIG_SMP)
94 # ifdef CONFIG_CPU_CAVIUM_OCTEON
95 # define smp_mb() __sync()
96 # define smp_rmb() barrier()
97 # define smp_wmb() __syncw()
99 # define smp_mb() __asm__ __volatile__("sync" : : :"memory")
100 # define smp_rmb() __asm__ __volatile__("sync" : : :"memory")
101 # define smp_wmb() __asm__ __volatile__("sync" : : :"memory")
104 #define smp_mb() barrier()
105 #define smp_rmb() barrier()
106 #define smp_wmb() barrier()
109 #if defined(CONFIG_WEAK_REORDERING_BEYOND_LLSC) && defined(CONFIG_SMP)
110 #define __WEAK_LLSC_MB " sync \n"
112 #define __WEAK_LLSC_MB " \n"
115 #define smp_store_mb(var, value) \
116 do { WRITE_ONCE(var, value); smp_mb(); } while (0)
118 #define smp_llsc_mb() __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory")
120 #ifdef CONFIG_CPU_CAVIUM_OCTEON
121 #define smp_mb__before_llsc() smp_wmb()
122 /* Cause previous writes to become visible on all CPUs as soon as possible */
123 #define nudge_writes() __asm__ __volatile__(".set push\n\t" \
124 ".set arch=octeon\n\t" \
126 ".set pop" : : : "memory")
128 #define smp_mb__before_llsc() smp_llsc_mb()
129 #define nudge_writes() mb()
132 #define smp_store_release(p, v) \
134 compiletime_assert_atomic_type(*p); \
139 #define smp_load_acquire(p) \
141 typeof(*p) ___p1 = READ_ONCE(*p); \
142 compiletime_assert_atomic_type(*p); \
147 #define smp_mb__before_atomic() smp_mb__before_llsc()
148 #define smp_mb__after_atomic() smp_llsc_mb()
150 #endif /* __ASM_BARRIER_H */