1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_METAG_CMPXCHG_LOCK1_H
3 #define __ASM_METAG_CMPXCHG_LOCK1_H
4
5 #include <asm/global_lock.h>
6
7 /* Use LOCK2 as these have to be atomic w.r.t. ordinary accesses. */
8
xchg_u32(volatile u32 * m,unsigned long val)9 static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
10 {
11 unsigned long flags, retval;
12
13 __global_lock2(flags);
14 fence();
15 retval = *m;
16 *m = val;
17 __global_unlock2(flags);
18 return retval;
19 }
20
xchg_u8(volatile u8 * m,unsigned long val)21 static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
22 {
23 unsigned long flags, retval;
24
25 __global_lock2(flags);
26 fence();
27 retval = *m;
28 *m = val & 0xff;
29 __global_unlock2(flags);
30 return retval;
31 }
32
__cmpxchg_u32(volatile int * m,unsigned long old,unsigned long new)33 static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
34 unsigned long new)
35 {
36 __u32 retval;
37 unsigned long flags;
38
39 __global_lock2(flags);
40 retval = *m;
41 if (retval == old) {
42 fence();
43 *m = new;
44 }
45 __global_unlock2(flags);
46 return retval;
47 }
48
49 #endif /* __ASM_METAG_CMPXCHG_LOCK1_H */
50