1 /* SPDX-License-Identifier: GPL-2.0 */
3 #if defined(__i386__) || defined(__x86_64__)
4 #define barrier() asm volatile("" ::: "memory")
5 #define virt_mb() __sync_synchronize()
6 #define virt_rmb() barrier()
7 #define virt_wmb() barrier()
8 /* Atomic store should be enough, but gcc generates worse code in that case. */
9 #define virt_store_mb(var, value) do { \
10 typeof(var) virt_store_mb_value = (value); \
11 __atomic_exchange(&(var), &virt_store_mb_value, &virt_store_mb_value, \
15 /* Weak barriers should be used. If not - it's a bug */
17 # define dma_rmb() abort()
18 # define dma_wmb() abort()
19 #elif defined(__aarch64__)
20 #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
21 #define virt_mb() __sync_synchronize()
22 #define virt_rmb() dmb(ishld)
23 #define virt_wmb() dmb(ishst)
24 #define virt_store_mb(var, value) do { WRITE_ONCE(var, value); dmb(ish); } while (0)
25 /* Weak barriers should be used. If not - it's a bug */
27 # define dma_rmb() abort()
28 # define dma_wmb() abort()
30 #error Please fill in barrier macros