tlbflush.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef _S390_TLBFLUSH_H
  2. #define _S390_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <asm/processor.h>
  5. #include <asm/pgalloc.h>
  6. /*
  7. * Flush all tlb entries on the local cpu.
  8. */
  9. static inline void __tlb_flush_local(void)
  10. {
  11. asm volatile("ptlb" : : : "memory");
  12. }
  13. /*
  14. * Flush all tlb entries on all cpus.
  15. */
  16. static inline void __tlb_flush_global(void)
  17. {
  18. extern void smp_ptlb_all(void);
  19. register unsigned long reg2 asm("2");
  20. register unsigned long reg3 asm("3");
  21. register unsigned long reg4 asm("4");
  22. long dummy;
  23. #ifndef __s390x__
  24. if (!MACHINE_HAS_CSP) {
  25. smp_ptlb_all();
  26. return;
  27. }
  28. #endif /* __s390x__ */
  29. dummy = 0;
  30. reg2 = reg3 = 0;
  31. reg4 = ((unsigned long) &dummy) + 1;
  32. asm volatile(
  33. " csp %0,%2"
  34. : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
  35. }
  36. /*
  37. * Flush all tlb entries of a page table on all cpus.
  38. */
  39. static inline void __tlb_flush_idte(pgd_t *pgd)
  40. {
  41. asm volatile(
  42. " .insn rrf,0xb98e0000,0,%0,%1,0"
  43. : : "a" (2048), "a" (__pa(pgd) & PAGE_MASK) : "cc" );
  44. }
  45. static inline void __tlb_flush_mm(struct mm_struct * mm)
  46. {
  47. cpumask_t local_cpumask;
  48. if (unlikely(cpus_empty(mm->cpu_vm_mask)))
  49. return;
  50. /*
  51. * If the machine has IDTE we prefer to do a per mm flush
  52. * on all cpus instead of doing a local flush if the mm
  53. * only ran on the local cpu.
  54. */
  55. if (MACHINE_HAS_IDTE) {
  56. pgd_t *shadow_pgd = get_shadow_table(mm->pgd);
  57. if (shadow_pgd)
  58. __tlb_flush_idte(shadow_pgd);
  59. __tlb_flush_idte(mm->pgd);
  60. return;
  61. }
  62. preempt_disable();
  63. /*
  64. * If the process only ran on the local cpu, do a local flush.
  65. */
  66. local_cpumask = cpumask_of_cpu(smp_processor_id());
  67. if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
  68. __tlb_flush_local();
  69. else
  70. __tlb_flush_global();
  71. preempt_enable();
  72. }
  73. static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
  74. {
  75. if (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm)
  76. __tlb_flush_mm(mm);
  77. }
  78. /*
  79. * TLB flushing:
  80. * flush_tlb() - flushes the current mm struct TLBs
  81. * flush_tlb_all() - flushes all processes TLBs
  82. * flush_tlb_mm(mm) - flushes the specified mm context TLB's
  83. * flush_tlb_page(vma, vmaddr) - flushes one page
  84. * flush_tlb_range(vma, start, end) - flushes a range of pages
  85. * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
  86. */
  87. /*
  88. * flush_tlb_mm goes together with ptep_set_wrprotect for the
  89. * copy_page_range operation and flush_tlb_range is related to
  90. * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
  91. * ptep_get_and_clear do not flush the TLBs directly if the mm has
  92. * only one user. At the end of the update the flush_tlb_mm and
  93. * flush_tlb_range functions need to do the flush.
  94. */
  95. #define flush_tlb() do { } while (0)
  96. #define flush_tlb_all() do { } while (0)
  97. #define flush_tlb_mm(mm) __tlb_flush_mm_cond(mm)
  98. #define flush_tlb_page(vma, addr) do { } while (0)
  99. #define flush_tlb_range(vma, start, end) __tlb_flush_mm_cond(mm)
  100. #define flush_tlb_kernel_range(start, end) __tlb_flush_mm(&init_mm)
  101. #endif /* _S390_TLBFLUSH_H */