xref: /linux/tools/virtio/asm/barrier.h (revision 48dea9a700c8728cc31a1dd44588b97578de86ee)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <stdlib.h>
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, \
12 			  __ATOMIC_SEQ_CST); \
13 	barrier(); \
14 } while (0);
15 /* Weak barriers should be used. If not - it's a bug */
16 # define mb() abort()
17 # define dma_rmb() abort()
18 # define dma_wmb() abort()
19 #else
20 #error Please fill in barrier macros
21 #endif
22 
23