2 * Copyright (C) 2012 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/futex.h>
22 #include <linux/uaccess.h>
24 #include <asm/errno.h>
26 #define FUTEX_MAX_LOOPS 128 /* What's the largest number you can think of? */
28 #define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
30 unsigned int loops = FUTEX_MAX_LOOPS; \
34 " prfm pstl1strm, %2\n" \
37 "2: stlxr %w0, %w3, %2\n" \
39 " sub %w4, %w4, %w0\n" \
44 " .pushsection .fixup,\"ax\"\n" \
49 _ASM_EXTABLE(1b, 4b) \
50 _ASM_EXTABLE(2b, 4b) \
51 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp), \
53 : "r" (oparg), "Ir" (-EFAULT), "Ir" (-EAGAIN) \
59 arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *_uaddr)
61 int oldval = 0, ret, tmp;
62 u32 __user *uaddr = __uaccess_mask_ptr(_uaddr);
68 __futex_atomic_op("mov %w3, %w5",
69 ret, oldval, uaddr, tmp, oparg);
72 __futex_atomic_op("add %w3, %w1, %w5",
73 ret, oldval, uaddr, tmp, oparg);
76 __futex_atomic_op("orr %w3, %w1, %w5",
77 ret, oldval, uaddr, tmp, oparg);
80 __futex_atomic_op("and %w3, %w1, %w5",
81 ret, oldval, uaddr, tmp, ~oparg);
84 __futex_atomic_op("eor %w3, %w1, %w5",
85 ret, oldval, uaddr, tmp, oparg);
100 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *_uaddr,
101 u32 oldval, u32 newval)
104 unsigned int loops = FUTEX_MAX_LOOPS;
108 if (!access_ok(_uaddr, sizeof(u32)))
111 uaddr = __uaccess_mask_ptr(_uaddr);
113 asm volatile("// futex_atomic_cmpxchg_inatomic\n"
114 " prfm pstl1strm, %2\n"
116 " sub %w3, %w1, %w5\n"
118 "2: stlxr %w3, %w6, %2\n"
120 " sub %w4, %w4, %w3\n"
126 " .pushsection .fixup,\"ax\"\n"
132 : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp), "+r" (loops)
133 : "r" (oldval), "r" (newval), "Ir" (-EFAULT), "Ir" (-EAGAIN)
143 #endif /* __KERNEL__ */
144 #endif /* __ASM_FUTEX_H */