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 if (!access_ok(uaddr
, sizeof(u32
)))
81 #ifndef CONFIG_ARC_HAS_LLSC
82 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
87 __futex_atomic_op("mov %0, %3", ret
, oldval
, uaddr
, oparg
);
90 /* oldval = *uaddr; *uaddr += oparg ; ret = *uaddr */
91 __futex_atomic_op("add %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
94 __futex_atomic_op("or %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
97 __futex_atomic_op("bic %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
100 __futex_atomic_op("xor %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
106 #ifndef CONFIG_ARC_HAS_LLSC
117 * cmpxchg of futex (pagefaults disabled by caller)
118 * Return 0 for success, -EFAULT otherwise
121 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
, u32 expval
,
127 if (!access_ok(uaddr
, sizeof(u32
)))
130 #ifndef CONFIG_ARC_HAS_LLSC
131 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
135 __asm__
__volatile__(
136 #ifdef CONFIG_ARC_HAS_LLSC
137 "1: llock %1, [%4] \n"
138 " brne %1, %2, 3f \n"
139 "2: scond %3, [%4] \n"
143 " brne %1, %2, 3f \n"
147 " .section .fixup,\"ax\" \n"
151 " .section __ex_table,\"a\" \n"
156 : "+&r"(ret
), "=&r"(existval
)
157 : "r"(expval
), "r"(newval
), "r"(uaddr
), "ir"(-EFAULT
)
162 #ifndef CONFIG_ARC_HAS_LLSC