tlbflush.h 3.7 KB

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