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_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
30 " prfm pstl1strm, %2\n" \
33 "2: stlxr %w3, %w0, %2\n" \
37 " .pushsection .fixup,\"ax\"\n" \
42 _ASM_EXTABLE(1b, 4b) \
43 _ASM_EXTABLE(2b, 4b) \
44 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp) \
45 : "r" (oparg), "Ir" (-EFAULT) \
51 arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *_uaddr)
53 int oldval = 0, ret, tmp;
54 u32 __user *uaddr = __uaccess_mask_ptr(_uaddr);
60 __futex_atomic_op("mov %w0, %w4",
61 ret, oldval, uaddr, tmp, oparg);
64 __futex_atomic_op("add %w0, %w1, %w4",
65 ret, oldval, uaddr, tmp, oparg);
68 __futex_atomic_op("orr %w0, %w1, %w4",
69 ret, oldval, uaddr, tmp, oparg);
72 __futex_atomic_op("and %w0, %w1, %w4",
73 ret, oldval, uaddr, tmp, ~oparg);
76 __futex_atomic_op("eor %w0, %w1, %w4",
77 ret, oldval, uaddr, tmp, oparg);
92 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *_uaddr,
93 u32 oldval, u32 newval)
99 if (!access_ok(VERIFY_WRITE, _uaddr, sizeof(u32)))
102 uaddr = __uaccess_mask_ptr(_uaddr);
104 asm volatile("// futex_atomic_cmpxchg_inatomic\n"
105 " prfm pstl1strm, %2\n"
107 " sub %w3, %w1, %w4\n"
109 "2: stlxr %w3, %w5, %2\n"
113 " .pushsection .fixup,\"ax\"\n"
119 : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
120 : "r" (oldval), "r" (newval), "Ir" (-EFAULT)
128 #endif /* __KERNEL__ */
129 #endif /* __ASM_FUTEX_H */