cmpxchg.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __ARCH_H8300_CMPXCHG__
  2. #define __ARCH_H8300_CMPXCHG__
  3. #include <linux/irqflags.h>
  4. #define xchg(ptr, x) \
  5. ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), \
  6. sizeof(*(ptr))))
  7. struct __xchg_dummy { unsigned long a[100]; };
  8. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  9. static inline unsigned long __xchg(unsigned long x,
  10. volatile void *ptr, int size)
  11. {
  12. unsigned long tmp, flags;
  13. local_irq_save(flags);
  14. switch (size) {
  15. case 1:
  16. __asm__ __volatile__
  17. ("mov.b %2,%0\n\t"
  18. "mov.b %1,%2"
  19. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)));
  20. break;
  21. case 2:
  22. __asm__ __volatile__
  23. ("mov.w %2,%0\n\t"
  24. "mov.w %1,%2"
  25. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)));
  26. break;
  27. case 4:
  28. __asm__ __volatile__
  29. ("mov.l %2,%0\n\t"
  30. "mov.l %1,%2"
  31. : "=&r" (tmp) : "r" (x), "m" (*__xg(ptr)));
  32. break;
  33. default:
  34. tmp = 0;
  35. }
  36. local_irq_restore(flags);
  37. return tmp;
  38. }
  39. #include <asm-generic/cmpxchg-local.h>
  40. /*
  41. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  42. * them available.
  43. */
  44. #define cmpxchg_local(ptr, o, n) \
  45. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
  46. (unsigned long)(o), \
  47. (unsigned long)(n), \
  48. sizeof(*(ptr))))
  49. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  50. #ifndef CONFIG_SMP
  51. #include <asm-generic/cmpxchg.h>
  52. #endif
  53. #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
  54. #endif /* __ARCH_H8300_CMPXCHG__ */