tlbflush.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifdef CONFIG_SMP
  15. /*
  16. * Flush all tlb entries on all cpus.
  17. */
  18. void smp_ptlb_all(void);
  19. static inline void __tlb_flush_global(void)
  20. {
  21. register unsigned long reg2 asm("2");
  22. register unsigned long reg3 asm("3");
  23. register unsigned long reg4 asm("4");
  24. long dummy;
  25. #ifndef __s390x__
  26. if (!MACHINE_HAS_CSP) {
  27. smp_ptlb_all();
  28. return;
  29. }
  30. #endif /* __s390x__ */
  31. dummy = 0;
  32. reg2 = reg3 = 0;
  33. reg4 = ((unsigned long) &dummy) + 1;
  34. asm volatile(
  35. " csp %0,%2"
  36. : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
  37. }
  38. static inline void __tlb_flush_full(struct mm_struct *mm)
  39. {
  40. cpumask_t local_cpumask;
  41. preempt_disable();
  42. /*
  43. * If the process only ran on the local cpu, do a local flush.
  44. */
  45. cpumask_copy(&local_cpumask, cpumask_of(smp_processor_id()));
  46. if (cpumask_equal(mm_cpumask(mm), &local_cpumask))
  47. __tlb_flush_local();
  48. else
  49. __tlb_flush_global();
  50. preempt_enable();
  51. }
  52. #else
  53. #define __tlb_flush_full(mm) __tlb_flush_local()
  54. #define __tlb_flush_global() __tlb_flush_local()
  55. #endif
  56. /*
  57. * Flush all tlb entries of a page table on all cpus.
  58. */
  59. static inline void __tlb_flush_idte(unsigned long asce)
  60. {
  61. asm volatile(
  62. " .insn rrf,0xb98e0000,0,%0,%1,0"
  63. : : "a" (2048), "a" (asce) : "cc" );
  64. }
  65. static inline void __tlb_flush_mm(struct mm_struct * mm)
  66. {
  67. if (unlikely(cpumask_empty(mm_cpumask(mm))))
  68. return;
  69. /*
  70. * If the machine has IDTE we prefer to do a per mm flush
  71. * on all cpus instead of doing a local flush if the mm
  72. * only ran on the local cpu.
  73. */
  74. if (MACHINE_HAS_IDTE && list_empty(&mm->context.gmap_list))
  75. __tlb_flush_idte((unsigned long) mm->pgd |
  76. mm->context.asce_bits);
  77. else
  78. __tlb_flush_full(mm);
  79. }
  80. static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
  81. {
  82. spin_lock(&mm->page_table_lock);
  83. if (mm->context.flush_mm) {
  84. __tlb_flush_mm(mm);
  85. mm->context.flush_mm = 0;
  86. }
  87. spin_unlock(&mm->page_table_lock);
  88. }
  89. /*
  90. * TLB flushing:
  91. * flush_tlb() - flushes the current mm struct TLBs
  92. * flush_tlb_all() - flushes all processes TLBs
  93. * flush_tlb_mm(mm) - flushes the specified mm context TLB's
  94. * flush_tlb_page(vma, vmaddr) - flushes one page
  95. * flush_tlb_range(vma, start, end) - flushes a range of pages
  96. * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
  97. */
  98. /*
  99. * flush_tlb_mm goes together with ptep_set_wrprotect for the
  100. * copy_page_range operation and flush_tlb_range is related to
  101. * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
  102. * ptep_get_and_clear do not flush the TLBs directly if the mm has
  103. * only one user. At the end of the update the flush_tlb_mm and
  104. * flush_tlb_range functions need to do the flush.
  105. */
  106. #define flush_tlb() do { } while (0)
  107. #define flush_tlb_all() do { } while (0)
  108. #define flush_tlb_page(vma, addr) do { } while (0)
  109. static inline void flush_tlb_mm(struct mm_struct *mm)
  110. {
  111. __tlb_flush_mm_cond(mm);
  112. }
  113. static inline void flush_tlb_range(struct vm_area_struct *vma,
  114. unsigned long start, unsigned long end)
  115. {
  116. __tlb_flush_mm_cond(vma->vm_mm);
  117. }
  118. static inline void flush_tlb_kernel_range(unsigned long start,
  119. unsigned long end)
  120. {
  121. __tlb_flush_mm(&init_mm);
  122. }
  123. #endif /* _S390_TLBFLUSH_H */