linux-bk/arch/ppc/mm/tlb.c
<<
>>
Prefs
   1/*
   2 * This file contains the routines for TLB flushing.
   3 * On machines where the MMU uses a hash table to store virtual to
   4 * physical translations, these routines flush entries from the
   5 * hash table also.
   6 *  -- paulus
   7 *
   8 *  Derived from arch/ppc/mm/init.c:
   9 *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10 *
  11 *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  12 *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
  13 *    Copyright (C) 1996 Paul Mackerras
  14 *  Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  15 *
  16 *  Derived from "arch/i386/mm/init.c"
  17 *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
  18 *
  19 *  This program is free software; you can redistribute it and/or
  20 *  modify it under the terms of the GNU General Public License
  21 *  as published by the Free Software Foundation; either version
  22 *  2 of the License, or (at your option) any later version.
  23 *
  24 */
  25
  26#include <linux/config.h>
  27#include <linux/kernel.h>
  28#include <linux/mm.h>
  29#include <linux/init.h>
  30#include <linux/highmem.h>
  31#include <asm/tlbflush.h>
  32#include <asm/tlb.h>
  33
  34#include "mmu_decl.h"
  35
  36/*
  37 * Called when unmapping pages to flush entries from the TLB/hash table.
  38 */
  39void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)
  40{
  41        unsigned long ptephys;
  42
  43        if (Hash != 0) {
  44                ptephys = __pa(ptep) & PAGE_MASK;
  45                flush_hash_pages(mm->context, addr, ptephys, 1);
  46        }
  47}
  48
  49/*
  50 * Called by ptep_test_and_clear_young()
  51 */
  52void flush_hash_one_pte(pte_t *ptep)
  53{
  54        struct page *ptepage;
  55        struct mm_struct *mm;
  56        unsigned long ptephys;
  57        unsigned long addr;
  58
  59        if (Hash == 0)
  60                return;
  61        
  62        ptepage = virt_to_page(ptep);
  63        mm = (struct mm_struct *) ptepage->mapping;
  64        ptephys = __pa(ptep) & PAGE_MASK;
  65        addr = ptepage->index + (((unsigned long)ptep & ~PAGE_MASK) << 10);
  66        flush_hash_pages(mm->context, addr, ptephys, 1);
  67}
  68
  69/*
  70 * Called by ptep_set_access_flags, must flush on CPUs for which the
  71 * DSI handler can't just "fixup" the TLB on a write fault
  72 */
  73void flush_tlb_page_nohash(struct vm_area_struct *vma, unsigned long addr)
  74{
  75        if (Hash != 0)
  76                return;
  77        _tlbie(addr);
  78}
  79
  80/*
  81 * Called at the end of a mmu_gather operation to make sure the
  82 * TLB flush is completely done.
  83 */
  84void tlb_flush(struct mmu_gather *tlb)
  85{
  86        if (Hash == 0) {
  87                /*
  88                 * 603 needs to flush the whole TLB here since
  89                 * it doesn't use a hash table.
  90                 */
  91                _tlbia();
  92        }
  93}
  94
  95/*
  96 * TLB flushing:
  97 *
  98 *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
  99 *  - flush_tlb_page(vma, vmaddr) flushes one page
 100 *  - flush_tlb_range(vma, start, end) flushes a range of pages
 101 *  - flush_tlb_kernel_range(start, end) flushes kernel pages
 102 *
 103 * since the hardware hash table functions as an extension of the
 104 * tlb as far as the linux tables are concerned, flush it too.
 105 *    -- Cort
 106 */
 107
 108/*
 109 * 750 SMP is a Bad Idea because the 750 doesn't broadcast all
 110 * the cache operations on the bus.  Hence we need to use an IPI
 111 * to get the other CPU(s) to invalidate their TLBs.
 112 */
 113#ifdef CONFIG_SMP_750
 114#define FINISH_FLUSH    smp_send_tlb_invalidate(0)
 115#else
 116#define FINISH_FLUSH    do { } while (0)
 117#endif
 118
 119static void flush_range(struct mm_struct *mm, unsigned long start,
 120                        unsigned long end)
 121{
 122        pmd_t *pmd;
 123        unsigned long pmd_end;
 124        int count;
 125        unsigned int ctx = mm->context;
 126
 127        if (Hash == 0) {
 128                _tlbia();
 129                return;
 130        }
 131        start &= PAGE_MASK;
 132        if (start >= end)
 133                return;
 134        end = (end - 1) | ~PAGE_MASK;
 135        pmd = pmd_offset(pgd_offset(mm, start), start);
 136        for (;;) {
 137                pmd_end = ((start + PGDIR_SIZE) & PGDIR_MASK) - 1;
 138                if (pmd_end > end)
 139                        pmd_end = end;
 140                if (!pmd_none(*pmd)) {
 141                        count = ((pmd_end - start) >> PAGE_SHIFT) + 1;
 142                        flush_hash_pages(ctx, start, pmd_val(*pmd), count);
 143                }
 144                if (pmd_end == end)
 145                        break;
 146                start = pmd_end + 1;
 147                ++pmd;
 148        }
 149}
 150
 151/*
 152 * Flush kernel TLB entries in the given range
 153 */
 154void flush_tlb_kernel_range(unsigned long start, unsigned long end)
 155{
 156        flush_range(&init_mm, start, end);
 157        FINISH_FLUSH;
 158}
 159
 160/*
 161 * Flush all the (user) entries for the address space described by mm.
 162 */
 163void flush_tlb_mm(struct mm_struct *mm)
 164{
 165        struct vm_area_struct *mp;
 166
 167        if (Hash == 0) {
 168                _tlbia();
 169                return;
 170        }
 171
 172        for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
 173                flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
 174        FINISH_FLUSH;
 175}
 176
 177void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
 178{
 179        struct mm_struct *mm;
 180        pmd_t *pmd;
 181
 182        if (Hash == 0) {
 183                _tlbie(vmaddr);
 184                return;
 185        }
 186        mm = (vmaddr < TASK_SIZE)? vma->vm_mm: &init_mm;
 187        pmd = pmd_offset(pgd_offset(mm, vmaddr), vmaddr);
 188        if (!pmd_none(*pmd))
 189                flush_hash_pages(mm->context, vmaddr, pmd_val(*pmd), 1);
 190        FINISH_FLUSH;
 191}
 192
 193/*
 194 * For each address in the range, find the pte for the address
 195 * and check _PAGE_HASHPTE bit; if it is set, find and destroy
 196 * the corresponding HPTE.
 197 */
 198void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
 199                     unsigned long end)
 200{
 201        flush_range(vma->vm_mm, start, end);
 202        FINISH_FLUSH;
 203}
 204
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.