blob: 70fa5ae581801b8a112edc0f71dfc9c9770ed83b [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
16/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020017 * Flush all tlb entries on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020019static inline void __tlb_flush_global(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020021 extern void smp_ptlb_all(void);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020022 register unsigned long reg2 asm("2");
23 register unsigned long reg3 asm("3");
24 register unsigned long reg4 asm("4");
25 long dummy;
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#ifndef __s390x__
28 if (!MACHINE_HAS_CSP) {
29 smp_ptlb_all();
30 return;
31 }
32#endif /* __s390x__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020034 dummy = 0;
35 reg2 = reg3 = 0;
36 reg4 = ((unsigned long) &dummy) + 1;
37 asm volatile(
38 " csp %0,%2"
39 : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020043 * Flush all tlb entries of a page table on all cpus.
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 */
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010045static inline void __tlb_flush_idte(unsigned long asce)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020046{
47 asm volatile(
48 " .insn rrf,0xb98e0000,0,%0,%1,0"
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010049 : : "a" (2048), "a" (asce) : "cc" );
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020050}
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020052static inline void __tlb_flush_mm(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 cpumask_t local_cpumask;
55
56 if (unlikely(cpus_empty(mm->cpu_vm_mask)))
57 return;
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020058 /*
59 * If the machine has IDTE we prefer to do a per mm flush
60 * on all cpus instead of doing a local flush if the mm
61 * only ran on the local cpu.
62 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 if (MACHINE_HAS_IDTE) {
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010064 pgd_t *shadow = get_shadow_table(mm->pgd);
Gerald Schaeferc1821c22007-02-05 21:18:17 +010065
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010066 if (shadow)
67 __tlb_flush_idte((unsigned long) shadow | mm->context);
68 __tlb_flush_idte((unsigned long) mm->pgd | mm->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return;
70 }
71 preempt_disable();
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020072 /*
73 * If the process only ran on the local cpu, do a local flush.
74 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 local_cpumask = cpumask_of_cpu(smp_processor_id());
76 if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020077 __tlb_flush_local();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 else
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020079 __tlb_flush_global();
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 preempt_enable();
81}
82
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020083static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020085 if (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm)
86 __tlb_flush_mm(mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020089/*
90 * TLB flushing:
91 * flush_tlb() - flushes the current mm struct TLBs
92 * flush_tlb_all() - flushes all processes TLBs
93 * flush_tlb_mm(mm) - flushes the specified mm context TLB's
94 * flush_tlb_page(vma, vmaddr) - flushes one page
95 * flush_tlb_range(vma, start, end) - flushes a range of pages
96 * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
97 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020099/*
100 * flush_tlb_mm goes together with ptep_set_wrprotect for the
101 * copy_page_range operation and flush_tlb_range is related to
102 * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
103 * ptep_get_and_clear do not flush the TLBs directly if the mm has
104 * only one user. At the end of the update the flush_tlb_mm and
105 * flush_tlb_range functions need to do the flush.
106 */
107#define flush_tlb() do { } while (0)
108#define flush_tlb_all() do { } while (0)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200109#define flush_tlb_page(vma, addr) do { } while (0)
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100110
111static inline void flush_tlb_mm(struct mm_struct *mm)
112{
113 __tlb_flush_mm_cond(mm);
114}
115
116static inline void flush_tlb_range(struct vm_area_struct *vma,
117 unsigned long start, unsigned long end)
118{
119 __tlb_flush_mm_cond(vma->vm_mm);
120}
121
122static inline void flush_tlb_kernel_range(unsigned long start,
123 unsigned long end)
124{
125 __tlb_flush_mm(&init_mm);
126}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif /* _S390_TLBFLUSH_H */