cmpxchg.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _ASM_IA64_CMPXCHG_H
  2. #define _ASM_IA64_CMPXCHG_H
  3. /*
  4. * Compare/Exchange, forked from asm/intrinsics.h
  5. * which was:
  6. *
  7. * Copyright (C) 2002-2003 Hewlett-Packard Co
  8. * David Mosberger-Tang <davidm@hpl.hp.com>
  9. */
  10. #ifndef __ASSEMBLY__
  11. #include <linux/types.h>
  12. /* include compiler specific intrinsics */
  13. #include <asm/ia64regs.h>
  14. #ifdef __INTEL_COMPILER
  15. # include <asm/intel_intrin.h>
  16. #else
  17. # include <asm/gcc_intrin.h>
  18. #endif
  19. /*
  20. * This function doesn't exist, so you'll get a linker error if
  21. * something tries to do an invalid xchg().
  22. */
  23. extern void ia64_xchg_called_with_bad_pointer(void);
  24. #define __xchg(x, ptr, size) \
  25. ({ \
  26. unsigned long __xchg_result; \
  27. \
  28. switch (size) { \
  29. case 1: \
  30. __xchg_result = ia64_xchg1((__u8 *)ptr, x); \
  31. break; \
  32. \
  33. case 2: \
  34. __xchg_result = ia64_xchg2((__u16 *)ptr, x); \
  35. break; \
  36. \
  37. case 4: \
  38. __xchg_result = ia64_xchg4((__u32 *)ptr, x); \
  39. break; \
  40. \
  41. case 8: \
  42. __xchg_result = ia64_xchg8((__u64 *)ptr, x); \
  43. break; \
  44. default: \
  45. ia64_xchg_called_with_bad_pointer(); \
  46. } \
  47. __xchg_result; \
  48. })
  49. #define xchg(ptr, x) \
  50. ((__typeof__(*(ptr))) __xchg((unsigned long) (x), (ptr), sizeof(*(ptr))))
  51. /*
  52. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  53. * store NEW in MEM. Return the initial value in MEM. Success is
  54. * indicated by comparing RETURN with OLD.
  55. */
  56. #define __HAVE_ARCH_CMPXCHG 1
  57. /*
  58. * This function doesn't exist, so you'll get a linker error
  59. * if something tries to do an invalid cmpxchg().
  60. */
  61. extern long ia64_cmpxchg_called_with_bad_pointer(void);
  62. #define ia64_cmpxchg(sem, ptr, old, new, size) \
  63. ({ \
  64. __u64 _o_, _r_; \
  65. \
  66. switch (size) { \
  67. case 1: \
  68. _o_ = (__u8) (long) (old); \
  69. break; \
  70. case 2: \
  71. _o_ = (__u16) (long) (old); \
  72. break; \
  73. case 4: \
  74. _o_ = (__u32) (long) (old); \
  75. break; \
  76. case 8: \
  77. _o_ = (__u64) (long) (old); \
  78. break; \
  79. default: \
  80. break; \
  81. } \
  82. switch (size) { \
  83. case 1: \
  84. _r_ = ia64_cmpxchg1_##sem((__u8 *) ptr, new, _o_); \
  85. break; \
  86. \
  87. case 2: \
  88. _r_ = ia64_cmpxchg2_##sem((__u16 *) ptr, new, _o_); \
  89. break; \
  90. \
  91. case 4: \
  92. _r_ = ia64_cmpxchg4_##sem((__u32 *) ptr, new, _o_); \
  93. break; \
  94. \
  95. case 8: \
  96. _r_ = ia64_cmpxchg8_##sem((__u64 *) ptr, new, _o_); \
  97. break; \
  98. \
  99. default: \
  100. _r_ = ia64_cmpxchg_called_with_bad_pointer(); \
  101. break; \
  102. } \
  103. (__typeof__(old)) _r_; \
  104. })
  105. #define cmpxchg_acq(ptr, o, n) \
  106. ia64_cmpxchg(acq, (ptr), (o), (n), sizeof(*(ptr)))
  107. #define cmpxchg_rel(ptr, o, n) \
  108. ia64_cmpxchg(rel, (ptr), (o), (n), sizeof(*(ptr)))
  109. /* for compatibility with other platforms: */
  110. #define cmpxchg(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
  111. #define cmpxchg64(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
  112. #define cmpxchg_local cmpxchg
  113. #define cmpxchg64_local cmpxchg64
  114. #ifdef CONFIG_IA64_DEBUG_CMPXCHG
  115. # define CMPXCHG_BUGCHECK_DECL int _cmpxchg_bugcheck_count = 128;
  116. # define CMPXCHG_BUGCHECK(v) \
  117. do { \
  118. if (_cmpxchg_bugcheck_count-- <= 0) { \
  119. void *ip; \
  120. extern int printk(const char *fmt, ...); \
  121. ip = (void *) ia64_getreg(_IA64_REG_IP); \
  122. printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));\
  123. break; \
  124. } \
  125. } while (0)
  126. #else /* !CONFIG_IA64_DEBUG_CMPXCHG */
  127. # define CMPXCHG_BUGCHECK_DECL
  128. # define CMPXCHG_BUGCHECK(v)
  129. #endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
  130. #endif /* !__ASSEMBLY__ */
  131. #endif /* _ASM_IA64_CMPXCHG_H */