/*1* This file contains the routines for TLB flushing.2* On machines where the MMU uses a hash table to store virtual to3* physical translations, these routines flush entries from the4* hash table also.5* -- paulus6*7* Derived from arch/ppc/mm/init.c:8* Copyright (C) 1995-1996 Gary Thomas ([email protected])9*10* Modifications by Paul Mackerras (PowerMac) ([email protected])11* and Cort Dougan (PReP) ([email protected])12* Copyright (C) 1996 Paul Mackerras13*14* Derived from "arch/i386/mm/init.c"15* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds16*17* This program is free software; you can redistribute it and/or18* modify it under the terms of the GNU General Public License19* as published by the Free Software Foundation; either version20* 2 of the License, or (at your option) any later version.21*22*/2324#include <linux/kernel.h>25#include <linux/mm.h>26#include <linux/init.h>27#include <linux/highmem.h>28#include <linux/pagemap.h>2930#include <asm/tlbflush.h>31#include <asm/tlb.h>3233#include "mmu_decl.h"3435/*36* Called when unmapping pages to flush entries from the TLB/hash table.37*/38void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)39{40unsigned long ptephys;4142if (Hash != 0) {43ptephys = __pa(ptep) & PAGE_MASK;44flush_hash_pages(mm->context.id, addr, ptephys, 1);45}46}47EXPORT_SYMBOL(flush_hash_entry);4849/*50* Called by ptep_set_access_flags, must flush on CPUs for which the51* DSI handler can't just "fixup" the TLB on a write fault52*/53void flush_tlb_page_nohash(struct vm_area_struct *vma, unsigned long addr)54{55if (Hash != 0)56return;57_tlbie(addr);58}5960/*61* Called at the end of a mmu_gather operation to make sure the62* TLB flush is completely done.63*/64void tlb_flush(struct mmu_gather *tlb)65{66if (Hash == 0) {67/*68* 603 needs to flush the whole TLB here since69* it doesn't use a hash table.70*/71_tlbia();72}73}7475/*76* TLB flushing:77*78* - flush_tlb_mm(mm) flushes the specified mm context TLB's79* - flush_tlb_page(vma, vmaddr) flushes one page80* - flush_tlb_range(vma, start, end) flushes a range of pages81* - flush_tlb_kernel_range(start, end) flushes kernel pages82*83* since the hardware hash table functions as an extension of the84* tlb as far as the linux tables are concerned, flush it too.85* -- Cort86*/8788static void flush_range(struct mm_struct *mm, unsigned long start,89unsigned long end)90{91pmd_t *pmd;92unsigned long pmd_end;93int count;94unsigned int ctx = mm->context.id;9596if (Hash == 0) {97_tlbia();98return;99}100start &= PAGE_MASK;101if (start >= end)102return;103end = (end - 1) | ~PAGE_MASK;104pmd = pmd_offset(pud_offset(pgd_offset(mm, start), start), start);105for (;;) {106pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;107if (pmd_end > end)108pmd_end = end;109if (!pmd_none(*pmd)) {110count = ((pmd_end - start) >> PAGE_SHIFT) + 1;111flush_hash_pages(ctx, start, pmd_val(*pmd), count);112}113if (pmd_end == end)114break;115start = pmd_end + 1;116++pmd;117}118}119120/*121* Flush kernel TLB entries in the given range122*/123void flush_tlb_kernel_range(unsigned long start, unsigned long end)124{125flush_range(&init_mm, start, end);126}127EXPORT_SYMBOL(flush_tlb_kernel_range);128129/*130* Flush all the (user) entries for the address space described by mm.131*/132void flush_tlb_mm(struct mm_struct *mm)133{134struct vm_area_struct *mp;135136if (Hash == 0) {137_tlbia();138return;139}140141/*142* It is safe to go down the mm's list of vmas when called143* from dup_mmap, holding mmap_sem. It would also be safe from144* unmap_region or exit_mmap, but not from vmtruncate on SMP -145* but it seems dup_mmap is the only SMP case which gets here.146*/147for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)148flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);149}150EXPORT_SYMBOL(flush_tlb_mm);151152void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)153{154struct mm_struct *mm;155pmd_t *pmd;156157if (Hash == 0) {158_tlbie(vmaddr);159return;160}161mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;162pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);163if (!pmd_none(*pmd))164flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);165}166EXPORT_SYMBOL(flush_tlb_page);167168/*169* For each address in the range, find the pte for the address170* and check _PAGE_HASHPTE bit; if it is set, find and destroy171* the corresponding HPTE.172*/173void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,174unsigned long end)175{176flush_range(vma->vm_mm, start, end);177}178EXPORT_SYMBOL(flush_tlb_range);179180181