atomic.h 1.0 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2 3 4
#ifndef __ASM_SH_ATOMIC_H
#define __ASM_SH_ATOMIC_H

5 6 7 8 9 10
#if defined(CONFIG_CPU_J2)

#include <asm-generic/atomic.h>

#else

L
Linus Torvalds 已提交
11 12 13 14 15 16
/*
 * Atomic operations that C can't guarantee us.  Useful for
 * resource counting etc..
 *
 */

17 18
#include <linux/compiler.h>
#include <linux/types.h>
D
David Howells 已提交
19
#include <asm/cmpxchg.h>
P
Peter Zijlstra 已提交
20
#include <asm/barrier.h>
L
Linus Torvalds 已提交
21

22
#define ATOMIC_INIT(i)	{ (i) }
L
Linus Torvalds 已提交
23

24 25
#define atomic_read(v)		READ_ONCE((v)->counter)
#define atomic_set(v,i)		WRITE_ONCE((v)->counter, (i))
L
Linus Torvalds 已提交
26

27 28 29
#if defined(CONFIG_GUSA_RB)
#include <asm/atomic-grb.h>
#elif defined(CONFIG_CPU_SH4A)
P
Paul Mundt 已提交
30
#include <asm/atomic-llsc.h>
31
#else
P
Paul Mundt 已提交
32
#include <asm/atomic-irq.h>
33
#endif
L
Linus Torvalds 已提交
34

35 36
#define atomic_dec_return(v)		atomic_sub_return(1, (v))
#define atomic_inc_return(v)		atomic_add_return(1, (v))
L
Linus Torvalds 已提交
37

38 39
#define atomic_inc(v)			atomic_add(1, (v))
#define atomic_dec(v)			atomic_sub(1, (v))
L
Linus Torvalds 已提交
40

41 42 43
#define atomic_xchg(v, new)		(xchg(&((v)->counter), new))
#define atomic_cmpxchg(v, o, n)		(cmpxchg(&((v)->counter), (o), (n)))

44 45
#endif /* CONFIG_CPU_J2 */

L
Linus Torvalds 已提交
46
#endif /* __ASM_SH_ATOMIC_H */