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/compiler.h>
18 #include <asm/errno.h>
21 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
23 if (cpu_has_llsc && R10000_LLSC_WAR) { \
24 __asm__ __volatile__( \
27 " .set arch=r4000 \n" \
28 "1: ll %1, %4 # __futex_atomic_op \n" \
31 " .set arch=r4000 \n" \
39 " .section .fixup,\"ax\" \n" \
43 " .section __ex_table,\"a\" \n" \
44 " "__UA_ADDR "\t1b, 4b \n" \
45 " "__UA_ADDR "\t2b, 4b \n" \
47 : "=r" (ret), "=&r" (oldval), \
48 "=" GCC_OFF_SMALL_ASM() (*uaddr) \
49 : "0" (0), GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oparg), \
52 } else if (cpu_has_llsc) { \
53 __asm__ __volatile__( \
56 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
57 "1: "user_ll("%1", "%4")" # __futex_atomic_op\n" \
60 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
61 "2: "user_sc("$1", "%2")" \n" \
68 " .section .fixup,\"ax\" \n" \
72 " .section __ex_table,\"a\" \n" \
73 " "__UA_ADDR "\t1b, 4b \n" \
74 " "__UA_ADDR "\t2b, 4b \n" \
76 : "=r" (ret), "=&r" (oldval), \
77 "=" GCC_OFF_SMALL_ASM() (*uaddr) \
78 : "0" (0), GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oparg), \
86 futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
88 int op
= (encoded_op
>> 28) & 7;
89 int cmp
= (encoded_op
>> 24) & 15;
90 int oparg
= (encoded_op
<< 8) >> 20;
91 int cmparg
= (encoded_op
<< 20) >> 20;
93 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
96 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(u32
)))
103 __futex_atomic_op("move $1, %z5", ret
, oldval
, uaddr
, oparg
);
107 __futex_atomic_op("addu $1, %1, %z5",
108 ret
, oldval
, uaddr
, oparg
);
111 __futex_atomic_op("or $1, %1, %z5",
112 ret
, oldval
, uaddr
, oparg
);
115 __futex_atomic_op("and $1, %1, %z5",
116 ret
, oldval
, uaddr
, ~oparg
);
119 __futex_atomic_op("xor $1, %1, %z5",
120 ret
, oldval
, uaddr
, oparg
);
130 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
131 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
132 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
133 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
134 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
135 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
136 default: ret
= -ENOSYS
;
143 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
144 u32 oldval
, u32 newval
)
149 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
152 if (cpu_has_llsc
&& R10000_LLSC_WAR
) {
153 __asm__
__volatile__(
154 "# futex_atomic_cmpxchg_inatomic \n"
157 " .set arch=r4000 \n"
159 " bne %1, %z4, 3f \n"
162 " .set arch=r4000 \n"
169 " .section .fixup,\"ax\" \n"
173 " .section __ex_table,\"a\" \n"
174 " "__UA_ADDR
"\t1b, 4b \n"
175 " "__UA_ADDR
"\t2b, 4b \n"
177 : "+r" (ret
), "=&r" (val
), "=" GCC_OFF_SMALL_ASM() (*uaddr
)
178 : GCC_OFF_SMALL_ASM() (*uaddr
), "Jr" (oldval
), "Jr" (newval
),
181 } else if (cpu_has_llsc
) {
182 __asm__
__volatile__(
183 "# futex_atomic_cmpxchg_inatomic \n"
186 " .set "MIPS_ISA_ARCH_LEVEL
" \n"
187 "1: "user_ll("%1", "%3")" \n"
188 " bne %1, %z4, 3f \n"
191 " .set "MIPS_ISA_ARCH_LEVEL
" \n"
192 "2: "user_sc("$1", "%2")" \n"
198 " .section .fixup,\"ax\" \n"
202 " .section __ex_table,\"a\" \n"
203 " "__UA_ADDR
"\t1b, 4b \n"
204 " "__UA_ADDR
"\t2b, 4b \n"
206 : "+r" (ret
), "=&r" (val
), "=" GCC_OFF_SMALL_ASM() (*uaddr
)
207 : GCC_OFF_SMALL_ASM() (*uaddr
), "Jr" (oldval
), "Jr" (newval
),
218 #endif /* _ASM_FUTEX_H */