2 * PowerPC atomic operations
5 #ifndef _ASM_PPC_ATOMIC_H_
6 #define _ASM_PPC_ATOMIC_H_
8 typedef struct { volatile int counter
; } atomic_t
;
10 #define ATOMIC_INIT(i) { (i) }
12 #define atomic_read(v) ((v)->counter)
13 #define atomic_set(v,i) (((v)->counter) = (i))
15 extern void atomic_clear_mask(unsigned long mask
, unsigned long *addr
);
17 #if 0 // We only do operation on one CPU at a time (LTT)
18 #define SMP_SYNC "sync"
19 #define SMP_ISYNC "\n\tisync"
25 /* Erratum #77 on the 405 means we need a sync or dcbt before every stwcx.
26 * The old ATOMIC_SYNC_FIX covered some but not all of this.
28 #ifdef CONFIG_IBM405_ERR77
29 #define PPC405_ERR77(ra,rb) "dcbt " #ra "," #rb ";"
31 #define PPC405_ERR77(ra,rb)
34 static __inline__
void atomic_add(int a
, atomic_t
*v
)
39 "1: lwarx %0,0,%3 # atomic_add\n\
44 : "=&r" (t
), "=m" (v
->counter
)
45 : "r" (a
), "r" (&v
->counter
), "m" (v
->counter
)
49 static __inline__
int atomic_add_return(int a
, atomic_t
*v
)
54 "1: lwarx %0,0,%2 # atomic_add_return\n\
61 : "r" (a
), "r" (&v
->counter
)
67 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
69 static __inline__
void atomic_sub(int a
, atomic_t
*v
)
74 "1: lwarx %0,0,%3 # atomic_sub\n\
79 : "=&r" (t
), "=m" (v
->counter
)
80 : "r" (a
), "r" (&v
->counter
), "m" (v
->counter
)
84 static __inline__
int atomic_sub_return(int a
, atomic_t
*v
)
89 "1: lwarx %0,0,%2 # atomic_sub_return\n\
96 : "r" (a
), "r" (&v
->counter
)
102 static __inline__
void atomic_inc(atomic_t
*v
)
106 __asm__
__volatile__(
107 "1: lwarx %0,0,%2 # atomic_inc\n\
112 : "=&r" (t
), "=m" (v
->counter
)
113 : "r" (&v
->counter
), "m" (v
->counter
)
117 static __inline__
int atomic_inc_return(atomic_t
*v
)
121 __asm__
__volatile__(
122 "1: lwarx %0,0,%1 # atomic_inc_return\n\
136 * atomic_inc_and_test - increment and test
137 * @v: pointer of type atomic_t
139 * Atomically increments @v by 1
140 * and returns true if the result is zero, or false for all
143 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
145 static __inline__
void atomic_dec(atomic_t
*v
)
149 __asm__
__volatile__(
150 "1: lwarx %0,0,%2 # atomic_dec\n\
155 : "=&r" (t
), "=m" (v
->counter
)
156 : "r" (&v
->counter
), "m" (v
->counter
)
160 static __inline__
int atomic_dec_return(atomic_t
*v
)
164 __asm__
__volatile__(
165 "1: lwarx %0,0,%1 # atomic_dec_return\n\
178 #define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
179 #define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
182 * Atomically test *v and decrement if it is greater than 0.
183 * The function returns the old value of *v minus 1.
185 static __inline__
int atomic_dec_if_positive(atomic_t
*v
)
189 __asm__
__volatile__(
190 "1: lwarx %0,0,%1 # atomic_dec_if_positive\n\
205 #define __MB __asm__ __volatile__ (SMP_SYNC : : : "memory")
206 #define smp_mb__before_atomic_dec() __MB
207 #define smp_mb__after_atomic_dec() __MB
208 #define smp_mb__before_atomic_inc() __MB
209 #define smp_mb__after_atomic_inc() __MB
211 #endif /* _ASM_PPC_ATOMIC_H_ */
This page took 0.043265 seconds and 4 git commands to generate.