1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __ASM_SH_FUTEX_H 3 #define __ASM_SH_FUTEX_H 4 5 #ifdef __KERNEL__ 6 7 #include <linux/futex.h> 8 #include <linux/uaccess.h> 9 #include <asm/errno.h> 10 11 #if !defined(CONFIG_SMP) 12 #include <asm/futex-irq.h> 13 #elif defined(CONFIG_CPU_J2) 14 #include <asm/futex-cas.h> 15 #elif defined(CONFIG_CPU_SH4A) 16 #include <asm/futex-llsc.h> 17 #else 18 #error SMP not supported on this configuration. 19 #endif 20 21 static inline int 22 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, 23 u32 oldval, u32 newval) 24 { 25 if (!access_ok(uaddr, sizeof(u32))) 26 return -EFAULT; 27 28 return atomic_futex_op_cmpxchg_inatomic(uval, uaddr, oldval, newval); 29 } 30 31 static inline int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, 32 u32 __user *uaddr) 33 { 34 u32 oldval, newval, prev; 35 int ret; 36 37 do { 38 ret = get_user(oldval, uaddr); 39 40 if (ret) break; 41 42 switch (op) { 43 case FUTEX_OP_SET: 44 newval = oparg; 45 break; 46 case FUTEX_OP_ADD: 47 newval = oldval + oparg; 48 break; 49 case FUTEX_OP_OR: 50 newval = oldval | oparg; 51 break; 52 case FUTEX_OP_ANDN: 53 newval = oldval & ~oparg; 54 break; 55 case FUTEX_OP_XOR: 56 newval = oldval ^ oparg; 57 break; 58 default: 59 ret = -ENOSYS; 60 break; 61 } 62 63 if (ret) break; 64 65 ret = futex_atomic_cmpxchg_inatomic(&prev, uaddr, oldval, newval); 66 } while (!ret && prev != oldval); 67 68 if (!ret) 69 *oval = oldval; 70 71 return ret; 72 } 73 74 #endif /* __KERNEL__ */ 75 #endif /* __ASM_SH_FUTEX_H */ 76