Path: blob/main/sys/compat/linuxkpi/common/include/asm/barrier.h
39604 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Vladimir Kondratyev <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice unmodified, this list of conditions, and the following10* disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef _LINUXKPI_ASM_BARRIER_H_28#define _LINUXKPI_ASM_BARRIER_H_2930#include <sys/types.h>31#include <machine/atomic.h>3233#include <asm/atomic.h>34#include <linux/compiler.h>3536/* TODO: Check other archs for atomic_thread_fence_* useability */37#if defined(__amd64__) || defined(__i386__)38#define smp_mb() atomic_thread_fence_seq_cst()39#define smp_wmb() atomic_thread_fence_rel()40#define smp_rmb() atomic_thread_fence_acq()41#define smp_store_mb(x, v) do { (void)xchg(&(x), v); } while (0)42#endif4344#ifndef smp_mb45#define smp_mb() mb()46#endif47#ifndef smp_wmb48#define smp_wmb() wmb()49#endif50#ifndef smp_rmb51#define smp_rmb() rmb()52#endif53#ifndef smp_store_mb54#define smp_store_mb(x, v) do { WRITE_ONCE(x, v); smp_mb(); } while (0)55#endif5657#define smp_mb__before_atomic() barrier()58#define smp_mb__after_atomic() barrier()5960#define smp_store_release(p, v) do { smp_mb(); WRITE_ONCE(*p, v); } while (0)61#define smp_load_acquire(p) ({ typeof(*p) _v = READ_ONCE(*p); smp_mb(); _v; })6263#endif /* _LINUXKPI_ASM_BARRIER_H_ */646566