tlbflush.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef _S390_TLBFLUSH_H
  2. #define _S390_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <linux/sched.h>
  5. #include <asm/processor.h>
  6. #include <asm/pgalloc.h>
  7. /*
  8. * Flush all TLB entries on the local CPU.
  9. */
  10. static inline void __tlb_flush_local(void)
  11. {
  12. asm volatile("ptlb" : : : "memory");
  13. }
  14. /*
  15. * Flush TLB entries for a specific ASCE on all CPUs
  16. */
  17. static inline void __tlb_flush_idte(unsigned long asce)
  18. {
  19. /* Global TLB flush for the mm */
  20. asm volatile(
  21. " .insn rrf,0xb98e0000,0,%0,%1,0"
  22. : : "a" (2048), "a" (asce) : "cc");
  23. }
  24. /*
  25. * Flush TLB entries for a specific ASCE on the local CPU
  26. */
  27. static inline void __tlb_flush_idte_local(unsigned long asce)
  28. {
  29. /* Local TLB flush for the mm */
  30. asm volatile(
  31. " .insn rrf,0xb98e0000,0,%0,%1,1"
  32. : : "a" (2048), "a" (asce) : "cc");
  33. }
  34. #ifdef CONFIG_SMP
  35. void smp_ptlb_all(void);
  36. /*
  37. * Flush all TLB entries on all CPUs.
  38. */
  39. static inline void __tlb_flush_global(void)
  40. {
  41. register unsigned long reg2 asm("2");
  42. register unsigned long reg3 asm("3");
  43. register unsigned long reg4 asm("4");
  44. long dummy;
  45. dummy = 0;
  46. reg2 = reg3 = 0;
  47. reg4 = ((unsigned long) &dummy) + 1;
  48. asm volatile(
  49. " csp %0,%2"
  50. : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
  51. }
  52. /*
  53. * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
  54. * this implicates multiple ASCEs!).
  55. */
  56. static inline void __tlb_flush_full(struct mm_struct *mm)
  57. {
  58. preempt_disable();
  59. atomic_add(0x10000, &mm->context.attach_count);
  60. if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
  61. /* Local TLB flush */
  62. __tlb_flush_local();
  63. } else {
  64. /* Global TLB flush */
  65. __tlb_flush_global();
  66. /* Reset TLB flush mask */
  67. if (MACHINE_HAS_TLB_LC)
  68. cpumask_copy(mm_cpumask(mm),
  69. &mm->context.cpu_attach_mask);
  70. }
  71. atomic_sub(0x10000, &mm->context.attach_count);
  72. preempt_enable();
  73. }
  74. /*
  75. * Flush TLB entries for a specific ASCE on all CPUs.
  76. */
  77. static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce)
  78. {
  79. int active, count;
  80. preempt_disable();
  81. active = (mm == current->active_mm) ? 1 : 0;
  82. count = atomic_add_return(0x10000, &mm->context.attach_count);
  83. if (MACHINE_HAS_TLB_LC && (count & 0xffff) <= active &&
  84. cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
  85. __tlb_flush_idte_local(asce);
  86. } else {
  87. if (MACHINE_HAS_IDTE)
  88. __tlb_flush_idte(asce);
  89. else
  90. __tlb_flush_global();
  91. /* Reset TLB flush mask */
  92. if (MACHINE_HAS_TLB_LC)
  93. cpumask_copy(mm_cpumask(mm),
  94. &mm->context.cpu_attach_mask);
  95. }
  96. atomic_sub(0x10000, &mm->context.attach_count);
  97. preempt_enable();
  98. }
  99. static inline void __tlb_flush_kernel(void)
  100. {
  101. if (MACHINE_HAS_IDTE)
  102. __tlb_flush_idte((unsigned long) init_mm.pgd |
  103. init_mm.context.asce_bits);
  104. else
  105. __tlb_flush_global();
  106. }
  107. #else
  108. #define __tlb_flush_global() __tlb_flush_local()
  109. #define __tlb_flush_full(mm) __tlb_flush_local()
  110. /*
  111. * Flush TLB entries for a specific ASCE on all CPUs.
  112. */
  113. static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce)
  114. {
  115. if (MACHINE_HAS_TLB_LC)
  116. __tlb_flush_idte_local(asce);
  117. else
  118. __tlb_flush_local();
  119. }
  120. static inline void __tlb_flush_kernel(void)
  121. {
  122. if (MACHINE_HAS_TLB_LC)
  123. __tlb_flush_idte_local((unsigned long) init_mm.pgd |
  124. init_mm.context.asce_bits);
  125. else
  126. __tlb_flush_local();
  127. }
  128. #endif
  129. static inline void __tlb_flush_mm(struct mm_struct * mm)
  130. {
  131. /*
  132. * If the machine has IDTE we prefer to do a per mm flush
  133. * on all cpus instead of doing a local flush if the mm
  134. * only ran on the local cpu.
  135. */
  136. if (MACHINE_HAS_IDTE && list_empty(&mm->context.gmap_list))
  137. __tlb_flush_asce(mm, (unsigned long) mm->pgd |
  138. mm->context.asce_bits);
  139. else
  140. __tlb_flush_full(mm);
  141. }
  142. static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
  143. {
  144. if (mm->context.flush_mm) {
  145. __tlb_flush_mm(mm);
  146. mm->context.flush_mm = 0;
  147. }
  148. }
  149. /*
  150. * TLB flushing:
  151. * flush_tlb() - flushes the current mm struct TLBs
  152. * flush_tlb_all() - flushes all processes TLBs
  153. * flush_tlb_mm(mm) - flushes the specified mm context TLB's
  154. * flush_tlb_page(vma, vmaddr) - flushes one page
  155. * flush_tlb_range(vma, start, end) - flushes a range of pages
  156. * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
  157. */
  158. /*
  159. * flush_tlb_mm goes together with ptep_set_wrprotect for the
  160. * copy_page_range operation and flush_tlb_range is related to
  161. * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
  162. * ptep_get_and_clear do not flush the TLBs directly if the mm has
  163. * only one user. At the end of the update the flush_tlb_mm and
  164. * flush_tlb_range functions need to do the flush.
  165. */
  166. #define flush_tlb() do { } while (0)
  167. #define flush_tlb_all() do { } while (0)
  168. #define flush_tlb_page(vma, addr) do { } while (0)
  169. static inline void flush_tlb_mm(struct mm_struct *mm)
  170. {
  171. __tlb_flush_mm_lazy(mm);
  172. }
  173. static inline void flush_tlb_range(struct vm_area_struct *vma,
  174. unsigned long start, unsigned long end)
  175. {
  176. __tlb_flush_mm_lazy(vma->vm_mm);
  177. }
  178. static inline void flush_tlb_kernel_range(unsigned long start,
  179. unsigned long end)
  180. {
  181. __tlb_flush_kernel();
  182. }
  183. #endif /* _S390_TLBFLUSH_H */