barrier.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #define smp_store_mb(var, value) do { WRITE_ONCE(var, value); mb(); } while (0)
  36. /* The sub-arch has lwsync */
  37. #if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
  38. # define SMPWMB LWSYNC
  39. #else
  40. # define SMPWMB eieio
  41. #endif
  42. #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
  43. #define dma_rmb() __lwsync()
  44. #define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  45. #ifdef CONFIG_SMP
  46. #define smp_lwsync() __lwsync()
  47. #define smp_mb() mb()
  48. #define smp_rmb() __lwsync()
  49. #define smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  50. #else
  51. #define smp_lwsync() barrier()
  52. #define smp_mb() barrier()
  53. #define smp_rmb() barrier()
  54. #define smp_wmb() barrier()
  55. #endif /* CONFIG_SMP */
  56. #define read_barrier_depends() do { } while (0)
  57. #define smp_read_barrier_depends() do { } while (0)
  58. /*
  59. * This is a barrier which prevents following instructions from being
  60. * started until the value of the argument x is known. For example, if
  61. * x is a variable loaded from memory, this prevents following
  62. * instructions from being executed until the load has been performed.
  63. */
  64. #define data_barrier(x) \
  65. asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
  66. #define smp_store_release(p, v) \
  67. do { \
  68. compiletime_assert_atomic_type(*p); \
  69. smp_lwsync(); \
  70. WRITE_ONCE(*p, v); \
  71. } while (0)
  72. #define smp_load_acquire(p) \
  73. ({ \
  74. typeof(*p) ___p1 = READ_ONCE(*p); \
  75. compiletime_assert_atomic_type(*p); \
  76. smp_lwsync(); \
  77. ___p1; \
  78. })
  79. #define smp_mb__before_atomic() smp_mb()
  80. #define smp_mb__after_atomic() smp_mb()
  81. #define smp_mb__before_spinlock() smp_mb()
  82. #endif /* _ASM_POWERPC_BARRIER_H */