1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TOOLS_LINUX_ASM_AARCH64_BARRIER_H
3 #define _TOOLS_LINUX_ASM_AARCH64_BARRIER_H
6 * From tools/perf/perf-sys.h, last modified in:
7 * f428ebd184c82a7914b2aa7e9f868918aaf7ea78 perf tools: Fix AAAAARGH64 memory barriers
9 * XXX: arch/arm64/include/asm/barrier.h in the kernel sources use dsb, is this
10 * a case like for arm32 where we do things differently in userspace?
13 #define mb() asm volatile("dmb ish" ::: "memory")
14 #define wmb() asm volatile("dmb ishst" ::: "memory")
15 #define rmb() asm volatile("dmb ishld" ::: "memory")
18 * Kernel uses dmb variants on arm64 for smp_*() barriers. Pretty much the same
19 * implementation as above mb()/wmb()/rmb(), though for the latter kernel uses
20 * dsb. In any case, should above mb()/wmb()/rmb() change, make sure the below
23 #define smp_mb() asm volatile("dmb ish" ::: "memory")
24 #define smp_wmb() asm volatile("dmb ishst" ::: "memory")
25 #define smp_rmb() asm volatile("dmb ishld" ::: "memory")
27 #define smp_store_release(p, v) \
29 union { typeof(*p) __val; char __c[1]; } __u = \
32 switch (sizeof(*p)) { \
34 asm volatile ("stlrb %w1, %0" \
36 : "r" (*(__u8_alias_t *)__u.__c) \
40 asm volatile ("stlrh %w1, %0" \
42 : "r" (*(__u16_alias_t *)__u.__c) \
46 asm volatile ("stlr %w1, %0" \
48 : "r" (*(__u32_alias_t *)__u.__c) \
52 asm volatile ("stlr %1, %0" \
54 : "r" (*(__u64_alias_t *)__u.__c) \
58 /* Only to shut up gcc ... */ \
64 #define smp_load_acquire(p) \
66 union { typeof(*p) __val; char __c[1]; } __u = \
69 switch (sizeof(*p)) { \
71 asm volatile ("ldarb %w0, %1" \
72 : "=r" (*(__u8_alias_t *)__u.__c) \
73 : "Q" (*p) : "memory"); \
76 asm volatile ("ldarh %w0, %1" \
77 : "=r" (*(__u16_alias_t *)__u.__c) \
78 : "Q" (*p) : "memory"); \
81 asm volatile ("ldar %w0, %1" \
82 : "=r" (*(__u32_alias_t *)__u.__c) \
83 : "Q" (*p) : "memory"); \
86 asm volatile ("ldar %0, %1" \
87 : "=r" (*(__u64_alias_t *)__u.__c) \
88 : "Q" (*p) : "memory"); \
91 /* Only to shut up gcc ... */ \
98 #endif /* _TOOLS_LINUX_ASM_AARCH64_BARRIER_H */