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