| David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 MMU context allocation and management | 
|  | 2 | * | 
|  | 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. | 
|  | 4 | * Written by David Howells (dhowells@redhat.com) | 
|  | 5 | * | 
|  | 6 | * This program is free software; you can redistribute it and/or | 
|  | 7 | * modify it under the terms of the GNU General Public Licence | 
|  | 8 | * as published by the Free Software Foundation; either version | 
|  | 9 | * 2 of the Licence, or (at your option) any later version. | 
|  | 10 | */ | 
|  | 11 | #include <linux/sched.h> | 
|  | 12 | #include <linux/mm.h> | 
|  | 13 | #include <asm/mmu_context.h> | 
|  | 14 | #include <asm/tlbflush.h> | 
|  | 15 |  | 
|  | 16 | /* | 
|  | 17 | * list of the MMU contexts last allocated on each CPU | 
|  | 18 | */ | 
|  | 19 | unsigned long mmu_context_cache[NR_CPUS] = { | 
|  | 20 | [0 ... NR_CPUS - 1] = MMU_CONTEXT_FIRST_VERSION * 2 - 1, | 
|  | 21 | }; | 
|  | 22 |  | 
|  | 23 | /* | 
|  | 24 | * flush the specified TLB entry | 
|  | 25 | */ | 
|  | 26 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) | 
|  | 27 | { | 
|  | 28 | unsigned long pteu, cnx, flags; | 
|  | 29 |  | 
|  | 30 | addr &= PAGE_MASK; | 
|  | 31 |  | 
|  | 32 | /* make sure the context doesn't migrate and defend against | 
|  | 33 | * interference from vmalloc'd regions */ | 
|  | 34 | local_irq_save(flags); | 
|  | 35 |  | 
|  | 36 | cnx = mm_context(vma->vm_mm); | 
|  | 37 |  | 
|  | 38 | if (cnx != MMU_NO_CONTEXT) { | 
|  | 39 | pteu = addr | (cnx & 0x000000ffUL); | 
|  | 40 | IPTEU = pteu; | 
|  | 41 | DPTEU = pteu; | 
|  | 42 | if (IPTEL & xPTEL_V) | 
|  | 43 | IPTEL = 0; | 
|  | 44 | if (DPTEL & xPTEL_V) | 
|  | 45 | DPTEL = 0; | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | local_irq_restore(flags); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | /* | 
|  | 52 | * preemptively set a TLB entry | 
|  | 53 | */ | 
|  | 54 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte) | 
|  | 55 | { | 
|  | 56 | unsigned long pteu, ptel, cnx, flags; | 
|  | 57 |  | 
|  | 58 | addr &= PAGE_MASK; | 
|  | 59 | ptel = pte_val(pte) & ~(xPTEL_UNUSED1 | xPTEL_UNUSED2); | 
|  | 60 |  | 
|  | 61 | /* make sure the context doesn't migrate and defend against | 
|  | 62 | * interference from vmalloc'd regions */ | 
|  | 63 | local_irq_save(flags); | 
|  | 64 |  | 
|  | 65 | cnx = mm_context(vma->vm_mm); | 
|  | 66 |  | 
|  | 67 | if (cnx != MMU_NO_CONTEXT) { | 
|  | 68 | pteu = addr | (cnx & 0x000000ffUL); | 
|  | 69 | if (!(pte_val(pte) & _PAGE_NX)) { | 
|  | 70 | IPTEU = pteu; | 
|  | 71 | if (IPTEL & xPTEL_V) | 
|  | 72 | IPTEL = ptel; | 
|  | 73 | } | 
|  | 74 | DPTEU = pteu; | 
|  | 75 | if (DPTEL & xPTEL_V) | 
|  | 76 | DPTEL = ptel; | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | local_irq_restore(flags); | 
|  | 80 | } |