futex.h 2.2 KB

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