tlbflush.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. * TLB flushing:
  8. *
  9. * - flush_tlb() flushes the current mm struct TLBs
  10. * - flush_tlb_all() flushes all processes TLBs
  11. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  12. * - flush_tlb_page(vma, vmaddr) flushes one page
  13. * - flush_tlb_range(vma, start, end) flushes a range of pages
  14. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  15. * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
  16. */
  17. /*
  18. * S/390 has three ways of flushing TLBs
  19. * 'ptlb' does a flush of the local processor
  20. * 'csp' flushes the TLBs on all PUs of a SMP
  21. * 'ipte' invalidates a pte in a page table and flushes that out of
  22. * the TLBs of all PUs of a SMP
  23. */
  24. #define local_flush_tlb() \
  25. do { asm volatile("ptlb": : :"memory"); } while (0)
  26. #ifndef CONFIG_SMP
  27. /*
  28. * We always need to flush, since s390 does not flush tlb
  29. * on each context switch
  30. */
  31. static inline void flush_tlb(void)
  32. {
  33. local_flush_tlb();
  34. }
  35. static inline void flush_tlb_all(void)
  36. {
  37. local_flush_tlb();
  38. }
  39. static inline void flush_tlb_mm(struct mm_struct *mm)
  40. {
  41. local_flush_tlb();
  42. }
  43. static inline void flush_tlb_page(struct vm_area_struct *vma,
  44. unsigned long addr)
  45. {
  46. local_flush_tlb();
  47. }
  48. static inline void flush_tlb_range(struct vm_area_struct *vma,
  49. unsigned long start, unsigned long end)
  50. {
  51. local_flush_tlb();
  52. }
  53. #define flush_tlb_kernel_range(start, end) \
  54. local_flush_tlb();
  55. #else
  56. #include <asm/smp.h>
  57. extern void smp_ptlb_all(void);
  58. static inline void global_flush_tlb(void)
  59. {
  60. register unsigned long reg2 asm("2");
  61. register unsigned long reg3 asm("3");
  62. register unsigned long reg4 asm("4");
  63. long dummy;
  64. #ifndef __s390x__
  65. if (!MACHINE_HAS_CSP) {
  66. smp_ptlb_all();
  67. return;
  68. }
  69. #endif /* __s390x__ */
  70. dummy = 0;
  71. reg2 = reg3 = 0;
  72. reg4 = ((unsigned long) &dummy) + 1;
  73. asm volatile(
  74. " csp %0,%2"
  75. : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
  76. }
  77. /*
  78. * We only have to do global flush of tlb if process run since last
  79. * flush on any other pu than current.
  80. * If we have threads (mm->count > 1) we always do a global flush,
  81. * since the process runs on more than one processor at the same time.
  82. */
  83. static inline void __flush_tlb_mm(struct mm_struct * mm)
  84. {
  85. cpumask_t local_cpumask;
  86. if (unlikely(cpus_empty(mm->cpu_vm_mask)))
  87. return;
  88. if (MACHINE_HAS_IDTE) {
  89. pgd_t *shadow_pgd = get_shadow_pgd(mm->pgd);
  90. if (shadow_pgd) {
  91. asm volatile(
  92. " .insn rrf,0xb98e0000,0,%0,%1,0"
  93. : : "a" (2048),
  94. "a" (__pa(shadow_pgd) & PAGE_MASK) : "cc" );
  95. }
  96. asm volatile(
  97. " .insn rrf,0xb98e0000,0,%0,%1,0"
  98. : : "a" (2048), "a" (__pa(mm->pgd)&PAGE_MASK) : "cc");
  99. return;
  100. }
  101. preempt_disable();
  102. local_cpumask = cpumask_of_cpu(smp_processor_id());
  103. if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
  104. local_flush_tlb();
  105. else
  106. global_flush_tlb();
  107. preempt_enable();
  108. }
  109. static inline void flush_tlb(void)
  110. {
  111. __flush_tlb_mm(current->mm);
  112. }
  113. static inline void flush_tlb_all(void)
  114. {
  115. global_flush_tlb();
  116. }
  117. static inline void flush_tlb_mm(struct mm_struct *mm)
  118. {
  119. __flush_tlb_mm(mm);
  120. }
  121. static inline void flush_tlb_page(struct vm_area_struct *vma,
  122. unsigned long addr)
  123. {
  124. __flush_tlb_mm(vma->vm_mm);
  125. }
  126. static inline void flush_tlb_range(struct vm_area_struct *vma,
  127. unsigned long start, unsigned long end)
  128. {
  129. __flush_tlb_mm(vma->vm_mm);
  130. }
  131. #define flush_tlb_kernel_range(start, end) global_flush_tlb()
  132. #endif
  133. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  134. unsigned long start, unsigned long end)
  135. {
  136. /* S/390 does not keep any page table caches in TLB */
  137. }
  138. #endif /* _S390_TLBFLUSH_H */