tlbflush_32.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _X86_TLBFLUSH_H
  2. #define _X86_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <linux/sched.h>
  5. #include <asm/processor.h>
  6. #include <asm/system.h>
  7. #ifdef CONFIG_PARAVIRT
  8. #include <asm/paravirt.h>
  9. #else
  10. #define __flush_tlb() __native_flush_tlb()
  11. #define __flush_tlb_global() __native_flush_tlb_global()
  12. #define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
  13. #endif
  14. static inline void __native_flush_tlb(void)
  15. {
  16. write_cr3(read_cr3());
  17. }
  18. static inline void __native_flush_tlb_global(void)
  19. {
  20. unsigned long cr4 = read_cr4();
  21. /* clear PGE */
  22. write_cr4(cr4 & ~X86_CR4_PGE);
  23. /* write old PGE again and flush TLBs */
  24. write_cr4(cr4);
  25. }
  26. static inline void __native_flush_tlb_single(unsigned long addr)
  27. {
  28. __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory");
  29. }
  30. static inline void __flush_tlb_all(void)
  31. {
  32. if (cpu_has_pge)
  33. __flush_tlb_global();
  34. else
  35. __flush_tlb();
  36. }
  37. static inline void __flush_tlb_one(unsigned long addr)
  38. {
  39. if (cpu_has_invlpg)
  40. __flush_tlb_single(addr);
  41. else
  42. __flush_tlb();
  43. }
  44. /*
  45. * TLB flushing:
  46. *
  47. * - flush_tlb() flushes the current mm struct TLBs
  48. * - flush_tlb_all() flushes all processes TLBs
  49. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  50. * - flush_tlb_page(vma, vmaddr) flushes one page
  51. * - flush_tlb_range(vma, start, end) flushes a range of pages
  52. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  53. * - flush_tlb_others(cpumask, mm, va) flushes a TLBs on other cpus
  54. *
  55. * ..but the i386 has somewhat limited tlb flushing capabilities,
  56. * and page-granular flushes are available only on i486 and up.
  57. */
  58. #define TLB_FLUSH_ALL 0xffffffff
  59. #ifndef CONFIG_SMP
  60. #define flush_tlb() __flush_tlb()
  61. #define flush_tlb_all() __flush_tlb_all()
  62. #define local_flush_tlb() __flush_tlb()
  63. static inline void flush_tlb_mm(struct mm_struct *mm)
  64. {
  65. if (mm == current->active_mm)
  66. __flush_tlb();
  67. }
  68. static inline void flush_tlb_page(struct vm_area_struct *vma,
  69. unsigned long addr)
  70. {
  71. if (vma->vm_mm == current->active_mm)
  72. __flush_tlb_one(addr);
  73. }
  74. static inline void flush_tlb_range(struct vm_area_struct *vma,
  75. unsigned long start, unsigned long end)
  76. {
  77. if (vma->vm_mm == current->active_mm)
  78. __flush_tlb();
  79. }
  80. static inline void native_flush_tlb_others(const cpumask_t *cpumask,
  81. struct mm_struct *mm,
  82. unsigned long va)
  83. {
  84. }
  85. #else /* SMP */
  86. #include <asm/smp.h>
  87. #define local_flush_tlb() __flush_tlb()
  88. extern void flush_tlb_all(void);
  89. extern void flush_tlb_current_task(void);
  90. extern void flush_tlb_mm(struct mm_struct *);
  91. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  92. #define flush_tlb() flush_tlb_current_task()
  93. static inline void flush_tlb_range(struct vm_area_struct *vma,
  94. unsigned long start, unsigned long end)
  95. {
  96. flush_tlb_mm(vma->vm_mm);
  97. }
  98. void native_flush_tlb_others(const cpumask_t *cpumask, struct mm_struct *mm,
  99. unsigned long va);
  100. #define TLBSTATE_OK 1
  101. #define TLBSTATE_LAZY 2
  102. struct tlb_state
  103. {
  104. struct mm_struct *active_mm;
  105. int state;
  106. char __cacheline_padding[L1_CACHE_BYTES-8];
  107. };
  108. DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
  109. #endif /* SMP */
  110. #ifndef CONFIG_PARAVIRT
  111. #define flush_tlb_others(mask, mm, va) native_flush_tlb_others(&mask, mm, va)
  112. #endif
  113. static inline void flush_tlb_kernel_range(unsigned long start,
  114. unsigned long end)
  115. {
  116. flush_tlb_all();
  117. }
  118. #endif /* _X86_TLBFLUSH_H */