1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 212751058SHeiko Carstens /* 3126b30c3SMartin Schwidefsky * Copyright IBM Corp. 1999, 2016 412751058SHeiko Carstens * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>, 512751058SHeiko Carstens * Denis Joseph Barrow, 6126b30c3SMartin Schwidefsky * Arnd Bergmann, 712751058SHeiko Carstens */ 812751058SHeiko Carstens 9a53c8fabSHeiko Carstens #ifndef __ARCH_S390_ATOMIC__ 10a53c8fabSHeiko Carstens #define __ARCH_S390_ATOMIC__ 11a53c8fabSHeiko Carstens 12c6557e7fSMartin Schwidefsky #include <linux/compiler.h> 13ea435467SMatthew Wilcox #include <linux/types.h> 14126b30c3SMartin Schwidefsky #include <asm/atomic_ops.h> 150ccc8b7aSHeiko Carstens #include <asm/barrier.h> 16a0616cdeSDavid Howells #include <asm/cmpxchg.h> 17c6557e7fSMartin Schwidefsky 18*00017423SHeiko Carstens static inline int arch_atomic_read(const atomic_t *v) 19c6557e7fSMartin Schwidefsky { 20c8a91c28SHeiko Carstens return __atomic_read(v); 21c6557e7fSMartin Schwidefsky } 22*00017423SHeiko Carstens #define arch_atomic_read arch_atomic_read 23c6557e7fSMartin Schwidefsky 24*00017423SHeiko Carstens static inline void arch_atomic_set(atomic_t *v, int i) 25c6557e7fSMartin Schwidefsky { 26c8a91c28SHeiko Carstens __atomic_set(v, i); 27c6557e7fSMartin Schwidefsky } 28*00017423SHeiko Carstens #define arch_atomic_set arch_atomic_set 29c6557e7fSMartin Schwidefsky 30*00017423SHeiko Carstens static inline int arch_atomic_add_return(int i, atomic_t *v) 31c6557e7fSMartin Schwidefsky { 32126b30c3SMartin Schwidefsky return __atomic_add_barrier(i, &v->counter) + i; 33c6557e7fSMartin Schwidefsky } 34*00017423SHeiko Carstens #define arch_atomic_add_return arch_atomic_add_return 3575287430SHeiko Carstens 36*00017423SHeiko Carstens static inline int arch_atomic_fetch_add(int i, atomic_t *v) 3756fefbbcSPeter Zijlstra { 38126b30c3SMartin Schwidefsky return __atomic_add_barrier(i, &v->counter); 3956fefbbcSPeter Zijlstra } 40*00017423SHeiko Carstens #define arch_atomic_fetch_add arch_atomic_fetch_add 4156fefbbcSPeter Zijlstra 42*00017423SHeiko Carstens static inline void arch_atomic_add(int i, atomic_t *v) 435692e4d1SHeiko Carstens { 44126b30c3SMartin Schwidefsky __atomic_add(i, &v->counter); 455692e4d1SHeiko Carstens } 46*00017423SHeiko Carstens #define arch_atomic_add arch_atomic_add 475692e4d1SHeiko Carstens 48*00017423SHeiko Carstens #define arch_atomic_sub(_i, _v) arch_atomic_add(-(int)(_i), _v) 49*00017423SHeiko Carstens #define arch_atomic_sub_return(_i, _v) arch_atomic_add_return(-(int)(_i), _v) 50*00017423SHeiko Carstens #define arch_atomic_fetch_sub(_i, _v) arch_atomic_fetch_add(-(int)(_i), _v) 51c6557e7fSMartin Schwidefsky 52126b30c3SMartin Schwidefsky #define ATOMIC_OPS(op) \ 53*00017423SHeiko Carstens static inline void arch_atomic_##op(int i, atomic_t *v) \ 54ae8c35c8SPeter Zijlstra { \ 55126b30c3SMartin Schwidefsky __atomic_##op(i, &v->counter); \ 5656fefbbcSPeter Zijlstra } \ 57*00017423SHeiko Carstens static inline int arch_atomic_fetch_##op(int i, atomic_t *v) \ 5856fefbbcSPeter Zijlstra { \ 59126b30c3SMartin Schwidefsky return __atomic_##op##_barrier(i, &v->counter); \ 60c6557e7fSMartin Schwidefsky } 61c6557e7fSMartin Schwidefsky 62126b30c3SMartin Schwidefsky ATOMIC_OPS(and) 63126b30c3SMartin Schwidefsky ATOMIC_OPS(or) 64126b30c3SMartin Schwidefsky ATOMIC_OPS(xor) 6556fefbbcSPeter Zijlstra 6656fefbbcSPeter Zijlstra #undef ATOMIC_OPS 67ae8c35c8SPeter Zijlstra 68*00017423SHeiko Carstens #define arch_atomic_and arch_atomic_and 69*00017423SHeiko Carstens #define arch_atomic_or arch_atomic_or 70*00017423SHeiko Carstens #define arch_atomic_xor arch_atomic_xor 71*00017423SHeiko Carstens #define arch_atomic_fetch_and arch_atomic_fetch_and 72*00017423SHeiko Carstens #define arch_atomic_fetch_or arch_atomic_fetch_or 73*00017423SHeiko Carstens #define arch_atomic_fetch_xor arch_atomic_fetch_xor 74c6557e7fSMartin Schwidefsky 75*00017423SHeiko Carstens #define arch_atomic_xchg(v, new) (arch_xchg(&((v)->counter), new)) 76*00017423SHeiko Carstens 77*00017423SHeiko Carstens static inline int arch_atomic_cmpxchg(atomic_t *v, int old, int new) 78c6557e7fSMartin Schwidefsky { 79126b30c3SMartin Schwidefsky return __atomic_cmpxchg(&v->counter, old, new); 80c6557e7fSMartin Schwidefsky } 81*00017423SHeiko Carstens #define arch_atomic_cmpxchg arch_atomic_cmpxchg 82c6557e7fSMartin Schwidefsky 83c6557e7fSMartin Schwidefsky #define ATOMIC64_INIT(i) { (i) } 84c6557e7fSMartin Schwidefsky 85*00017423SHeiko Carstens static inline s64 arch_atomic64_read(const atomic64_t *v) 86c6557e7fSMartin Schwidefsky { 87c8a91c28SHeiko Carstens return __atomic64_read(v); 88c6557e7fSMartin Schwidefsky } 89*00017423SHeiko Carstens #define arch_atomic64_read arch_atomic64_read 90c6557e7fSMartin Schwidefsky 91*00017423SHeiko Carstens static inline void arch_atomic64_set(atomic64_t *v, s64 i) 92c6557e7fSMartin Schwidefsky { 93c8a91c28SHeiko Carstens __atomic64_set(v, i); 94c6557e7fSMartin Schwidefsky } 95*00017423SHeiko Carstens #define arch_atomic64_set arch_atomic64_set 96c6557e7fSMartin Schwidefsky 97*00017423SHeiko Carstens static inline s64 arch_atomic64_add_return(s64 i, atomic64_t *v) 98c6557e7fSMartin Schwidefsky { 990ca94800SMark Rutland return __atomic64_add_barrier(i, (long *)&v->counter) + i; 1000ccc8b7aSHeiko Carstens } 101*00017423SHeiko Carstens #define arch_atomic64_add_return arch_atomic64_add_return 1020ccc8b7aSHeiko Carstens 103*00017423SHeiko Carstens static inline s64 arch_atomic64_fetch_add(s64 i, atomic64_t *v) 10456fefbbcSPeter Zijlstra { 1050ca94800SMark Rutland return __atomic64_add_barrier(i, (long *)&v->counter); 10656fefbbcSPeter Zijlstra } 107*00017423SHeiko Carstens #define arch_atomic64_fetch_add arch_atomic64_fetch_add 10856fefbbcSPeter Zijlstra 109*00017423SHeiko Carstens static inline void arch_atomic64_add(s64 i, atomic64_t *v) 1100ccc8b7aSHeiko Carstens { 1110ca94800SMark Rutland __atomic64_add(i, (long *)&v->counter); 112c6557e7fSMartin Schwidefsky } 113*00017423SHeiko Carstens #define arch_atomic64_add arch_atomic64_add 114c6557e7fSMartin Schwidefsky 115*00017423SHeiko Carstens #define arch_atomic64_xchg(v, new) (arch_xchg(&((v)->counter), new)) 116c6557e7fSMartin Schwidefsky 117*00017423SHeiko Carstens static inline s64 arch_atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new) 118c6557e7fSMartin Schwidefsky { 1190ca94800SMark Rutland return __atomic64_cmpxchg((long *)&v->counter, old, new); 120c6557e7fSMartin Schwidefsky } 121*00017423SHeiko Carstens #define arch_atomic64_cmpxchg arch_atomic64_cmpxchg 122c6557e7fSMartin Schwidefsky 123126b30c3SMartin Schwidefsky #define ATOMIC64_OPS(op) \ 124*00017423SHeiko Carstens static inline void arch_atomic64_##op(s64 i, atomic64_t *v) \ 125ae8c35c8SPeter Zijlstra { \ 1260ca94800SMark Rutland __atomic64_##op(i, (long *)&v->counter); \ 12756fefbbcSPeter Zijlstra } \ 128*00017423SHeiko Carstens static inline long arch_atomic64_fetch_##op(s64 i, atomic64_t *v) \ 12956fefbbcSPeter Zijlstra { \ 1300ca94800SMark Rutland return __atomic64_##op##_barrier(i, (long *)&v->counter); \ 131ae8c35c8SPeter Zijlstra } 132ae8c35c8SPeter Zijlstra 133126b30c3SMartin Schwidefsky ATOMIC64_OPS(and) 134126b30c3SMartin Schwidefsky ATOMIC64_OPS(or) 135126b30c3SMartin Schwidefsky ATOMIC64_OPS(xor) 136ae8c35c8SPeter Zijlstra 13756fefbbcSPeter Zijlstra #undef ATOMIC64_OPS 13812751058SHeiko Carstens 139*00017423SHeiko Carstens #define arch_atomic64_and arch_atomic64_and 140*00017423SHeiko Carstens #define arch_atomic64_or arch_atomic64_or 141*00017423SHeiko Carstens #define arch_atomic64_xor arch_atomic64_xor 142*00017423SHeiko Carstens #define arch_atomic64_fetch_and arch_atomic64_fetch_and 143*00017423SHeiko Carstens #define arch_atomic64_fetch_or arch_atomic64_fetch_or 144*00017423SHeiko Carstens #define arch_atomic64_fetch_xor arch_atomic64_fetch_xor 145*00017423SHeiko Carstens 146*00017423SHeiko Carstens #define arch_atomic64_sub_return(_i, _v) arch_atomic64_add_return(-(s64)(_i), _v) 147*00017423SHeiko Carstens #define arch_atomic64_fetch_sub(_i, _v) arch_atomic64_fetch_add(-(s64)(_i), _v) 148*00017423SHeiko Carstens #define arch_atomic64_sub(_i, _v) arch_atomic64_add(-(s64)(_i), _v) 149*00017423SHeiko Carstens 150*00017423SHeiko Carstens #define ARCH_ATOMIC 151c6557e7fSMartin Schwidefsky 152c6557e7fSMartin Schwidefsky #endif /* __ARCH_S390_ATOMIC__ */ 153