1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5 * Vineetg: August 2010: From Android kernel work
11 #include <linux/futex.h>
12 #include <linux/preempt.h>
13 #include <linux/uaccess.h>
14 #include <asm/errno.h>
16 #ifdef CONFIG_ARC_HAS_LLSC
18 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
21 __asm__ __volatile__( \
22 "1: llock %1, [%2] \n" \
24 "2: scond %0, [%2] \n" \
28 " .section .fixup,\"ax\" \n" \
33 " .section __ex_table,\"a\" \n" \
39 : "=&r" (ret), "=&r" (oldval) \
40 : "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
44 #else /* !CONFIG_ARC_HAS_LLSC */
46 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
49 __asm__ __volatile__( \
55 " .section .fixup,\"ax\" \n" \
60 " .section __ex_table,\"a\" \n" \
66 : "=&r" (ret), "=&r" (oldval) \
67 : "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
73 static inline int arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
,
78 #ifndef CONFIG_ARC_HAS_LLSC
79 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
85 __futex_atomic_op("mov %0, %3", ret
, oldval
, uaddr
, oparg
);
88 /* oldval = *uaddr; *uaddr += oparg ; ret = *uaddr */
89 __futex_atomic_op("add %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
92 __futex_atomic_op("or %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
95 __futex_atomic_op("bic %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
98 __futex_atomic_op("xor %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
105 #ifndef CONFIG_ARC_HAS_LLSC
116 * cmpxchg of futex (pagefaults disabled by caller)
117 * Return 0 for success, -EFAULT otherwise
120 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
, u32 expval
,
126 if (!access_ok(uaddr
, sizeof(u32
)))
129 #ifndef CONFIG_ARC_HAS_LLSC
130 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
134 __asm__
__volatile__(
135 #ifdef CONFIG_ARC_HAS_LLSC
136 "1: llock %1, [%4] \n"
137 " brne %1, %2, 3f \n"
138 "2: scond %3, [%4] \n"
142 " brne %1, %2, 3f \n"
146 " .section .fixup,\"ax\" \n"
150 " .section __ex_table,\"a\" \n"
155 : "+&r"(ret
), "=&r"(existval
)
156 : "r"(expval
), "r"(newval
), "r"(uaddr
), "ir"(-EFAULT
)
161 #ifndef CONFIG_ARC_HAS_LLSC