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 | |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 16 | #ifdef CONFIG_MN10300_TLB_USE_PIDR |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 17 | /* |
| 18 | * list of the MMU contexts last allocated on each CPU |
| 19 | */ |
| 20 | unsigned long mmu_context_cache[NR_CPUS] = { |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 21 | [0 ... NR_CPUS - 1] = |
| 22 | MMU_CONTEXT_FIRST_VERSION * 2 - (1 - MMU_CONTEXT_TLBPID_LOCK_NR), |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 23 | }; |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 24 | #endif /* CONFIG_MN10300_TLB_USE_PIDR */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * preemptively set a TLB entry |
| 28 | */ |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 29 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 30 | { |
| 31 | unsigned long pteu, ptel, cnx, flags; |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 32 | pte_t pte = *ptep; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 33 | |
| 34 | addr &= PAGE_MASK; |
| 35 | ptel = pte_val(pte) & ~(xPTEL_UNUSED1 | xPTEL_UNUSED2); |
| 36 | |
| 37 | /* make sure the context doesn't migrate and defend against |
| 38 | * interference from vmalloc'd regions */ |
| 39 | local_irq_save(flags); |
| 40 | |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 41 | cnx = ~MMU_NO_CONTEXT; |
| 42 | #ifdef CONFIG_MN10300_TLB_USE_PIDR |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 43 | cnx = mm_context(vma->vm_mm); |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 44 | #endif |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 45 | |
| 46 | if (cnx != MMU_NO_CONTEXT) { |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 47 | pteu = addr; |
| 48 | #ifdef CONFIG_MN10300_TLB_USE_PIDR |
| 49 | pteu |= cnx & MMU_CONTEXT_TLBPID_MASK; |
| 50 | #endif |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 51 | if (!(pte_val(pte) & _PAGE_NX)) { |
| 52 | IPTEU = pteu; |
| 53 | if (IPTEL & xPTEL_V) |
| 54 | IPTEL = ptel; |
| 55 | } |
| 56 | DPTEU = pteu; |
| 57 | if (DPTEL & xPTEL_V) |
| 58 | DPTEL = ptel; |
| 59 | } |
| 60 | |
| 61 | local_irq_restore(flags); |
| 62 | } |