blob: 6f45c1f8a7fedd72a3d839190cfa33d5acc4d53e [file] [log] [blame]
Paul Mundt26ff6c12006-09-27 15:13:36 +09001/*
2 * TLB flushing operations for SH with an MMU.
3 *
4 * Copyright (C) 1999 Niibe Yutaka
Paul Mundt39e688a2007-03-05 19:46:47 +09005 * Copyright (C) 2003 Paul Mundt
Paul Mundt26ff6c12006-09-27 15:13:36 +09006 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/mm.h>
12#include <asm/mmu_context.h>
13#include <asm/tlbflush.h>
14
Paul Mundtea9af692006-12-25 19:28:54 +090015void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
Paul Mundt26ff6c12006-09-27 15:13:36 +090016{
Paul Mundtaec5e0e2006-12-25 09:51:47 +090017 unsigned int cpu = smp_processor_id();
18
19 if (vma->vm_mm && cpu_context(cpu, vma->vm_mm) != NO_CONTEXT) {
Paul Mundt26ff6c12006-09-27 15:13:36 +090020 unsigned long flags;
21 unsigned long asid;
22 unsigned long saved_asid = MMU_NO_ASID;
23
Paul Mundtaec5e0e2006-12-25 09:51:47 +090024 asid = cpu_asid(cpu, vma->vm_mm);
Paul Mundt26ff6c12006-09-27 15:13:36 +090025 page &= PAGE_MASK;
26
27 local_irq_save(flags);
28 if (vma->vm_mm != current->mm) {
29 saved_asid = get_asid();
30 set_asid(asid);
31 }
Paul Mundt00720322006-12-25 19:37:56 +090032 local_flush_tlb_one(asid, page);
Paul Mundt26ff6c12006-09-27 15:13:36 +090033 if (saved_asid != MMU_NO_ASID)
34 set_asid(saved_asid);
35 local_irq_restore(flags);
36 }
37}
38
Paul Mundtea9af692006-12-25 19:28:54 +090039void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
40 unsigned long end)
Paul Mundt26ff6c12006-09-27 15:13:36 +090041{
42 struct mm_struct *mm = vma->vm_mm;
Paul Mundtaec5e0e2006-12-25 09:51:47 +090043 unsigned int cpu = smp_processor_id();
Paul Mundt26ff6c12006-09-27 15:13:36 +090044
Paul Mundtaec5e0e2006-12-25 09:51:47 +090045 if (cpu_context(cpu, mm) != NO_CONTEXT) {
Paul Mundt26ff6c12006-09-27 15:13:36 +090046 unsigned long flags;
47 int size;
48
49 local_irq_save(flags);
50 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
51 if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
Paul Mundtaec5e0e2006-12-25 09:51:47 +090052 cpu_context(cpu, mm) = NO_CONTEXT;
Paul Mundt26ff6c12006-09-27 15:13:36 +090053 if (mm == current->mm)
Paul Mundtaec5e0e2006-12-25 09:51:47 +090054 activate_context(mm, cpu);
Paul Mundt26ff6c12006-09-27 15:13:36 +090055 } else {
Paul Mundt19f9a342006-09-27 18:33:49 +090056 unsigned long asid;
Paul Mundt26ff6c12006-09-27 15:13:36 +090057 unsigned long saved_asid = MMU_NO_ASID;
58
Paul Mundtaec5e0e2006-12-25 09:51:47 +090059 asid = cpu_asid(cpu, mm);
Paul Mundt26ff6c12006-09-27 15:13:36 +090060 start &= PAGE_MASK;
61 end += (PAGE_SIZE - 1);
62 end &= PAGE_MASK;
63 if (mm != current->mm) {
64 saved_asid = get_asid();
65 set_asid(asid);
66 }
67 while (start < end) {
Paul Mundt00720322006-12-25 19:37:56 +090068 local_flush_tlb_one(asid, start);
Paul Mundt26ff6c12006-09-27 15:13:36 +090069 start += PAGE_SIZE;
70 }
71 if (saved_asid != MMU_NO_ASID)
72 set_asid(saved_asid);
73 }
74 local_irq_restore(flags);
75 }
76}
77
Paul Mundtea9af692006-12-25 19:28:54 +090078void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
Paul Mundt26ff6c12006-09-27 15:13:36 +090079{
Paul Mundtaec5e0e2006-12-25 09:51:47 +090080 unsigned int cpu = smp_processor_id();
Paul Mundt26ff6c12006-09-27 15:13:36 +090081 unsigned long flags;
82 int size;
83
84 local_irq_save(flags);
85 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
86 if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
Paul Mundtea9af692006-12-25 19:28:54 +090087 local_flush_tlb_all();
Paul Mundt26ff6c12006-09-27 15:13:36 +090088 } else {
Paul Mundt19f9a342006-09-27 18:33:49 +090089 unsigned long asid;
Paul Mundt26ff6c12006-09-27 15:13:36 +090090 unsigned long saved_asid = get_asid();
91
Paul Mundtaec5e0e2006-12-25 09:51:47 +090092 asid = cpu_asid(cpu, &init_mm);
Paul Mundt26ff6c12006-09-27 15:13:36 +090093 start &= PAGE_MASK;
94 end += (PAGE_SIZE - 1);
95 end &= PAGE_MASK;
96 set_asid(asid);
97 while (start < end) {
Paul Mundt00720322006-12-25 19:37:56 +090098 local_flush_tlb_one(asid, start);
Paul Mundt26ff6c12006-09-27 15:13:36 +090099 start += PAGE_SIZE;
100 }
101 set_asid(saved_asid);
102 }
103 local_irq_restore(flags);
104}
105
Paul Mundtea9af692006-12-25 19:28:54 +0900106void local_flush_tlb_mm(struct mm_struct *mm)
Paul Mundt26ff6c12006-09-27 15:13:36 +0900107{
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900108 unsigned int cpu = smp_processor_id();
109
Paul Mundt26ff6c12006-09-27 15:13:36 +0900110 /* Invalidate all TLB of this process. */
111 /* Instead of invalidating each TLB, we get new MMU context. */
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900112 if (cpu_context(cpu, mm) != NO_CONTEXT) {
Paul Mundt26ff6c12006-09-27 15:13:36 +0900113 unsigned long flags;
114
115 local_irq_save(flags);
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900116 cpu_context(cpu, mm) = NO_CONTEXT;
Paul Mundt26ff6c12006-09-27 15:13:36 +0900117 if (mm == current->mm)
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900118 activate_context(mm, cpu);
Paul Mundt26ff6c12006-09-27 15:13:36 +0900119 local_irq_restore(flags);
120 }
121}
122
Paul Mundtea9af692006-12-25 19:28:54 +0900123void local_flush_tlb_all(void)
Paul Mundt26ff6c12006-09-27 15:13:36 +0900124{
125 unsigned long flags, status;
126
127 /*
128 * Flush all the TLB.
129 *
130 * Write to the MMU control register's bit:
131 * TF-bit for SH-3, TI-bit for SH-4.
132 * It's same position, bit #2.
133 */
134 local_irq_save(flags);
135 status = ctrl_inl(MMUCR);
136 status |= 0x04;
137 ctrl_outl(status, MMUCR);
138 ctrl_barrier();
139 local_irq_restore(flags);
140}