1 #ifndef _ASM_X86_BARRIER_H
2 #define _ASM_X86_BARRIER_H
4 #include <asm/alternative.h>
8 * Force strict CPU ordering.
9 * And yes, this is required on UP too when we're talking
15 * Some non-Intel clones support out of order store. wmb() ceases to be a
18 #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
19 #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
20 #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
22 #define mb() asm volatile("mfence":::"memory")
23 #define rmb() asm volatile("lfence":::"memory")
24 #define wmb() asm volatile("sfence" ::: "memory")
27 #ifdef CONFIG_X86_PPRO_FENCE
28 #define dma_rmb() rmb()
30 #define dma_rmb() barrier()
32 #define dma_wmb() barrier()
36 #define smp_rmb() dma_rmb()
37 #define smp_wmb() barrier()
38 #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
40 #define smp_mb() barrier()
41 #define smp_rmb() barrier()
42 #define smp_wmb() barrier()
43 #define set_mb(var, value) do { var = value; barrier(); } while (0)
46 #define read_barrier_depends() do { } while (0)
47 #define smp_read_barrier_depends() do { } while (0)
49 #if defined(CONFIG_X86_PPRO_FENCE)
52 * For this option x86 doesn't have a strong TSO memory
53 * model and we should fall back to full barriers.
56 #define smp_store_release(p, v) \
58 compiletime_assert_atomic_type(*p); \
60 ACCESS_ONCE(*p) = (v); \
63 #define smp_load_acquire(p) \
65 typeof(*p) ___p1 = ACCESS_ONCE(*p); \
66 compiletime_assert_atomic_type(*p); \
71 #else /* regular x86 TSO memory ordering */
73 #define smp_store_release(p, v) \
75 compiletime_assert_atomic_type(*p); \
77 ACCESS_ONCE(*p) = (v); \
80 #define smp_load_acquire(p) \
82 typeof(*p) ___p1 = ACCESS_ONCE(*p); \
83 compiletime_assert_atomic_type(*p); \
90 /* Atomic operations are already serializing on x86 */
91 #define smp_mb__before_atomic() barrier()
92 #define smp_mb__after_atomic() barrier()
95 * Stop RDTSC speculation. This is needed when you need to use RDTSC
96 * (or get_cycles or vread that possibly accesses the TSC) in a defined
99 static __always_inline void rdtsc_barrier(void)
101 alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC,
102 "lfence", X86_FEATURE_LFENCE_RDTSC);
105 #endif /* _ASM_X86_BARRIER_H */