1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 ARM Ltd.
8 #include <linux/futex.h>
9 #include <linux/uaccess.h>
11 #include <asm/errno.h>
13 #define FUTEX_MAX_LOOPS 128 /* What's the largest number you can think of? */
15 #define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
17 unsigned int loops = FUTEX_MAX_LOOPS; \
21 " prfm pstl1strm, %2\n" \
24 "2: stlxr %w0, %w3, %2\n" \
26 " sub %w4, %w4, %w0\n" \
31 " .pushsection .fixup,\"ax\"\n" \
36 _ASM_EXTABLE(1b, 4b) \
37 _ASM_EXTABLE(2b, 4b) \
38 : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp), \
40 : "r" (oparg), "Ir" (-EFAULT), "Ir" (-EAGAIN) \
46 arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
, u32 __user
*_uaddr
)
48 int oldval
= 0, ret
, tmp
;
49 u32 __user
*uaddr
= __uaccess_mask_ptr(_uaddr
);
55 __futex_atomic_op("mov %w3, %w5",
56 ret
, oldval
, uaddr
, tmp
, oparg
);
59 __futex_atomic_op("add %w3, %w1, %w5",
60 ret
, oldval
, uaddr
, tmp
, oparg
);
63 __futex_atomic_op("orr %w3, %w1, %w5",
64 ret
, oldval
, uaddr
, tmp
, oparg
);
67 __futex_atomic_op("and %w3, %w1, %w5",
68 ret
, oldval
, uaddr
, tmp
, ~oparg
);
71 __futex_atomic_op("eor %w3, %w1, %w5",
72 ret
, oldval
, uaddr
, tmp
, oparg
);
87 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*_uaddr
,
88 u32 oldval
, u32 newval
)
91 unsigned int loops
= FUTEX_MAX_LOOPS
;
95 if (!access_ok(_uaddr
, sizeof(u32
)))
98 uaddr
= __uaccess_mask_ptr(_uaddr
);
100 asm volatile("// futex_atomic_cmpxchg_inatomic\n"
101 " prfm pstl1strm, %2\n"
103 " sub %w3, %w1, %w5\n"
105 "2: stlxr %w3, %w6, %2\n"
107 " sub %w4, %w4, %w3\n"
113 " .pushsection .fixup,\"ax\"\n"
119 : "+r" (ret
), "=&r" (val
), "+Q" (*uaddr
), "=&r" (tmp
), "+r" (loops
)
120 : "r" (oldval
), "r" (newval
), "Ir" (-EFAULT
), "Ir" (-EAGAIN
)
130 #endif /* __ASM_FUTEX_H */