18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Generic implementation of 64-bit atomics using spinlocks,
48c2ecf20Sopenharmony_ci * useful on processors that don't have 64-bit atomic instructions.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#ifndef _ASM_GENERIC_ATOMIC64_H
98c2ecf20Sopenharmony_ci#define _ASM_GENERIC_ATOMIC64_H
108c2ecf20Sopenharmony_ci#include <linux/types.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_citypedef struct {
138c2ecf20Sopenharmony_ci	s64 counter;
148c2ecf20Sopenharmony_ci} atomic64_t;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define ATOMIC64_INIT(i)	{ (i) }
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciextern s64 atomic64_read(const atomic64_t *v);
198c2ecf20Sopenharmony_ciextern void atomic64_set(atomic64_t *v, s64 i);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define atomic64_set_release(v, i)	atomic64_set((v), (i))
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define ATOMIC64_OP(op)							\
248c2ecf20Sopenharmony_ciextern void	 atomic64_##op(s64 a, atomic64_t *v);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define ATOMIC64_OP_RETURN(op)						\
278c2ecf20Sopenharmony_ciextern s64 atomic64_##op##_return(s64 a, atomic64_t *v);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define ATOMIC64_FETCH_OP(op)						\
308c2ecf20Sopenharmony_ciextern s64 atomic64_fetch_##op(s64 a, atomic64_t *v);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define ATOMIC64_OPS(op)	ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op) ATOMIC64_FETCH_OP(op)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciATOMIC64_OPS(add)
358c2ecf20Sopenharmony_ciATOMIC64_OPS(sub)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#undef ATOMIC64_OPS
388c2ecf20Sopenharmony_ci#define ATOMIC64_OPS(op)	ATOMIC64_OP(op) ATOMIC64_FETCH_OP(op)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciATOMIC64_OPS(and)
418c2ecf20Sopenharmony_ciATOMIC64_OPS(or)
428c2ecf20Sopenharmony_ciATOMIC64_OPS(xor)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#undef ATOMIC64_OPS
458c2ecf20Sopenharmony_ci#undef ATOMIC64_FETCH_OP
468c2ecf20Sopenharmony_ci#undef ATOMIC64_OP_RETURN
478c2ecf20Sopenharmony_ci#undef ATOMIC64_OP
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciextern s64 atomic64_dec_if_positive(atomic64_t *v);
508c2ecf20Sopenharmony_ci#define atomic64_dec_if_positive atomic64_dec_if_positive
518c2ecf20Sopenharmony_ciextern s64 atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n);
528c2ecf20Sopenharmony_ciextern s64 atomic64_xchg(atomic64_t *v, s64 new);
538c2ecf20Sopenharmony_ciextern s64 atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u);
548c2ecf20Sopenharmony_ci#define atomic64_fetch_add_unless atomic64_fetch_add_unless
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#endif  /*  _ASM_GENERIC_ATOMIC64_H  */
57