blob: e80ed1093e2fb20ccdb22ced64c02460e08597e3 [file] [log] [blame]
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +00001/*
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 Herrenschmidt25d21ad2009-07-23 23:15:47 +000010 * Copyright 2008,2009 Ben Herrenschmidt <benh@kernel.crashing.org>
11 * IBM Corp.
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000012 *
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>
31#include <linux/mm.h>
32#include <linux/init.h>
33#include <linux/highmem.h>
34#include <linux/pagemap.h>
35#include <linux/preempt.h>
36#include <linux/spinlock.h>
Yinghai Lu95f72d12010-07-12 14:36:09 +100037#include <linux/memblock.h>
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000038
39#include <asm/tlbflush.h>
40#include <asm/tlb.h>
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000041#include <asm/code-patching.h>
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +000042
43#include "mmu_decl.h"
44
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000045#ifdef CONFIG_PPC_BOOK3E
46struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
47 [MMU_PAGE_4K] = {
48 .shift = 12,
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +100049 .ind = 20,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000050 .enc = BOOK3E_PAGESZ_4K,
51 },
52 [MMU_PAGE_16K] = {
53 .shift = 14,
54 .enc = BOOK3E_PAGESZ_16K,
55 },
56 [MMU_PAGE_64K] = {
57 .shift = 16,
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +100058 .ind = 28,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000059 .enc = BOOK3E_PAGESZ_64K,
60 },
61 [MMU_PAGE_1M] = {
62 .shift = 20,
63 .enc = BOOK3E_PAGESZ_1M,
64 },
65 [MMU_PAGE_16M] = {
66 .shift = 24,
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +100067 .ind = 36,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000068 .enc = BOOK3E_PAGESZ_16M,
69 },
70 [MMU_PAGE_256M] = {
71 .shift = 28,
72 .enc = BOOK3E_PAGESZ_256M,
73 },
74 [MMU_PAGE_1G] = {
75 .shift = 30,
76 .enc = BOOK3E_PAGESZ_1GB,
77 },
78};
79static inline int mmu_get_tsize(int psize)
80{
81 return mmu_psize_defs[psize].enc;
82}
83#else
84static inline int mmu_get_tsize(int psize)
85{
86 /* This isn't used on !Book3E for now */
87 return 0;
88}
89#endif
90
91/* The variables below are currently only used on 64-bit Book3E
92 * though this will probably be made common with other nohash
93 * implementations at some point
94 */
95#ifdef CONFIG_PPC64
96
97int mmu_linear_psize; /* Page size used for the linear mapping */
98int mmu_pte_psize; /* Page size used for PTE pages */
Benjamin Herrenschmidt32a74942009-07-23 23:15:58 +000099int mmu_vmemmap_psize; /* Page size used for the virtual mem map */
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000100int book3e_htw_enabled; /* Is HW tablewalk enabled ? */
101unsigned long linear_map_top; /* Top of linear mapping */
102
103#endif /* CONFIG_PPC64 */
104
Becky Bruce3160b092011-06-28 14:54:47 -0500105#ifdef CONFIG_PPC_FSL_BOOK3E
106/* next_tlbcam_idx is used to round-robin tlbcam entry assignment */
107DEFINE_PER_CPU(int, next_tlbcam_idx);
108EXPORT_PER_CPU_SYMBOL(next_tlbcam_idx);
109#endif
110
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000111/*
112 * Base TLB flushing operations:
113 *
114 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
115 * - flush_tlb_page(vma, vmaddr) flushes one page
116 * - flush_tlb_range(vma, start, end) flushes a range of pages
117 * - flush_tlb_kernel_range(start, end) flushes kernel pages
118 *
119 * - local_* variants of page and mm only apply to the current
120 * processor
121 */
122
123/*
124 * These are the base non-SMP variants of page and mm flushing
125 */
126void local_flush_tlb_mm(struct mm_struct *mm)
127{
128 unsigned int pid;
129
130 preempt_disable();
131 pid = mm->context.id;
132 if (pid != MMU_NO_CONTEXT)
133 _tlbil_pid(pid);
134 preempt_enable();
135}
136EXPORT_SYMBOL(local_flush_tlb_mm);
137
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000138void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
139 int tsize, int ind)
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000140{
141 unsigned int pid;
142
143 preempt_disable();
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000144 pid = mm ? mm->context.id : 0;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000145 if (pid != MMU_NO_CONTEXT)
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000146 _tlbil_va(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000147 preempt_enable();
148}
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000149
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000150void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
151{
152 __local_flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000153 mmu_get_tsize(mmu_virtual_psize), 0);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000154}
155EXPORT_SYMBOL(local_flush_tlb_page);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000156
157/*
158 * And here are the SMP non-local implementations
159 */
160#ifdef CONFIG_SMP
161
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000162static DEFINE_RAW_SPINLOCK(tlbivax_lock);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000163
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000164static int mm_is_core_local(struct mm_struct *mm)
165{
166 return cpumask_subset(mm_cpumask(mm),
167 topology_thread_cpumask(smp_processor_id()));
168}
169
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000170struct tlb_flush_param {
171 unsigned long addr;
172 unsigned int pid;
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000173 unsigned int tsize;
174 unsigned int ind;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000175};
176
177static void do_flush_tlb_mm_ipi(void *param)
178{
179 struct tlb_flush_param *p = param;
180
181 _tlbil_pid(p ? p->pid : 0);
182}
183
184static void do_flush_tlb_page_ipi(void *param)
185{
186 struct tlb_flush_param *p = param;
187
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000188 _tlbil_va(p->addr, p->pid, p->tsize, p->ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000189}
190
191
192/* Note on invalidations and PID:
193 *
194 * We snapshot the PID with preempt disabled. At this point, it can still
195 * change either because:
196 * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
197 * - we are invaliating some target that isn't currently running here
198 * and is concurrently acquiring a new PID on another CPU
199 * - some other CPU is re-acquiring a lost PID for this mm
200 * etc...
201 *
202 * However, this shouldn't be a problem as we only guarantee
203 * invalidation of TLB entries present prior to this call, so we
204 * don't care about the PID changing, and invalidating a stale PID
205 * is generally harmless.
206 */
207
208void flush_tlb_mm(struct mm_struct *mm)
209{
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000210 unsigned int pid;
211
212 preempt_disable();
213 pid = mm->context.id;
214 if (unlikely(pid == MMU_NO_CONTEXT))
215 goto no_context;
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000216 if (!mm_is_core_local(mm)) {
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000217 struct tlb_flush_param p = { .pid = pid };
Rusty Russell56aa4122009-03-15 18:16:43 +0000218 /* Ignores smp_processor_id() even if set. */
219 smp_call_function_many(mm_cpumask(mm),
220 do_flush_tlb_mm_ipi, &p, 1);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000221 }
222 _tlbil_pid(pid);
223 no_context:
224 preempt_enable();
225}
226EXPORT_SYMBOL(flush_tlb_mm);
227
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000228void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
229 int tsize, int ind)
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000230{
Rusty Russell56aa4122009-03-15 18:16:43 +0000231 struct cpumask *cpu_mask;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000232 unsigned int pid;
233
234 preempt_disable();
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000235 pid = mm ? mm->context.id : 0;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000236 if (unlikely(pid == MMU_NO_CONTEXT))
237 goto bail;
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000238 cpu_mask = mm_cpumask(mm);
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000239 if (!mm_is_core_local(mm)) {
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000240 /* If broadcast tlbivax is supported, use it */
241 if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
242 int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
243 if (lock)
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000244 raw_spin_lock(&tlbivax_lock);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000245 _tlbivax_bcast(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000246 if (lock)
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000247 raw_spin_unlock(&tlbivax_lock);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000248 goto bail;
249 } else {
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000250 struct tlb_flush_param p = {
251 .pid = pid,
252 .addr = vmaddr,
253 .tsize = tsize,
254 .ind = ind,
255 };
Rusty Russell56aa4122009-03-15 18:16:43 +0000256 /* Ignores smp_processor_id() even if set in cpu_mask */
257 smp_call_function_many(cpu_mask,
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000258 do_flush_tlb_page_ipi, &p, 1);
259 }
260 }
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000261 _tlbil_va(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000262 bail:
263 preempt_enable();
264}
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000265
266void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
267{
268 __flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000269 mmu_get_tsize(mmu_virtual_psize), 0);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000270}
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000271EXPORT_SYMBOL(flush_tlb_page);
272
273#endif /* CONFIG_SMP */
274
275/*
276 * Flush kernel TLB entries in the given range
277 */
278void flush_tlb_kernel_range(unsigned long start, unsigned long end)
279{
280#ifdef CONFIG_SMP
281 preempt_disable();
282 smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
283 _tlbil_pid(0);
284 preempt_enable();
Dave Liud6a09e02008-12-30 23:42:55 +0000285#else
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000286 _tlbil_pid(0);
Dave Liud6a09e02008-12-30 23:42:55 +0000287#endif
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000288}
289EXPORT_SYMBOL(flush_tlb_kernel_range);
290
291/*
292 * Currently, for range flushing, we just do a full mm flush. This should
293 * be optimized based on a threshold on the size of the range, since
294 * some implementation can stack multiple tlbivax before a tlbsync but
295 * for now, we keep it that way
296 */
297void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
298 unsigned long end)
299
300{
301 flush_tlb_mm(vma->vm_mm);
302}
303EXPORT_SYMBOL(flush_tlb_range);
Benjamin Herrenschmidtc7cc58a2009-07-23 23:15:28 +0000304
305void tlb_flush(struct mmu_gather *tlb)
306{
307 flush_tlb_mm(tlb->mm);
Benjamin Herrenschmidtc7cc58a2009-07-23 23:15:28 +0000308}
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000309
310/*
311 * Below are functions specific to the 64-bit variant of Book3E though that
312 * may change in the future
313 */
314
315#ifdef CONFIG_PPC64
316
317/*
318 * Handling of virtual linear page tables or indirect TLB entries
319 * flushing when PTE pages are freed
320 */
321void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
322{
323 int tsize = mmu_psize_defs[mmu_pte_psize].enc;
324
325 if (book3e_htw_enabled) {
326 unsigned long start = address & PMD_MASK;
327 unsigned long end = address + PMD_SIZE;
328 unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift;
329
330 /* This isn't the most optimal, ideally we would factor out the
331 * while preempt & CPU mask mucking around, or even the IPI but
332 * it will do for now
333 */
334 while (start < end) {
335 __flush_tlb_page(tlb->mm, start, tsize, 1);
336 start += size;
337 }
338 } else {
339 unsigned long rmask = 0xf000000000000000ul;
340 unsigned long rid = (address & rmask) | 0x1000000000000000ul;
341 unsigned long vpte = address & ~rmask;
342
343#ifdef CONFIG_PPC_64K_PAGES
344 vpte = (vpte >> (PAGE_SHIFT - 4)) & ~0xfffful;
345#else
346 vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful;
347#endif
348 vpte |= rid;
349 __flush_tlb_page(tlb->mm, vpte, tsize, 0);
350 }
351}
352
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000353static void setup_page_sizes(void)
354{
Kumar Gala988cf862010-10-08 02:13:25 -0500355 unsigned int tlb0cfg;
356 unsigned int tlb0ps;
357 unsigned int eptcfg;
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000358 int i, psize;
359
Kumar Gala988cf862010-10-08 02:13:25 -0500360#ifdef CONFIG_PPC_FSL_BOOK3E
361 unsigned int mmucfg = mfspr(SPRN_MMUCFG);
362
363 if (((mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) &&
364 (mmu_has_feature(MMU_FTR_TYPE_FSL_E))) {
365 unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG);
366 unsigned int min_pg, max_pg;
367
368 min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT;
369 max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT;
370
371 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
372 struct mmu_psize_def *def;
373 unsigned int shift;
374
375 def = &mmu_psize_defs[psize];
376 shift = def->shift;
377
378 if (shift == 0)
379 continue;
380
381 /* adjust to be in terms of 4^shift Kb */
382 shift = (shift - 10) >> 1;
383
384 if ((shift >= min_pg) && (shift <= max_pg))
385 def->flags |= MMU_PAGE_SIZE_DIRECT;
386 }
387
388 goto no_indirect;
389 }
390#endif
391
392 tlb0cfg = mfspr(SPRN_TLB0CFG);
393 tlb0ps = mfspr(SPRN_TLB0PS);
394 eptcfg = mfspr(SPRN_EPTCFG);
395
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000396 /* Look for supported direct sizes */
397 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
398 struct mmu_psize_def *def = &mmu_psize_defs[psize];
399
400 if (tlb0ps & (1U << (def->shift - 10)))
401 def->flags |= MMU_PAGE_SIZE_DIRECT;
402 }
403
404 /* Indirect page sizes supported ? */
405 if ((tlb0cfg & TLBnCFG_IND) == 0)
406 goto no_indirect;
407
408 /* Now, we only deal with one IND page size for each
409 * direct size. Hopefully all implementations today are
410 * unambiguous, but we might want to be careful in the
411 * future.
412 */
413 for (i = 0; i < 3; i++) {
414 unsigned int ps, sps;
415
416 sps = eptcfg & 0x1f;
417 eptcfg >>= 5;
418 ps = eptcfg & 0x1f;
419 eptcfg >>= 5;
420 if (!ps || !sps)
421 continue;
422 for (psize = 0; psize < MMU_PAGE_COUNT; psize++) {
423 struct mmu_psize_def *def = &mmu_psize_defs[psize];
424
425 if (ps == (def->shift - 10))
426 def->flags |= MMU_PAGE_SIZE_INDIRECT;
427 if (sps == (def->shift - 10))
428 def->ind = ps + 10;
429 }
430 }
431 no_indirect:
432
433 /* Cleanup array and print summary */
434 pr_info("MMU: Supported page sizes\n");
435 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
436 struct mmu_psize_def *def = &mmu_psize_defs[psize];
437 const char *__page_type_names[] = {
438 "unsupported",
439 "direct",
440 "indirect",
441 "direct & indirect"
442 };
443 if (def->flags == 0) {
444 def->shift = 0;
445 continue;
446 }
447 pr_info(" %8ld KB as %s\n", 1ul << (def->shift - 10),
448 __page_type_names[def->flags & 0x3]);
449 }
450}
451
Scott Woodf67f4ef2011-06-22 11:25:42 +0000452static void __patch_exception(int exc, unsigned long addr)
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000453{
454 extern unsigned int interrupt_base_book3e;
Scott Woodf67f4ef2011-06-22 11:25:42 +0000455 unsigned int *ibase = &interrupt_base_book3e;
456
457 /* Our exceptions vectors start with a NOP and -then- a branch
458 * to deal with single stepping from userspace which stops on
459 * the second instruction. Thus we need to patch the second
460 * instruction of the exception, not the first one
461 */
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000462
Scott Woodf67f4ef2011-06-22 11:25:42 +0000463 patch_branch(ibase + (exc / 4) + 1, addr, 0);
464}
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000465
Scott Woodf67f4ef2011-06-22 11:25:42 +0000466#define patch_exception(exc, name) do { \
467 extern unsigned int name; \
468 __patch_exception((exc), (unsigned long)&name); \
469} while (0)
470
471static void setup_mmu_htw(void)
472{
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000473 /* Check if HW tablewalk is present, and if yes, enable it by:
474 *
475 * - patching the TLB miss handlers to branch to the
476 * one dedicates to it
477 *
478 * - setting the global book3e_htw_enabled
479 */
480 unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG);
481
482 if ((tlb0cfg & TLBnCFG_IND) &&
483 (tlb0cfg & TLBnCFG_PT)) {
Scott Woodf67f4ef2011-06-22 11:25:42 +0000484 patch_exception(0x1c0, exc_data_tlb_miss_htw_book3e);
485 patch_exception(0x1e0, exc_instruction_tlb_miss_htw_book3e);
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000486 book3e_htw_enabled = 1;
487 }
Kumar Gala32d206e2011-05-19 20:09:28 +0000488 pr_info("MMU: Book3E HW tablewalk %s\n",
489 book3e_htw_enabled ? "enabled" : "not supported");
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000490}
491
492/*
493 * Early initialization of the MMU TLB code
494 */
495static void __early_init_mmu(int boot_cpu)
496{
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000497 unsigned int mas4;
498
499 /* XXX This will have to be decided at runtime, but right
Benjamin Herrenschmidt32a74942009-07-23 23:15:58 +0000500 * now our boot and TLB miss code hard wires it. Ideally
501 * we should find out a suitable page size and patch the
502 * TLB miss code (either that or use the PACA to store
503 * the value we want)
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000504 */
505 mmu_linear_psize = MMU_PAGE_1G;
506
Benjamin Herrenschmidt32a74942009-07-23 23:15:58 +0000507 /* XXX This should be decided at runtime based on supported
508 * page sizes in the TLB, but for now let's assume 16M is
509 * always there and a good fit (which it probably is)
510 */
511 mmu_vmemmap_psize = MMU_PAGE_16M;
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000512
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000513 /* XXX This code only checks for TLB 0 capabilities and doesn't
514 * check what page size combos are supported by the HW. It
515 * also doesn't handle the case where a separate array holds
516 * the IND entries from the array loaded by the PT.
517 */
518 if (boot_cpu) {
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000519 /* Look for supported page sizes */
520 setup_page_sizes();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000521
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000522 /* Look for HW tablewalk support */
523 setup_mmu_htw();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000524 }
525
526 /* Set MAS4 based on page table setting */
527
528 mas4 = 0x4 << MAS4_WIMGED_SHIFT;
529 if (book3e_htw_enabled) {
530 mas4 |= mas4 | MAS4_INDD;
531#ifdef CONFIG_PPC_64K_PAGES
532 mas4 |= BOOK3E_PAGESZ_256M << MAS4_TSIZED_SHIFT;
533 mmu_pte_psize = MMU_PAGE_256M;
534#else
535 mas4 |= BOOK3E_PAGESZ_1M << MAS4_TSIZED_SHIFT;
536 mmu_pte_psize = MMU_PAGE_1M;
537#endif
538 } else {
539#ifdef CONFIG_PPC_64K_PAGES
540 mas4 |= BOOK3E_PAGESZ_64K << MAS4_TSIZED_SHIFT;
541#else
542 mas4 |= BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT;
543#endif
544 mmu_pte_psize = mmu_virtual_psize;
545 }
546 mtspr(SPRN_MAS4, mas4);
547
548 /* Set the global containing the top of the linear mapping
549 * for use by the TLB miss code
550 */
Yinghai Lu95f72d12010-07-12 14:36:09 +1000551 linear_map_top = memblock_end_of_DRAM();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000552
Kumar Gala55fd7662009-10-16 18:48:40 -0500553#ifdef CONFIG_PPC_FSL_BOOK3E
554 if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
555 unsigned int num_cams;
556
557 /* use a quarter of the TLBCAM for bolted linear map */
558 num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
559 linear_map_top = map_mem_in_cams(linear_map_top, num_cams);
560
561 /* limit memory so we dont have linear faults */
562 memblock_enforce_memory_limit(linear_map_top);
563 memblock_analyze();
Scott Woodf67f4ef2011-06-22 11:25:42 +0000564
565 patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e);
566 patch_exception(0x1e0, exc_instruction_tlb_miss_bolted_book3e);
Kumar Gala55fd7662009-10-16 18:48:40 -0500567 }
568#endif
569
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000570 /* A sync won't hurt us after mucking around with
571 * the MMU configuration
572 */
573 mb();
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700574
575 memblock_set_current_limit(linear_map_top);
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000576}
577
578void __init early_init_mmu(void)
579{
580 __early_init_mmu(1);
581}
582
583void __cpuinit early_init_mmu_secondary(void)
584{
585 __early_init_mmu(0);
586}
587
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700588void setup_initial_memory_limit(phys_addr_t first_memblock_base,
589 phys_addr_t first_memblock_size)
590{
591 /* On Embedded 64-bit, we adjust the RMA size to match
592 * the bolted TLB entry. We know for now that only 1G
593 * entries are supported though that may eventually
594 * change. We crop it to the size of the first MEMBLOCK to
595 * avoid going over total available memory just in case...
596 */
597 ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
598
599 /* Finally limit subsequent allocations */
Kumar Gala4a892612010-11-10 12:29:49 +0000600 memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700601}
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000602#endif /* CONFIG_PPC64 */