futex.h 2.1 KB

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