]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/score/include/asm/cmpxchg.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / arch / score / include / asm / cmpxchg.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_SCORE_CMPXCHG_H
3 #define _ASM_SCORE_CMPXCHG_H
4
5 #include <linux/irqflags.h>
6
7 struct __xchg_dummy { unsigned long a[100]; };
8 #define __xg(x) ((struct __xchg_dummy *)(x))
9
10 static inline
11 unsigned long __xchg(volatile unsigned long *m, unsigned long val)
12 {
13 unsigned long retval;
14 unsigned long flags;
15
16 local_irq_save(flags);
17 retval = *m;
18 *m = val;
19 local_irq_restore(flags);
20 return retval;
21 }
22
23 #define xchg(ptr, v) \
24 ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr), \
25 (unsigned long)(v)))
26
27 static inline unsigned long __cmpxchg(volatile unsigned long *m,
28 unsigned long old, unsigned long new)
29 {
30 unsigned long retval;
31 unsigned long flags;
32
33 local_irq_save(flags);
34 retval = *m;
35 if (retval == old)
36 *m = new;
37 local_irq_restore(flags);
38 return retval;
39 }
40
41 #define cmpxchg(ptr, o, n) \
42 ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
43 (unsigned long)(o), \
44 (unsigned long)(n)))
45
46 #include <asm-generic/cmpxchg-local.h>
47
48 #endif /* _ASM_SCORE_CMPXCHG_H */