2 * This file contains the routines for TLB flushing.
3 * On machines where the MMU does not use a hash table to store virtual to
4 * physical translations (ie, SW loaded TLBs or Book3E compilant processors,
5 * this does -not- include 603 however which shares the implementation with
6 * hash based processors)
10 * Copyright 2008 Ben Herrenschmidt <benh@kernel.crashing.org>
13 * Derived from arch/ppc/mm/init.c:
14 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
16 * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
17 * and Cort Dougan (PReP) (cort@cs.nmt.edu)
18 * Copyright (C) 1996 Paul Mackerras
20 * Derived from "arch/i386/mm/init.c"
21 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version
26 * 2 of the License, or (at your option) any later version.
30 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <linux/highmem.h>
34 #include <linux/pagemap.h>
35 #include <linux/preempt.h>
36 #include <linux/spinlock.h>
38 #include <asm/tlbflush.h>
44 * Base TLB flushing operations:
46 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
47 * - flush_tlb_page(vma, vmaddr) flushes one page
48 * - flush_tlb_range(vma, start, end) flushes a range of pages
49 * - flush_tlb_kernel_range(start, end) flushes kernel pages
51 * - local_* variants of page and mm only apply to the current
56 * These are the base non-SMP variants of page and mm flushing
58 void local_flush_tlb_mm(struct mm_struct
*mm
)
64 if (pid
!= MMU_NO_CONTEXT
)
68 EXPORT_SYMBOL(local_flush_tlb_mm
);
70 void local_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long vmaddr
)
75 pid
= vma
? vma
->vm_mm
->context
.id
: 0;
76 if (pid
!= MMU_NO_CONTEXT
)
77 _tlbil_va(vmaddr
, pid
);
80 EXPORT_SYMBOL(local_flush_tlb_page
);
84 * And here are the SMP non-local implementations
88 static DEFINE_SPINLOCK(tlbivax_lock
);
90 struct tlb_flush_param
{
95 static void do_flush_tlb_mm_ipi(void *param
)
97 struct tlb_flush_param
*p
= param
;
99 _tlbil_pid(p
? p
->pid
: 0);
102 static void do_flush_tlb_page_ipi(void *param
)
104 struct tlb_flush_param
*p
= param
;
106 _tlbil_va(p
->addr
, p
->pid
);
110 /* Note on invalidations and PID:
112 * We snapshot the PID with preempt disabled. At this point, it can still
113 * change either because:
114 * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
115 * - we are invaliating some target that isn't currently running here
116 * and is concurrently acquiring a new PID on another CPU
117 * - some other CPU is re-acquiring a lost PID for this mm
120 * However, this shouldn't be a problem as we only guarantee
121 * invalidation of TLB entries present prior to this call, so we
122 * don't care about the PID changing, and invalidating a stale PID
123 * is generally harmless.
126 void flush_tlb_mm(struct mm_struct
*mm
)
132 pid
= mm
->context
.id
;
133 if (unlikely(pid
== MMU_NO_CONTEXT
))
135 if (!cpumask_equal(mm_cpumask(mm
), cpumask_of(smp_processor_id()))) {
136 struct tlb_flush_param p
= { .pid
= pid
};
137 /* Ignores smp_processor_id() even if set. */
138 smp_call_function_many(mm_cpumask(mm
),
139 do_flush_tlb_mm_ipi
, &p
, 1);
145 EXPORT_SYMBOL(flush_tlb_mm
);
147 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long vmaddr
)
149 struct cpumask
*cpu_mask
;
153 pid
= vma
? vma
->vm_mm
->context
.id
: 0;
154 if (unlikely(pid
== MMU_NO_CONTEXT
))
156 cpu_mask
= mm_cpumask(vma
->vm_mm
);
157 if (!cpumask_equal(cpu_mask
, cpumask_of(smp_processor_id()))) {
158 /* If broadcast tlbivax is supported, use it */
159 if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST
)) {
160 int lock
= mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL
);
162 spin_lock(&tlbivax_lock
);
163 _tlbivax_bcast(vmaddr
, pid
);
165 spin_unlock(&tlbivax_lock
);
168 struct tlb_flush_param p
= { .pid
= pid
, .addr
= vmaddr
};
169 /* Ignores smp_processor_id() even if set in cpu_mask */
170 smp_call_function_many(cpu_mask
,
171 do_flush_tlb_page_ipi
, &p
, 1);
174 _tlbil_va(vmaddr
, pid
);
178 EXPORT_SYMBOL(flush_tlb_page
);
180 #endif /* CONFIG_SMP */
183 * Flush kernel TLB entries in the given range
185 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
189 smp_call_function(do_flush_tlb_mm_ipi
, NULL
, 1);
196 EXPORT_SYMBOL(flush_tlb_kernel_range
);
199 * Currently, for range flushing, we just do a full mm flush. This should
200 * be optimized based on a threshold on the size of the range, since
201 * some implementation can stack multiple tlbivax before a tlbsync but
202 * for now, we keep it that way
204 void flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
,
208 flush_tlb_mm(vma
->vm_mm
);
210 EXPORT_SYMBOL(flush_tlb_range
);