18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#include <stdlib.h> 38c2ecf20Sopenharmony_ci#if defined(__i386__) || defined(__x86_64__) 48c2ecf20Sopenharmony_ci#define barrier() asm volatile("" ::: "memory") 58c2ecf20Sopenharmony_ci#define virt_mb() __sync_synchronize() 68c2ecf20Sopenharmony_ci#define virt_rmb() barrier() 78c2ecf20Sopenharmony_ci#define virt_wmb() barrier() 88c2ecf20Sopenharmony_ci/* Atomic store should be enough, but gcc generates worse code in that case. */ 98c2ecf20Sopenharmony_ci#define virt_store_mb(var, value) do { \ 108c2ecf20Sopenharmony_ci typeof(var) virt_store_mb_value = (value); \ 118c2ecf20Sopenharmony_ci __atomic_exchange(&(var), &virt_store_mb_value, &virt_store_mb_value, \ 128c2ecf20Sopenharmony_ci __ATOMIC_SEQ_CST); \ 138c2ecf20Sopenharmony_ci barrier(); \ 148c2ecf20Sopenharmony_ci} while (0); 158c2ecf20Sopenharmony_ci/* Weak barriers should be used. If not - it's a bug */ 168c2ecf20Sopenharmony_ci# define mb() abort() 178c2ecf20Sopenharmony_ci# define dma_rmb() abort() 188c2ecf20Sopenharmony_ci# define dma_wmb() abort() 198c2ecf20Sopenharmony_ci#else 208c2ecf20Sopenharmony_ci#error Please fill in barrier macros 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci 23