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