^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ALPHA_CMPXCHG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ALPHA_CMPXCHG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Atomic exchange routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define ____xchg(type, args...) __xchg ## type ## _local(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define ____cmpxchg(type, args...) __cmpxchg ## type ## _local(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/xchg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define xchg_local(ptr, x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) __typeof__(*(ptr)) _x_ = (x); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) (__typeof__(*(ptr))) __xchg_local((ptr), (unsigned long)_x_, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) sizeof(*(ptr))); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define cmpxchg_local(ptr, o, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) __typeof__(*(ptr)) _o_ = (o); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) __typeof__(*(ptr)) _n_ = (n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) (unsigned long)_n_, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) sizeof(*(ptr))); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define cmpxchg64_local(ptr, o, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) cmpxchg_local((ptr), (o), (n)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #undef ____xchg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #undef ____cmpxchg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define ____xchg(type, args...) __xchg ##type(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define ____cmpxchg(type, args...) __cmpxchg ##type(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/xchg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * The leading and the trailing memory barriers guarantee that these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * operations are fully ordered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define xchg(ptr, x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) __typeof__(*(ptr)) __ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __typeof__(*(ptr)) _x_ = (x); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) smp_mb(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __ret = (__typeof__(*(ptr))) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) smp_mb(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define cmpxchg(ptr, o, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __typeof__(*(ptr)) __ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) __typeof__(*(ptr)) _o_ = (o); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __typeof__(*(ptr)) _n_ = (n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) smp_mb(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __ret = (__typeof__(*(ptr))) __cmpxchg((ptr), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) (unsigned long)_o_, (unsigned long)_n_, sizeof(*(ptr)));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) smp_mb(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define cmpxchg64(ptr, o, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) cmpxchg((ptr), (o), (n)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #undef ____cmpxchg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif /* _ALPHA_CMPXCHG_H */