David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 TLB flushing functions |
| 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 | #ifndef _ASM_TLBFLUSH_H |
| 12 | #define _ASM_TLBFLUSH_H |
| 13 | |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 14 | #include <linux/mm.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 15 | #include <asm/processor.h> |
| 16 | |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 17 | struct tlb_state { |
| 18 | struct mm_struct *active_mm; |
| 19 | int state; |
| 20 | }; |
| 21 | DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate); |
| 22 | |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 23 | /** |
| 24 | * local_flush_tlb - Flush the current MM's entries from the local CPU's TLBs |
| 25 | */ |
| 26 | static inline void local_flush_tlb(void) |
| 27 | { |
| 28 | int w; |
| 29 | asm volatile( |
| 30 | " mov %1,%0 \n" |
| 31 | " or %2,%0 \n" |
| 32 | " mov %0,%1 \n" |
| 33 | : "=d"(w) |
| 34 | : "m"(MMUCTR), "i"(MMUCTR_IIV|MMUCTR_DIV) |
| 35 | : "cc", "memory"); |
| 36 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 37 | |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 38 | /** |
| 39 | * local_flush_tlb_all - Flush all entries from the local CPU's TLBs |
| 40 | */ |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 41 | static inline void local_flush_tlb_all(void) |
| 42 | { |
| 43 | local_flush_tlb(); |
| 44 | } |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * local_flush_tlb_one - Flush one entry from the local CPU's TLBs |
| 48 | */ |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 49 | static inline void local_flush_tlb_one(unsigned long addr) |
| 50 | { |
| 51 | local_flush_tlb(); |
| 52 | } |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * local_flush_tlb_page - Flush a page's entry from the local CPU's TLBs |
| 56 | * @mm: The MM to flush for |
| 57 | * @addr: The address of the target page in RAM (not its page struct) |
| 58 | */ |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 59 | static inline |
| 60 | void local_flush_tlb_page(struct mm_struct *mm, unsigned long addr) |
| 61 | { |
| 62 | unsigned long pteu, flags, cnx; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 63 | |
Akira Takeuchi | a9bc60e | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 64 | addr &= PAGE_MASK; |
| 65 | |
| 66 | local_irq_save(flags); |
| 67 | |
| 68 | cnx = 1; |
| 69 | #ifdef CONFIG_MN10300_TLB_USE_PIDR |
| 70 | cnx = mm->context.tlbpid[smp_processor_id()]; |
| 71 | #endif |
| 72 | if (cnx) { |
| 73 | pteu = addr; |
| 74 | #ifdef CONFIG_MN10300_TLB_USE_PIDR |
| 75 | pteu |= cnx & xPTEU_PID; |
| 76 | #endif |
| 77 | IPTEU = pteu; |
| 78 | DPTEU = pteu; |
| 79 | if (IPTEL & xPTEL_V) |
| 80 | IPTEL = 0; |
| 81 | if (DPTEL & xPTEL_V) |
| 82 | DPTEL = 0; |
| 83 | } |
| 84 | local_irq_restore(flags); |
| 85 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * TLB flushing: |
| 89 | * |
| 90 | * - flush_tlb() flushes the current mm struct TLBs |
| 91 | * - flush_tlb_all() flushes all processes TLBs |
| 92 | * - flush_tlb_mm(mm) flushes the specified mm context TLB's |
| 93 | * - flush_tlb_page(vma, vmaddr) flushes one page |
| 94 | * - flush_tlb_range(mm, start, end) flushes a range of pages |
| 95 | * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables |
| 96 | */ |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 97 | #ifdef CONFIG_SMP |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 98 | |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 99 | #include <asm/smp.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 100 | |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 101 | extern void flush_tlb_all(void); |
| 102 | extern void flush_tlb_current_task(void); |
| 103 | extern void flush_tlb_mm(struct mm_struct *); |
| 104 | extern void flush_tlb_page(struct vm_area_struct *, unsigned long); |
| 105 | |
| 106 | #define flush_tlb() flush_tlb_current_task() |
| 107 | |
| 108 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 109 | unsigned long start, unsigned long end) |
| 110 | { |
| 111 | flush_tlb_mm(vma->vm_mm); |
| 112 | } |
| 113 | |
| 114 | #else /* CONFIG_SMP */ |
| 115 | |
| 116 | static inline void flush_tlb_all(void) |
| 117 | { |
| 118 | preempt_disable(); |
| 119 | local_flush_tlb_all(); |
| 120 | preempt_enable(); |
| 121 | } |
| 122 | |
| 123 | static inline void flush_tlb_mm(struct mm_struct *mm) |
| 124 | { |
| 125 | preempt_disable(); |
| 126 | local_flush_tlb_all(); |
| 127 | preempt_enable(); |
| 128 | } |
| 129 | |
| 130 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 131 | unsigned long start, unsigned long end) |
| 132 | { |
| 133 | preempt_disable(); |
| 134 | local_flush_tlb_all(); |
| 135 | preempt_enable(); |
| 136 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 137 | |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 138 | #define flush_tlb_page(vma, addr) local_flush_tlb_page((vma)->vm_mm, addr) |
| 139 | #define flush_tlb() flush_tlb_all() |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 140 | |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 141 | #endif /* CONFIG_SMP */ |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 142 | |
Akira Takeuchi | 965ea4b | 2010-10-27 17:28:51 +0100 | [diff] [blame] | 143 | static inline void flush_tlb_kernel_range(unsigned long start, |
| 144 | unsigned long end) |
| 145 | { |
| 146 | flush_tlb_all(); |
| 147 | } |
| 148 | |
| 149 | static inline void flush_tlb_pgtables(struct mm_struct *mm, |
| 150 | unsigned long start, unsigned long end) |
| 151 | { |
| 152 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 153 | |
| 154 | #endif /* _ASM_TLBFLUSH_H */ |