barrier.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_CSKY_BARRIER_H
  3. #define __ASM_CSKY_BARRIER_H
  4. #ifndef __ASSEMBLY__
  5. #define nop() asm volatile ("nop\n":::"memory")
  6. #ifdef CONFIG_SMP
  7. /*
  8. * bar.brwarws: ordering barrier for all load/store instructions
  9. * before/after
  10. *
  11. * |31|30 26|25 21|20 16|15 10|9 5|4 0|
  12. * 1 10000 00000 00000 100001 00001 0 bw br aw ar
  13. *
  14. * b: before
  15. * a: after
  16. * r: read
  17. * w: write
  18. *
  19. * Here are all combinations:
  20. *
  21. * bar.brw
  22. * bar.br
  23. * bar.bw
  24. * bar.arw
  25. * bar.ar
  26. * bar.aw
  27. * bar.brwarw
  28. * bar.brarw
  29. * bar.bwarw
  30. * bar.brwar
  31. * bar.brwaw
  32. * bar.brar
  33. * bar.bwaw
  34. */
  35. #define FULL_FENCE ".long 0x842fc000\n"
  36. #define ACQUIRE_FENCE ".long 0x8427c000\n"
  37. #define RELEASE_FENCE ".long 0x842ec000\n"
  38. #define __bar_brw() asm volatile (".long 0x842cc000\n":::"memory")
  39. #define __bar_br() asm volatile (".long 0x8424c000\n":::"memory")
  40. #define __bar_bw() asm volatile (".long 0x8428c000\n":::"memory")
  41. #define __bar_arw() asm volatile (".long 0x8423c000\n":::"memory")
  42. #define __bar_ar() asm volatile (".long 0x8421c000\n":::"memory")
  43. #define __bar_aw() asm volatile (".long 0x8422c000\n":::"memory")
  44. #define __bar_brwarw() asm volatile (FULL_FENCE:::"memory")
  45. #define __bar_brarw() asm volatile (ACQUIRE_FENCE:::"memory")
  46. #define __bar_bwarw() asm volatile (".long 0x842bc000\n":::"memory")
  47. #define __bar_brwar() asm volatile (".long 0x842dc000\n":::"memory")
  48. #define __bar_brwaw() asm volatile (RELEASE_FENCE:::"memory")
  49. #define __bar_brar() asm volatile (".long 0x8425c000\n":::"memory")
  50. #define __bar_brar() asm volatile (".long 0x8425c000\n":::"memory")
  51. #define __bar_bwaw() asm volatile (".long 0x842ac000\n":::"memory")
  52. #define __smp_mb() __bar_brwarw()
  53. #define __smp_rmb() __bar_brar()
  54. #define __smp_wmb() __bar_bwaw()
  55. #define __smp_acquire_fence() __bar_brarw()
  56. #define __smp_release_fence() __bar_brwaw()
  57. #endif /* CONFIG_SMP */
  58. /*
  59. * sync: completion barrier, all sync.xx instructions
  60. * guarantee the last response received by bus transaction
  61. * made by ld/st instructions before sync.s
  62. * sync.s: inherit from sync, but also shareable to other cores
  63. * sync.i: inherit from sync, but also flush cpu pipeline
  64. * sync.is: the same with sync.i + sync.s
  65. */
  66. #define mb() asm volatile ("sync\n":::"memory")
  67. #ifdef CONFIG_CPU_HAS_CACHEV2
  68. /*
  69. * Using three sync.is to prevent speculative PTW
  70. */
  71. #define sync_is() asm volatile ("sync.is\nsync.is\nsync.is\n":::"memory")
  72. #endif
  73. #include <asm-generic/barrier.h>
  74. #endif /* __ASSEMBLY__ */
  75. #endif /* __ASM_CSKY_BARRIER_H */