tlbflush_32.h 4.4 KB

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