18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copied from the kernel sources to tools/:
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Memory barrier definitions.  This is based on information published
68c2ecf20Sopenharmony_ci * in the Processor Abstraction Layer and the System Abstraction Layer
78c2ecf20Sopenharmony_ci * manual.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 1998-2003 Hewlett-Packard Co
108c2ecf20Sopenharmony_ci *	David Mosberger-Tang <davidm@hpl.hp.com>
118c2ecf20Sopenharmony_ci * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
128c2ecf20Sopenharmony_ci * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#ifndef _TOOLS_LINUX_ASM_IA64_BARRIER_H
158c2ecf20Sopenharmony_ci#define _TOOLS_LINUX_ASM_IA64_BARRIER_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/compiler.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/*
208c2ecf20Sopenharmony_ci * Macros to force memory ordering.  In these descriptions, "previous"
218c2ecf20Sopenharmony_ci * and "subsequent" refer to program order; "visible" means that all
228c2ecf20Sopenharmony_ci * architecturally visible effects of a memory access have occurred
238c2ecf20Sopenharmony_ci * (at a minimum, this means the memory has been read or written).
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci *   wmb():	Guarantees that all preceding stores to memory-
268c2ecf20Sopenharmony_ci *		like regions are visible before any subsequent
278c2ecf20Sopenharmony_ci *		stores and that all following stores will be
288c2ecf20Sopenharmony_ci *		visible only after all previous stores.
298c2ecf20Sopenharmony_ci *   rmb():	Like wmb(), but for reads.
308c2ecf20Sopenharmony_ci *   mb():	wmb()/rmb() combo, i.e., all previous memory
318c2ecf20Sopenharmony_ci *		accesses are visible before all subsequent
328c2ecf20Sopenharmony_ci *		accesses and vice versa.  This is also known as
338c2ecf20Sopenharmony_ci *		a "fence."
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci * Note: "mb()" and its variants cannot be used as a fence to order
368c2ecf20Sopenharmony_ci * accesses to memory mapped I/O registers.  For that, mf.a needs to
378c2ecf20Sopenharmony_ci * be used.  However, we don't want to always use mf.a because (a)
388c2ecf20Sopenharmony_ci * it's (presumably) much slower than mf and (b) mf.a is supported for
398c2ecf20Sopenharmony_ci * sequential memory pages only.
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define mb()		ia64_mf()
438c2ecf20Sopenharmony_ci#define rmb()		mb()
448c2ecf20Sopenharmony_ci#define wmb()		mb()
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define smp_store_release(p, v)			\
478c2ecf20Sopenharmony_cido {						\
488c2ecf20Sopenharmony_ci	barrier();				\
498c2ecf20Sopenharmony_ci	WRITE_ONCE(*p, v);			\
508c2ecf20Sopenharmony_ci} while (0)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define smp_load_acquire(p)			\
538c2ecf20Sopenharmony_ci({						\
548c2ecf20Sopenharmony_ci	typeof(*p) ___p1 = READ_ONCE(*p);	\
558c2ecf20Sopenharmony_ci	barrier();				\
568c2ecf20Sopenharmony_ci	___p1;					\
578c2ecf20Sopenharmony_ci})
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#endif /* _TOOLS_LINUX_ASM_IA64_BARRIER_H */
60