tlbflush.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. extern unsigned long pgkern_mask;
  36. # define __flush_tlb_all() \
  37. do { \
  38. if (cpu_has_pge) \
  39. __flush_tlb_global(); \
  40. else \
  41. __flush_tlb(); \
  42. } while (0)
  43. #define cpu_has_invlpg (boot_cpu_data.x86 > 3)
  44. #define __flush_tlb_single(addr) \
  45. __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
  46. #ifdef CONFIG_X86_INVLPG
  47. # define __flush_tlb_one(addr) __flush_tlb_single(addr)
  48. #else
  49. # define __flush_tlb_one(addr) \
  50. do { \
  51. if (cpu_has_invlpg) \
  52. __flush_tlb_single(addr); \
  53. else \
  54. __flush_tlb(); \
  55. } while (0)
  56. #endif
  57. /*
  58. * TLB flushing:
  59. *
  60. * - flush_tlb() flushes the current mm struct TLBs
  61. * - flush_tlb_all() flushes all processes TLBs
  62. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  63. * - flush_tlb_page(vma, vmaddr) flushes one page
  64. * - flush_tlb_range(vma, start, end) flushes a range of pages
  65. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  66. * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
  67. *
  68. * ..but the i386 has somewhat limited tlb flushing capabilities,
  69. * and page-granular flushes are available only on i486 and up.
  70. */
  71. #ifndef CONFIG_SMP
  72. #define flush_tlb() __flush_tlb()
  73. #define flush_tlb_all() __flush_tlb_all()
  74. #define local_flush_tlb() __flush_tlb()
  75. static inline void flush_tlb_mm(struct mm_struct *mm)
  76. {
  77. if (mm == current->active_mm)
  78. __flush_tlb();
  79. }
  80. static inline void flush_tlb_page(struct vm_area_struct *vma,
  81. unsigned long addr)
  82. {
  83. if (vma->vm_mm == current->active_mm)
  84. __flush_tlb_one(addr);
  85. }
  86. static inline void flush_tlb_range(struct vm_area_struct *vma,
  87. unsigned long start, unsigned long end)
  88. {
  89. if (vma->vm_mm == current->active_mm)
  90. __flush_tlb();
  91. }
  92. #else
  93. #include <asm/smp.h>
  94. #define local_flush_tlb() \
  95. __flush_tlb()
  96. extern void flush_tlb_all(void);
  97. extern void flush_tlb_current_task(void);
  98. extern void flush_tlb_mm(struct mm_struct *);
  99. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  100. #define flush_tlb() flush_tlb_current_task()
  101. static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
  102. {
  103. flush_tlb_mm(vma->vm_mm);
  104. }
  105. #define TLBSTATE_OK 1
  106. #define TLBSTATE_LAZY 2
  107. struct tlb_state
  108. {
  109. struct mm_struct *active_mm;
  110. int state;
  111. char __cacheline_padding[L1_CACHE_BYTES-8];
  112. };
  113. DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
  114. #endif
  115. #define flush_tlb_kernel_range(start, end) flush_tlb_all()
  116. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  117. unsigned long start, unsigned long end)
  118. {
  119. /* i386 does not keep any page table caches in TLB */
  120. }
  121. #endif /* _I386_TLBFLUSH_H */