blob: 6de2632a3e4f5ac1fb6c63431c4de4bf51148a9c [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/*
9 * TLB flushing:
10 *
11 * - flush_tlb() flushes the current mm struct TLBs
12 * - flush_tlb_all() flushes all processes TLBs
13 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
14 * - flush_tlb_page(vma, vmaddr) flushes one page
15 * - flush_tlb_range(vma, start, end) flushes a range of pages
16 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19/*
20 * S/390 has three ways of flushing TLBs
21 * 'ptlb' does a flush of the local processor
22 * 'csp' flushes the TLBs on all PUs of a SMP
23 * 'ipte' invalidates a pte in a page table and flushes that out of
24 * the TLBs of all PUs of a SMP
25 */
26
27#define local_flush_tlb() \
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020028do { asm volatile("ptlb": : :"memory"); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#ifndef CONFIG_SMP
31
32/*
33 * We always need to flush, since s390 does not flush tlb
34 * on each context switch
35 */
36
37static inline void flush_tlb(void)
38{
39 local_flush_tlb();
40}
41static inline void flush_tlb_all(void)
42{
43 local_flush_tlb();
44}
45static inline void flush_tlb_mm(struct mm_struct *mm)
46{
47 local_flush_tlb();
48}
49static inline void flush_tlb_page(struct vm_area_struct *vma,
50 unsigned long addr)
51{
52 local_flush_tlb();
53}
54static inline void flush_tlb_range(struct vm_area_struct *vma,
55 unsigned long start, unsigned long end)
56{
57 local_flush_tlb();
58}
59
60#define flush_tlb_kernel_range(start, end) \
61 local_flush_tlb();
62
63#else
64
65#include <asm/smp.h>
66
67extern void smp_ptlb_all(void);
68
69static inline void global_flush_tlb(void)
70{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020071 register unsigned long reg2 asm("2");
72 register unsigned long reg3 asm("3");
73 register unsigned long reg4 asm("4");
74 long dummy;
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#ifndef __s390x__
77 if (!MACHINE_HAS_CSP) {
78 smp_ptlb_all();
79 return;
80 }
81#endif /* __s390x__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020083 dummy = 0;
84 reg2 = reg3 = 0;
85 reg4 = ((unsigned long) &dummy) + 1;
86 asm volatile(
87 " csp %0,%2"
88 : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91/*
92 * We only have to do global flush of tlb if process run since last
93 * flush on any other pu than current.
94 * If we have threads (mm->count > 1) we always do a global flush,
95 * since the process runs on more than one processor at the same time.
96 */
97
98static inline void __flush_tlb_mm(struct mm_struct * mm)
99{
100 cpumask_t local_cpumask;
101
102 if (unlikely(cpus_empty(mm->cpu_vm_mask)))
103 return;
104 if (MACHINE_HAS_IDTE) {
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100105 pgd_t *shadow_pgd = get_shadow_pgd(mm->pgd);
106
107 if (shadow_pgd) {
108 asm volatile(
109 " .insn rrf,0xb98e0000,0,%0,%1,0"
110 : : "a" (2048),
111 "a" (__pa(shadow_pgd) & PAGE_MASK) : "cc" );
112 }
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200113 asm volatile(
114 " .insn rrf,0xb98e0000,0,%0,%1,0"
115 : : "a" (2048), "a" (__pa(mm->pgd)&PAGE_MASK) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return;
117 }
118 preempt_disable();
119 local_cpumask = cpumask_of_cpu(smp_processor_id());
120 if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
121 local_flush_tlb();
122 else
123 global_flush_tlb();
124 preempt_enable();
125}
126
127static inline void flush_tlb(void)
128{
129 __flush_tlb_mm(current->mm);
130}
131static inline void flush_tlb_all(void)
132{
133 global_flush_tlb();
134}
135static inline void flush_tlb_mm(struct mm_struct *mm)
136{
137 __flush_tlb_mm(mm);
138}
139static inline void flush_tlb_page(struct vm_area_struct *vma,
140 unsigned long addr)
141{
142 __flush_tlb_mm(vma->vm_mm);
143}
144static inline void flush_tlb_range(struct vm_area_struct *vma,
145 unsigned long start, unsigned long end)
146{
147 __flush_tlb_mm(vma->vm_mm);
148}
149
150#define flush_tlb_kernel_range(start, end) global_flush_tlb()
151
152#endif
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif /* _S390_TLBFLUSH_H */