1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_FUTEX_H
3 #define _ASM_POWERPC_FUTEX_H
7 #include <linux/futex.h>
8 #include <linux/uaccess.h>
10 #include <asm/synch.h>
11 #include <asm/asm-405.h>
13 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
14 __asm__ __volatile ( \
15 PPC_ATOMIC_ENTRY_BARRIER \
16 "1: lwarx %0,0,%2\n" \
19 "2: stwcx. %1,0,%2\n" \
21 PPC_ATOMIC_EXIT_BARRIER \
23 "3: .section .fixup,\"ax\"\n" \
29 : "=&r" (oldval), "=&r" (ret) \
30 : "b" (uaddr), "i" (-EFAULT), "r" (oparg) \
33 static inline int arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
,
38 allow_write_to_user(uaddr
, sizeof(*uaddr
));
43 __futex_atomic_op("mr %1,%4\n", ret
, oldval
, uaddr
, oparg
);
46 __futex_atomic_op("add %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
49 __futex_atomic_op("or %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
52 __futex_atomic_op("andc %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
55 __futex_atomic_op("xor %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
65 prevent_write_to_user(uaddr
, sizeof(*uaddr
));
70 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
71 u32 oldval
, u32 newval
)
76 if (!access_ok(uaddr
, sizeof(u32
)))
79 allow_write_to_user(uaddr
, sizeof(*uaddr
));
80 __asm__
__volatile__ (
81 PPC_ATOMIC_ENTRY_BARRIER
82 "1: lwarx %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
88 PPC_ATOMIC_EXIT_BARRIER
89 "3: .section .fixup,\"ax\"\n\
95 : "+r" (ret
), "=&r" (prev
), "+m" (*uaddr
)
96 : "r" (uaddr
), "r" (oldval
), "r" (newval
), "i" (-EFAULT
)
100 prevent_write_to_user(uaddr
, sizeof(*uaddr
));
104 #endif /* __KERNEL__ */
105 #endif /* _ASM_POWERPC_FUTEX_H */