| 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 | 163b2f0 | 2009-06-25 02:49:03 +0900 | [diff] [blame] | 6 | * Copyright (C) 2003 - 2009 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 |  | 
|  | 31 | extern void die(const char *,struct pt_regs *,long); | 
|  | 32 |  | 
|  | 33 | #define PFLAG(val,flag)   (( (val) & (flag) ) ? #flag : "" ) | 
|  | 34 | #define PPROT(flag) PFLAG(pgprot_val(prot),flag) | 
|  | 35 |  | 
|  | 36 | static inline void print_prots(pgprot_t prot) | 
|  | 37 | { | 
| Matt Fleming | 24ef7fc | 2009-11-19 21:11:05 +0000 | [diff] [blame] | 38 | printk("prot is 0x%016llx\n",pgprot_val(prot)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 |  | 
|  | 40 | printk("%s %s %s %s %s\n",PPROT(_PAGE_SHARED),PPROT(_PAGE_READ), | 
|  | 41 | PPROT(_PAGE_EXECUTE),PPROT(_PAGE_WRITE),PPROT(_PAGE_USER)); | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | static inline void print_vma(struct vm_area_struct *vma) | 
|  | 45 | { | 
|  | 46 | printk("vma start 0x%08lx\n", vma->vm_start); | 
|  | 47 | printk("vma end   0x%08lx\n", vma->vm_end); | 
|  | 48 |  | 
|  | 49 | print_prots(vma->vm_page_prot); | 
|  | 50 | printk("vm_flags 0x%08lx\n", vma->vm_flags); | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | static inline void print_task(struct task_struct *tsk) | 
|  | 54 | { | 
| Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 55 | printk("Task pid %d\n", task_pid_nr(tsk)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
|  | 58 | static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address) | 
|  | 59 | { | 
|  | 60 | pgd_t *dir; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 61 | pud_t *pud; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | pmd_t *pmd; | 
|  | 63 | pte_t *pte; | 
|  | 64 | pte_t entry; | 
|  | 65 |  | 
|  | 66 | dir = pgd_offset(mm, address); | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 67 | if (pgd_none(*dir)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 70 | pud = pud_offset(dir, address); | 
|  | 71 | if (pud_none(*pud)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return NULL; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 73 |  | 
|  | 74 | pmd = pmd_offset(pud, address); | 
|  | 75 | if (pmd_none(*pmd)) | 
|  | 76 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
|  | 78 | pte = pte_offset_kernel(pmd, address); | 
|  | 79 | entry = *pte; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 80 | if (pte_none(entry) || !pte_present(entry)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | return pte; | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | /* | 
|  | 87 | * This routine handles page faults.  It determines the address, | 
|  | 88 | * and the problem, and then passes it off to one of the appropriate | 
|  | 89 | * routines. | 
|  | 90 | */ | 
|  | 91 | asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess, | 
|  | 92 | unsigned long textaccess, unsigned long address) | 
|  | 93 | { | 
|  | 94 | struct task_struct *tsk; | 
|  | 95 | struct mm_struct *mm; | 
|  | 96 | struct vm_area_struct * vma; | 
|  | 97 | const struct exception_table_entry *fixup; | 
|  | 98 | pte_t *pte; | 
| Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 99 | int fault; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* SIM | 
|  | 102 | * Note this is now called with interrupts still disabled | 
|  | 103 | * This is to cope with being called for a missing IO port | 
| Simon Arlott | 0a35477 | 2007-05-14 08:25:48 +0900 | [diff] [blame] | 104 | * address with interrupts disabled. This should be fixed as | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * soon as we have a better 'fast path' miss handler. | 
|  | 106 | * | 
|  | 107 | * Plus take care how you try and debug this stuff. | 
|  | 108 | * For example, writing debug data to a port which you | 
|  | 109 | * have just faulted on is not going to work. | 
|  | 110 | */ | 
|  | 111 |  | 
|  | 112 | tsk = current; | 
|  | 113 | mm = tsk->mm; | 
|  | 114 |  | 
|  | 115 | /* Not an IO address, so reenable interrupts */ | 
|  | 116 | local_irq_enable(); | 
|  | 117 |  | 
| Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 118 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); | 
| Paul Mundt | 163b2f0 | 2009-06-25 02:49:03 +0900 | [diff] [blame] | 119 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* | 
|  | 121 | * If we're in an interrupt or have no user | 
|  | 122 | * context, we must not take the fault.. | 
|  | 123 | */ | 
| Peter Zijlstra | 6edaf68 | 2006-12-06 20:32:18 -0800 | [diff] [blame] | 124 | if (in_atomic() || !mm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | goto no_context; | 
|  | 126 |  | 
|  | 127 | /* TLB misses upon some cache flushes get done under cli() */ | 
|  | 128 | down_read(&mm->mmap_sem); | 
|  | 129 |  | 
|  | 130 | vma = find_vma(mm, address); | 
|  | 131 |  | 
|  | 132 | if (!vma) { | 
|  | 133 | #ifdef DEBUG_FAULT | 
|  | 134 | print_task(tsk); | 
|  | 135 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 
| Harvey Harrison | 866e6b9 | 2008-03-04 15:23:47 -0800 | [diff] [blame] | 136 | __func__, __LINE__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | address,regs->pc,textaccess,writeaccess); | 
|  | 138 | show_regs(regs); | 
|  | 139 | #endif | 
|  | 140 | goto bad_area; | 
|  | 141 | } | 
|  | 142 | if (vma->vm_start <= address) { | 
|  | 143 | goto good_area; | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | if (!(vma->vm_flags & VM_GROWSDOWN)) { | 
|  | 147 | #ifdef DEBUG_FAULT | 
|  | 148 | print_task(tsk); | 
|  | 149 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 
| Harvey Harrison | 866e6b9 | 2008-03-04 15:23:47 -0800 | [diff] [blame] | 150 | __func__, __LINE__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | address,regs->pc,textaccess,writeaccess); | 
|  | 152 | show_regs(regs); | 
|  | 153 |  | 
|  | 154 | print_vma(vma); | 
|  | 155 | #endif | 
|  | 156 | goto bad_area; | 
|  | 157 | } | 
|  | 158 | if (expand_stack(vma, address)) { | 
|  | 159 | #ifdef DEBUG_FAULT | 
|  | 160 | print_task(tsk); | 
|  | 161 | printk("%s:%d fault, address is 0x%08x PC %016Lx textaccess %d writeaccess %d\n", | 
| Harvey Harrison | 866e6b9 | 2008-03-04 15:23:47 -0800 | [diff] [blame] | 162 | __func__, __LINE__, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | address,regs->pc,textaccess,writeaccess); | 
|  | 164 | show_regs(regs); | 
|  | 165 | #endif | 
|  | 166 | goto bad_area; | 
|  | 167 | } | 
|  | 168 | /* | 
|  | 169 | * Ok, we have a good vm_area for this memory access, so | 
|  | 170 | * we can handle it.. | 
|  | 171 | */ | 
|  | 172 | good_area: | 
|  | 173 | if (textaccess) { | 
|  | 174 | if (!(vma->vm_flags & VM_EXEC)) | 
|  | 175 | goto bad_area; | 
|  | 176 | } else { | 
|  | 177 | if (writeaccess) { | 
|  | 178 | if (!(vma->vm_flags & VM_WRITE)) | 
|  | 179 | goto bad_area; | 
|  | 180 | } else { | 
|  | 181 | if (!(vma->vm_flags & VM_READ)) | 
|  | 182 | goto bad_area; | 
|  | 183 | } | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | /* | 
|  | 187 | * If for any reason at all we couldn't handle the fault, | 
|  | 188 | * make sure we exit gracefully rather than endlessly redo | 
|  | 189 | * the fault. | 
|  | 190 | */ | 
| Linus Torvalds | d06063c | 2009-04-10 09:01:23 -0700 | [diff] [blame] | 191 | fault = handle_mm_fault(mm, vma, address, writeaccess ? FAULT_FLAG_WRITE : 0); | 
| Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 192 | if (unlikely(fault & VM_FAULT_ERROR)) { | 
|  | 193 | if (fault & VM_FAULT_OOM) | 
|  | 194 | goto out_of_memory; | 
|  | 195 | else if (fault & VM_FAULT_SIGBUS) | 
|  | 196 | goto do_sigbus; | 
|  | 197 | BUG(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } | 
| Paul Mundt | 163b2f0 | 2009-06-25 02:49:03 +0900 | [diff] [blame] | 199 |  | 
|  | 200 | if (fault & VM_FAULT_MAJOR) { | 
| Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 201 | tsk->maj_flt++; | 
| Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 202 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, | 
| Paul Mundt | 163b2f0 | 2009-06-25 02:49:03 +0900 | [diff] [blame] | 203 | regs, address); | 
|  | 204 | } else { | 
| Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 205 | tsk->min_flt++; | 
| Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 206 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, | 
| Paul Mundt | 163b2f0 | 2009-06-25 02:49:03 +0900 | [diff] [blame] | 207 | regs, address); | 
|  | 208 | } | 
| Nick Piggin | 83c5407 | 2007-07-19 01:47:05 -0700 | [diff] [blame] | 209 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* If we get here, the page fault has been handled.  Do the TLB refill | 
|  | 211 | now from the newly-setup PTE, to avoid having to fault again right | 
|  | 212 | away on the same instruction. */ | 
|  | 213 | pte = lookup_pte (mm, address); | 
|  | 214 | if (!pte) { | 
|  | 215 | /* From empirical evidence, we can get here, due to | 
|  | 216 | !pte_present(pte).  (e.g. if a swap-in occurs, and the page | 
|  | 217 | is swapped back out again before the process that wanted it | 
|  | 218 | gets rescheduled?) */ | 
|  | 219 | goto no_pte; | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | __do_tlb_refill(address, textaccess, pte); | 
|  | 223 |  | 
|  | 224 | no_pte: | 
|  | 225 |  | 
|  | 226 | up_read(&mm->mmap_sem); | 
|  | 227 | return; | 
|  | 228 |  | 
|  | 229 | /* | 
|  | 230 | * Something tried to access memory that isn't in our memory map.. | 
|  | 231 | * Fix it, but check if it's kernel or user first.. | 
|  | 232 | */ | 
|  | 233 | bad_area: | 
|  | 234 | #ifdef DEBUG_FAULT | 
|  | 235 | printk("fault:bad area\n"); | 
|  | 236 | #endif | 
|  | 237 | up_read(&mm->mmap_sem); | 
|  | 238 |  | 
|  | 239 | if (user_mode(regs)) { | 
|  | 240 | static int count=0; | 
|  | 241 | siginfo_t info; | 
|  | 242 | if (count < 4) { | 
|  | 243 | /* This is really to help debug faults when starting | 
|  | 244 | * usermode, so only need a few */ | 
|  | 245 | count++; | 
|  | 246 | printk("user mode bad_area address=%08lx pid=%d (%s) pc=%08lx\n", | 
| Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 247 | address, task_pid_nr(current), current->comm, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | (unsigned long) regs->pc); | 
|  | 249 | #if 0 | 
|  | 250 | show_regs(regs); | 
|  | 251 | #endif | 
|  | 252 | } | 
| Serge E. Hallyn | b460cbc | 2007-10-18 23:39:52 -0700 | [diff] [blame] | 253 | if (is_global_init(tsk)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | panic("INIT had user mode bad_area\n"); | 
|  | 255 | } | 
|  | 256 | tsk->thread.address = address; | 
|  | 257 | tsk->thread.error_code = writeaccess; | 
|  | 258 | info.si_signo = SIGSEGV; | 
|  | 259 | info.si_errno = 0; | 
|  | 260 | info.si_addr = (void *) address; | 
|  | 261 | force_sig_info(SIGSEGV, &info, tsk); | 
|  | 262 | return; | 
|  | 263 | } | 
|  | 264 |  | 
|  | 265 | no_context: | 
|  | 266 | #ifdef DEBUG_FAULT | 
|  | 267 | printk("fault:No context\n"); | 
|  | 268 | #endif | 
|  | 269 | /* Are we prepared to handle this kernel fault?  */ | 
|  | 270 | fixup = search_exception_tables(regs->pc); | 
|  | 271 | if (fixup) { | 
|  | 272 | regs->pc = fixup->fixup; | 
|  | 273 | return; | 
|  | 274 | } | 
|  | 275 |  | 
|  | 276 | /* | 
|  | 277 | * Oops. The kernel tried to access some bad page. We'll have to | 
|  | 278 | * terminate things with extreme prejudice. | 
|  | 279 | * | 
|  | 280 | */ | 
|  | 281 | if (address < PAGE_SIZE) | 
|  | 282 | printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference"); | 
|  | 283 | else | 
|  | 284 | printk(KERN_ALERT "Unable to handle kernel paging request"); | 
|  | 285 | printk(" at virtual address %08lx\n", address); | 
|  | 286 | printk(KERN_ALERT "pc = %08Lx%08Lx\n", regs->pc >> 32, regs->pc & 0xffffffff); | 
|  | 287 | die("Oops", regs, writeaccess); | 
|  | 288 | do_exit(SIGKILL); | 
|  | 289 |  | 
|  | 290 | /* | 
|  | 291 | * We ran out of memory, or some other thing happened to us that made | 
|  | 292 | * us unable to handle the page fault gracefully. | 
|  | 293 | */ | 
|  | 294 | out_of_memory: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | up_read(&mm->mmap_sem); | 
| Nick Piggin | 6b6b18e | 2010-04-22 16:06:26 +0000 | [diff] [blame] | 296 | if (!user_mode(regs)) | 
|  | 297 | goto no_context; | 
|  | 298 | pagefault_out_of_memory(); | 
|  | 299 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 |  | 
|  | 301 | do_sigbus: | 
|  | 302 | printk("fault:Do sigbus\n"); | 
|  | 303 | up_read(&mm->mmap_sem); | 
|  | 304 |  | 
|  | 305 | /* | 
|  | 306 | * Send a sigbus, regardless of whether we were in kernel | 
|  | 307 | * or user mode. | 
|  | 308 | */ | 
|  | 309 | tsk->thread.address = address; | 
|  | 310 | tsk->thread.error_code = writeaccess; | 
|  | 311 | tsk->thread.trap_no = 14; | 
|  | 312 | force_sig(SIGBUS, tsk); | 
|  | 313 |  | 
|  | 314 | /* Kernel mode? Handle exceptions or die */ | 
|  | 315 | if (!user_mode(regs)) | 
|  | 316 | goto no_context; | 
|  | 317 | } | 
|  | 318 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 319 | void local_flush_tlb_one(unsigned long asid, unsigned long page) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { | 
|  | 321 | unsigned long long match, pteh=0, lpage; | 
|  | 322 | unsigned long tlb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | /* | 
|  | 325 | * Sign-extend based on neff. | 
|  | 326 | */ | 
| Paul Mundt | c791483 | 2009-08-04 17:14:39 +0900 | [diff] [blame] | 327 | lpage = neff_sign_extend(page); | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 328 | match = (asid << PTEH_ASID_SHIFT) | PTEH_VALID; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | match |= lpage; | 
|  | 330 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 331 | for_each_itlb_entry(tlb) { | 
|  | 332 | asm volatile ("getcfg	%1, 0, %0" | 
|  | 333 | : "=r" (pteh) | 
|  | 334 | : "r" (tlb) ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 336 | if (pteh == match) { | 
|  | 337 | __flush_tlb_slot(tlb); | 
|  | 338 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } | 
|  | 340 | } | 
|  | 341 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | for_each_dtlb_entry(tlb) { | 
|  | 343 | asm volatile ("getcfg	%1, 0, %0" | 
|  | 344 | : "=r" (pteh) | 
|  | 345 | : "r" (tlb) ); | 
|  | 346 |  | 
|  | 347 | if (pteh == match) { | 
|  | 348 | __flush_tlb_slot(tlb); | 
|  | 349 | break; | 
|  | 350 | } | 
|  | 351 |  | 
|  | 352 | } | 
|  | 353 | } | 
|  | 354 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 355 | 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] | 356 | { | 
|  | 357 | unsigned long flags; | 
|  | 358 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (vma->vm_mm) { | 
|  | 360 | page &= PAGE_MASK; | 
|  | 361 | local_irq_save(flags); | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 362 | local_flush_tlb_one(get_asid(), page); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | local_irq_restore(flags); | 
|  | 364 | } | 
|  | 365 | } | 
|  | 366 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 367 | void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, | 
|  | 368 | unsigned long end) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { | 
|  | 370 | unsigned long flags; | 
|  | 371 | unsigned long long match, pteh=0, pteh_epn, pteh_low; | 
|  | 372 | unsigned long tlb; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 373 | unsigned int cpu = smp_processor_id(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | struct mm_struct *mm; | 
|  | 375 |  | 
|  | 376 | mm = vma->vm_mm; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 377 | if (cpu_context(cpu, mm) == NO_CONTEXT) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | return; | 
|  | 379 |  | 
|  | 380 | local_irq_save(flags); | 
|  | 381 |  | 
|  | 382 | start &= PAGE_MASK; | 
|  | 383 | end &= PAGE_MASK; | 
|  | 384 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 385 | match = (cpu_asid(cpu, mm) << PTEH_ASID_SHIFT) | PTEH_VALID; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 |  | 
|  | 387 | /* Flush ITLB */ | 
|  | 388 | for_each_itlb_entry(tlb) { | 
|  | 389 | asm volatile ("getcfg	%1, 0, %0" | 
|  | 390 | : "=r" (pteh) | 
|  | 391 | : "r" (tlb) ); | 
|  | 392 |  | 
|  | 393 | pteh_epn = pteh & PAGE_MASK; | 
|  | 394 | pteh_low = pteh & ~PAGE_MASK; | 
|  | 395 |  | 
|  | 396 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) | 
|  | 397 | __flush_tlb_slot(tlb); | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | /* Flush DTLB */ | 
|  | 401 | for_each_dtlb_entry(tlb) { | 
|  | 402 | asm volatile ("getcfg	%1, 0, %0" | 
|  | 403 | : "=r" (pteh) | 
|  | 404 | : "r" (tlb) ); | 
|  | 405 |  | 
|  | 406 | pteh_epn = pteh & PAGE_MASK; | 
|  | 407 | pteh_low = pteh & ~PAGE_MASK; | 
|  | 408 |  | 
|  | 409 | if (pteh_low == match && pteh_epn >= start && pteh_epn <= end) | 
|  | 410 | __flush_tlb_slot(tlb); | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | local_irq_restore(flags); | 
|  | 414 | } | 
|  | 415 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 416 | void local_flush_tlb_mm(struct mm_struct *mm) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { | 
|  | 418 | unsigned long flags; | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 419 | unsigned int cpu = smp_processor_id(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 421 | if (cpu_context(cpu, mm) == NO_CONTEXT) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return; | 
|  | 423 |  | 
|  | 424 | local_irq_save(flags); | 
|  | 425 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 426 | cpu_context(cpu, mm) = NO_CONTEXT; | 
|  | 427 | if (mm == current->mm) | 
|  | 428 | activate_context(mm, cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 |  | 
|  | 430 | local_irq_restore(flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } | 
|  | 432 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 433 | void local_flush_tlb_all(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { | 
|  | 435 | /* Invalidate all, including shared pages, excluding fixed TLBs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | unsigned long flags, tlb; | 
|  | 437 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | local_irq_save(flags); | 
|  | 439 |  | 
|  | 440 | /* Flush each ITLB entry */ | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 441 | for_each_itlb_entry(tlb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | __flush_tlb_slot(tlb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 |  | 
|  | 444 | /* Flush each DTLB entry */ | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 445 | for_each_dtlb_entry(tlb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | __flush_tlb_slot(tlb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 |  | 
|  | 448 | local_irq_restore(flags); | 
|  | 449 | } | 
|  | 450 |  | 
| Paul Mundt | 3eeffb3 | 2007-11-19 18:57:03 +0900 | [diff] [blame] | 451 | void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { | 
|  | 453 | /* FIXME: Optimize this later.. */ | 
|  | 454 | flush_tlb_all(); | 
|  | 455 | } | 
| Paul Mundt | 9cef749 | 2009-07-29 00:12:17 +0900 | [diff] [blame] | 456 |  | 
| Paul Mundt | 59615ec | 2010-07-02 15:44:09 +0900 | [diff] [blame] | 457 | void __flush_tlb_global(void) | 
|  | 458 | { | 
|  | 459 | flush_tlb_all(); | 
|  | 460 | } | 
|  | 461 |  | 
| Paul Mundt | 9cef749 | 2009-07-29 00:12:17 +0900 | [diff] [blame] | 462 | void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte) | 
|  | 463 | { | 
|  | 464 | } |