diff options
author | Jaroslav Kysela <perex@tm8103> | 2005-11-07 05:02:51 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@tm8103> | 2005-11-07 05:02:51 -0500 |
commit | 1d4ae4a119e5ba711f12b05cdf27f794460add4b (patch) | |
tree | 13a196ce55115d8f64acf0db86314f5abc847b40 /include/asm-powerpc/futex.h | |
parent | c2f2f0fa3829a8da1e029346c4f7e8da82f95d62 (diff) | |
parent | 0b154bb7d0cce80e9c0bcf11d4f9e71b59409d26 (diff) |
Merge with rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Diffstat (limited to 'include/asm-powerpc/futex.h')
-rw-r--r-- | include/asm-powerpc/futex.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/include/asm-powerpc/futex.h b/include/asm-powerpc/futex.h new file mode 100644 index 000000000000..37c94e52ab6d --- /dev/null +++ b/include/asm-powerpc/futex.h | |||
@@ -0,0 +1,84 @@ | |||
1 | #ifndef _ASM_POWERPC_FUTEX_H | ||
2 | #define _ASM_POWERPC_FUTEX_H | ||
3 | |||
4 | #ifdef __KERNEL__ | ||
5 | |||
6 | #include <linux/futex.h> | ||
7 | #include <asm/errno.h> | ||
8 | #include <asm/synch.h> | ||
9 | #include <asm/uaccess.h> | ||
10 | #include <asm/ppc_asm.h> | ||
11 | |||
12 | #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \ | ||
13 | __asm__ __volatile ( \ | ||
14 | SYNC_ON_SMP \ | ||
15 | "1: lwarx %0,0,%2\n" \ | ||
16 | insn \ | ||
17 | "2: stwcx. %1,0,%2\n" \ | ||
18 | "bne- 1b\n" \ | ||
19 | "li %1,0\n" \ | ||
20 | "3: .section .fixup,\"ax\"\n" \ | ||
21 | "4: li %1,%3\n" \ | ||
22 | "b 3b\n" \ | ||
23 | ".previous\n" \ | ||
24 | ".section __ex_table,\"a\"\n" \ | ||
25 | ".align 3\n" \ | ||
26 | DATAL " 1b,4b,2b,4b\n" \ | ||
27 | ".previous" \ | ||
28 | : "=&r" (oldval), "=&r" (ret) \ | ||
29 | : "b" (uaddr), "i" (-EFAULT), "1" (oparg) \ | ||
30 | : "cr0", "memory") | ||
31 | |||
32 | static inline int futex_atomic_op_inuser (int encoded_op, int __user *uaddr) | ||
33 | { | ||
34 | int op = (encoded_op >> 28) & 7; | ||
35 | int cmp = (encoded_op >> 24) & 15; | ||
36 | int oparg = (encoded_op << 8) >> 20; | ||
37 | int cmparg = (encoded_op << 20) >> 20; | ||
38 | int oldval = 0, ret; | ||
39 | if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) | ||
40 | oparg = 1 << oparg; | ||
41 | |||
42 | if (! access_ok (VERIFY_WRITE, uaddr, sizeof(int))) | ||
43 | return -EFAULT; | ||
44 | |||
45 | inc_preempt_count(); | ||
46 | |||
47 | switch (op) { | ||
48 | case FUTEX_OP_SET: | ||
49 | __futex_atomic_op("", ret, oldval, uaddr, oparg); | ||
50 | break; | ||
51 | case FUTEX_OP_ADD: | ||
52 | __futex_atomic_op("add %1,%0,%1\n", ret, oldval, uaddr, oparg); | ||
53 | break; | ||
54 | case FUTEX_OP_OR: | ||
55 | __futex_atomic_op("or %1,%0,%1\n", ret, oldval, uaddr, oparg); | ||
56 | break; | ||
57 | case FUTEX_OP_ANDN: | ||
58 | __futex_atomic_op("andc %1,%0,%1\n", ret, oldval, uaddr, oparg); | ||
59 | break; | ||
60 | case FUTEX_OP_XOR: | ||
61 | __futex_atomic_op("xor %1,%0,%1\n", ret, oldval, uaddr, oparg); | ||
62 | break; | ||
63 | default: | ||
64 | ret = -ENOSYS; | ||
65 | } | ||
66 | |||
67 | dec_preempt_count(); | ||
68 | |||
69 | if (!ret) { | ||
70 | switch (cmp) { | ||
71 | case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break; | ||
72 | case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break; | ||
73 | case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break; | ||
74 | case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break; | ||
75 | case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break; | ||
76 | case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break; | ||
77 | default: ret = -ENOSYS; | ||
78 | } | ||
79 | } | ||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | #endif /* __KERNEL__ */ | ||
84 | #endif /* _ASM_POWERPC_FUTEX_H */ | ||