barrier.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 read_barrier_depends() do { } while(0)
  36. #define set_mb(var, value) do { var = value; mb(); } while (0)
  37. #ifdef CONFIG_SMP
  38. #ifdef __SUBARCH_HAS_LWSYNC
  39. # define SMPWMB LWSYNC
  40. #else
  41. # define SMPWMB eieio
  42. #endif
  43. #define smp_mb() mb()
  44. #define smp_rmb() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
  45. #define smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
  46. #define smp_read_barrier_depends() read_barrier_depends()
  47. #else
  48. #define smp_mb() barrier()
  49. #define smp_rmb() barrier()
  50. #define smp_wmb() barrier()
  51. #define smp_read_barrier_depends() do { } while(0)
  52. #endif /* CONFIG_SMP */
  53. /*
  54. * This is a barrier which prevents following instructions from being
  55. * started until the value of the argument x is known. For example, if
  56. * x is a variable loaded from memory, this prevents following
  57. * instructions from being executed until the load has been performed.
  58. */
  59. #define data_barrier(x) \
  60. asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
  61. #endif /* _ASM_POWERPC_BARRIER_H */