1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ARCH_H8300_ATOMIC__
3 #define __ARCH_H8300_ATOMIC__
5 #include <linux/compiler.h>
6 #include <linux/types.h>
7 #include <asm/cmpxchg.h>
8 #include <asm/irqflags.h>
11 * Atomic operations that C can't guarantee us. Useful for
12 * resource counting etc..
15 #define atomic_read(v) READ_ONCE((v)->counter)
16 #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
18 #define ATOMIC_OP_RETURN(op, c_op) \
19 static inline int atomic_##op##_return(int i, atomic_t *v) \
24 flags = arch_local_irq_save(); \
25 ret = v->counter c_op i; \
26 arch_local_irq_restore(flags); \
30 #define ATOMIC_FETCH_OP(op, c_op) \
31 static inline int atomic_fetch_##op(int i, atomic_t *v) \
36 flags = arch_local_irq_save(); \
39 arch_local_irq_restore(flags); \
43 #define ATOMIC_OP(op, c_op) \
44 static inline void atomic_##op(int i, atomic_t *v) \
48 flags = arch_local_irq_save(); \
50 arch_local_irq_restore(flags); \
53 ATOMIC_OP_RETURN(add, +=)
54 ATOMIC_OP_RETURN(sub, -=)
56 #define ATOMIC_OPS(op, c_op) \
58 ATOMIC_FETCH_OP(op, c_op)
67 #undef ATOMIC_OP_RETURN
70 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
75 flags = arch_local_irq_save();
77 if (likely(ret == old))
79 arch_local_irq_restore(flags);
83 static inline int atomic_fetch_add_unless(atomic_t *v, int a, int u)
88 flags = arch_local_irq_save();
92 arch_local_irq_restore(flags);
95 #define atomic_fetch_add_unless atomic_fetch_add_unless
97 #endif /* __ARCH_H8300_ATOMIC __ */