barrier.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Based on arch/arm/include/asm/barrier.h
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __ASM_BARRIER_H
  19. #define __ASM_BARRIER_H
  20. #ifndef __ASSEMBLY__
  21. #define sev() asm volatile("sev" : : : "memory")
  22. #define wfe() asm volatile("wfe" : : : "memory")
  23. #define wfi() asm volatile("wfi" : : : "memory")
  24. #define isb() asm volatile("isb" : : : "memory")
  25. #define dmb(opt) asm volatile("dmb " #opt : : : "memory")
  26. #define dsb(opt) asm volatile("dsb " #opt : : : "memory")
  27. #define mb() dsb(sy)
  28. #define rmb() dsb(ld)
  29. #define wmb() dsb(st)
  30. #define dma_rmb() dmb(oshld)
  31. #define dma_wmb() dmb(oshst)
  32. #define smp_mb() dmb(ish)
  33. #define smp_rmb() dmb(ishld)
  34. #define smp_wmb() dmb(ishst)
  35. #define smp_store_release(p, v) \
  36. do { \
  37. union { typeof(*p) __val; char __c[1]; } __u = \
  38. { .__val = (__force typeof(*p)) (v) }; \
  39. compiletime_assert_atomic_type(*p); \
  40. switch (sizeof(*p)) { \
  41. case 1: \
  42. asm volatile ("stlrb %w1, %0" \
  43. : "=Q" (*p) \
  44. : "r" (*(__u8 *)__u.__c) \
  45. : "memory"); \
  46. break; \
  47. case 2: \
  48. asm volatile ("stlrh %w1, %0" \
  49. : "=Q" (*p) \
  50. : "r" (*(__u16 *)__u.__c) \
  51. : "memory"); \
  52. break; \
  53. case 4: \
  54. asm volatile ("stlr %w1, %0" \
  55. : "=Q" (*p) \
  56. : "r" (*(__u32 *)__u.__c) \
  57. : "memory"); \
  58. break; \
  59. case 8: \
  60. asm volatile ("stlr %1, %0" \
  61. : "=Q" (*p) \
  62. : "r" (*(__u64 *)__u.__c) \
  63. : "memory"); \
  64. break; \
  65. } \
  66. } while (0)
  67. #define smp_load_acquire(p) \
  68. ({ \
  69. union { typeof(*p) __val; char __c[1]; } __u; \
  70. compiletime_assert_atomic_type(*p); \
  71. switch (sizeof(*p)) { \
  72. case 1: \
  73. asm volatile ("ldarb %w0, %1" \
  74. : "=r" (*(__u8 *)__u.__c) \
  75. : "Q" (*p) : "memory"); \
  76. break; \
  77. case 2: \
  78. asm volatile ("ldarh %w0, %1" \
  79. : "=r" (*(__u16 *)__u.__c) \
  80. : "Q" (*p) : "memory"); \
  81. break; \
  82. case 4: \
  83. asm volatile ("ldar %w0, %1" \
  84. : "=r" (*(__u32 *)__u.__c) \
  85. : "Q" (*p) : "memory"); \
  86. break; \
  87. case 8: \
  88. asm volatile ("ldar %0, %1" \
  89. : "=r" (*(__u64 *)__u.__c) \
  90. : "Q" (*p) : "memory"); \
  91. break; \
  92. } \
  93. __u.__val; \
  94. })
  95. #define read_barrier_depends() do { } while(0)
  96. #define smp_read_barrier_depends() do { } while(0)
  97. #define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
  98. #define nop() asm volatile("nop");
  99. #define smp_mb__before_atomic() smp_mb()
  100. #define smp_mb__after_atomic() smp_mb()
  101. #endif /* __ASSEMBLY__ */
  102. #endif /* __ASM_BARRIER_H */