2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 2006 Ralf Baechle (ralf@linux-mips.org)
13 #include <linux/futex.h>
14 #include <asm/barrier.h>
15 #include <asm/errno.h>
16 #include <asm/uaccess.h>
19 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
21 if (cpu_has_llsc && R10000_LLSC_WAR) { \
22 __asm__ __volatile__( \
26 "1: ll %1, %4 # __futex_atomic_op \n" \
36 " .section .fixup,\"ax\" \n" \
40 " .section __ex_table,\"a\" \n" \
41 " "__UA_ADDR "\t1b, 4b \n" \
42 " "__UA_ADDR "\t2b, 4b \n" \
44 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
45 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
47 } else if (cpu_has_llsc) { \
48 __asm__ __volatile__( \
52 "1: ll %1, %4 # __futex_atomic_op \n" \
62 " .section .fixup,\"ax\" \n" \
66 " .section __ex_table,\"a\" \n" \
67 " "__UA_ADDR "\t1b, 4b \n" \
68 " "__UA_ADDR "\t2b, 4b \n" \
70 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
71 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
78 futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
80 int op = (encoded_op >> 28) & 7;
81 int cmp = (encoded_op >> 24) & 15;
82 int oparg = (encoded_op << 8) >> 20;
83 int cmparg = (encoded_op << 20) >> 20;
85 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
88 if (! access_ok (VERIFY_WRITE, uaddr, sizeof(int)))
95 __futex_atomic_op("move $1, %z5", ret, oldval, uaddr, oparg);
99 __futex_atomic_op("addu $1, %1, %z5",
100 ret, oldval, uaddr, oparg);
103 __futex_atomic_op("or $1, %1, %z5",
104 ret, oldval, uaddr, oparg);
107 __futex_atomic_op("and $1, %1, %z5",
108 ret, oldval, uaddr, ~oparg);
111 __futex_atomic_op("xor $1, %1, %z5",
112 ret, oldval, uaddr, oparg);
122 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
123 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
124 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
125 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
126 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
127 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
128 default: ret = -ENOSYS;
135 futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
139 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
142 if (cpu_has_llsc && R10000_LLSC_WAR) {
143 __asm__ __volatile__(
144 "# futex_atomic_cmpxchg_inatomic \n"
149 " bne %0, %z3, 3f \n"
158 " .section .fixup,\"ax\" \n"
162 " .section __ex_table,\"a\" \n"
163 " "__UA_ADDR "\t1b, 4b \n"
164 " "__UA_ADDR "\t2b, 4b \n"
166 : "=&r" (retval), "=R" (*uaddr)
167 : "R" (*uaddr), "Jr" (oldval), "Jr" (newval), "i" (-EFAULT)
169 } else if (cpu_has_llsc) {
170 __asm__ __volatile__(
171 "# futex_atomic_cmpxchg_inatomic \n"
176 " bne %0, %z3, 3f \n"
185 " .section .fixup,\"ax\" \n"
189 " .section __ex_table,\"a\" \n"
190 " "__UA_ADDR "\t1b, 4b \n"
191 " "__UA_ADDR "\t2b, 4b \n"
193 : "=&r" (retval), "=R" (*uaddr)
194 : "R" (*uaddr), "Jr" (oldval), "Jr" (newval), "i" (-EFAULT)