blob: 490014c48b1356d604ab2c2ea849540ac170e297 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _S390_TLBFLUSH_H
2#define _S390_TLBFLUSH_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/mm.h>
Gerald Schaefer53492b12008-04-30 13:38:46 +02005#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/processor.h>
Gerald Schaeferc1821c22007-02-05 21:18:17 +01007#include <asm/pgalloc.h>
Heiko Carstens4ccccc52016-05-14 10:46:33 +02008#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10/*
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020011 * Flush all TLB entries on the local CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020013static inline void __tlb_flush_local(void)
14{
15 asm volatile("ptlb" : : : "memory");
16}
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/*
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020019 * Flush TLB entries for a specific ASCE on all CPUs
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020021static inline void __tlb_flush_idte(unsigned long asce)
22{
23 /* Global TLB flush for the mm */
24 asm volatile(
25 " .insn rrf,0xb98e0000,0,%0,%1,0"
26 : : "a" (2048), "a" (asce) : "cc");
27}
28
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020029#ifdef CONFIG_SMP
Heiko Carstensa8061702008-04-17 07:46:26 +020030void smp_ptlb_all(void);
31
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020032/*
33 * Flush all TLB entries on all CPUs.
34 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020035static inline void __tlb_flush_global(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Heiko Carstens4ccccc52016-05-14 10:46:33 +020037 unsigned int dummy = 0;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020038
Heiko Carstens4ccccc52016-05-14 10:46:33 +020039 csp(&dummy, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020042/*
43 * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
44 * this implicates multiple ASCEs!).
45 */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020046static inline void __tlb_flush_full(struct mm_struct *mm)
47{
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020048 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020049 atomic_inc(&mm->context.flush_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020050 if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
51 /* Local TLB flush */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020052 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020053 } else {
54 /* Global TLB flush */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020055 __tlb_flush_global();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020056 /* Reset TLB flush mask */
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +020057 cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020058 }
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020059 atomic_dec(&mm->context.flush_count);
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020060 preempt_enable();
61}
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
David Hildenbrandf0454022016-07-07 10:44:10 +020064 * Flush TLB entries for a specific ASCE on all CPUs. Should never be used
65 * when more than one asce (e.g. gmap) ran on this mm.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020067static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020068{
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020069 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020070 atomic_inc(&mm->context.flush_count);
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +020071 if (MACHINE_HAS_IDTE)
72 __tlb_flush_idte(asce);
73 else
74 __tlb_flush_global();
75 /* Reset TLB flush mask */
76 cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020077 atomic_dec(&mm->context.flush_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020078 preempt_enable();
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020079}
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020081static inline void __tlb_flush_kernel(void)
82{
83 if (MACHINE_HAS_IDTE)
Gerald Schaefer723cacb2016-04-15 16:38:40 +020084 __tlb_flush_idte(init_mm.context.asce);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020085 else
86 __tlb_flush_global();
87}
88#else
89#define __tlb_flush_global() __tlb_flush_local()
90#define __tlb_flush_full(mm) __tlb_flush_local()
91
92/*
93 * Flush TLB entries for a specific ASCE on all CPUs.
94 */
95static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce)
96{
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +020097 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020098}
99
100static inline void __tlb_flush_kernel(void)
101{
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +0200102 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200103}
104#endif
105
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200106static inline void __tlb_flush_mm(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200108 /*
109 * If the machine has IDTE we prefer to do a per mm flush
110 * on all cpus instead of doing a local flush if the mm
111 * only ran on the local cpu.
112 */
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200113 if (MACHINE_HAS_IDTE && list_empty(&mm->context.gmap_list))
Gerald Schaefer723cacb2016-04-15 16:38:40 +0200114 __tlb_flush_asce(mm, mm->context.asce);
Martin Schwidefsky043d0702011-05-23 10:24:23 +0200115 else
116 __tlb_flush_full(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200119static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200121 if (mm->context.flush_mm) {
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200122 __tlb_flush_mm(mm);
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200123 mm->context.flush_mm = 0;
124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200127/*
128 * TLB flushing:
129 * flush_tlb() - flushes the current mm struct TLBs
130 * flush_tlb_all() - flushes all processes TLBs
131 * flush_tlb_mm(mm) - flushes the specified mm context TLB's
132 * flush_tlb_page(vma, vmaddr) - flushes one page
133 * flush_tlb_range(vma, start, end) - flushes a range of pages
134 * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
135 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200137/*
138 * flush_tlb_mm goes together with ptep_set_wrprotect for the
139 * copy_page_range operation and flush_tlb_range is related to
140 * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
141 * ptep_get_and_clear do not flush the TLBs directly if the mm has
142 * only one user. At the end of the update the flush_tlb_mm and
143 * flush_tlb_range functions need to do the flush.
144 */
145#define flush_tlb() do { } while (0)
146#define flush_tlb_all() do { } while (0)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200147#define flush_tlb_page(vma, addr) do { } while (0)
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100148
149static inline void flush_tlb_mm(struct mm_struct *mm)
150{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200151 __tlb_flush_mm_lazy(mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100152}
153
154static inline void flush_tlb_range(struct vm_area_struct *vma,
155 unsigned long start, unsigned long end)
156{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200157 __tlb_flush_mm_lazy(vma->vm_mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100158}
159
160static inline void flush_tlb_kernel_range(unsigned long start,
161 unsigned long end)
162{
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200163 __tlb_flush_kernel();
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100164}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#endif /* _S390_TLBFLUSH_H */