aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/include/asm/atomic.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-08-01 13:53:43 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-08-01 13:53:43 -0400
commit00e9028a95fb8a4d79f2fb695a853f33ea7d3b57 (patch)
tree2dea2ae498a6ce57de8890e87185aca5e9f3ad2d /arch/sh/include/asm/atomic.h
parent57b1494d2ba544c62673234da6115c21fac27ffc (diff)
parent7cb93181629c613ee2b8f4ffe3446f8003074842 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6: (28 commits) mm/hugetlb.c must #include <asm/io.h> video: Fix up hp6xx driver build regressions. sh: defconfig updates. sh: Kill off stray mach-rsk7203 reference. serial: sh-sci: Fix up SH7760/SH7780/SH7785 early printk regression. sh: Move out individual boards without mach groups. sh: Make sure AT_SYSINFO_EHDR is exposed to userspace in asm/auxvec.h. sh: Allow SH-3 and SH-5 to use common headers. sh: Provide common CPU headers, prune the SH-2 and SH-2A directories. sh/maple: clean maple bus code sh: More header path fixups for mach dir refactoring. sh: Move out the solution engine headers to arch/sh/include/mach-se/ sh: I2C fix for AP325RXA and Migo-R sh: Shuffle the board directories in to mach groups. sh: dma-sh: Fix up dreamcast dma.h mach path. sh: Switch KBUILD_DEFCONFIG to shx3_defconfig. sh: Add ARCH_DEFCONFIG entries for sh and sh64. sh: Fix compile error of Solution Engine sh: Proper __put_user_asm() size mismatch fix. sh: Stub in a dummy ENTRY_OFFSET for uImage offset calculation. ...
Diffstat (limited to 'arch/sh/include/asm/atomic.h')
-rw-r--r--arch/sh/include/asm/atomic.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/arch/sh/include/asm/atomic.h b/arch/sh/include/asm/atomic.h
new file mode 100644
index 000000000000..c043ef003028
--- /dev/null
+++ b/arch/sh/include/asm/atomic.h
@@ -0,0 +1,89 @@
1#ifndef __ASM_SH_ATOMIC_H
2#define __ASM_SH_ATOMIC_H
3
4/*
5 * Atomic operations that C can't guarantee us. Useful for
6 * resource counting etc..
7 *
8 */
9
10typedef struct { volatile int counter; } atomic_t;
11
12#define ATOMIC_INIT(i) ( (atomic_t) { (i) } )
13
14#define atomic_read(v) ((v)->counter)
15#define atomic_set(v,i) ((v)->counter = (i))
16
17#include <linux/compiler.h>
18#include <asm/system.h>
19
20#if defined(CONFIG_GUSA_RB)
21#include <asm/atomic-grb.h>
22#elif defined(CONFIG_CPU_SH4A)
23#include <asm/atomic-llsc.h>
24#else
25#include <asm/atomic-irq.h>
26#endif
27
28#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
29
30#define atomic_dec_return(v) atomic_sub_return(1,(v))
31#define atomic_inc_return(v) atomic_add_return(1,(v))
32
33/*
34 * atomic_inc_and_test - increment and test
35 * @v: pointer of type atomic_t
36 *
37 * Atomically increments @v by 1
38 * and returns true if the result is zero, or false for all
39 * other cases.
40 */
41#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
42
43#define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
44#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
45
46#define atomic_inc(v) atomic_add(1,(v))
47#define atomic_dec(v) atomic_sub(1,(v))
48
49#ifndef CONFIG_GUSA_RB
50static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
51{
52 int ret;
53 unsigned long flags;
54
55 local_irq_save(flags);
56 ret = v->counter;
57 if (likely(ret == old))
58 v->counter = new;
59 local_irq_restore(flags);
60
61 return ret;
62}
63
64static inline int atomic_add_unless(atomic_t *v, int a, int u)
65{
66 int ret;
67 unsigned long flags;
68
69 local_irq_save(flags);
70 ret = v->counter;
71 if (ret != u)
72 v->counter += a;
73 local_irq_restore(flags);
74
75 return ret != u;
76}
77#endif
78
79#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
80#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
81
82/* Atomic operations are already serializing on SH */
83#define smp_mb__before_atomic_dec() barrier()
84#define smp_mb__after_atomic_dec() barrier()
85#define smp_mb__before_atomic_inc() barrier()
86#define smp_mb__after_atomic_inc() barrier()
87
88#include <asm-generic/atomic.h>
89#endif /* __ASM_SH_ATOMIC_H */