Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 1 | #ifndef __ASM_SH_FUTEX_H |
| 2 | #define __ASM_SH_FUTEX_H |
Jakub Jelinek | 4732efb | 2005-09-06 15:16:25 -0700 | [diff] [blame] | 3 | |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 4 | #ifdef __KERNEL__ |
Jakub Jelinek | 4732efb | 2005-09-06 15:16:25 -0700 | [diff] [blame] | 5 | |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 6 | #include <linux/futex.h> |
Jeff Dike | 730f412 | 2008-04-30 00:54:49 -0700 | [diff] [blame] | 7 | #include <linux/uaccess.h> |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 8 | #include <asm/errno.h> |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 9 | |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 10 | #if !defined(CONFIG_SMP) |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 11 | #include <asm/futex-irq.h> |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 12 | #elif defined(CONFIG_CPU_J2) |
| 13 | #include <asm/futex-cas.h> |
| 14 | #elif defined(CONFIG_CPU_SH4A) |
| 15 | #include <asm/futex-llsc.h> |
| 16 | #else |
| 17 | #error SMP not supported on this configuration. |
| 18 | #endif |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 19 | |
| 20 | static inline int |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame] | 21 | futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, |
| 22 | u32 oldval, u32 newval) |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 23 | { |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame] | 24 | if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 25 | return -EFAULT; |
| 26 | |
Michel Lespinasse | 37a9d91 | 2011-03-10 18:48:51 -0800 | [diff] [blame] | 27 | return atomic_futex_op_cmpxchg_inatomic(uval, uaddr, oldval, newval); |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 28 | } |
| 29 | |
Jiri Slaby | 30d6e0a | 2017-08-24 09:31:05 +0200 | [diff] [blame] | 30 | static inline int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, |
| 31 | u32 __user *uaddr) |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 32 | { |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 33 | u32 oldval, newval, prev; |
| 34 | int ret; |
| 35 | |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 36 | pagefault_disable(); |
| 37 | |
| 38 | do { |
| 39 | if (op == FUTEX_OP_SET) |
| 40 | ret = oldval = 0; |
| 41 | else |
| 42 | ret = get_user(oldval, uaddr); |
| 43 | |
| 44 | if (ret) break; |
| 45 | |
| 46 | switch (op) { |
| 47 | case FUTEX_OP_SET: |
| 48 | newval = oparg; |
| 49 | break; |
| 50 | case FUTEX_OP_ADD: |
| 51 | newval = oldval + oparg; |
| 52 | break; |
| 53 | case FUTEX_OP_OR: |
| 54 | newval = oldval | oparg; |
| 55 | break; |
| 56 | case FUTEX_OP_ANDN: |
| 57 | newval = oldval & ~oparg; |
| 58 | break; |
| 59 | case FUTEX_OP_XOR: |
| 60 | newval = oldval ^ oparg; |
| 61 | break; |
| 62 | default: |
| 63 | ret = -ENOSYS; |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | if (ret) break; |
| 68 | |
| 69 | ret = futex_atomic_cmpxchg_inatomic(&prev, uaddr, oldval, newval); |
| 70 | } while (!ret && prev != oldval); |
| 71 | |
| 72 | pagefault_enable(); |
| 73 | |
Jiri Slaby | 30d6e0a | 2017-08-24 09:31:05 +0200 | [diff] [blame] | 74 | if (!ret) |
| 75 | *oval = oldval; |
Rich Felker | 00b73d8 | 2016-04-25 21:58:03 +0000 | [diff] [blame] | 76 | |
| 77 | return ret; |
| 78 | } |
| 79 | |
Kaz Kojima | fc1d4c9 | 2007-06-18 13:58:32 +0900 | [diff] [blame] | 80 | #endif /* __KERNEL__ */ |
| 81 | #endif /* __ASM_SH_FUTEX_H */ |