Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the routines for TLB flushing. |
| 3 | * On machines where the MMU does not use a hash table to store virtual to |
| 4 | * physical translations (ie, SW loaded TLBs or Book3E compilant processors, |
| 5 | * this does -not- include 603 however which shares the implementation with |
| 6 | * hash based processors) |
| 7 | * |
| 8 | * -- BenH |
| 9 | * |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 10 | * Copyright 2008,2009 Ben Herrenschmidt <benh@kernel.crashing.org> |
| 11 | * IBM Corp. |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 12 | * |
| 13 | * Derived from arch/ppc/mm/init.c: |
| 14 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 15 | * |
| 16 | * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) |
| 17 | * and Cort Dougan (PReP) (cort@cs.nmt.edu) |
| 18 | * Copyright (C) 1996 Paul Mackerras |
| 19 | * |
| 20 | * Derived from "arch/i386/mm/init.c" |
| 21 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
| 22 | * |
| 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public License |
| 25 | * as published by the Free Software Foundation; either version |
| 26 | * 2 of the License, or (at your option) any later version. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <linux/kernel.h> |
Paul Gortmaker | 9308794 | 2011-07-29 16:19:31 +1000 | [diff] [blame] | 31 | #include <linux/export.h> |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 32 | #include <linux/mm.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/highmem.h> |
| 35 | #include <linux/pagemap.h> |
| 36 | #include <linux/preempt.h> |
| 37 | #include <linux/spinlock.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 38 | #include <linux/memblock.h> |
Dave Kleikamp | 91b191c | 2011-07-04 18:38:03 +0000 | [diff] [blame] | 39 | #include <linux/of_fdt.h> |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 40 | #include <linux/hugetlb.h> |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 41 | |
| 42 | #include <asm/tlbflush.h> |
| 43 | #include <asm/tlb.h> |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 44 | #include <asm/code-patching.h> |
Scott Wood | d9e1831 | 2015-10-06 22:48:09 -0500 | [diff] [blame^] | 45 | #include <asm/cputhreads.h> |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 46 | #include <asm/hugetlb.h> |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 47 | #include <asm/paca.h> |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 48 | |
| 49 | #include "mmu_decl.h" |
| 50 | |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 51 | /* |
| 52 | * This struct lists the sw-supported page sizes. The hardawre MMU may support |
| 53 | * other sizes not listed here. The .ind field is only used on MMUs that have |
| 54 | * indirect page table entries. |
| 55 | */ |
| 56 | #ifdef CONFIG_PPC_BOOK3E_MMU |
Becky Bruce | 881fde1 | 2011-10-10 10:50:40 +0000 | [diff] [blame] | 57 | #ifdef CONFIG_PPC_FSL_BOOK3E |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 58 | struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = { |
| 59 | [MMU_PAGE_4K] = { |
| 60 | .shift = 12, |
| 61 | .enc = BOOK3E_PAGESZ_4K, |
| 62 | }, |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 63 | [MMU_PAGE_2M] = { |
| 64 | .shift = 21, |
| 65 | .enc = BOOK3E_PAGESZ_2M, |
| 66 | }, |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 67 | [MMU_PAGE_4M] = { |
| 68 | .shift = 22, |
| 69 | .enc = BOOK3E_PAGESZ_4M, |
| 70 | }, |
| 71 | [MMU_PAGE_16M] = { |
| 72 | .shift = 24, |
| 73 | .enc = BOOK3E_PAGESZ_16M, |
| 74 | }, |
| 75 | [MMU_PAGE_64M] = { |
| 76 | .shift = 26, |
| 77 | .enc = BOOK3E_PAGESZ_64M, |
| 78 | }, |
| 79 | [MMU_PAGE_256M] = { |
| 80 | .shift = 28, |
| 81 | .enc = BOOK3E_PAGESZ_256M, |
| 82 | }, |
| 83 | [MMU_PAGE_1G] = { |
| 84 | .shift = 30, |
| 85 | .enc = BOOK3E_PAGESZ_1GB, |
| 86 | }, |
| 87 | }; |
| 88 | #else |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 89 | struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = { |
| 90 | [MMU_PAGE_4K] = { |
| 91 | .shift = 12, |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 92 | .ind = 20, |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 93 | .enc = BOOK3E_PAGESZ_4K, |
| 94 | }, |
| 95 | [MMU_PAGE_16K] = { |
| 96 | .shift = 14, |
| 97 | .enc = BOOK3E_PAGESZ_16K, |
| 98 | }, |
| 99 | [MMU_PAGE_64K] = { |
| 100 | .shift = 16, |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 101 | .ind = 28, |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 102 | .enc = BOOK3E_PAGESZ_64K, |
| 103 | }, |
| 104 | [MMU_PAGE_1M] = { |
| 105 | .shift = 20, |
| 106 | .enc = BOOK3E_PAGESZ_1M, |
| 107 | }, |
| 108 | [MMU_PAGE_16M] = { |
| 109 | .shift = 24, |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 110 | .ind = 36, |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 111 | .enc = BOOK3E_PAGESZ_16M, |
| 112 | }, |
| 113 | [MMU_PAGE_256M] = { |
| 114 | .shift = 28, |
| 115 | .enc = BOOK3E_PAGESZ_256M, |
| 116 | }, |
| 117 | [MMU_PAGE_1G] = { |
| 118 | .shift = 30, |
| 119 | .enc = BOOK3E_PAGESZ_1GB, |
| 120 | }, |
| 121 | }; |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 122 | #endif /* CONFIG_FSL_BOOKE */ |
| 123 | |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 124 | static inline int mmu_get_tsize(int psize) |
| 125 | { |
| 126 | return mmu_psize_defs[psize].enc; |
| 127 | } |
| 128 | #else |
| 129 | static inline int mmu_get_tsize(int psize) |
| 130 | { |
| 131 | /* This isn't used on !Book3E for now */ |
| 132 | return 0; |
| 133 | } |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 134 | #endif /* CONFIG_PPC_BOOK3E_MMU */ |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 135 | |
| 136 | /* The variables below are currently only used on 64-bit Book3E |
| 137 | * though this will probably be made common with other nohash |
| 138 | * implementations at some point |
| 139 | */ |
| 140 | #ifdef CONFIG_PPC64 |
| 141 | |
| 142 | int mmu_linear_psize; /* Page size used for the linear mapping */ |
| 143 | int mmu_pte_psize; /* Page size used for PTE pages */ |
Benjamin Herrenschmidt | 32a7494 | 2009-07-23 23:15:58 +0000 | [diff] [blame] | 144 | int mmu_vmemmap_psize; /* Page size used for the virtual mem map */ |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 145 | int book3e_htw_mode; /* HW tablewalk? Value is PPC_HTW_* */ |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 146 | unsigned long linear_map_top; /* Top of linear mapping */ |
| 147 | |
Scott Wood | 609af38 | 2014-03-10 17:29:38 -0500 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Number of bytes to add to SPRN_SPRG_TLB_EXFRAME on crit/mcheck/debug |
| 151 | * exceptions. This is used for bolted and e6500 TLB miss handlers which |
| 152 | * do not modify this SPRG in the TLB miss code; for other TLB miss handlers, |
| 153 | * this is set to zero. |
| 154 | */ |
| 155 | int extlb_level_exc; |
| 156 | |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 157 | #endif /* CONFIG_PPC64 */ |
| 158 | |
Becky Bruce | 3160b09 | 2011-06-28 14:54:47 -0500 | [diff] [blame] | 159 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 160 | /* next_tlbcam_idx is used to round-robin tlbcam entry assignment */ |
| 161 | DEFINE_PER_CPU(int, next_tlbcam_idx); |
| 162 | EXPORT_PER_CPU_SYMBOL(next_tlbcam_idx); |
| 163 | #endif |
| 164 | |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 165 | /* |
| 166 | * Base TLB flushing operations: |
| 167 | * |
| 168 | * - flush_tlb_mm(mm) flushes the specified mm context TLB's |
| 169 | * - flush_tlb_page(vma, vmaddr) flushes one page |
| 170 | * - flush_tlb_range(vma, start, end) flushes a range of pages |
| 171 | * - flush_tlb_kernel_range(start, end) flushes kernel pages |
| 172 | * |
| 173 | * - local_* variants of page and mm only apply to the current |
| 174 | * processor |
| 175 | */ |
| 176 | |
| 177 | /* |
| 178 | * These are the base non-SMP variants of page and mm flushing |
| 179 | */ |
| 180 | void local_flush_tlb_mm(struct mm_struct *mm) |
| 181 | { |
| 182 | unsigned int pid; |
| 183 | |
| 184 | preempt_disable(); |
| 185 | pid = mm->context.id; |
| 186 | if (pid != MMU_NO_CONTEXT) |
| 187 | _tlbil_pid(pid); |
| 188 | preempt_enable(); |
| 189 | } |
| 190 | EXPORT_SYMBOL(local_flush_tlb_mm); |
| 191 | |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 192 | void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, |
| 193 | int tsize, int ind) |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 194 | { |
| 195 | unsigned int pid; |
| 196 | |
| 197 | preempt_disable(); |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 198 | pid = mm ? mm->context.id : 0; |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 199 | if (pid != MMU_NO_CONTEXT) |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 200 | _tlbil_va(vmaddr, pid, tsize, ind); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 201 | preempt_enable(); |
| 202 | } |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 203 | |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 204 | void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr) |
| 205 | { |
| 206 | __local_flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr, |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 207 | mmu_get_tsize(mmu_virtual_psize), 0); |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 208 | } |
| 209 | EXPORT_SYMBOL(local_flush_tlb_page); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * And here are the SMP non-local implementations |
| 213 | */ |
| 214 | #ifdef CONFIG_SMP |
| 215 | |
Thomas Gleixner | 3eb93c5 | 2010-02-18 02:22:44 +0000 | [diff] [blame] | 216 | static DEFINE_RAW_SPINLOCK(tlbivax_lock); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 217 | |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 218 | static int mm_is_core_local(struct mm_struct *mm) |
| 219 | { |
| 220 | return cpumask_subset(mm_cpumask(mm), |
Bartosz Golaszewski | 06931e6 | 2015-05-26 15:11:28 +0200 | [diff] [blame] | 221 | topology_sibling_cpumask(smp_processor_id())); |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 224 | struct tlb_flush_param { |
| 225 | unsigned long addr; |
| 226 | unsigned int pid; |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 227 | unsigned int tsize; |
| 228 | unsigned int ind; |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | static void do_flush_tlb_mm_ipi(void *param) |
| 232 | { |
| 233 | struct tlb_flush_param *p = param; |
| 234 | |
| 235 | _tlbil_pid(p ? p->pid : 0); |
| 236 | } |
| 237 | |
| 238 | static void do_flush_tlb_page_ipi(void *param) |
| 239 | { |
| 240 | struct tlb_flush_param *p = param; |
| 241 | |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 242 | _tlbil_va(p->addr, p->pid, p->tsize, p->ind); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | |
| 246 | /* Note on invalidations and PID: |
| 247 | * |
| 248 | * We snapshot the PID with preempt disabled. At this point, it can still |
| 249 | * change either because: |
| 250 | * - our context is being stolen (PID -> NO_CONTEXT) on another CPU |
| 251 | * - we are invaliating some target that isn't currently running here |
| 252 | * and is concurrently acquiring a new PID on another CPU |
| 253 | * - some other CPU is re-acquiring a lost PID for this mm |
| 254 | * etc... |
| 255 | * |
| 256 | * However, this shouldn't be a problem as we only guarantee |
| 257 | * invalidation of TLB entries present prior to this call, so we |
| 258 | * don't care about the PID changing, and invalidating a stale PID |
| 259 | * is generally harmless. |
| 260 | */ |
| 261 | |
| 262 | void flush_tlb_mm(struct mm_struct *mm) |
| 263 | { |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 264 | unsigned int pid; |
| 265 | |
| 266 | preempt_disable(); |
| 267 | pid = mm->context.id; |
| 268 | if (unlikely(pid == MMU_NO_CONTEXT)) |
| 269 | goto no_context; |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 270 | if (!mm_is_core_local(mm)) { |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 271 | struct tlb_flush_param p = { .pid = pid }; |
Rusty Russell | 56aa412 | 2009-03-15 18:16:43 +0000 | [diff] [blame] | 272 | /* Ignores smp_processor_id() even if set. */ |
| 273 | smp_call_function_many(mm_cpumask(mm), |
| 274 | do_flush_tlb_mm_ipi, &p, 1); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 275 | } |
| 276 | _tlbil_pid(pid); |
| 277 | no_context: |
| 278 | preempt_enable(); |
| 279 | } |
| 280 | EXPORT_SYMBOL(flush_tlb_mm); |
| 281 | |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 282 | void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr, |
| 283 | int tsize, int ind) |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 284 | { |
Rusty Russell | 56aa412 | 2009-03-15 18:16:43 +0000 | [diff] [blame] | 285 | struct cpumask *cpu_mask; |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 286 | unsigned int pid; |
| 287 | |
Arseny Solokha | c2c896b | 2015-02-04 13:18:02 +1100 | [diff] [blame] | 288 | /* |
| 289 | * This function as well as __local_flush_tlb_page() must only be called |
| 290 | * for user contexts. |
| 291 | */ |
| 292 | if (unlikely(WARN_ON(!mm))) |
Arseny Solokha | 0dc294f | 2015-01-30 19:08:27 +0700 | [diff] [blame] | 293 | return; |
| 294 | |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 295 | preempt_disable(); |
Arseny Solokha | 0dc294f | 2015-01-30 19:08:27 +0700 | [diff] [blame] | 296 | pid = mm->context.id; |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 297 | if (unlikely(pid == MMU_NO_CONTEXT)) |
| 298 | goto bail; |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 299 | cpu_mask = mm_cpumask(mm); |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 300 | if (!mm_is_core_local(mm)) { |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 301 | /* If broadcast tlbivax is supported, use it */ |
| 302 | if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) { |
| 303 | int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL); |
| 304 | if (lock) |
Thomas Gleixner | 3eb93c5 | 2010-02-18 02:22:44 +0000 | [diff] [blame] | 305 | raw_spin_lock(&tlbivax_lock); |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 306 | _tlbivax_bcast(vmaddr, pid, tsize, ind); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 307 | if (lock) |
Thomas Gleixner | 3eb93c5 | 2010-02-18 02:22:44 +0000 | [diff] [blame] | 308 | raw_spin_unlock(&tlbivax_lock); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 309 | goto bail; |
| 310 | } else { |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 311 | struct tlb_flush_param p = { |
| 312 | .pid = pid, |
| 313 | .addr = vmaddr, |
| 314 | .tsize = tsize, |
| 315 | .ind = ind, |
| 316 | }; |
Rusty Russell | 56aa412 | 2009-03-15 18:16:43 +0000 | [diff] [blame] | 317 | /* Ignores smp_processor_id() even if set in cpu_mask */ |
| 318 | smp_call_function_many(cpu_mask, |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 319 | do_flush_tlb_page_ipi, &p, 1); |
| 320 | } |
| 321 | } |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 322 | _tlbil_va(vmaddr, pid, tsize, ind); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 323 | bail: |
| 324 | preempt_enable(); |
| 325 | } |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 326 | |
| 327 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr) |
| 328 | { |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 329 | #ifdef CONFIG_HUGETLB_PAGE |
Scott Wood | d742aa1 | 2013-11-21 18:26:42 -0600 | [diff] [blame] | 330 | if (vma && is_vm_hugetlb_page(vma)) |
Becky Bruce | 41151e7 | 2011-06-28 09:54:48 +0000 | [diff] [blame] | 331 | flush_hugetlb_page(vma, vmaddr); |
| 332 | #endif |
| 333 | |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 334 | __flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr, |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 335 | mmu_get_tsize(mmu_virtual_psize), 0); |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 336 | } |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 337 | EXPORT_SYMBOL(flush_tlb_page); |
| 338 | |
| 339 | #endif /* CONFIG_SMP */ |
| 340 | |
Dave Kleikamp | 91b191c | 2011-07-04 18:38:03 +0000 | [diff] [blame] | 341 | #ifdef CONFIG_PPC_47x |
| 342 | void __init early_init_mmu_47x(void) |
| 343 | { |
| 344 | #ifdef CONFIG_SMP |
| 345 | unsigned long root = of_get_flat_dt_root(); |
| 346 | if (of_get_flat_dt_prop(root, "cooperative-partition", NULL)) |
| 347 | mmu_clear_feature(MMU_FTR_USE_TLBIVAX_BCAST); |
| 348 | #endif /* CONFIG_SMP */ |
| 349 | } |
| 350 | #endif /* CONFIG_PPC_47x */ |
| 351 | |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 352 | /* |
| 353 | * Flush kernel TLB entries in the given range |
| 354 | */ |
| 355 | void flush_tlb_kernel_range(unsigned long start, unsigned long end) |
| 356 | { |
| 357 | #ifdef CONFIG_SMP |
| 358 | preempt_disable(); |
| 359 | smp_call_function(do_flush_tlb_mm_ipi, NULL, 1); |
| 360 | _tlbil_pid(0); |
| 361 | preempt_enable(); |
Dave Liu | d6a09e0 | 2008-12-30 23:42:55 +0000 | [diff] [blame] | 362 | #else |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 363 | _tlbil_pid(0); |
Dave Liu | d6a09e0 | 2008-12-30 23:42:55 +0000 | [diff] [blame] | 364 | #endif |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 365 | } |
| 366 | EXPORT_SYMBOL(flush_tlb_kernel_range); |
| 367 | |
| 368 | /* |
| 369 | * Currently, for range flushing, we just do a full mm flush. This should |
| 370 | * be optimized based on a threshold on the size of the range, since |
| 371 | * some implementation can stack multiple tlbivax before a tlbsync but |
| 372 | * for now, we keep it that way |
| 373 | */ |
| 374 | void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, |
| 375 | unsigned long end) |
| 376 | |
| 377 | { |
| 378 | flush_tlb_mm(vma->vm_mm); |
| 379 | } |
| 380 | EXPORT_SYMBOL(flush_tlb_range); |
Benjamin Herrenschmidt | c7cc58a1 | 2009-07-23 23:15:28 +0000 | [diff] [blame] | 381 | |
| 382 | void tlb_flush(struct mmu_gather *tlb) |
| 383 | { |
| 384 | flush_tlb_mm(tlb->mm); |
Benjamin Herrenschmidt | c7cc58a1 | 2009-07-23 23:15:28 +0000 | [diff] [blame] | 385 | } |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * Below are functions specific to the 64-bit variant of Book3E though that |
| 389 | * may change in the future |
| 390 | */ |
| 391 | |
| 392 | #ifdef CONFIG_PPC64 |
| 393 | |
| 394 | /* |
| 395 | * Handling of virtual linear page tables or indirect TLB entries |
| 396 | * flushing when PTE pages are freed |
| 397 | */ |
| 398 | void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address) |
| 399 | { |
| 400 | int tsize = mmu_psize_defs[mmu_pte_psize].enc; |
| 401 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 402 | if (book3e_htw_mode != PPC_HTW_NONE) { |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 403 | unsigned long start = address & PMD_MASK; |
| 404 | unsigned long end = address + PMD_SIZE; |
| 405 | unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift; |
| 406 | |
| 407 | /* This isn't the most optimal, ideally we would factor out the |
| 408 | * while preempt & CPU mask mucking around, or even the IPI but |
| 409 | * it will do for now |
| 410 | */ |
| 411 | while (start < end) { |
| 412 | __flush_tlb_page(tlb->mm, start, tsize, 1); |
| 413 | start += size; |
| 414 | } |
| 415 | } else { |
| 416 | unsigned long rmask = 0xf000000000000000ul; |
| 417 | unsigned long rid = (address & rmask) | 0x1000000000000000ul; |
| 418 | unsigned long vpte = address & ~rmask; |
| 419 | |
| 420 | #ifdef CONFIG_PPC_64K_PAGES |
| 421 | vpte = (vpte >> (PAGE_SHIFT - 4)) & ~0xfffful; |
| 422 | #else |
| 423 | vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful; |
| 424 | #endif |
| 425 | vpte |= rid; |
| 426 | __flush_tlb_page(tlb->mm, vpte, tsize, 0); |
| 427 | } |
| 428 | } |
| 429 | |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 430 | static void setup_page_sizes(void) |
| 431 | { |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 432 | unsigned int tlb0cfg; |
| 433 | unsigned int tlb0ps; |
| 434 | unsigned int eptcfg; |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 435 | int i, psize; |
| 436 | |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 437 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 438 | unsigned int mmucfg = mfspr(SPRN_MMUCFG); |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 439 | int fsl_mmu = mmu_has_feature(MMU_FTR_TYPE_FSL_E); |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 440 | |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 441 | if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) { |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 442 | unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG); |
| 443 | unsigned int min_pg, max_pg; |
| 444 | |
| 445 | min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT; |
| 446 | max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT; |
| 447 | |
| 448 | for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) { |
| 449 | struct mmu_psize_def *def; |
| 450 | unsigned int shift; |
| 451 | |
| 452 | def = &mmu_psize_defs[psize]; |
| 453 | shift = def->shift; |
| 454 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 455 | if (shift == 0 || shift & 1) |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 456 | continue; |
| 457 | |
| 458 | /* adjust to be in terms of 4^shift Kb */ |
| 459 | shift = (shift - 10) >> 1; |
| 460 | |
| 461 | if ((shift >= min_pg) && (shift <= max_pg)) |
| 462 | def->flags |= MMU_PAGE_SIZE_DIRECT; |
| 463 | } |
| 464 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 465 | goto out; |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 466 | } |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 467 | |
| 468 | if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V2) { |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 469 | u32 tlb1cfg, tlb1ps; |
| 470 | |
| 471 | tlb0cfg = mfspr(SPRN_TLB0CFG); |
| 472 | tlb1cfg = mfspr(SPRN_TLB1CFG); |
| 473 | tlb1ps = mfspr(SPRN_TLB1PS); |
| 474 | eptcfg = mfspr(SPRN_EPTCFG); |
| 475 | |
| 476 | if ((tlb1cfg & TLBnCFG_IND) && (tlb0cfg & TLBnCFG_PT)) |
| 477 | book3e_htw_mode = PPC_HTW_E6500; |
| 478 | |
| 479 | /* |
| 480 | * We expect 4K subpage size and unrestricted indirect size. |
| 481 | * The lack of a restriction on indirect size is a Freescale |
| 482 | * extension, indicated by PSn = 0 but SPSn != 0. |
| 483 | */ |
| 484 | if (eptcfg != 2) |
| 485 | book3e_htw_mode = PPC_HTW_NONE; |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 486 | |
| 487 | for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) { |
| 488 | struct mmu_psize_def *def = &mmu_psize_defs[psize]; |
| 489 | |
| 490 | if (tlb1ps & (1U << (def->shift - 10))) { |
| 491 | def->flags |= MMU_PAGE_SIZE_DIRECT; |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 492 | |
| 493 | if (book3e_htw_mode && psize == MMU_PAGE_2M) |
| 494 | def->flags |= MMU_PAGE_SIZE_INDIRECT; |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 498 | goto out; |
Kumar Gala | 1b29187 | 2013-03-05 12:08:32 -0600 | [diff] [blame] | 499 | } |
Kumar Gala | 988cf86 | 2010-10-08 02:13:25 -0500 | [diff] [blame] | 500 | #endif |
| 501 | |
| 502 | tlb0cfg = mfspr(SPRN_TLB0CFG); |
| 503 | tlb0ps = mfspr(SPRN_TLB0PS); |
| 504 | eptcfg = mfspr(SPRN_EPTCFG); |
| 505 | |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 506 | /* Look for supported direct sizes */ |
| 507 | for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) { |
| 508 | struct mmu_psize_def *def = &mmu_psize_defs[psize]; |
| 509 | |
| 510 | if (tlb0ps & (1U << (def->shift - 10))) |
| 511 | def->flags |= MMU_PAGE_SIZE_DIRECT; |
| 512 | } |
| 513 | |
| 514 | /* Indirect page sizes supported ? */ |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 515 | if ((tlb0cfg & TLBnCFG_IND) == 0 || |
| 516 | (tlb0cfg & TLBnCFG_PT) == 0) |
| 517 | goto out; |
| 518 | |
| 519 | book3e_htw_mode = PPC_HTW_IBM; |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 520 | |
| 521 | /* Now, we only deal with one IND page size for each |
| 522 | * direct size. Hopefully all implementations today are |
| 523 | * unambiguous, but we might want to be careful in the |
| 524 | * future. |
| 525 | */ |
| 526 | for (i = 0; i < 3; i++) { |
| 527 | unsigned int ps, sps; |
| 528 | |
| 529 | sps = eptcfg & 0x1f; |
| 530 | eptcfg >>= 5; |
| 531 | ps = eptcfg & 0x1f; |
| 532 | eptcfg >>= 5; |
| 533 | if (!ps || !sps) |
| 534 | continue; |
| 535 | for (psize = 0; psize < MMU_PAGE_COUNT; psize++) { |
| 536 | struct mmu_psize_def *def = &mmu_psize_defs[psize]; |
| 537 | |
| 538 | if (ps == (def->shift - 10)) |
| 539 | def->flags |= MMU_PAGE_SIZE_INDIRECT; |
| 540 | if (sps == (def->shift - 10)) |
| 541 | def->ind = ps + 10; |
| 542 | } |
| 543 | } |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 544 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 545 | out: |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 546 | /* Cleanup array and print summary */ |
| 547 | pr_info("MMU: Supported page sizes\n"); |
| 548 | for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) { |
| 549 | struct mmu_psize_def *def = &mmu_psize_defs[psize]; |
| 550 | const char *__page_type_names[] = { |
| 551 | "unsupported", |
| 552 | "direct", |
| 553 | "indirect", |
| 554 | "direct & indirect" |
| 555 | }; |
| 556 | if (def->flags == 0) { |
| 557 | def->shift = 0; |
| 558 | continue; |
| 559 | } |
| 560 | pr_info(" %8ld KB as %s\n", 1ul << (def->shift - 10), |
| 561 | __page_type_names[def->flags & 0x3]); |
| 562 | } |
| 563 | } |
| 564 | |
Scott Wood | f67f4ef | 2011-06-22 11:25:42 +0000 | [diff] [blame] | 565 | static void setup_mmu_htw(void) |
| 566 | { |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 567 | /* |
| 568 | * If we want to use HW tablewalk, enable it by patching the TLB miss |
| 569 | * handlers to branch to the one dedicated to it. |
| 570 | */ |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 571 | |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 572 | switch (book3e_htw_mode) { |
| 573 | case PPC_HTW_IBM: |
Scott Wood | f67f4ef | 2011-06-22 11:25:42 +0000 | [diff] [blame] | 574 | patch_exception(0x1c0, exc_data_tlb_miss_htw_book3e); |
| 575 | patch_exception(0x1e0, exc_instruction_tlb_miss_htw_book3e); |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 576 | break; |
Scott Wood | 9841c79 | 2014-01-17 18:36:38 -0600 | [diff] [blame] | 577 | #ifdef CONFIG_PPC_FSL_BOOK3E |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 578 | case PPC_HTW_E6500: |
Scott Wood | 609af38 | 2014-03-10 17:29:38 -0500 | [diff] [blame] | 579 | extlb_level_exc = EX_TLB_SIZE; |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 580 | patch_exception(0x1c0, exc_data_tlb_miss_e6500_book3e); |
| 581 | patch_exception(0x1e0, exc_instruction_tlb_miss_e6500_book3e); |
| 582 | break; |
Scott Wood | 9841c79 | 2014-01-17 18:36:38 -0600 | [diff] [blame] | 583 | #endif |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 584 | } |
Kumar Gala | 32d206e | 2011-05-19 20:09:28 +0000 | [diff] [blame] | 585 | pr_info("MMU: Book3E HW tablewalk %s\n", |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 586 | book3e_htw_mode != PPC_HTW_NONE ? "enabled" : "not supported"); |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Early initialization of the MMU TLB code |
| 591 | */ |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 592 | static void early_init_this_mmu(void) |
Benjamin Herrenschmidt | f2b26c9 | 2010-07-09 14:57:43 +1000 | [diff] [blame] | 593 | { |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 594 | unsigned int mas4; |
| 595 | |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 596 | /* Set MAS4 based on page table setting */ |
| 597 | |
| 598 | mas4 = 0x4 << MAS4_WIMGED_SHIFT; |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 599 | switch (book3e_htw_mode) { |
| 600 | case PPC_HTW_E6500: |
| 601 | mas4 |= MAS4_INDD; |
| 602 | mas4 |= BOOK3E_PAGESZ_2M << MAS4_TSIZED_SHIFT; |
| 603 | mas4 |= MAS4_TLBSELD(1); |
| 604 | mmu_pte_psize = MMU_PAGE_2M; |
| 605 | break; |
| 606 | |
| 607 | case PPC_HTW_IBM: |
| 608 | mas4 |= MAS4_INDD; |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 609 | #ifdef CONFIG_PPC_64K_PAGES |
| 610 | mas4 |= BOOK3E_PAGESZ_256M << MAS4_TSIZED_SHIFT; |
| 611 | mmu_pte_psize = MMU_PAGE_256M; |
| 612 | #else |
| 613 | mas4 |= BOOK3E_PAGESZ_1M << MAS4_TSIZED_SHIFT; |
| 614 | mmu_pte_psize = MMU_PAGE_1M; |
| 615 | #endif |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 616 | break; |
| 617 | |
| 618 | case PPC_HTW_NONE: |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 619 | #ifdef CONFIG_PPC_64K_PAGES |
| 620 | mas4 |= BOOK3E_PAGESZ_64K << MAS4_TSIZED_SHIFT; |
| 621 | #else |
| 622 | mas4 |= BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT; |
| 623 | #endif |
| 624 | mmu_pte_psize = mmu_virtual_psize; |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 625 | break; |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 626 | } |
| 627 | mtspr(SPRN_MAS4, mas4); |
| 628 | |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 629 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 630 | if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) { |
| 631 | unsigned int num_cams; |
Scott Wood | d9e1831 | 2015-10-06 22:48:09 -0500 | [diff] [blame^] | 632 | int __maybe_unused cpu = smp_processor_id(); |
| 633 | bool map = true; |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 634 | |
| 635 | /* use a quarter of the TLBCAM for bolted linear map */ |
| 636 | num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4; |
Scott Wood | d9e1831 | 2015-10-06 22:48:09 -0500 | [diff] [blame^] | 637 | |
| 638 | /* |
| 639 | * Only do the mapping once per core, or else the |
| 640 | * transient mapping would cause problems. |
| 641 | */ |
| 642 | #ifdef CONFIG_SMP |
| 643 | if (cpu != boot_cpuid && |
| 644 | (cpu != cpu_first_thread_sibling(cpu) || |
| 645 | cpu == cpu_first_thread_sibling(boot_cpuid))) |
| 646 | map = false; |
| 647 | #endif |
| 648 | |
| 649 | if (map) |
| 650 | linear_map_top = map_mem_in_cams(linear_map_top, |
| 651 | num_cams); |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 652 | } |
| 653 | #endif |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 654 | |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 655 | /* A sync won't hurt us after mucking around with |
| 656 | * the MMU configuration |
| 657 | */ |
| 658 | mb(); |
| 659 | } |
Scott Wood | f67f4ef | 2011-06-22 11:25:42 +0000 | [diff] [blame] | 660 | |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 661 | static void __init early_init_mmu_global(void) |
| 662 | { |
| 663 | /* XXX This will have to be decided at runtime, but right |
| 664 | * now our boot and TLB miss code hard wires it. Ideally |
| 665 | * we should find out a suitable page size and patch the |
| 666 | * TLB miss code (either that or use the PACA to store |
| 667 | * the value we want) |
| 668 | */ |
| 669 | mmu_linear_psize = MMU_PAGE_1G; |
| 670 | |
| 671 | /* XXX This should be decided at runtime based on supported |
| 672 | * page sizes in the TLB, but for now let's assume 16M is |
| 673 | * always there and a good fit (which it probably is) |
| 674 | * |
| 675 | * Freescale booke only supports 4K pages in TLB0, so use that. |
| 676 | */ |
| 677 | if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) |
| 678 | mmu_vmemmap_psize = MMU_PAGE_4K; |
| 679 | else |
| 680 | mmu_vmemmap_psize = MMU_PAGE_16M; |
| 681 | |
| 682 | /* XXX This code only checks for TLB 0 capabilities and doesn't |
| 683 | * check what page size combos are supported by the HW. It |
| 684 | * also doesn't handle the case where a separate array holds |
| 685 | * the IND entries from the array loaded by the PT. |
| 686 | */ |
| 687 | /* Look for supported page sizes */ |
| 688 | setup_page_sizes(); |
| 689 | |
| 690 | /* Look for HW tablewalk support */ |
| 691 | setup_mmu_htw(); |
| 692 | |
| 693 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 694 | if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) { |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 695 | if (book3e_htw_mode == PPC_HTW_NONE) { |
Scott Wood | 609af38 | 2014-03-10 17:29:38 -0500 | [diff] [blame] | 696 | extlb_level_exc = EX_TLB_SIZE; |
Scott Wood | 28efc35 | 2013-10-11 19:22:38 -0500 | [diff] [blame] | 697 | patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e); |
| 698 | patch_exception(0x1e0, |
| 699 | exc_instruction_tlb_miss_bolted_book3e); |
| 700 | } |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 701 | } |
| 702 | #endif |
| 703 | |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 704 | /* Set the global containing the top of the linear mapping |
| 705 | * for use by the TLB miss code |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 706 | */ |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 707 | linear_map_top = memblock_end_of_DRAM(); |
| 708 | } |
| 709 | |
| 710 | static void __init early_mmu_set_memory_limit(void) |
| 711 | { |
| 712 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 713 | if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) { |
| 714 | /* |
| 715 | * Limit memory so we dont have linear faults. |
| 716 | * Unlike memblock_set_current_limit, which limits |
| 717 | * memory available during early boot, this permanently |
| 718 | * reduces the memory available to Linux. We need to |
| 719 | * do this because highmem is not supported on 64-bit. |
| 720 | */ |
| 721 | memblock_enforce_memory_limit(linear_map_top); |
| 722 | } |
| 723 | #endif |
Benjamin Herrenschmidt | e63075a | 2010-07-06 15:39:01 -0700 | [diff] [blame] | 724 | |
| 725 | memblock_set_current_limit(linear_map_top); |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 728 | /* boot cpu only */ |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 729 | void __init early_init_mmu(void) |
| 730 | { |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 731 | early_init_mmu_global(); |
| 732 | early_init_this_mmu(); |
| 733 | early_mmu_set_memory_limit(); |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Paul Gortmaker | 061d19f | 2013-06-24 15:30:09 -0400 | [diff] [blame] | 736 | void early_init_mmu_secondary(void) |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 737 | { |
Scott Wood | 5d61a21 | 2014-08-08 18:44:01 -0500 | [diff] [blame] | 738 | early_init_this_mmu(); |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 741 | void setup_initial_memory_limit(phys_addr_t first_memblock_base, |
| 742 | phys_addr_t first_memblock_size) |
| 743 | { |
Kumar Gala | 1dc91c3 | 2011-09-16 10:39:59 -0500 | [diff] [blame] | 744 | /* On non-FSL Embedded 64-bit, we adjust the RMA size to match |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 745 | * the bolted TLB entry. We know for now that only 1G |
| 746 | * entries are supported though that may eventually |
Kumar Gala | 1dc91c3 | 2011-09-16 10:39:59 -0500 | [diff] [blame] | 747 | * change. |
| 748 | * |
| 749 | * on FSL Embedded 64-bit, we adjust the RMA size to match the |
| 750 | * first bolted TLB entry size. We still limit max to 1G even if |
| 751 | * the TLB could cover more. This is due to what the early init |
| 752 | * code is setup to do. |
| 753 | * |
| 754 | * We crop it to the size of the first MEMBLOCK to |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 755 | * avoid going over total available memory just in case... |
| 756 | */ |
Kumar Gala | 1dc91c3 | 2011-09-16 10:39:59 -0500 | [diff] [blame] | 757 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 758 | if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) { |
| 759 | unsigned long linear_sz; |
| 760 | linear_sz = calc_cam_sz(first_memblock_size, PAGE_OFFSET, |
| 761 | first_memblock_base); |
| 762 | ppc64_rma_size = min_t(u64, linear_sz, 0x40000000); |
| 763 | } else |
| 764 | #endif |
| 765 | ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000); |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 766 | |
| 767 | /* Finally limit subsequent allocations */ |
Kumar Gala | 4a89261 | 2010-11-10 12:29:49 +0000 | [diff] [blame] | 768 | memblock_set_current_limit(first_memblock_base + ppc64_rma_size); |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 769 | } |
Dave Kleikamp | 91b191c | 2011-07-04 18:38:03 +0000 | [diff] [blame] | 770 | #else /* ! CONFIG_PPC64 */ |
| 771 | void __init early_init_mmu(void) |
| 772 | { |
| 773 | #ifdef CONFIG_PPC_47x |
| 774 | early_init_mmu_47x(); |
| 775 | #endif |
| 776 | } |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 777 | #endif /* CONFIG_PPC64 */ |