tlb-flush.c 3.3 KB
Newer Older
1 2 3 4
/*
 * TLB flushing operations for SH with an MMU.
 *
 *  Copyright (C) 1999  Niibe Yutaka
5
 *  Copyright (C) 2003  Paul Mundt
6 7 8 9 10 11 12 13 14
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/mm.h>
#include <asm/mmu_context.h>
#include <asm/tlbflush.h>

15
void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
16
{
P
Paul Mundt 已提交
17 18 19
	unsigned int cpu = smp_processor_id();

	if (vma->vm_mm && cpu_context(cpu, vma->vm_mm) != NO_CONTEXT) {
20 21 22 23
		unsigned long flags;
		unsigned long asid;
		unsigned long saved_asid = MMU_NO_ASID;

P
Paul Mundt 已提交
24
		asid = cpu_asid(cpu, vma->vm_mm);
25 26 27 28 29 30 31
		page &= PAGE_MASK;

		local_irq_save(flags);
		if (vma->vm_mm != current->mm) {
			saved_asid = get_asid();
			set_asid(asid);
		}
32
		local_flush_tlb_one(asid, page);
33 34 35 36 37 38
		if (saved_asid != MMU_NO_ASID)
			set_asid(saved_asid);
		local_irq_restore(flags);
	}
}

39 40
void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
			   unsigned long end)
41 42
{
	struct mm_struct *mm = vma->vm_mm;
P
Paul Mundt 已提交
43
	unsigned int cpu = smp_processor_id();
44

P
Paul Mundt 已提交
45
	if (cpu_context(cpu, mm) != NO_CONTEXT) {
46 47 48 49 50 51
		unsigned long flags;
		int size;

		local_irq_save(flags);
		size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
		if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
P
Paul Mundt 已提交
52
			cpu_context(cpu, mm) = NO_CONTEXT;
53
			if (mm == current->mm)
P
Paul Mundt 已提交
54
				activate_context(mm, cpu);
55
		} else {
P
Paul Mundt 已提交
56
			unsigned long asid;
57 58
			unsigned long saved_asid = MMU_NO_ASID;

P
Paul Mundt 已提交
59
			asid = cpu_asid(cpu, mm);
60 61 62 63 64 65 66 67
			start &= PAGE_MASK;
			end += (PAGE_SIZE - 1);
			end &= PAGE_MASK;
			if (mm != current->mm) {
				saved_asid = get_asid();
				set_asid(asid);
			}
			while (start < end) {
68
				local_flush_tlb_one(asid, start);
69 70 71 72 73 74 75 76 77
				start += PAGE_SIZE;
			}
			if (saved_asid != MMU_NO_ASID)
				set_asid(saved_asid);
		}
		local_irq_restore(flags);
	}
}

78
void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
79
{
P
Paul Mundt 已提交
80
	unsigned int cpu = smp_processor_id();
81 82 83 84 85 86
	unsigned long flags;
	int size;

	local_irq_save(flags);
	size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
	if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
87
		local_flush_tlb_all();
88
	} else {
P
Paul Mundt 已提交
89
		unsigned long asid;
90 91
		unsigned long saved_asid = get_asid();

P
Paul Mundt 已提交
92
		asid = cpu_asid(cpu, &init_mm);
93 94 95 96 97
		start &= PAGE_MASK;
		end += (PAGE_SIZE - 1);
		end &= PAGE_MASK;
		set_asid(asid);
		while (start < end) {
98
			local_flush_tlb_one(asid, start);
99 100 101 102 103 104 105
			start += PAGE_SIZE;
		}
		set_asid(saved_asid);
	}
	local_irq_restore(flags);
}

106
void local_flush_tlb_mm(struct mm_struct *mm)
107
{
P
Paul Mundt 已提交
108 109
	unsigned int cpu = smp_processor_id();

110 111
	/* Invalidate all TLB of this process. */
	/* Instead of invalidating each TLB, we get new MMU context. */
P
Paul Mundt 已提交
112
	if (cpu_context(cpu, mm) != NO_CONTEXT) {
113 114 115
		unsigned long flags;

		local_irq_save(flags);
P
Paul Mundt 已提交
116
		cpu_context(cpu, mm) = NO_CONTEXT;
117
		if (mm == current->mm)
P
Paul Mundt 已提交
118
			activate_context(mm, cpu);
119 120 121 122
		local_irq_restore(flags);
	}
}

123
void local_flush_tlb_all(void)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
{
	unsigned long flags, status;

	/*
	 * Flush all the TLB.
	 *
	 * Write to the MMU control register's bit:
	 *	TF-bit for SH-3, TI-bit for SH-4.
	 *      It's same position, bit #2.
	 */
	local_irq_save(flags);
	status = ctrl_inl(MMUCR);
	status |= 0x04;
	ctrl_outl(status, MMUCR);
	ctrl_barrier();
	local_irq_restore(flags);
}