futex.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef _ASM_POWERPC_FUTEX_H
  2. #define _ASM_POWERPC_FUTEX_H
  3. #ifdef __KERNEL__
  4. #include <linux/futex.h>
  5. #include <linux/uaccess.h>
  6. #include <asm/errno.h>
  7. #include <asm/synch.h>
  8. #include <asm/asm-compat.h>
  9. #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
  10. __asm__ __volatile ( \
  11. PPC_ATOMIC_ENTRY_BARRIER \
  12. "1: lwarx %0,0,%2\n" \
  13. insn \
  14. PPC405_ERR77(0, %2) \
  15. "2: stwcx. %1,0,%2\n" \
  16. "bne- 1b\n" \
  17. PPC_ATOMIC_EXIT_BARRIER \
  18. "li %1,0\n" \
  19. "3: .section .fixup,\"ax\"\n" \
  20. "4: li %1,%3\n" \
  21. "b 3b\n" \
  22. ".previous\n" \
  23. ".section __ex_table,\"a\"\n" \
  24. ".align 3\n" \
  25. PPC_LONG "1b,4b,2b,4b\n" \
  26. ".previous" \
  27. : "=&r" (oldval), "=&r" (ret) \
  28. : "b" (uaddr), "i" (-EFAULT), "r" (oparg) \
  29. : "cr0", "memory")
  30. static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
  31. u32 __user *uaddr)
  32. {
  33. int oldval = 0, ret;
  34. pagefault_disable();
  35. switch (op) {
  36. case FUTEX_OP_SET:
  37. __futex_atomic_op("mr %1,%4\n", ret, oldval, uaddr, oparg);
  38. break;
  39. case FUTEX_OP_ADD:
  40. __futex_atomic_op("add %1,%0,%4\n", ret, oldval, uaddr, oparg);
  41. break;
  42. case FUTEX_OP_OR:
  43. __futex_atomic_op("or %1,%0,%4\n", ret, oldval, uaddr, oparg);
  44. break;
  45. case FUTEX_OP_ANDN:
  46. __futex_atomic_op("andc %1,%0,%4\n", ret, oldval, uaddr, oparg);
  47. break;
  48. case FUTEX_OP_XOR:
  49. __futex_atomic_op("xor %1,%0,%4\n", ret, oldval, uaddr, oparg);
  50. break;
  51. default:
  52. ret = -ENOSYS;
  53. }
  54. pagefault_enable();
  55. if (!ret)
  56. *oval = oldval;
  57. return ret;
  58. }
  59. static inline int
  60. futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  61. u32 oldval, u32 newval)
  62. {
  63. int ret = 0;
  64. u32 prev;
  65. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  66. return -EFAULT;
  67. __asm__ __volatile__ (
  68. PPC_ATOMIC_ENTRY_BARRIER
  69. "1: lwarx %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
  70. cmpw 0,%1,%4\n\
  71. bne- 3f\n"
  72. PPC405_ERR77(0,%3)
  73. "2: stwcx. %5,0,%3\n\
  74. bne- 1b\n"
  75. PPC_ATOMIC_EXIT_BARRIER
  76. "3: .section .fixup,\"ax\"\n\
  77. 4: li %0,%6\n\
  78. b 3b\n\
  79. .previous\n\
  80. .section __ex_table,\"a\"\n\
  81. .align 3\n\
  82. " PPC_LONG "1b,4b,2b,4b\n\
  83. .previous" \
  84. : "+r" (ret), "=&r" (prev), "+m" (*uaddr)
  85. : "r" (uaddr), "r" (oldval), "r" (newval), "i" (-EFAULT)
  86. : "cc", "memory");
  87. *uval = prev;
  88. return ret;
  89. }
  90. #endif /* __KERNEL__ */
  91. #endif /* _ASM_POWERPC_FUTEX_H */