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 arch_futex_atomic_op_inuser arch_futex_atomic_op_inuser
22 #define futex_atomic_cmpxchg_inatomic futex_atomic_cmpxchg_inatomic
23 #include <asm-generic/futex.h>
25 #define __futex_atomic_op(op, insn, ret, oldval, uaddr, oparg) \
27 if (cpu_has_llsc && IS_ENABLED(CONFIG_WAR_R10000_LLSC)) { \
28 __asm__ __volatile__( \
32 " .set arch=r4000 \n" \
33 "1: ll %1, %4 # __futex_atomic_op \n" \
36 " .set arch=r4000 \n" \
39 __stringify(__WEAK_LLSC_MB) " \n" \
43 " .section .fixup,\"ax\" \n" \
47 " .section __ex_table,\"a\" \n" \
48 " "__UA_ADDR "\t1b, 4b \n" \
49 " "__UA_ADDR "\t2b, 4b \n" \
51 : "=r" (ret), "=&r" (oldval), \
52 "=" GCC_OFF_SMALL_ASM() (*uaddr) \
53 : "0" (0), GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oparg), \
56 } else if (cpu_has_llsc) { \
57 __asm__ __volatile__( \
61 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
62 " " __SYNC(full, loongson3_war) " \n" \
63 "1: "user_ll("%1", "%4")" # __futex_atomic_op\n" \
66 " .set "MIPS_ISA_ARCH_LEVEL" \n" \
67 "2: "user_sc("$1", "%2")" \n" \
69 __stringify(__WEAK_LLSC_MB) " \n" \
73 " .section .fixup,\"ax\" \n" \
77 " .section __ex_table,\"a\" \n" \
78 " "__UA_ADDR "\t1b, 4b \n" \
79 " "__UA_ADDR "\t2b, 4b \n" \
81 : "=r" (ret), "=&r" (oldval), \
82 "=" GCC_OFF_SMALL_ASM() (*uaddr) \
83 : "0" (0), GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oparg), \
87 /* fallback for non-SMP */ \
88 ret = futex_atomic_op_inuser_local(op, oparg, oval, uaddr); \
93 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*uaddr
)
97 if (!access_ok(uaddr
, sizeof(u32
)))
102 __futex_atomic_op(op
, "move $1, %z5", ret
, oldval
, uaddr
, oparg
);
106 __futex_atomic_op(op
, "addu $1, %1, %z5",
107 ret
, oldval
, uaddr
, oparg
);
110 __futex_atomic_op(op
, "or $1, %1, %z5",
111 ret
, oldval
, uaddr
, oparg
);
114 __futex_atomic_op(op
, "and $1, %1, %z5",
115 ret
, oldval
, uaddr
, ~oparg
);
118 __futex_atomic_op(op
, "xor $1, %1, %z5",
119 ret
, oldval
, uaddr
, oparg
);
132 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
133 u32 oldval
, u32 newval
)
138 if (!access_ok(uaddr
, sizeof(u32
)))
141 if (cpu_has_llsc
&& IS_ENABLED(CONFIG_WAR_R10000_LLSC
)) {
142 __asm__
__volatile__(
143 "# futex_atomic_cmpxchg_inatomic \n"
147 " .set arch=r4000 \n"
149 " bne %1, %z4, 3f \n"
152 " .set arch=r4000 \n"
155 __stringify(__WEAK_LLSC_MB
) " \n"
159 " .section .fixup,\"ax\" \n"
163 " .section __ex_table,\"a\" \n"
164 " "__UA_ADDR
"\t1b, 4b \n"
165 " "__UA_ADDR
"\t2b, 4b \n"
167 : "+r" (ret
), "=&r" (val
), "=" GCC_OFF_SMALL_ASM() (*uaddr
)
168 : GCC_OFF_SMALL_ASM() (*uaddr
), "Jr" (oldval
), "Jr" (newval
),
171 } else if (cpu_has_llsc
) {
172 __asm__
__volatile__(
173 "# futex_atomic_cmpxchg_inatomic \n"
177 " .set "MIPS_ISA_ARCH_LEVEL
" \n"
178 " " __SYNC(full
, loongson3_war
) " \n"
179 "1: "user_ll("%1", "%3")" \n"
180 " bne %1, %z4, 3f \n"
183 " .set "MIPS_ISA_ARCH_LEVEL
" \n"
184 "2: "user_sc("$1", "%2")" \n"
186 "3: " __SYNC_ELSE(full
, loongson3_war
, __WEAK_LLSC_MB
) "\n"
189 " .section .fixup,\"ax\" \n"
193 " .section __ex_table,\"a\" \n"
194 " "__UA_ADDR
"\t1b, 4b \n"
195 " "__UA_ADDR
"\t2b, 4b \n"
197 : "+r" (ret
), "=&r" (val
), "=" GCC_OFF_SMALL_ASM() (*uaddr
)
198 : GCC_OFF_SMALL_ASM() (*uaddr
), "Jr" (oldval
), "Jr" (newval
),
202 return futex_atomic_cmpxchg_inatomic_local(uval
, uaddr
, oldval
, newval
);
210 #endif /* _ASM_FUTEX_H */