xref: /linux/arch/sh/mm/tlbflush_32.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
1efddb4c8SPaul Mundt /*
2efddb4c8SPaul Mundt  * TLB flushing operations for SH with an MMU.
3efddb4c8SPaul Mundt  *
4efddb4c8SPaul Mundt  *  Copyright (C) 1999  Niibe Yutaka
5efddb4c8SPaul Mundt  *  Copyright (C) 2003  Paul Mundt
6efddb4c8SPaul Mundt  *
7efddb4c8SPaul Mundt  * This file is subject to the terms and conditions of the GNU General Public
8efddb4c8SPaul Mundt  * License.  See the file "COPYING" in the main directory of this archive
9efddb4c8SPaul Mundt  * for more details.
10efddb4c8SPaul Mundt  */
11efddb4c8SPaul Mundt #include <linux/mm.h>
12efddb4c8SPaul Mundt #include <asm/mmu_context.h>
13efddb4c8SPaul Mundt #include <asm/tlbflush.h>
14efddb4c8SPaul Mundt 
local_flush_tlb_page(struct vm_area_struct * vma,unsigned long page)15efddb4c8SPaul Mundt void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
16efddb4c8SPaul Mundt {
17efddb4c8SPaul Mundt 	unsigned int cpu = smp_processor_id();
18efddb4c8SPaul Mundt 
19efddb4c8SPaul Mundt 	if (vma->vm_mm && cpu_context(cpu, vma->vm_mm) != NO_CONTEXT) {
20efddb4c8SPaul Mundt 		unsigned long flags;
21efddb4c8SPaul Mundt 		unsigned long asid;
22efddb4c8SPaul Mundt 		unsigned long saved_asid = MMU_NO_ASID;
23efddb4c8SPaul Mundt 
24efddb4c8SPaul Mundt 		asid = cpu_asid(cpu, vma->vm_mm);
25efddb4c8SPaul Mundt 		page &= PAGE_MASK;
26efddb4c8SPaul Mundt 
27efddb4c8SPaul Mundt 		local_irq_save(flags);
28efddb4c8SPaul Mundt 		if (vma->vm_mm != current->mm) {
29efddb4c8SPaul Mundt 			saved_asid = get_asid();
30efddb4c8SPaul Mundt 			set_asid(asid);
31efddb4c8SPaul Mundt 		}
32efddb4c8SPaul Mundt 		local_flush_tlb_one(asid, page);
33efddb4c8SPaul Mundt 		if (saved_asid != MMU_NO_ASID)
34efddb4c8SPaul Mundt 			set_asid(saved_asid);
35efddb4c8SPaul Mundt 		local_irq_restore(flags);
36efddb4c8SPaul Mundt 	}
37efddb4c8SPaul Mundt }
38efddb4c8SPaul Mundt 
local_flush_tlb_range(struct vm_area_struct * vma,unsigned long start,unsigned long end)39efddb4c8SPaul Mundt void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
40efddb4c8SPaul Mundt 			   unsigned long end)
41efddb4c8SPaul Mundt {
42efddb4c8SPaul Mundt 	struct mm_struct *mm = vma->vm_mm;
43efddb4c8SPaul Mundt 	unsigned int cpu = smp_processor_id();
44efddb4c8SPaul Mundt 
45efddb4c8SPaul Mundt 	if (cpu_context(cpu, mm) != NO_CONTEXT) {
46efddb4c8SPaul Mundt 		unsigned long flags;
47efddb4c8SPaul Mundt 		int size;
48efddb4c8SPaul Mundt 
49efddb4c8SPaul Mundt 		local_irq_save(flags);
50efddb4c8SPaul Mundt 		size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
51efddb4c8SPaul Mundt 		if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
52efddb4c8SPaul Mundt 			cpu_context(cpu, mm) = NO_CONTEXT;
53efddb4c8SPaul Mundt 			if (mm == current->mm)
54efddb4c8SPaul Mundt 				activate_context(mm, cpu);
55efddb4c8SPaul Mundt 		} else {
56efddb4c8SPaul Mundt 			unsigned long asid;
57efddb4c8SPaul Mundt 			unsigned long saved_asid = MMU_NO_ASID;
58efddb4c8SPaul Mundt 
59efddb4c8SPaul Mundt 			asid = cpu_asid(cpu, mm);
60efddb4c8SPaul Mundt 			start &= PAGE_MASK;
61efddb4c8SPaul Mundt 			end += (PAGE_SIZE - 1);
62efddb4c8SPaul Mundt 			end &= PAGE_MASK;
63efddb4c8SPaul Mundt 			if (mm != current->mm) {
64efddb4c8SPaul Mundt 				saved_asid = get_asid();
65efddb4c8SPaul Mundt 				set_asid(asid);
66efddb4c8SPaul Mundt 			}
67efddb4c8SPaul Mundt 			while (start < end) {
68efddb4c8SPaul Mundt 				local_flush_tlb_one(asid, start);
69efddb4c8SPaul Mundt 				start += PAGE_SIZE;
70efddb4c8SPaul Mundt 			}
71efddb4c8SPaul Mundt 			if (saved_asid != MMU_NO_ASID)
72efddb4c8SPaul Mundt 				set_asid(saved_asid);
73efddb4c8SPaul Mundt 		}
74efddb4c8SPaul Mundt 		local_irq_restore(flags);
75efddb4c8SPaul Mundt 	}
76efddb4c8SPaul Mundt }
77efddb4c8SPaul Mundt 
local_flush_tlb_kernel_range(unsigned long start,unsigned long end)78efddb4c8SPaul Mundt void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
79efddb4c8SPaul Mundt {
80efddb4c8SPaul Mundt 	unsigned int cpu = smp_processor_id();
81efddb4c8SPaul Mundt 	unsigned long flags;
82efddb4c8SPaul Mundt 	int size;
83efddb4c8SPaul Mundt 
84efddb4c8SPaul Mundt 	local_irq_save(flags);
85efddb4c8SPaul Mundt 	size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
86efddb4c8SPaul Mundt 	if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
87efddb4c8SPaul Mundt 		local_flush_tlb_all();
88efddb4c8SPaul Mundt 	} else {
89efddb4c8SPaul Mundt 		unsigned long asid;
90efddb4c8SPaul Mundt 		unsigned long saved_asid = get_asid();
91efddb4c8SPaul Mundt 
92efddb4c8SPaul Mundt 		asid = cpu_asid(cpu, &init_mm);
93efddb4c8SPaul Mundt 		start &= PAGE_MASK;
94efddb4c8SPaul Mundt 		end += (PAGE_SIZE - 1);
95efddb4c8SPaul Mundt 		end &= PAGE_MASK;
96efddb4c8SPaul Mundt 		set_asid(asid);
97efddb4c8SPaul Mundt 		while (start < end) {
98efddb4c8SPaul Mundt 			local_flush_tlb_one(asid, start);
99efddb4c8SPaul Mundt 			start += PAGE_SIZE;
100efddb4c8SPaul Mundt 		}
101efddb4c8SPaul Mundt 		set_asid(saved_asid);
102efddb4c8SPaul Mundt 	}
103efddb4c8SPaul Mundt 	local_irq_restore(flags);
104efddb4c8SPaul Mundt }
105efddb4c8SPaul Mundt 
local_flush_tlb_mm(struct mm_struct * mm)106efddb4c8SPaul Mundt void local_flush_tlb_mm(struct mm_struct *mm)
107efddb4c8SPaul Mundt {
108efddb4c8SPaul Mundt 	unsigned int cpu = smp_processor_id();
109efddb4c8SPaul Mundt 
110efddb4c8SPaul Mundt 	/* Invalidate all TLB of this process. */
111efddb4c8SPaul Mundt 	/* Instead of invalidating each TLB, we get new MMU context. */
112efddb4c8SPaul Mundt 	if (cpu_context(cpu, mm) != NO_CONTEXT) {
113efddb4c8SPaul Mundt 		unsigned long flags;
114efddb4c8SPaul Mundt 
115efddb4c8SPaul Mundt 		local_irq_save(flags);
116efddb4c8SPaul Mundt 		cpu_context(cpu, mm) = NO_CONTEXT;
117efddb4c8SPaul Mundt 		if (mm == current->mm)
118efddb4c8SPaul Mundt 			activate_context(mm, cpu);
119efddb4c8SPaul Mundt 		local_irq_restore(flags);
120efddb4c8SPaul Mundt 	}
121efddb4c8SPaul Mundt }
122*59615ecdSPaul Mundt 
__flush_tlb_global(void)123*59615ecdSPaul Mundt void __flush_tlb_global(void)
124*59615ecdSPaul Mundt {
125*59615ecdSPaul Mundt 	unsigned long flags;
126*59615ecdSPaul Mundt 
127*59615ecdSPaul Mundt 	local_irq_save(flags);
128*59615ecdSPaul Mundt 
129*59615ecdSPaul Mundt 	/*
130*59615ecdSPaul Mundt 	 * This is the most destructive of the TLB flushing options,
131*59615ecdSPaul Mundt 	 * and will tear down all of the UTLB/ITLB mappings, including
132*59615ecdSPaul Mundt 	 * wired entries.
133*59615ecdSPaul Mundt 	 */
134*59615ecdSPaul Mundt 	__raw_writel(__raw_readl(MMUCR) | MMUCR_TI, MMUCR);
135*59615ecdSPaul Mundt 
136*59615ecdSPaul Mundt 	local_irq_restore(flags);
137*59615ecdSPaul Mundt }
138