barrier.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. * Tony Kou (tonyko@lineo.ca)
  4. *
  5. * Licensed under the GPL-2 or later
  6. */
  7. #ifndef _BLACKFIN_BARRIER_H
  8. #define _BLACKFIN_BARRIER_H
  9. #include <asm/cache.h>
  10. #define nop() __asm__ __volatile__ ("nop;\n\t" : : )
  11. /*
  12. * Force strict CPU ordering.
  13. */
  14. #ifdef CONFIG_SMP
  15. #ifdef __ARCH_SYNC_CORE_DCACHE
  16. /* Force Core data cache coherence */
  17. # define mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0)
  18. # define rmb() do { barrier(); smp_check_barrier(); } while (0)
  19. # define wmb() do { barrier(); smp_mark_barrier(); } while (0)
  20. /*
  21. * read_barrier_depends - Flush all pending reads that subsequents reads
  22. * depend on.
  23. *
  24. * No data-dependent reads from memory-like regions are ever reordered
  25. * over this barrier. All reads preceding this primitive are guaranteed
  26. * to access memory (but not necessarily other CPUs' caches) before any
  27. * reads following this primitive that depend on the data return by
  28. * any of the preceding reads. This primitive is much lighter weight than
  29. * rmb() on most CPUs, and is never heavier weight than is
  30. * rmb().
  31. *
  32. * These ordering constraints are respected by both the local CPU
  33. * and the compiler.
  34. *
  35. * Ordering is not guaranteed by anything other than these primitives,
  36. * not even by data dependencies. See the documentation for
  37. * memory_barrier() for examples and URLs to more information.
  38. *
  39. * For example, the following code would force ordering (the initial
  40. * value of "a" is zero, "b" is one, and "p" is "&a"):
  41. *
  42. * <programlisting>
  43. * CPU 0 CPU 1
  44. *
  45. * b = 2;
  46. * memory_barrier();
  47. * p = &b; q = p;
  48. * read_barrier_depends();
  49. * d = *q;
  50. * </programlisting>
  51. *
  52. * because the read of "*q" depends on the read of "p" and these
  53. * two reads are separated by a read_barrier_depends(). However,
  54. * the following code, with the same initial values for "a" and "b":
  55. *
  56. * <programlisting>
  57. * CPU 0 CPU 1
  58. *
  59. * a = 2;
  60. * memory_barrier();
  61. * b = 3; y = b;
  62. * read_barrier_depends();
  63. * x = a;
  64. * </programlisting>
  65. *
  66. * does not enforce ordering, since there is no data dependency between
  67. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  68. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  69. * in cases like this where there are no data dependencies.
  70. */
  71. # define read_barrier_depends() do { barrier(); smp_check_barrier(); } while (0)
  72. #endif
  73. #endif /* !CONFIG_SMP */
  74. #define __smp_mb__before_atomic() barrier()
  75. #define __smp_mb__after_atomic() barrier()
  76. #include <asm-generic/barrier.h>
  77. #endif /* _BLACKFIN_BARRIER_H */