tlbflush.h 3.4 KB

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