barrier.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  3. */
  4. #ifndef _ASM_POWERPC_BARRIER_H
  5. #define _ASM_POWERPC_BARRIER_H
  6. /*
  7. * Memory barrier.
  8. * The sync instruction guarantees that all memory accesses initiated
  9. * by this processor have been performed (with respect to all other
  10. * mechanisms that access memory). The eieio instruction is a barrier
  11. * providing an ordering (separately) for (a) cacheable stores and (b)
  12. * loads and stores to non-cacheable memory (e.g. I/O devices).
  13. *
  14. * mb() prevents loads and stores being reordered across this point.
  15. * rmb() prevents loads being reordered across this point.
  16. * wmb() prevents stores being reordered across this point.
  17. * read_barrier_depends() prevents data-dependent loads being reordered
  18. * across this point (nop on PPC).
  19. *
  20. * *mb() variants without smp_ prefix must order all types of memory
  21. * operations with one another. sync is the only instruction sufficient
  22. * to do this.
  23. *
  24. * For the smp_ barriers, ordering is for cacheable memory operations
  25. * only. We have to use the sync instruction for smp_mb(), since lwsync
  26. * doesn't order loads with respect to previous stores. Lwsync can be
  27. * used for smp_rmb() and smp_wmb().
  28. *
  29. * However, on CPUs that don't support lwsync, lwsync actually maps to a
  30. * heavy-weight sync, so smp_wmb() can be a lighter-weight eieio.
  31. */
  32. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  33. #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
  34. #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
  35. /* The sub-arch has lwsync */
  36. #if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
  37. # define SMPWMB LWSYNC
  38. #else
  39. # define SMPWMB eieio
  40. #endif
  41. #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
  42. #define dma_rmb() __lwsync()
  43. #define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  44. #define __smp_lwsync() __lwsync()
  45. #define __smp_mb() mb()
  46. #define __smp_rmb() __lwsync()
  47. #define __smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  48. /*
  49. * This is a barrier which prevents following instructions from being
  50. * started until the value of the argument x is known. For example, if
  51. * x is a variable loaded from memory, this prevents following
  52. * instructions from being executed until the load has been performed.
  53. */
  54. #define data_barrier(x) \
  55. asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
  56. #define __smp_store_release(p, v) \
  57. do { \
  58. compiletime_assert_atomic_type(*p); \
  59. __smp_lwsync(); \
  60. WRITE_ONCE(*p, v); \
  61. } while (0)
  62. #define __smp_load_acquire(p) \
  63. ({ \
  64. typeof(*p) ___p1 = READ_ONCE(*p); \
  65. compiletime_assert_atomic_type(*p); \
  66. __smp_lwsync(); \
  67. ___p1; \
  68. })
  69. #define smp_mb__before_spinlock() smp_mb()
  70. #include <asm-generic/barrier.h>
  71. #endif /* _ASM_POWERPC_BARRIER_H */