blob: 9e57a93d7de153dfcfb094bd07d73cc29d31599f [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>
5#include <asm/processor.h>
Gerald Schaeferc1821c22007-02-05 21:18:17 +01006#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +02009 * Flush all tlb entries on the local cpu.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020011static inline void __tlb_flush_local(void)
12{
13 asm volatile("ptlb" : : : "memory");
14}
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020016#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020018 * Flush all tlb entries on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
Heiko Carstensa8061702008-04-17 07:46:26 +020020void smp_ptlb_all(void);
21
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020022static inline void __tlb_flush_global(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020024 register unsigned long reg2 asm("2");
25 register unsigned long reg3 asm("3");
26 register unsigned long reg4 asm("4");
27 long dummy;
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#ifndef __s390x__
30 if (!MACHINE_HAS_CSP) {
31 smp_ptlb_all();
32 return;
33 }
34#endif /* __s390x__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020036 dummy = 0;
37 reg2 = reg3 = 0;
38 reg4 = ((unsigned long) &dummy) + 1;
39 asm volatile(
40 " csp %0,%2"
41 : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020044static inline void __tlb_flush_full(struct mm_struct *mm)
45{
46 cpumask_t local_cpumask;
47
48 preempt_disable();
49 /*
50 * If the process only ran on the local cpu, do a local flush.
51 */
52 local_cpumask = cpumask_of_cpu(smp_processor_id());
53 if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
54 __tlb_flush_local();
55 else
56 __tlb_flush_global();
57 preempt_enable();
58}
59#else
60#define __tlb_flush_full(mm) __tlb_flush_local()
61#endif
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020064 * Flush all tlb entries of a page table on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010066static inline void __tlb_flush_idte(unsigned long asce)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020067{
68 asm volatile(
69 " .insn rrf,0xb98e0000,0,%0,%1,0"
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010070 : : "a" (2048), "a" (asce) : "cc" );
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020071}
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020073static inline void __tlb_flush_mm(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 if (unlikely(cpus_empty(mm->cpu_vm_mask)))
76 return;
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 if (MACHINE_HAS_IDTE) {
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010083 if (mm->context.noexec)
84 __tlb_flush_idte((unsigned long)
85 get_shadow_table(mm->pgd) |
86 mm->context.asce_bits);
87 __tlb_flush_idte((unsigned long) mm->pgd |
88 mm->context.asce_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return;
90 }
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020091 __tlb_flush_full(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020094static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020096 if (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm)
97 __tlb_flush_mm(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200100/*
101 * TLB flushing:
102 * flush_tlb() - flushes the current mm struct TLBs
103 * flush_tlb_all() - flushes all processes TLBs
104 * flush_tlb_mm(mm) - flushes the specified mm context TLB's
105 * flush_tlb_page(vma, vmaddr) - flushes one page
106 * flush_tlb_range(vma, start, end) - flushes a range of pages
107 * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
108 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200110/*
111 * flush_tlb_mm goes together with ptep_set_wrprotect for the
112 * copy_page_range operation and flush_tlb_range is related to
113 * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
114 * ptep_get_and_clear do not flush the TLBs directly if the mm has
115 * only one user. At the end of the update the flush_tlb_mm and
116 * flush_tlb_range functions need to do the flush.
117 */
118#define flush_tlb() do { } while (0)
119#define flush_tlb_all() do { } while (0)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200120#define flush_tlb_page(vma, addr) do { } while (0)
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100121
122static inline void flush_tlb_mm(struct mm_struct *mm)
123{
124 __tlb_flush_mm_cond(mm);
125}
126
127static inline void flush_tlb_range(struct vm_area_struct *vma,
128 unsigned long start, unsigned long end)
129{
130 __tlb_flush_mm_cond(vma->vm_mm);
131}
132
133static inline void flush_tlb_kernel_range(unsigned long start,
134 unsigned long end)
135{
136 __tlb_flush_mm(&init_mm);
137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif /* _S390_TLBFLUSH_H */