Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 2 | * arch/sh/mm/tlb-flush_64.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2000, 2001 Paolo Alberelli |
| 5 | * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes) |
Paul Mundt | a1e2030 | 2012-04-11 12:44:50 +0900 | [diff] [blame] | 6 | * Copyright (C) 2003 - 2012 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file "COPYING" in the main directory of this archive |
| 10 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/signal.h> |
| 13 | #include <linux/rwsem.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/mman.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/smp.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 23 | #include <linux/perf_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | #include <asm/tlb.h> |
| 27 | #include <asm/uaccess.h> |
| 28 | #include <asm/pgalloc.h> |
| 29 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 31 | void local_flush_tlb_one(unsigned long asid, unsigned long page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
| 33 | unsigned long long match, pteh=0, lpage; |
| 34 | unsigned long tlb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Sign-extend based on neff. |
| 38 | */ |
Paul Mundt | c791483 | 2009-08-04 17:14:39 +0900 | [diff] [blame] | 39 | lpage = neff_sign_extend(page); |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 40 | match = (asid << PTEH_ASID_SHIFT) | PTEH_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | match |= lpage; |
| 42 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 43 | for_each_itlb_entry(tlb) { |
| 44 | asm volatile ("getcfg %1, 0, %0" |
| 45 | : "=r" (pteh) |
| 46 | : "r" (tlb) ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 48 | if (pteh == match) { |
| 49 | __flush_tlb_slot(tlb); |
| 50 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | for_each_dtlb_entry(tlb) { |
| 55 | asm volatile ("getcfg %1, 0, %0" |
| 56 | : "=r" (pteh) |
| 57 | : "r" (tlb) ); |
| 58 | |
| 59 | if (pteh == match) { |
| 60 | __flush_tlb_slot(tlb); |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | } |
| 66 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 67 | void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | unsigned long flags; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if (vma->vm_mm) { |
| 72 | page &= PAGE_MASK; |
| 73 | local_irq_save(flags); |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 74 | local_flush_tlb_one(get_asid(), page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | local_irq_restore(flags); |
| 76 | } |
| 77 | } |
| 78 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 79 | void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, |
| 80 | unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | unsigned long flags; |
| 83 | unsigned long long match, pteh=0, pteh_epn, pteh_low; |
| 84 | unsigned long tlb; |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 85 | unsigned int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct mm_struct *mm; |
| 87 | |
| 88 | mm = vma->vm_mm; |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 89 | if (cpu_context(cpu, mm) == NO_CONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return; |
| 91 | |
| 92 | local_irq_save(flags); |
| 93 | |
| 94 | start &= PAGE_MASK; |
| 95 | end &= PAGE_MASK; |
| 96 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 97 | match = (cpu_asid(cpu, mm) << PTEH_ASID_SHIFT) | PTEH_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* Flush ITLB */ |
| 100 | for_each_itlb_entry(tlb) { |
| 101 | asm volatile ("getcfg %1, 0, %0" |
| 102 | : "=r" (pteh) |
| 103 | : "r" (tlb) ); |
| 104 | |
| 105 | pteh_epn = pteh & PAGE_MASK; |
| 106 | pteh_low = pteh & ~PAGE_MASK; |
| 107 | |
| 108 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) |
| 109 | __flush_tlb_slot(tlb); |
| 110 | } |
| 111 | |
| 112 | /* Flush DTLB */ |
| 113 | for_each_dtlb_entry(tlb) { |
| 114 | asm volatile ("getcfg %1, 0, %0" |
| 115 | : "=r" (pteh) |
| 116 | : "r" (tlb) ); |
| 117 | |
| 118 | pteh_epn = pteh & PAGE_MASK; |
| 119 | pteh_low = pteh & ~PAGE_MASK; |
| 120 | |
| 121 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) |
| 122 | __flush_tlb_slot(tlb); |
| 123 | } |
| 124 | |
| 125 | local_irq_restore(flags); |
| 126 | } |
| 127 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 128 | void local_flush_tlb_mm(struct mm_struct *mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | unsigned long flags; |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 131 | unsigned int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 133 | if (cpu_context(cpu, mm) == NO_CONTEXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return; |
| 135 | |
| 136 | local_irq_save(flags); |
| 137 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 138 | cpu_context(cpu, mm) = NO_CONTEXT; |
| 139 | if (mm == current->mm) |
| 140 | activate_context(mm, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 145 | void local_flush_tlb_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | /* Invalidate all, including shared pages, excluding fixed TLBs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | unsigned long flags, tlb; |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | local_irq_save(flags); |
| 151 | |
| 152 | /* Flush each ITLB entry */ |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 153 | for_each_itlb_entry(tlb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | __flush_tlb_slot(tlb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* Flush each DTLB entry */ |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 157 | for_each_dtlb_entry(tlb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | __flush_tlb_slot(tlb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | local_irq_restore(flags); |
| 161 | } |
| 162 | |
Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 163 | void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
| 165 | /* FIXME: Optimize this later.. */ |
| 166 | flush_tlb_all(); |
| 167 | } |
Paul Mundt | 9cef749 | 2009-07-29 00:12:17 +0900 | [diff] [blame] | 168 | |
Paul Mundt | 59615ec | 2010-07-02 15:44:09 +0900 | [diff] [blame] | 169 | void __flush_tlb_global(void) |
| 170 | { |
| 171 | flush_tlb_all(); |
| 172 | } |