1 #ifndef _ASM_POWERPC_FUTEX_H
2 #define _ASM_POWERPC_FUTEX_H
6 #include <linux/futex.h>
7 #include <linux/uaccess.h>
10 #include <asm/asm-compat.h>
12 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
13 __asm__ __volatile ( \
14 PPC_ATOMIC_ENTRY_BARRIER \
15 "1: lwarx %0,0,%2\n" \
18 "2: stwcx. %1,0,%2\n" \
20 PPC_ATOMIC_EXIT_BARRIER \
22 "3: .section .fixup,\"ax\"\n" \
26 ".section __ex_table,\"a\"\n" \
28 PPC_LONG "1b,4b,2b,4b\n" \
30 : "=&r" (oldval), "=&r" (ret) \
31 : "b" (uaddr), "i" (-EFAULT), "r" (oparg) \
34 static inline int futex_atomic_op_inuser (int encoded_op
, u32 __user
*uaddr
)
36 int op
= (encoded_op
>> 28) & 7;
37 int cmp
= (encoded_op
>> 24) & 15;
38 int oparg
= (encoded_op
<< 8) >> 20;
39 int cmparg
= (encoded_op
<< 20) >> 20;
41 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
44 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(u32
)))
51 __futex_atomic_op("mr %1,%4\n", ret
, oldval
, uaddr
, oparg
);
54 __futex_atomic_op("add %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
57 __futex_atomic_op("or %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
60 __futex_atomic_op("andc %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
63 __futex_atomic_op("xor %1,%0,%4\n", ret
, oldval
, uaddr
, oparg
);
73 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
74 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
75 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
76 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
77 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
78 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
79 default: ret
= -ENOSYS
;
86 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
87 u32 oldval
, u32 newval
)
92 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
95 __asm__
__volatile__ (
96 PPC_ATOMIC_ENTRY_BARRIER
97 "1: lwarx %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
101 "2: stwcx. %5,0,%3\n\
103 PPC_ATOMIC_EXIT_BARRIER
104 "3: .section .fixup,\"ax\"\n\
108 .section __ex_table,\"a\"\n\
110 " PPC_LONG
"1b,4b,2b,4b\n\
112 : "+r" (ret
), "=&r" (prev
), "+m" (*uaddr
)
113 : "r" (uaddr
), "r" (oldval
), "r" (newval
), "i" (-EFAULT
)
120 #endif /* __KERNEL__ */
121 #endif /* _ASM_POWERPC_FUTEX_H */