barrier.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifdef __SUBARCH_HAS_LWSYNC
  36. # define SMPWMB LWSYNC
  37. #else
  38. # define SMPWMB eieio
  39. #endif
  40. #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
  41. #define dma_rmb() __lwsync()
  42. #define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  43. #define __smp_lwsync() __lwsync()
  44. #define __smp_mb() mb()
  45. #define __smp_rmb() __lwsync()
  46. #define __smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  47. /*
  48. * This is a barrier which prevents following instructions from being
  49. * started until the value of the argument x is known. For example, if
  50. * x is a variable loaded from memory, this prevents following
  51. * instructions from being executed until the load has been performed.
  52. */
  53. #define data_barrier(x) \
  54. asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
  55. #define __smp_store_release(p, v) \
  56. do { \
  57. compiletime_assert_atomic_type(*p); \
  58. __smp_lwsync(); \
  59. WRITE_ONCE(*p, v); \
  60. } while (0)
  61. #define __smp_load_acquire(p) \
  62. ({ \
  63. typeof(*p) ___p1 = READ_ONCE(*p); \
  64. compiletime_assert_atomic_type(*p); \
  65. __smp_lwsync(); \
  66. ___p1; \
  67. })
  68. #define smp_mb__before_spinlock() smp_mb()
  69. #include <asm-generic/barrier.h>
  70. #endif /* _ASM_POWERPC_BARRIER_H */