blob: f9fef0425feecdd808e33bcbe4a457b8ece374ac [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020010 * Flush all tlb entries on the local cpu.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020012static inline void __tlb_flush_local(void)
13{
14 asm volatile("ptlb" : : : "memory");
15}
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020017#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020019 * Flush all tlb entries on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
Heiko Carstensa8061702008-04-17 07:46:26 +020021void smp_ptlb_all(void);
22
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020023static inline void __tlb_flush_global(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020025 register unsigned long reg2 asm("2");
26 register unsigned long reg3 asm("3");
27 register unsigned long reg4 asm("4");
28 long dummy;
29
Heiko Carstensf4815ac2012-05-23 16:24:51 +020030#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 if (!MACHINE_HAS_CSP) {
32 smp_ptlb_all();
33 return;
34 }
Heiko Carstensf4815ac2012-05-23 16:24:51 +020035#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020037 dummy = 0;
38 reg2 = reg3 = 0;
39 reg4 = ((unsigned long) &dummy) + 1;
40 asm volatile(
41 " csp %0,%2"
42 : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020045static inline void __tlb_flush_full(struct mm_struct *mm)
46{
47 cpumask_t local_cpumask;
48
49 preempt_disable();
50 /*
51 * If the process only ran on the local cpu, do a local flush.
52 */
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020053 cpumask_copy(&local_cpumask, cpumask_of(smp_processor_id()));
Rusty Russell005f8ee2009-03-26 15:25:01 +010054 if (cpumask_equal(mm_cpumask(mm), &local_cpumask))
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020055 __tlb_flush_local();
56 else
57 __tlb_flush_global();
58 preempt_enable();
59}
60#else
61#define __tlb_flush_full(mm) __tlb_flush_local()
Jan Glaubere1c4d012011-10-30 15:17:18 +010062#define __tlb_flush_global() __tlb_flush_local()
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020063#endif
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020066 * Flush all tlb entries of a page table on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010068static inline void __tlb_flush_idte(unsigned long asce)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020069{
70 asm volatile(
71 " .insn rrf,0xb98e0000,0,%0,%1,0"
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010072 : : "a" (2048), "a" (asce) : "cc" );
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020073}
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020075static inline void __tlb_flush_mm(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020077 /*
78 * If the machine has IDTE we prefer to do a per mm flush
79 * on all cpus instead of doing a local flush if the mm
80 * only ran on the local cpu.
81 */
Martin Schwidefskye5992f22011-07-24 10:48:20 +020082 if (MACHINE_HAS_IDTE && list_empty(&mm->context.gmap_list))
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010083 __tlb_flush_idte((unsigned long) mm->pgd |
84 mm->context.asce_bits);
Martin Schwidefsky043d0702011-05-23 10:24:23 +020085 else
86 __tlb_flush_full(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Martin Schwidefsky5c474a12013-08-16 13:31:40 +020089static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Martin Schwidefsky050eef32010-08-24 09:26:21 +020091 if (mm->context.flush_mm) {
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020092 __tlb_flush_mm(mm);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020093 mm->context.flush_mm = 0;
94 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020097/*
98 * TLB flushing:
99 * flush_tlb() - flushes the current mm struct TLBs
100 * flush_tlb_all() - flushes all processes TLBs
101 * flush_tlb_mm(mm) - flushes the specified mm context TLB's
102 * flush_tlb_page(vma, vmaddr) - flushes one page
103 * flush_tlb_range(vma, start, end) - flushes a range of pages
104 * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
105 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200107/*
108 * flush_tlb_mm goes together with ptep_set_wrprotect for the
109 * copy_page_range operation and flush_tlb_range is related to
110 * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
111 * ptep_get_and_clear do not flush the TLBs directly if the mm has
112 * only one user. At the end of the update the flush_tlb_mm and
113 * flush_tlb_range functions need to do the flush.
114 */
115#define flush_tlb() do { } while (0)
116#define flush_tlb_all() do { } while (0)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200117#define flush_tlb_page(vma, addr) do { } while (0)
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100118
119static inline void flush_tlb_mm(struct mm_struct *mm)
120{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200121 __tlb_flush_mm_lazy(mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100122}
123
124static inline void flush_tlb_range(struct vm_area_struct *vma,
125 unsigned long start, unsigned long end)
126{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200127 __tlb_flush_mm_lazy(vma->vm_mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100128}
129
130static inline void flush_tlb_kernel_range(unsigned long start,
131 unsigned long end)
132{
133 __tlb_flush_mm(&init_mm);
134}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif /* _S390_TLBFLUSH_H */