Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _S390_TLBFLUSH_H |
| 2 | #define _S390_TLBFLUSH_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/mm.h> |
| 5 | #include <asm/processor.h> |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 6 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | /* |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 9 | * Flush all tlb entries on the local cpu. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 11 | static inline void __tlb_flush_local(void) |
| 12 | { |
| 13 | asm volatile("ptlb" : : : "memory"); |
| 14 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame^] | 16 | #ifdef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 18 | * Flush all tlb entries on all cpus. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 20 | static inline void __tlb_flush_global(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 22 | extern void smp_ptlb_all(void); |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 23 | register unsigned long reg2 asm("2"); |
| 24 | register unsigned long reg3 asm("3"); |
| 25 | register unsigned long reg4 asm("4"); |
| 26 | long dummy; |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #ifndef __s390x__ |
| 29 | if (!MACHINE_HAS_CSP) { |
| 30 | smp_ptlb_all(); |
| 31 | return; |
| 32 | } |
| 33 | #endif /* __s390x__ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 35 | dummy = 0; |
| 36 | reg2 = reg3 = 0; |
| 37 | reg4 = ((unsigned long) &dummy) + 1; |
| 38 | asm volatile( |
| 39 | " csp %0,%2" |
| 40 | : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame^] | 43 | static inline void __tlb_flush_full(struct mm_struct *mm) |
| 44 | { |
| 45 | cpumask_t local_cpumask; |
| 46 | |
| 47 | preempt_disable(); |
| 48 | /* |
| 49 | * If the process only ran on the local cpu, do a local flush. |
| 50 | */ |
| 51 | local_cpumask = cpumask_of_cpu(smp_processor_id()); |
| 52 | if (cpus_equal(mm->cpu_vm_mask, local_cpumask)) |
| 53 | __tlb_flush_local(); |
| 54 | else |
| 55 | __tlb_flush_global(); |
| 56 | preempt_enable(); |
| 57 | } |
| 58 | #else |
| 59 | #define __tlb_flush_full(mm) __tlb_flush_local() |
| 60 | #endif |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 63 | * Flush all tlb entries of a page table on all cpus. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 65 | static inline void __tlb_flush_idte(unsigned long asce) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 66 | { |
| 67 | asm volatile( |
| 68 | " .insn rrf,0xb98e0000,0,%0,%1,0" |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 69 | : : "a" (2048), "a" (asce) : "cc" ); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 70 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 72 | static inline void __tlb_flush_mm(struct mm_struct * mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if (unlikely(cpus_empty(mm->cpu_vm_mask))) |
| 75 | return; |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 76 | /* |
| 77 | * If the machine has IDTE we prefer to do a per mm flush |
| 78 | * on all cpus instead of doing a local flush if the mm |
| 79 | * only ran on the local cpu. |
| 80 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | if (MACHINE_HAS_IDTE) { |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 82 | if (mm->context.noexec) |
| 83 | __tlb_flush_idte((unsigned long) |
| 84 | get_shadow_table(mm->pgd) | |
| 85 | mm->context.asce_bits); |
| 86 | __tlb_flush_idte((unsigned long) mm->pgd | |
| 87 | mm->context.asce_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return; |
| 89 | } |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame^] | 90 | __tlb_flush_full(mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 93 | static inline void __tlb_flush_mm_cond(struct mm_struct * mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 95 | if (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm) |
| 96 | __tlb_flush_mm(mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 99 | /* |
| 100 | * TLB flushing: |
| 101 | * flush_tlb() - flushes the current mm struct TLBs |
| 102 | * flush_tlb_all() - flushes all processes TLBs |
| 103 | * flush_tlb_mm(mm) - flushes the specified mm context TLB's |
| 104 | * flush_tlb_page(vma, vmaddr) - flushes one page |
| 105 | * flush_tlb_range(vma, start, end) - flushes a range of pages |
| 106 | * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages |
| 107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 109 | /* |
| 110 | * flush_tlb_mm goes together with ptep_set_wrprotect for the |
| 111 | * copy_page_range operation and flush_tlb_range is related to |
| 112 | * ptep_get_and_clear for change_protection. ptep_set_wrprotect and |
| 113 | * ptep_get_and_clear do not flush the TLBs directly if the mm has |
| 114 | * only one user. At the end of the update the flush_tlb_mm and |
| 115 | * flush_tlb_range functions need to do the flush. |
| 116 | */ |
| 117 | #define flush_tlb() do { } while (0) |
| 118 | #define flush_tlb_all() do { } while (0) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 119 | #define flush_tlb_page(vma, addr) do { } while (0) |
Martin Schwidefsky | 8ffd74a | 2008-01-26 14:10:59 +0100 | [diff] [blame] | 120 | |
| 121 | static inline void flush_tlb_mm(struct mm_struct *mm) |
| 122 | { |
| 123 | __tlb_flush_mm_cond(mm); |
| 124 | } |
| 125 | |
| 126 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 127 | unsigned long start, unsigned long end) |
| 128 | { |
| 129 | __tlb_flush_mm_cond(vma->vm_mm); |
| 130 | } |
| 131 | |
| 132 | static inline void flush_tlb_kernel_range(unsigned long start, |
| 133 | unsigned long end) |
| 134 | { |
| 135 | __tlb_flush_mm(&init_mm); |
| 136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif /* _S390_TLBFLUSH_H */ |