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 <linux/uaccess.h>
15 #include <asm/asm-eva.h>
16 #include <asm/barrier.h>
17 #include <asm/errno.h>
20 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
22 if (cpu_has_llsc && R10000_LLSC_WAR) { \
23 __asm__ __volatile__( \
26 " .set arch=r4000 \n" \
27 "1: ll %1, %4 # __futex_atomic_op \n" \
30 " .set arch=r4000 \n" \
37 " .section .fixup,\"ax\" \n" \
41 " .section __ex_table,\"a\" \n" \
42 " "__UA_ADDR "\t1b, 4b \n" \
43 " "__UA_ADDR "\t2b, 4b \n" \
45 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
46 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
48 } else if (cpu_has_llsc) { \
49 __asm__ __volatile__( \
52 " .set arch=r4000 \n" \
53 "1: "user_ll("%1", "%4")" # __futex_atomic_op\n" \
56 " .set arch=r4000 \n" \
57 "2: "user_sc("$1", "%2")" \n" \
63 " .section .fixup,\"ax\" \n" \
67 " .section __ex_table,\"a\" \n" \
68 " "__UA_ADDR "\t1b, 4b \n" \
69 " "__UA_ADDR "\t2b, 4b \n" \
71 : "=r" (ret), "=&r" (oldval), "=R" (*uaddr) \
72 : "0" (0), "R" (*uaddr), "Jr" (oparg), "i" (-EFAULT) \
79 futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
81 int op
= (encoded_op
>> 28) & 7;
82 int cmp
= (encoded_op
>> 24) & 15;
83 int oparg
= (encoded_op
<< 8) >> 20;
84 int cmparg
= (encoded_op
<< 20) >> 20;
86 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
89 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(u32
)))
96 __futex_atomic_op("move $1, %z5", ret
, oldval
, uaddr
, oparg
);
100 __futex_atomic_op("addu $1, %1, %z5",
101 ret
, oldval
, uaddr
, oparg
);
104 __futex_atomic_op("or $1, %1, %z5",
105 ret
, oldval
, uaddr
, oparg
);
108 __futex_atomic_op("and $1, %1, %z5",
109 ret
, oldval
, uaddr
, ~oparg
);
112 __futex_atomic_op("xor $1, %1, %z5",
113 ret
, oldval
, uaddr
, oparg
);
123 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
124 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
125 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
126 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
127 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
128 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
129 default: ret
= -ENOSYS
;
136 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
137 u32 oldval
, u32 newval
)
142 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
145 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
146 __asm__
__volatile__(
147 "# futex_atomic_cmpxchg_inatomic \n"
150 " .set arch=r4000 \n"
152 " bne %1, %z4, 3f \n"
155 " .set arch=r4000 \n"
161 " .section .fixup,\"ax\" \n"
165 " .section __ex_table,\"a\" \n"
166 " "__UA_ADDR
"\t1b, 4b \n"
167 " "__UA_ADDR
"\t2b, 4b \n"
169 : "+r" (ret
), "=&r" (val
), "=R" (*uaddr
)
170 : "R" (*uaddr
), "Jr" (oldval
), "Jr" (newval
), "i" (-EFAULT
)
172 } else if (cpu_has_llsc
) {
173 __asm__
__volatile__(
174 "# futex_atomic_cmpxchg_inatomic \n"
177 " .set arch=r4000 \n"
178 "1: "user_ll("%1", "%3")" \n"
179 " bne %1, %z4, 3f \n"
182 " .set arch=r4000 \n"
183 "2: "user_sc("$1", "%2")" \n"
188 " .section .fixup,\"ax\" \n"
192 " .section __ex_table,\"a\" \n"
193 " "__UA_ADDR
"\t1b, 4b \n"
194 " "__UA_ADDR
"\t2b, 4b \n"
196 : "+r" (ret
), "=&r" (val
), "=R" (*uaddr
)
197 : "R" (*uaddr
), "Jr" (oldval
), "Jr" (newval
), "i" (-EFAULT
)
207 #endif /* _ASM_FUTEX_H */