]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/metag/include/asm/cmpxchg_lock1.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / arch / metag / include / asm / cmpxchg_lock1.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6006c0d8
JH
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
9static 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
21static 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
33static 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 */