diff options
Diffstat (limited to 'arch/mn10300/include/asm/atomic.h')
-rw-r--r-- | arch/mn10300/include/asm/atomic.h | 109 |
1 files changed, 3 insertions, 106 deletions
diff --git a/arch/mn10300/include/asm/atomic.h b/arch/mn10300/include/asm/atomic.h index b9a8f8461262..975e1841ca64 100644 --- a/arch/mn10300/include/asm/atomic.h +++ b/arch/mn10300/include/asm/atomic.h | |||
@@ -12,112 +12,7 @@ | |||
12 | #define _ASM_ATOMIC_H | 12 | #define _ASM_ATOMIC_H |
13 | 13 | ||
14 | #include <asm/irqflags.h> | 14 | #include <asm/irqflags.h> |
15 | 15 | #include <asm/cmpxchg.h> | |
16 | #ifndef __ASSEMBLY__ | ||
17 | |||
18 | #ifdef CONFIG_SMP | ||
19 | #ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT | ||
20 | static inline | ||
21 | unsigned long __xchg(volatile unsigned long *m, unsigned long val) | ||
22 | { | ||
23 | unsigned long status; | ||
24 | unsigned long oldval; | ||
25 | |||
26 | asm volatile( | ||
27 | "1: mov %4,(_AAR,%3) \n" | ||
28 | " mov (_ADR,%3),%1 \n" | ||
29 | " mov %5,(_ADR,%3) \n" | ||
30 | " mov (_ADR,%3),%0 \n" /* flush */ | ||
31 | " mov (_ASR,%3),%0 \n" | ||
32 | " or %0,%0 \n" | ||
33 | " bne 1b \n" | ||
34 | : "=&r"(status), "=&r"(oldval), "=m"(*m) | ||
35 | : "a"(ATOMIC_OPS_BASE_ADDR), "r"(m), "r"(val) | ||
36 | : "memory", "cc"); | ||
37 | |||
38 | return oldval; | ||
39 | } | ||
40 | |||
41 | static inline unsigned long __cmpxchg(volatile unsigned long *m, | ||
42 | unsigned long old, unsigned long new) | ||
43 | { | ||
44 | unsigned long status; | ||
45 | unsigned long oldval; | ||
46 | |||
47 | asm volatile( | ||
48 | "1: mov %4,(_AAR,%3) \n" | ||
49 | " mov (_ADR,%3),%1 \n" | ||
50 | " cmp %5,%1 \n" | ||
51 | " bne 2f \n" | ||
52 | " mov %6,(_ADR,%3) \n" | ||
53 | "2: mov (_ADR,%3),%0 \n" /* flush */ | ||
54 | " mov (_ASR,%3),%0 \n" | ||
55 | " or %0,%0 \n" | ||
56 | " bne 1b \n" | ||
57 | : "=&r"(status), "=&r"(oldval), "=m"(*m) | ||
58 | : "a"(ATOMIC_OPS_BASE_ADDR), "r"(m), | ||
59 | "r"(old), "r"(new) | ||
60 | : "memory", "cc"); | ||
61 | |||
62 | return oldval; | ||
63 | } | ||
64 | #else /* CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT */ | ||
65 | #error "No SMP atomic operation support!" | ||
66 | #endif /* CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT */ | ||
67 | |||
68 | #else /* CONFIG_SMP */ | ||
69 | |||
70 | /* | ||
71 | * Emulate xchg for non-SMP MN10300 | ||
72 | */ | ||
73 | struct __xchg_dummy { unsigned long a[100]; }; | ||
74 | #define __xg(x) ((struct __xchg_dummy *)(x)) | ||
75 | |||
76 | static inline | ||
77 | unsigned long __xchg(volatile unsigned long *m, unsigned long val) | ||
78 | { | ||
79 | unsigned long oldval; | ||
80 | unsigned long flags; | ||
81 | |||
82 | flags = arch_local_cli_save(); | ||
83 | oldval = *m; | ||
84 | *m = val; | ||
85 | arch_local_irq_restore(flags); | ||
86 | return oldval; | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * Emulate cmpxchg for non-SMP MN10300 | ||
91 | */ | ||
92 | static inline unsigned long __cmpxchg(volatile unsigned long *m, | ||
93 | unsigned long old, unsigned long new) | ||
94 | { | ||
95 | unsigned long oldval; | ||
96 | unsigned long flags; | ||
97 | |||
98 | flags = arch_local_cli_save(); | ||
99 | oldval = *m; | ||
100 | if (oldval == old) | ||
101 | *m = new; | ||
102 | arch_local_irq_restore(flags); | ||
103 | return oldval; | ||
104 | } | ||
105 | |||
106 | #endif /* CONFIG_SMP */ | ||
107 | |||
108 | #define xchg(ptr, v) \ | ||
109 | ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr), \ | ||
110 | (unsigned long)(v))) | ||
111 | |||
112 | #define cmpxchg(ptr, o, n) \ | ||
113 | ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \ | ||
114 | (unsigned long)(o), \ | ||
115 | (unsigned long)(n))) | ||
116 | |||
117 | #define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) | ||
118 | #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) | ||
119 | |||
120 | #endif /* !__ASSEMBLY__ */ | ||
121 | 16 | ||
122 | #ifndef CONFIG_SMP | 17 | #ifndef CONFIG_SMP |
123 | #include <asm-generic/atomic.h> | 18 | #include <asm-generic/atomic.h> |
@@ -269,6 +164,8 @@ static inline void atomic_dec(atomic_t *v) | |||
269 | c; \ | 164 | c; \ |
270 | }) | 165 | }) |
271 | 166 | ||
167 | #define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) | ||
168 | #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) | ||
272 | 169 | ||
273 | /** | 170 | /** |
274 | * atomic_clear_mask - Atomically clear bits in memory | 171 | * atomic_clear_mask - Atomically clear bits in memory |