18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* atomic.h: Thankfully the V9 is at least reasonable for this
38c2ecf20Sopenharmony_ci *           stuff.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1996, 1997, 2000, 2012 David S. Miller (davem@redhat.com)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __ARCH_SPARC64_ATOMIC__
98c2ecf20Sopenharmony_ci#define __ARCH_SPARC64_ATOMIC__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/types.h>
128c2ecf20Sopenharmony_ci#include <asm/cmpxchg.h>
138c2ecf20Sopenharmony_ci#include <asm/barrier.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define ATOMIC64_INIT(i)	{ (i) }
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define atomic_read(v)		READ_ONCE((v)->counter)
188c2ecf20Sopenharmony_ci#define atomic64_read(v)	READ_ONCE((v)->counter)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define atomic_set(v, i)	WRITE_ONCE(((v)->counter), (i))
218c2ecf20Sopenharmony_ci#define atomic64_set(v, i)	WRITE_ONCE(((v)->counter), (i))
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define ATOMIC_OP(op)							\
248c2ecf20Sopenharmony_civoid atomic_##op(int, atomic_t *);					\
258c2ecf20Sopenharmony_civoid atomic64_##op(s64, atomic64_t *);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define ATOMIC_OP_RETURN(op)						\
288c2ecf20Sopenharmony_ciint atomic_##op##_return(int, atomic_t *);				\
298c2ecf20Sopenharmony_cis64 atomic64_##op##_return(s64, atomic64_t *);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define ATOMIC_FETCH_OP(op)						\
328c2ecf20Sopenharmony_ciint atomic_fetch_##op(int, atomic_t *);					\
338c2ecf20Sopenharmony_cis64 atomic64_fetch_##op(s64, atomic64_t *);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) ATOMIC_FETCH_OP(op)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciATOMIC_OPS(add)
388c2ecf20Sopenharmony_ciATOMIC_OPS(sub)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#undef ATOMIC_OPS
418c2ecf20Sopenharmony_ci#define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_FETCH_OP(op)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciATOMIC_OPS(and)
448c2ecf20Sopenharmony_ciATOMIC_OPS(or)
458c2ecf20Sopenharmony_ciATOMIC_OPS(xor)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#undef ATOMIC_OPS
488c2ecf20Sopenharmony_ci#undef ATOMIC_FETCH_OP
498c2ecf20Sopenharmony_ci#undef ATOMIC_OP_RETURN
508c2ecf20Sopenharmony_ci#undef ATOMIC_OP
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline int atomic_xchg(atomic_t *v, int new)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return xchg(&v->counter, new);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define atomic64_cmpxchg(v, o, n) \
608c2ecf20Sopenharmony_ci	((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
618c2ecf20Sopenharmony_ci#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cis64 atomic64_dec_if_positive(atomic64_t *v);
648c2ecf20Sopenharmony_ci#define atomic64_dec_if_positive atomic64_dec_if_positive
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#endif /* !(__ARCH_SPARC64_ATOMIC__) */
67