2 * TLB flushing operations for SH with an MMU.
4 * Copyright (C) 1999 Niibe Yutaka
5 * Copyright (C) 2003 - 2006 Paul Mundt
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
13 #include <asm/mmu_context.h>
14 #include <asm/tlbflush.h>
15 #include <asm/cacheflush.h>
17 void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
19 unsigned int cpu = smp_processor_id();
21 if (vma->vm_mm && cpu_context(cpu, vma->vm_mm) != NO_CONTEXT) {
24 unsigned long saved_asid = MMU_NO_ASID;
26 asid = cpu_asid(cpu, vma->vm_mm);
29 local_irq_save(flags);
30 if (vma->vm_mm != current->mm) {
31 saved_asid = get_asid();
34 local_flush_tlb_one(asid, page);
35 if (saved_asid != MMU_NO_ASID)
37 local_irq_restore(flags);
41 void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
44 struct mm_struct *mm = vma->vm_mm;
45 unsigned int cpu = smp_processor_id();
47 if (cpu_context(cpu, mm) != NO_CONTEXT) {
51 local_irq_save(flags);
52 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
53 if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
54 cpu_context(cpu, mm) = NO_CONTEXT;
55 if (mm == current->mm)
56 activate_context(mm, cpu);
59 unsigned long saved_asid = MMU_NO_ASID;
61 asid = cpu_asid(cpu, mm);
63 end += (PAGE_SIZE - 1);
65 if (mm != current->mm) {
66 saved_asid = get_asid();
70 local_flush_tlb_one(asid, start);
73 if (saved_asid != MMU_NO_ASID)
76 local_irq_restore(flags);
80 void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
82 unsigned int cpu = smp_processor_id();
86 local_irq_save(flags);
87 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
88 if (size > (MMU_NTLB_ENTRIES/4)) { /* Too many TLB to flush */
89 local_flush_tlb_all();
92 unsigned long saved_asid = get_asid();
94 asid = cpu_asid(cpu, &init_mm);
96 end += (PAGE_SIZE - 1);
100 local_flush_tlb_one(asid, start);
103 set_asid(saved_asid);
105 local_irq_restore(flags);
108 void local_flush_tlb_mm(struct mm_struct *mm)
110 unsigned int cpu = smp_processor_id();
112 /* Invalidate all TLB of this process. */
113 /* Instead of invalidating each TLB, we get new MMU context. */
114 if (cpu_context(cpu, mm) != NO_CONTEXT) {
117 local_irq_save(flags);
118 cpu_context(cpu, mm) = NO_CONTEXT;
119 if (mm == current->mm)
120 activate_context(mm, cpu);
121 local_irq_restore(flags);
125 void local_flush_tlb_all(void)
127 unsigned long flags, status;
132 * Write to the MMU control register's bit:
133 * TF-bit for SH-3, TI-bit for SH-4.
134 * It's same position, bit #2.
136 local_irq_save(flags);
137 status = ctrl_inl(MMUCR);
139 ctrl_outl(status, MMUCR);
141 local_irq_restore(flags);
144 void update_mmu_cache(struct vm_area_struct *vma,
145 unsigned long address, pte_t pte)
148 unsigned long pteval;
151 unsigned long pfn = pte_pfn(pte);
152 struct address_space *mapping;
157 page = pfn_to_page(pfn);
158 mapping = page_mapping(page);
160 unsigned long phys = pte_val(pte) & PTE_PHYS_MASK;
161 int dirty = test_and_clear_bit(PG_dcache_dirty, &page->flags);
164 __flush_wback_region((void *)P1SEGADDR(phys),
168 local_irq_save(flags);
170 /* Set PTEH register */
171 vpn = (address & MMU_VPN_MASK) | get_asid();
172 ctrl_outl(vpn, MMU_PTEH);
174 pteval = pte_val(pte);
176 #ifdef CONFIG_CPU_HAS_PTEA
177 /* Set PTEA register */
178 /* TODO: make this look less hacky */
179 ctrl_outl(((pteval >> 28) & 0xe) | (pteval & 0x1), MMU_PTEA);
182 /* Set PTEL register */
183 pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
184 #if defined(CONFIG_SH_WRITETHROUGH) && defined(CONFIG_CPU_SH4)
187 /* conveniently, we want all the software flags to be 0 anyway */
188 ctrl_outl(pteval, MMU_PTEL);
191 asm volatile("ldtlb": /* no output */ : /* no input */ : "memory");
192 local_irq_restore(flags);