~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/openrisc/include/asm/futex.h

Version: ~ [ linux-5.11 ] ~ [ linux-5.10.17 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.99 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.176 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.221 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.257 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.257 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __ASM_OPENRISC_FUTEX_H
  3 #define __ASM_OPENRISC_FUTEX_H
  4 
  5 #ifdef __KERNEL__
  6 
  7 #include <linux/futex.h>
  8 #include <linux/uaccess.h>
  9 #include <asm/errno.h>
 10 
 11 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
 12 ({                                                              \
 13         __asm__ __volatile__ (                                  \
 14                 "1:     l.lwa   %0, %2                  \n"     \
 15                         insn                            "\n"    \
 16                 "2:     l.swa   %2, %1                  \n"     \
 17                 "       l.bnf   1b                      \n"     \
 18                 "        l.ori  %1, r0, 0               \n"     \
 19                 "3:                                     \n"     \
 20                 ".section .fixup,\"ax\"                 \n"     \
 21                 "4:     l.j     3b                      \n"     \
 22                 "        l.addi %1, r0, %3              \n"     \
 23                 ".previous                              \n"     \
 24                 ".section __ex_table,\"a\"              \n"     \
 25                 ".word  1b,4b,2b,4b                     \n"     \
 26                 ".previous                              \n"     \
 27                 : "=&r" (oldval), "=&r" (ret), "+m" (*uaddr)    \
 28                 : "i" (-EFAULT), "r" (oparg)                    \
 29                 : "cc", "memory"                                \
 30                 );                                              \
 31 })
 32 
 33 static inline int
 34 arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
 35 {
 36         int oldval = 0, ret;
 37 
 38         pagefault_disable();
 39 
 40         switch (op) {
 41         case FUTEX_OP_SET:
 42                 __futex_atomic_op("l.or %1,%4,%4", ret, oldval, uaddr, oparg);
 43                 break;
 44         case FUTEX_OP_ADD:
 45                 __futex_atomic_op("l.add %1,%0,%4", ret, oldval, uaddr, oparg);
 46                 break;
 47         case FUTEX_OP_OR:
 48                 __futex_atomic_op("l.or %1,%0,%4", ret, oldval, uaddr, oparg);
 49                 break;
 50         case FUTEX_OP_ANDN:
 51                 __futex_atomic_op("l.and %1,%0,%4", ret, oldval, uaddr, ~oparg);
 52                 break;
 53         case FUTEX_OP_XOR:
 54                 __futex_atomic_op("l.xor %1,%0,%4", ret, oldval, uaddr, oparg);
 55                 break;
 56         default:
 57                 ret = -ENOSYS;
 58         }
 59 
 60         pagefault_enable();
 61 
 62         if (!ret)
 63                 *oval = oldval;
 64 
 65         return ret;
 66 }
 67 
 68 static inline int
 69 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 70                               u32 oldval, u32 newval)
 71 {
 72         int ret = 0;
 73         u32 prev;
 74 
 75         if (!access_ok(uaddr, sizeof(u32)))
 76                 return -EFAULT;
 77 
 78         __asm__ __volatile__ (                          \
 79                 "1:     l.lwa   %1, %2          \n"     \
 80                 "       l.sfeq  %1, %3          \n"     \
 81                 "       l.bnf   3f              \n"     \
 82                 "        l.nop                  \n"     \
 83                 "2:     l.swa   %2, %4          \n"     \
 84                 "       l.bnf   1b              \n"     \
 85                 "        l.nop                  \n"     \
 86                 "3:                             \n"     \
 87                 ".section .fixup,\"ax\"         \n"     \
 88                 "4:     l.j     3b              \n"     \
 89                 "        l.addi %0, r0, %5      \n"     \
 90                 ".previous                      \n"     \
 91                 ".section __ex_table,\"a\"      \n"     \
 92                 ".word  1b,4b,2b,4b             \n"     \
 93                 ".previous                      \n"     \
 94                 : "+r" (ret), "=&r" (prev), "+m" (*uaddr) \
 95                 : "r" (oldval), "r" (newval), "i" (-EFAULT) \
 96                 : "cc", "memory"                        \
 97                 );
 98 
 99         *uval = prev;
100         return ret;
101 }
102 
103 #endif /* __KERNEL__ */
104 
105 #endif /* __ASM_OPENRISC_FUTEX_H */
106 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp