aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-powerpc/atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-powerpc/atomic.h')
-rw-r--r--include/asm-powerpc/atomic.h34
1 files changed, 28 insertions, 6 deletions
diff --git a/include/asm-powerpc/atomic.h b/include/asm-powerpc/atomic.h
index c44810b9d322..f3fc733758f5 100644
--- a/include/asm-powerpc/atomic.h
+++ b/include/asm-powerpc/atomic.h
@@ -5,7 +5,7 @@
5 * PowerPC atomic operations 5 * PowerPC atomic operations
6 */ 6 */
7 7
8typedef struct { volatile int counter; } atomic_t; 8typedef struct { int counter; } atomic_t;
9 9
10#ifdef __KERNEL__ 10#ifdef __KERNEL__
11#include <linux/compiler.h> 11#include <linux/compiler.h>
@@ -15,8 +15,19 @@ typedef struct { volatile int counter; } atomic_t;
15 15
16#define ATOMIC_INIT(i) { (i) } 16#define ATOMIC_INIT(i) { (i) }
17 17
18#define atomic_read(v) ((v)->counter) 18static __inline__ int atomic_read(const atomic_t *v)
19#define atomic_set(v,i) (((v)->counter) = (i)) 19{
20 int t;
21
22 __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
23
24 return t;
25}
26
27static __inline__ void atomic_set(atomic_t *v, int i)
28{
29 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
30}
20 31
21static __inline__ void atomic_add(int a, atomic_t *v) 32static __inline__ void atomic_add(int a, atomic_t *v)
22{ 33{
@@ -240,12 +251,23 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
240 251
241#ifdef __powerpc64__ 252#ifdef __powerpc64__
242 253
243typedef struct { volatile long counter; } atomic64_t; 254typedef struct { long counter; } atomic64_t;
244 255
245#define ATOMIC64_INIT(i) { (i) } 256#define ATOMIC64_INIT(i) { (i) }
246 257
247#define atomic64_read(v) ((v)->counter) 258static __inline__ long atomic64_read(const atomic64_t *v)
248#define atomic64_set(v,i) (((v)->counter) = (i)) 259{
260 long t;
261
262 __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
263
264 return t;
265}
266
267static __inline__ void atomic64_set(atomic64_t *v, long i)
268{
269 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
270}
249 271
250static __inline__ void atomic64_add(long a, atomic64_t *v) 272static __inline__ void atomic64_add(long a, atomic64_t *v)
251{ 273{