tlbflush.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef _I386_TLBFLUSH_H
  2. #define _I386_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <asm/processor.h>
  5. #define __flush_tlb() \
  6. do { \
  7. unsigned int tmpreg; \
  8. \
  9. __asm__ __volatile__( \
  10. "movl %%cr3, %0; \n" \
  11. "movl %0, %%cr3; # flush TLB \n" \
  12. : "=r" (tmpreg) \
  13. :: "memory"); \
  14. } while (0)
  15. /*
  16. * Global pages have to be flushed a bit differently. Not a real
  17. * performance problem because this does not happen often.
  18. */
  19. #define __flush_tlb_global() \
  20. do { \
  21. unsigned int tmpreg, cr4, cr4_orig; \
  22. \
  23. __asm__ __volatile__( \
  24. "movl %%cr4, %2; # turn off PGE \n" \
  25. "movl %2, %1; \n" \
  26. "andl %3, %1; \n" \
  27. "movl %1, %%cr4; \n" \
  28. "movl %%cr3, %0; \n" \
  29. "movl %0, %%cr3; # flush TLB \n" \
  30. "movl %2, %%cr4; # turn PGE back on \n" \
  31. : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
  32. : "i" (~X86_CR4_PGE) \
  33. : "memory"); \
  34. } while (0)
  35. # define __flush_tlb_all() \
  36. do { \
  37. if (cpu_has_pge) \
  38. __flush_tlb_global(); \
  39. else \
  40. __flush_tlb(); \
  41. } while (0)
  42. #define cpu_has_invlpg (boot_cpu_data.x86 > 3)
  43. #define __flush_tlb_single(addr) \
  44. __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory")
  45. #ifdef CONFIG_X86_INVLPG
  46. # define __flush_tlb_one(addr) __flush_tlb_single(addr)
  47. #else
  48. # define __flush_tlb_one(addr) \
  49. do { \
  50. if (cpu_has_invlpg) \
  51. __flush_tlb_single(addr); \
  52. else \
  53. __flush_tlb(); \
  54. } while (0)
  55. #endif
  56. /*
  57. * TLB flushing:
  58. *
  59. * - flush_tlb() flushes the current mm struct TLBs
  60. * - flush_tlb_all() flushes all processes TLBs
  61. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  62. * - flush_tlb_page(vma, vmaddr) flushes one page
  63. * - flush_tlb_range(vma, start, end) flushes a range of pages
  64. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  65. * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
  66. *
  67. * ..but the i386 has somewhat limited tlb flushing capabilities,
  68. * and page-granular flushes are available only on i486 and up.
  69. */
  70. #ifndef CONFIG_SMP
  71. #define flush_tlb() __flush_tlb()
  72. #define flush_tlb_all() __flush_tlb_all()
  73. #define local_flush_tlb() __flush_tlb()
  74. static inline void flush_tlb_mm(struct mm_struct *mm)
  75. {
  76. if (mm == current->active_mm)
  77. __flush_tlb();
  78. }
  79. static inline void flush_tlb_page(struct vm_area_struct *vma,
  80. unsigned long addr)
  81. {
  82. if (vma->vm_mm == current->active_mm)
  83. __flush_tlb_one(addr);
  84. }
  85. static inline void flush_tlb_range(struct vm_area_struct *vma,
  86. unsigned long start, unsigned long end)
  87. {
  88. if (vma->vm_mm == current->active_mm)
  89. __flush_tlb();
  90. }
  91. #else
  92. #include <asm/smp.h>
  93. #define local_flush_tlb() \
  94. __flush_tlb()
  95. extern void flush_tlb_all(void);
  96. extern void flush_tlb_current_task(void);
  97. extern void flush_tlb_mm(struct mm_struct *);
  98. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  99. #define flush_tlb() flush_tlb_current_task()
  100. static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
  101. {
  102. flush_tlb_mm(vma->vm_mm);
  103. }
  104. #define TLBSTATE_OK 1
  105. #define TLBSTATE_LAZY 2
  106. struct tlb_state
  107. {
  108. struct mm_struct *active_mm;
  109. int state;
  110. char __cacheline_padding[L1_CACHE_BYTES-8];
  111. };
  112. DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
  113. #endif
  114. #define flush_tlb_kernel_range(start, end) flush_tlb_all()
  115. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  116. unsigned long start, unsigned long end)
  117. {
  118. /* i386 does not keep any page table caches in TLB */
  119. }
  120. #endif /* _I386_TLBFLUSH_H */