1 #ifndef __ARCH_M68K_ATOMIC__
2 #define __ARCH_M68K_ATOMIC__
5 #include <asm/system.h> /* local_irq_XXX() */
8 * Atomic operations that C can't guarantee us. Useful for
9 * resource counting etc..
13 * We do not have SMP m68k systems, so we don't have to deal with that.
16 typedef struct { int counter; } atomic_t;
17 #define ATOMIC_INIT(i) { (i) }
19 #define atomic_read(v) ((v)->counter)
20 #define atomic_set(v, i) (((v)->counter) = i)
22 static inline void atomic_add(int i, atomic_t *v)
24 __asm__ __volatile__("addl %1,%0" : "+m" (*v) : "id" (i));
27 static inline void atomic_sub(int i, atomic_t *v)
29 __asm__ __volatile__("subl %1,%0" : "+m" (*v) : "id" (i));
32 static inline void atomic_inc(atomic_t *v)
34 __asm__ __volatile__("addql #1,%0" : "+m" (*v));
37 static inline void atomic_dec(atomic_t *v)
39 __asm__ __volatile__("subql #1,%0" : "+m" (*v));
42 static inline int atomic_dec_and_test(atomic_t *v)
45 __asm__ __volatile__("subql #1,%1; seq %0" : "=d" (c), "+m" (*v));
49 static inline int atomic_inc_and_test(atomic_t *v)
52 __asm__ __volatile__("addql #1,%1; seq %0" : "=d" (c), "+m" (*v));
56 #ifdef CONFIG_RMW_INSNS
58 static inline int atomic_add_return(int i, atomic_t *v)
67 : "+m" (*v), "=&d" (t), "=&d" (tmp)
68 : "g" (i), "2" (atomic_read(v)));
72 static inline int atomic_sub_return(int i, atomic_t *v)
81 : "+m" (*v), "=&d" (t), "=&d" (tmp)
82 : "g" (i), "2" (atomic_read(v)));
86 #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
87 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
89 #else /* !CONFIG_RMW_INSNS */
91 static inline int atomic_add_return(int i, atomic_t * v)
96 local_irq_save(flags);
100 local_irq_restore(flags);
105 static inline int atomic_sub_return(int i, atomic_t * v)
110 local_irq_save(flags);
114 local_irq_restore(flags);
119 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
124 local_irq_save(flags);
125 prev = atomic_read(v);
128 local_irq_restore(flags);
132 static inline int atomic_xchg(atomic_t *v, int new)
137 local_irq_save(flags);
138 prev = atomic_read(v);
140 local_irq_restore(flags);
144 #endif /* !CONFIG_RMW_INSNS */
146 #define atomic_dec_return(v) atomic_sub_return(1, (v))
147 #define atomic_inc_return(v) atomic_add_return(1, (v))
149 static inline int atomic_sub_and_test(int i, atomic_t *v)
152 __asm__ __volatile__("subl %2,%1; seq %0" : "=d" (c), "+m" (*v): "g" (i));
156 static inline int atomic_add_negative(int i, atomic_t *v)
159 __asm__ __volatile__("addl %2,%1; smi %0" : "=d" (c), "+m" (*v): "g" (i));
163 static inline void atomic_clear_mask(unsigned long mask, unsigned long *v)
165 __asm__ __volatile__("andl %1,%0" : "+m" (*v) : "id" (~(mask)));
168 static inline void atomic_set_mask(unsigned long mask, unsigned long *v)
170 __asm__ __volatile__("orl %1,%0" : "+m" (*v) : "id" (mask));
173 #define atomic_add_unless(v, a, u) \
176 c = atomic_read(v); \
178 if (unlikely(c == (u))) \
180 old = atomic_cmpxchg((v), c, c + (a)); \
181 if (likely(old == c)) \
187 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
189 /* Atomic operations are already serializing */
190 #define smp_mb__before_atomic_dec() barrier()
191 #define smp_mb__after_atomic_dec() barrier()
192 #define smp_mb__before_atomic_inc() barrier()
193 #define smp_mb__after_atomic_inc() barrier()
195 #include <asm-generic/atomic.h>
196 #endif /* __ARCH_M68K_ATOMIC __ */