system.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef _ASM_X86_SYSTEM_H_
  2. #define _ASM_X86_SYSTEM_H_
  3. #include <asm/asm.h>
  4. #include <asm/segment.h>
  5. #include <asm/cpufeature.h>
  6. #include <asm/cmpxchg.h>
  7. #include <asm/nops.h>
  8. #include <linux/kernel.h>
  9. #include <linux/irqflags.h>
  10. /* entries in ARCH_DLINFO: */
  11. #ifdef CONFIG_IA32_EMULATION
  12. # define AT_VECTOR_SIZE_ARCH 2
  13. #else
  14. # define AT_VECTOR_SIZE_ARCH 1
  15. #endif
  16. extern unsigned long arch_align_stack(unsigned long sp);
  17. void default_idle(void);
  18. /*
  19. * Force strict CPU ordering.
  20. * And yes, this is required on UP too when we're talking
  21. * to devices.
  22. */
  23. #ifdef CONFIG_X86_32
  24. /*
  25. * Some non-Intel clones support out of order store. wmb() ceases to be a
  26. * nop for these.
  27. */
  28. #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
  29. #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
  30. #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
  31. #else
  32. #define mb() asm volatile("mfence":::"memory")
  33. #define rmb() asm volatile("lfence":::"memory")
  34. #define wmb() asm volatile("sfence" ::: "memory")
  35. #endif
  36. /**
  37. * read_barrier_depends - Flush all pending reads that subsequents reads
  38. * depend on.
  39. *
  40. * No data-dependent reads from memory-like regions are ever reordered
  41. * over this barrier. All reads preceding this primitive are guaranteed
  42. * to access memory (but not necessarily other CPUs' caches) before any
  43. * reads following this primitive that depend on the data return by
  44. * any of the preceding reads. This primitive is much lighter weight than
  45. * rmb() on most CPUs, and is never heavier weight than is
  46. * rmb().
  47. *
  48. * These ordering constraints are respected by both the local CPU
  49. * and the compiler.
  50. *
  51. * Ordering is not guaranteed by anything other than these primitives,
  52. * not even by data dependencies. See the documentation for
  53. * memory_barrier() for examples and URLs to more information.
  54. *
  55. * For example, the following code would force ordering (the initial
  56. * value of "a" is zero, "b" is one, and "p" is "&a"):
  57. *
  58. * <programlisting>
  59. * CPU 0 CPU 1
  60. *
  61. * b = 2;
  62. * memory_barrier();
  63. * p = &b; q = p;
  64. * read_barrier_depends();
  65. * d = *q;
  66. * </programlisting>
  67. *
  68. * because the read of "*q" depends on the read of "p" and these
  69. * two reads are separated by a read_barrier_depends(). However,
  70. * the following code, with the same initial values for "a" and "b":
  71. *
  72. * <programlisting>
  73. * CPU 0 CPU 1
  74. *
  75. * a = 2;
  76. * memory_barrier();
  77. * b = 3; y = b;
  78. * read_barrier_depends();
  79. * x = a;
  80. * </programlisting>
  81. *
  82. * does not enforce ordering, since there is no data dependency between
  83. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  84. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  85. * in cases like this where there are no data dependencies.
  86. **/
  87. #define read_barrier_depends() do { } while (0)
  88. #ifdef CONFIG_SMP
  89. #define smp_mb() mb()
  90. #ifdef CONFIG_X86_PPRO_FENCE
  91. # define smp_rmb() rmb()
  92. #else
  93. # define smp_rmb() barrier()
  94. #endif
  95. #ifdef CONFIG_X86_OOSTORE
  96. # define smp_wmb() wmb()
  97. #else
  98. # define smp_wmb() barrier()
  99. #endif
  100. #define smp_read_barrier_depends() read_barrier_depends()
  101. #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
  102. #else
  103. #define smp_mb() barrier()
  104. #define smp_rmb() barrier()
  105. #define smp_wmb() barrier()
  106. #define smp_read_barrier_depends() do { } while (0)
  107. #define set_mb(var, value) do { var = value; barrier(); } while (0)
  108. #endif
  109. /*
  110. * Stop RDTSC speculation. This is needed when you need to use RDTSC
  111. * (or get_cycles or vread that possibly accesses the TSC) in a defined
  112. * code region.
  113. *
  114. * (Could use an alternative three way for this if there was one.)
  115. */
  116. static inline void rdtsc_barrier(void)
  117. {
  118. alternative(ASM_NOP3, "mfence", X86_FEATURE_MFENCE_RDTSC);
  119. alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
  120. }
  121. #endif