18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _TOOLS_LINUX_ASM_AARCH64_BARRIER_H 38c2ecf20Sopenharmony_ci#define _TOOLS_LINUX_ASM_AARCH64_BARRIER_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * From tools/perf/perf-sys.h, last modified in: 78c2ecf20Sopenharmony_ci * f428ebd184c82a7914b2aa7e9f868918aaf7ea78 perf tools: Fix AAAAARGH64 memory barriers 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * XXX: arch/arm64/include/asm/barrier.h in the kernel sources use dsb, is this 108c2ecf20Sopenharmony_ci * a case like for arm32 where we do things differently in userspace? 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define mb() asm volatile("dmb ish" ::: "memory") 148c2ecf20Sopenharmony_ci#define wmb() asm volatile("dmb ishst" ::: "memory") 158c2ecf20Sopenharmony_ci#define rmb() asm volatile("dmb ishld" ::: "memory") 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * Kernel uses dmb variants on arm64 for smp_*() barriers. Pretty much the same 198c2ecf20Sopenharmony_ci * implementation as above mb()/wmb()/rmb(), though for the latter kernel uses 208c2ecf20Sopenharmony_ci * dsb. In any case, should above mb()/wmb()/rmb() change, make sure the below 218c2ecf20Sopenharmony_ci * smp_*() don't. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci#define smp_mb() asm volatile("dmb ish" ::: "memory") 248c2ecf20Sopenharmony_ci#define smp_wmb() asm volatile("dmb ishst" ::: "memory") 258c2ecf20Sopenharmony_ci#define smp_rmb() asm volatile("dmb ishld" ::: "memory") 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define smp_store_release(p, v) \ 288c2ecf20Sopenharmony_cido { \ 298c2ecf20Sopenharmony_ci union { typeof(*p) __val; char __c[1]; } __u = \ 308c2ecf20Sopenharmony_ci { .__val = (v) }; \ 318c2ecf20Sopenharmony_ci \ 328c2ecf20Sopenharmony_ci switch (sizeof(*p)) { \ 338c2ecf20Sopenharmony_ci case 1: \ 348c2ecf20Sopenharmony_ci asm volatile ("stlrb %w1, %0" \ 358c2ecf20Sopenharmony_ci : "=Q" (*p) \ 368c2ecf20Sopenharmony_ci : "r" (*(__u8_alias_t *)__u.__c) \ 378c2ecf20Sopenharmony_ci : "memory"); \ 388c2ecf20Sopenharmony_ci break; \ 398c2ecf20Sopenharmony_ci case 2: \ 408c2ecf20Sopenharmony_ci asm volatile ("stlrh %w1, %0" \ 418c2ecf20Sopenharmony_ci : "=Q" (*p) \ 428c2ecf20Sopenharmony_ci : "r" (*(__u16_alias_t *)__u.__c) \ 438c2ecf20Sopenharmony_ci : "memory"); \ 448c2ecf20Sopenharmony_ci break; \ 458c2ecf20Sopenharmony_ci case 4: \ 468c2ecf20Sopenharmony_ci asm volatile ("stlr %w1, %0" \ 478c2ecf20Sopenharmony_ci : "=Q" (*p) \ 488c2ecf20Sopenharmony_ci : "r" (*(__u32_alias_t *)__u.__c) \ 498c2ecf20Sopenharmony_ci : "memory"); \ 508c2ecf20Sopenharmony_ci break; \ 518c2ecf20Sopenharmony_ci case 8: \ 528c2ecf20Sopenharmony_ci asm volatile ("stlr %1, %0" \ 538c2ecf20Sopenharmony_ci : "=Q" (*p) \ 548c2ecf20Sopenharmony_ci : "r" (*(__u64_alias_t *)__u.__c) \ 558c2ecf20Sopenharmony_ci : "memory"); \ 568c2ecf20Sopenharmony_ci break; \ 578c2ecf20Sopenharmony_ci default: \ 588c2ecf20Sopenharmony_ci /* Only to shut up gcc ... */ \ 598c2ecf20Sopenharmony_ci mb(); \ 608c2ecf20Sopenharmony_ci break; \ 618c2ecf20Sopenharmony_ci } \ 628c2ecf20Sopenharmony_ci} while (0) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define smp_load_acquire(p) \ 658c2ecf20Sopenharmony_ci({ \ 668c2ecf20Sopenharmony_ci union { typeof(*p) __val; char __c[1]; } __u = \ 678c2ecf20Sopenharmony_ci { .__c = { 0 } }; \ 688c2ecf20Sopenharmony_ci \ 698c2ecf20Sopenharmony_ci switch (sizeof(*p)) { \ 708c2ecf20Sopenharmony_ci case 1: \ 718c2ecf20Sopenharmony_ci asm volatile ("ldarb %w0, %1" \ 728c2ecf20Sopenharmony_ci : "=r" (*(__u8_alias_t *)__u.__c) \ 738c2ecf20Sopenharmony_ci : "Q" (*p) : "memory"); \ 748c2ecf20Sopenharmony_ci break; \ 758c2ecf20Sopenharmony_ci case 2: \ 768c2ecf20Sopenharmony_ci asm volatile ("ldarh %w0, %1" \ 778c2ecf20Sopenharmony_ci : "=r" (*(__u16_alias_t *)__u.__c) \ 788c2ecf20Sopenharmony_ci : "Q" (*p) : "memory"); \ 798c2ecf20Sopenharmony_ci break; \ 808c2ecf20Sopenharmony_ci case 4: \ 818c2ecf20Sopenharmony_ci asm volatile ("ldar %w0, %1" \ 828c2ecf20Sopenharmony_ci : "=r" (*(__u32_alias_t *)__u.__c) \ 838c2ecf20Sopenharmony_ci : "Q" (*p) : "memory"); \ 848c2ecf20Sopenharmony_ci break; \ 858c2ecf20Sopenharmony_ci case 8: \ 868c2ecf20Sopenharmony_ci asm volatile ("ldar %0, %1" \ 878c2ecf20Sopenharmony_ci : "=r" (*(__u64_alias_t *)__u.__c) \ 888c2ecf20Sopenharmony_ci : "Q" (*p) : "memory"); \ 898c2ecf20Sopenharmony_ci break; \ 908c2ecf20Sopenharmony_ci default: \ 918c2ecf20Sopenharmony_ci /* Only to shut up gcc ... */ \ 928c2ecf20Sopenharmony_ci mb(); \ 938c2ecf20Sopenharmony_ci break; \ 948c2ecf20Sopenharmony_ci } \ 958c2ecf20Sopenharmony_ci __u.__val; \ 968c2ecf20Sopenharmony_ci}) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#endif /* _TOOLS_LINUX_ASM_AARCH64_BARRIER_H */ 99