162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Memory barrier definitions.  This is based on information published
462306a36Sopenharmony_ci * in the Processor Abstraction Layer and the System Abstraction Layer
562306a36Sopenharmony_ci * manual.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 1998-2003 Hewlett-Packard Co
862306a36Sopenharmony_ci *	David Mosberger-Tang <davidm@hpl.hp.com>
962306a36Sopenharmony_ci * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
1062306a36Sopenharmony_ci * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci#ifndef _ASM_IA64_BARRIER_H
1362306a36Sopenharmony_ci#define _ASM_IA64_BARRIER_H
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/compiler.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/*
1862306a36Sopenharmony_ci * Macros to force memory ordering.  In these descriptions, "previous"
1962306a36Sopenharmony_ci * and "subsequent" refer to program order; "visible" means that all
2062306a36Sopenharmony_ci * architecturally visible effects of a memory access have occurred
2162306a36Sopenharmony_ci * (at a minimum, this means the memory has been read or written).
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci *   wmb():	Guarantees that all preceding stores to memory-
2462306a36Sopenharmony_ci *		like regions are visible before any subsequent
2562306a36Sopenharmony_ci *		stores and that all following stores will be
2662306a36Sopenharmony_ci *		visible only after all previous stores.
2762306a36Sopenharmony_ci *   rmb():	Like wmb(), but for reads.
2862306a36Sopenharmony_ci *   mb():	wmb()/rmb() combo, i.e., all previous memory
2962306a36Sopenharmony_ci *		accesses are visible before all subsequent
3062306a36Sopenharmony_ci *		accesses and vice versa.  This is also known as
3162306a36Sopenharmony_ci *		a "fence."
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * Note: "mb()" and its variants cannot be used as a fence to order
3462306a36Sopenharmony_ci * accesses to memory mapped I/O registers.  For that, mf.a needs to
3562306a36Sopenharmony_ci * be used.  However, we don't want to always use mf.a because (a)
3662306a36Sopenharmony_ci * it's (presumably) much slower than mf and (b) mf.a is supported for
3762306a36Sopenharmony_ci * sequential memory pages only.
3862306a36Sopenharmony_ci */
3962306a36Sopenharmony_ci#define mb()		ia64_mf()
4062306a36Sopenharmony_ci#define rmb()		mb()
4162306a36Sopenharmony_ci#define wmb()		mb()
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define dma_rmb()	mb()
4462306a36Sopenharmony_ci#define dma_wmb()	mb()
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci# define __smp_mb()	mb()
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define __smp_mb__before_atomic()	barrier()
4962306a36Sopenharmony_ci#define __smp_mb__after_atomic()	barrier()
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/*
5262306a36Sopenharmony_ci * IA64 GCC turns volatile stores into st.rel and volatile loads into ld.acq no
5362306a36Sopenharmony_ci * need for asm trickery!
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define __smp_store_release(p, v)						\
5762306a36Sopenharmony_cido {									\
5862306a36Sopenharmony_ci	compiletime_assert_atomic_type(*p);				\
5962306a36Sopenharmony_ci	barrier();							\
6062306a36Sopenharmony_ci	WRITE_ONCE(*p, v);						\
6162306a36Sopenharmony_ci} while (0)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define __smp_load_acquire(p)						\
6462306a36Sopenharmony_ci({									\
6562306a36Sopenharmony_ci	typeof(*p) ___p1 = READ_ONCE(*p);				\
6662306a36Sopenharmony_ci	compiletime_assert_atomic_type(*p);				\
6762306a36Sopenharmony_ci	barrier();							\
6862306a36Sopenharmony_ci	___p1;								\
6962306a36Sopenharmony_ci})
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/*
7262306a36Sopenharmony_ci * The group barrier in front of the rsm & ssm are necessary to ensure
7362306a36Sopenharmony_ci * that none of the previous instructions in the same group are
7462306a36Sopenharmony_ci * affected by the rsm/ssm.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#include <asm-generic/barrier.h>
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#endif /* _ASM_IA64_BARRIER_H */
80