1 #ifndef __ARCH_BLACKFIN_ATOMIC__
2 #define __ARCH_BLACKFIN_ATOMIC__
5 # include <asm-generic/atomic.h>
8 #include <linux/types.h>
9 #include <asm/system.h> /* local_irq_XXX() */
12 * Atomic operations that C can't guarantee us. Useful for
13 * resource counting etc..
16 #define ATOMIC_INIT(i) { (i) }
17 #define atomic_set(v, i) (((v)->counter) = i)
19 #define atomic_read(v) __raw_uncached_fetch_asm(&(v)->counter)
21 asmlinkage int __raw_uncached_fetch_asm(const volatile int *ptr);
23 asmlinkage int __raw_atomic_update_asm(volatile int *ptr, int value);
25 asmlinkage int __raw_atomic_clear_asm(volatile int *ptr, int value);
27 asmlinkage int __raw_atomic_set_asm(volatile int *ptr, int value);
29 asmlinkage int __raw_atomic_xor_asm(volatile int *ptr, int value);
31 asmlinkage int __raw_atomic_test_asm(const volatile int *ptr, int value);
33 static inline void atomic_add(int i, atomic_t *v)
35 __raw_atomic_update_asm(&v->counter, i);
38 static inline void atomic_sub(int i, atomic_t *v)
40 __raw_atomic_update_asm(&v->counter, -i);
43 static inline int atomic_add_return(int i, atomic_t *v)
45 return __raw_atomic_update_asm(&v->counter, i);
48 static inline int atomic_sub_return(int i, atomic_t *v)
50 return __raw_atomic_update_asm(&v->counter, -i);
53 static inline void atomic_inc(volatile atomic_t *v)
55 __raw_atomic_update_asm(&v->counter, 1);
58 static inline void atomic_dec(volatile atomic_t *v)
60 __raw_atomic_update_asm(&v->counter, -1);
63 static inline void atomic_clear_mask(int mask, atomic_t *v)
65 __raw_atomic_clear_asm(&v->counter, mask);
68 static inline void atomic_set_mask(int mask, atomic_t *v)
70 __raw_atomic_set_asm(&v->counter, mask);
73 static inline int atomic_test_mask(int mask, atomic_t *v)
75 return __raw_atomic_test_asm(&v->counter, mask);
78 /* Atomic operations are already serializing */
79 #define smp_mb__before_atomic_dec() barrier()
80 #define smp_mb__after_atomic_dec() barrier()
81 #define smp_mb__before_atomic_inc() barrier()
82 #define smp_mb__after_atomic_inc() barrier()
84 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
85 #define atomic_dec_return(v) atomic_sub_return(1,(v))
86 #define atomic_inc_return(v) atomic_add_return(1,(v))
88 #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
89 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
91 #define atomic_add_unless(v, a, u) \
95 while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
99 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
102 * atomic_inc_and_test - increment and test
103 * @v: pointer of type atomic_t
105 * Atomically increments @v by 1
106 * and returns true if the result is zero, or false for all
109 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
111 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
112 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
114 #include <asm-generic/atomic-long.h>