xref: /openbmc/linux/arch/sh/include/asm/atomic.h (revision e3d786a3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_ATOMIC_H
3 #define __ASM_SH_ATOMIC_H
4 
5 #if defined(CONFIG_CPU_J2)
6 
7 #include <asm-generic/atomic.h>
8 
9 #else
10 
11 /*
12  * Atomic operations that C can't guarantee us.  Useful for
13  * resource counting etc..
14  *
15  */
16 
17 #include <linux/compiler.h>
18 #include <linux/types.h>
19 #include <asm/cmpxchg.h>
20 #include <asm/barrier.h>
21 
22 #define ATOMIC_INIT(i)	{ (i) }
23 
24 #define atomic_read(v)		READ_ONCE((v)->counter)
25 #define atomic_set(v,i)		WRITE_ONCE((v)->counter, (i))
26 
27 #if defined(CONFIG_GUSA_RB)
28 #include <asm/atomic-grb.h>
29 #elif defined(CONFIG_CPU_SH4A)
30 #include <asm/atomic-llsc.h>
31 #else
32 #include <asm/atomic-irq.h>
33 #endif
34 
35 #define atomic_xchg(v, new)		(xchg(&((v)->counter), new))
36 #define atomic_cmpxchg(v, o, n)		(cmpxchg(&((v)->counter), (o), (n)))
37 
38 #endif /* CONFIG_CPU_J2 */
39 
40 #endif /* __ASM_SH_ATOMIC_H */
41