18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ALPHA_CMPXCHG_H 38c2ecf20Sopenharmony_ci#define _ALPHA_CMPXCHG_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Atomic exchange routines. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define ____xchg(type, args...) __xchg ## type ## _local(args) 108c2ecf20Sopenharmony_ci#define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args) 118c2ecf20Sopenharmony_ci#include <asm/xchg.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define xchg_local(ptr, x) \ 148c2ecf20Sopenharmony_ci({ \ 158c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _x_ = (x); \ 168c2ecf20Sopenharmony_ci (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \ 178c2ecf20Sopenharmony_ci sizeof(*(ptr))); \ 188c2ecf20Sopenharmony_ci}) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define cmpxchg_local(ptr, o, n) \ 218c2ecf20Sopenharmony_ci({ \ 228c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _o_ = (o); \ 238c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _n_ = (n); \ 248c2ecf20Sopenharmony_ci (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \ 258c2ecf20Sopenharmony_ci (unsigned long)_n_, \ 268c2ecf20Sopenharmony_ci sizeof(*(ptr))); \ 278c2ecf20Sopenharmony_ci}) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define cmpxchg64_local(ptr, o, n) \ 308c2ecf20Sopenharmony_ci({ \ 318c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ 328c2ecf20Sopenharmony_ci cmpxchg_local((ptr), (o), (n)); \ 338c2ecf20Sopenharmony_ci}) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#undef ____xchg 368c2ecf20Sopenharmony_ci#undef ____cmpxchg 378c2ecf20Sopenharmony_ci#define ____xchg(type, args...) __xchg ##type(args) 388c2ecf20Sopenharmony_ci#define ____cmpxchg(type, args...) __cmpxchg ##type(args) 398c2ecf20Sopenharmony_ci#include <asm/xchg.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * The leading and the trailing memory barriers guarantee that these 438c2ecf20Sopenharmony_ci * operations are fully ordered. 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci#define xchg(ptr, x) \ 468c2ecf20Sopenharmony_ci({ \ 478c2ecf20Sopenharmony_ci __typeof__(*(ptr)) __ret; \ 488c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _x_ = (x); \ 498c2ecf20Sopenharmony_ci smp_mb(); \ 508c2ecf20Sopenharmony_ci __ret = (__typeof__(*(ptr))) \ 518c2ecf20Sopenharmony_ci __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \ 528c2ecf20Sopenharmony_ci smp_mb(); \ 538c2ecf20Sopenharmony_ci __ret; \ 548c2ecf20Sopenharmony_ci}) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define cmpxchg(ptr, o, n) \ 578c2ecf20Sopenharmony_ci({ \ 588c2ecf20Sopenharmony_ci __typeof__(*(ptr)) __ret; \ 598c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _o_ = (o); \ 608c2ecf20Sopenharmony_ci __typeof__(*(ptr)) _n_ = (n); \ 618c2ecf20Sopenharmony_ci smp_mb(); \ 628c2ecf20Sopenharmony_ci __ret = (__typeof__(*(ptr))) __cmpxchg((ptr), \ 638c2ecf20Sopenharmony_ci (unsigned long)_o_, (unsigned long)_n_, sizeof(*(ptr)));\ 648c2ecf20Sopenharmony_ci smp_mb(); \ 658c2ecf20Sopenharmony_ci __ret; \ 668c2ecf20Sopenharmony_ci}) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define cmpxchg64(ptr, o, n) \ 698c2ecf20Sopenharmony_ci({ \ 708c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ 718c2ecf20Sopenharmony_ci cmpxchg((ptr), (o), (n)); \ 728c2ecf20Sopenharmony_ci}) 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#undef ____cmpxchg 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#endif /* _ALPHA_CMPXCHG_H */ 77