1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
8 #include <linux/futex.h>
9 #include <linux/uaccess.h>
10 #include <asm/asm-extable.h>
11 #include <asm/barrier.h>
12 #include <asm/errno.h>
14 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
16 __asm__ __volatile__( \
17 "1: ll.w %1, %4 # __futex_atomic_op\n" \
19 "2: sc.w $t0, %2 \n" \
22 _ASM_EXTABLE_UACCESS_ERR(1b, 3b, %0) \
23 _ASM_EXTABLE_UACCESS_ERR(2b, 3b, %0) \
24 : "=r" (ret), "=&r" (oldval), \
26 : "0" (0), "ZC" (*uaddr), "Jr" (oparg) \
31 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*uaddr
)
33 int oldval
= 0, ret
= 0;
39 __futex_atomic_op("move $t0, %z5", ret
, oldval
, uaddr
, oparg
);
42 __futex_atomic_op("add.w $t0, %1, %z5", ret
, oldval
, uaddr
, oparg
);
45 __futex_atomic_op("or $t0, %1, %z5", ret
, oldval
, uaddr
, oparg
);
48 __futex_atomic_op("and $t0, %1, %z5", ret
, oldval
, uaddr
, ~oparg
);
51 __futex_atomic_op("xor $t0, %1, %z5", ret
, oldval
, uaddr
, oparg
);
66 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
, u32 oldval
, u32 newval
)
71 if (!access_ok(uaddr
, sizeof(u32
)))
75 "# futex_atomic_cmpxchg_inatomic \n"
83 _ASM_EXTABLE_UACCESS_ERR(1b
, 3b
, %0)
84 _ASM_EXTABLE_UACCESS_ERR(2b
, 3b
, %0)
85 : "+r" (ret
), "=&r" (val
), "=ZC" (*uaddr
)
86 : "ZC" (*uaddr
), "Jr" (oldval
), "Jr" (newval
)
94 #endif /* _ASM_FUTEX_H */