blob: 56934991647193a010d7ce4b480a3f317d5c1d0e [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
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000105/*
106 * Base TLB flushing operations:
107 *
108 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
109 * - flush_tlb_page(vma, vmaddr) flushes one page
110 * - flush_tlb_range(vma, start, end) flushes a range of pages
111 * - flush_tlb_kernel_range(start, end) flushes kernel pages
112 *
113 * - local_* variants of page and mm only apply to the current
114 * processor
115 */
116
117/*
118 * These are the base non-SMP variants of page and mm flushing
119 */
120void local_flush_tlb_mm(struct mm_struct *mm)
121{
122 unsigned int pid;
123
124 preempt_disable();
125 pid = mm->context.id;
126 if (pid != MMU_NO_CONTEXT)
127 _tlbil_pid(pid);
128 preempt_enable();
129}
130EXPORT_SYMBOL(local_flush_tlb_mm);
131
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000132void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
133 int tsize, int ind)
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000134{
135 unsigned int pid;
136
137 preempt_disable();
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000138 pid = mm ? mm->context.id : 0;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000139 if (pid != MMU_NO_CONTEXT)
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000140 _tlbil_va(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000141 preempt_enable();
142}
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000143
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000144void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
145{
146 __local_flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000147 mmu_get_tsize(mmu_virtual_psize), 0);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000148}
149EXPORT_SYMBOL(local_flush_tlb_page);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000150
151/*
152 * And here are the SMP non-local implementations
153 */
154#ifdef CONFIG_SMP
155
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000156static DEFINE_RAW_SPINLOCK(tlbivax_lock);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000157
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000158static int mm_is_core_local(struct mm_struct *mm)
159{
160 return cpumask_subset(mm_cpumask(mm),
161 topology_thread_cpumask(smp_processor_id()));
162}
163
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000164struct tlb_flush_param {
165 unsigned long addr;
166 unsigned int pid;
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000167 unsigned int tsize;
168 unsigned int ind;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000169};
170
171static void do_flush_tlb_mm_ipi(void *param)
172{
173 struct tlb_flush_param *p = param;
174
175 _tlbil_pid(p ? p->pid : 0);
176}
177
178static void do_flush_tlb_page_ipi(void *param)
179{
180 struct tlb_flush_param *p = param;
181
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000182 _tlbil_va(p->addr, p->pid, p->tsize, p->ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000183}
184
185
186/* Note on invalidations and PID:
187 *
188 * We snapshot the PID with preempt disabled. At this point, it can still
189 * change either because:
190 * - our context is being stolen (PID -> NO_CONTEXT) on another CPU
191 * - we are invaliating some target that isn't currently running here
192 * and is concurrently acquiring a new PID on another CPU
193 * - some other CPU is re-acquiring a lost PID for this mm
194 * etc...
195 *
196 * However, this shouldn't be a problem as we only guarantee
197 * invalidation of TLB entries present prior to this call, so we
198 * don't care about the PID changing, and invalidating a stale PID
199 * is generally harmless.
200 */
201
202void flush_tlb_mm(struct mm_struct *mm)
203{
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000204 unsigned int pid;
205
206 preempt_disable();
207 pid = mm->context.id;
208 if (unlikely(pid == MMU_NO_CONTEXT))
209 goto no_context;
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000210 if (!mm_is_core_local(mm)) {
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000211 struct tlb_flush_param p = { .pid = pid };
Rusty Russell56aa4122009-03-15 18:16:43 +0000212 /* Ignores smp_processor_id() even if set. */
213 smp_call_function_many(mm_cpumask(mm),
214 do_flush_tlb_mm_ipi, &p, 1);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000215 }
216 _tlbil_pid(pid);
217 no_context:
218 preempt_enable();
219}
220EXPORT_SYMBOL(flush_tlb_mm);
221
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000222void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
223 int tsize, int ind)
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000224{
Rusty Russell56aa4122009-03-15 18:16:43 +0000225 struct cpumask *cpu_mask;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000226 unsigned int pid;
227
228 preempt_disable();
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000229 pid = mm ? mm->context.id : 0;
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000230 if (unlikely(pid == MMU_NO_CONTEXT))
231 goto bail;
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000232 cpu_mask = mm_cpumask(mm);
Benjamin Herrenschmidtfcce8102009-07-23 23:15:10 +0000233 if (!mm_is_core_local(mm)) {
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000234 /* If broadcast tlbivax is supported, use it */
235 if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
236 int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
237 if (lock)
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000238 raw_spin_lock(&tlbivax_lock);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000239 _tlbivax_bcast(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000240 if (lock)
Thomas Gleixner3eb93c52010-02-18 02:22:44 +0000241 raw_spin_unlock(&tlbivax_lock);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000242 goto bail;
243 } else {
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000244 struct tlb_flush_param p = {
245 .pid = pid,
246 .addr = vmaddr,
247 .tsize = tsize,
248 .ind = ind,
249 };
Rusty Russell56aa4122009-03-15 18:16:43 +0000250 /* Ignores smp_processor_id() even if set in cpu_mask */
251 smp_call_function_many(cpu_mask,
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000252 do_flush_tlb_page_ipi, &p, 1);
253 }
254 }
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000255 _tlbil_va(vmaddr, pid, tsize, ind);
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000256 bail:
257 preempt_enable();
258}
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000259
260void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
261{
262 __flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr,
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000263 mmu_get_tsize(mmu_virtual_psize), 0);
Benjamin Herrenschmidtd4e167d2009-07-23 23:15:24 +0000264}
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000265EXPORT_SYMBOL(flush_tlb_page);
266
267#endif /* CONFIG_SMP */
268
269/*
270 * Flush kernel TLB entries in the given range
271 */
272void flush_tlb_kernel_range(unsigned long start, unsigned long end)
273{
274#ifdef CONFIG_SMP
275 preempt_disable();
276 smp_call_function(do_flush_tlb_mm_ipi, NULL, 1);
277 _tlbil_pid(0);
278 preempt_enable();
Dave Liud6a09e02008-12-30 23:42:55 +0000279#else
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000280 _tlbil_pid(0);
Dave Liud6a09e02008-12-30 23:42:55 +0000281#endif
Benjamin Herrenschmidtf048aac2008-12-18 19:13:38 +0000282}
283EXPORT_SYMBOL(flush_tlb_kernel_range);
284
285/*
286 * Currently, for range flushing, we just do a full mm flush. This should
287 * be optimized based on a threshold on the size of the range, since
288 * some implementation can stack multiple tlbivax before a tlbsync but
289 * for now, we keep it that way
290 */
291void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
292 unsigned long end)
293
294{
295 flush_tlb_mm(vma->vm_mm);
296}
297EXPORT_SYMBOL(flush_tlb_range);
Benjamin Herrenschmidtc7cc58a12009-07-23 23:15:28 +0000298
299void tlb_flush(struct mmu_gather *tlb)
300{
301 flush_tlb_mm(tlb->mm);
Benjamin Herrenschmidtc7cc58a12009-07-23 23:15:28 +0000302}
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000303
304/*
305 * Below are functions specific to the 64-bit variant of Book3E though that
306 * may change in the future
307 */
308
309#ifdef CONFIG_PPC64
310
311/*
312 * Handling of virtual linear page tables or indirect TLB entries
313 * flushing when PTE pages are freed
314 */
315void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
316{
317 int tsize = mmu_psize_defs[mmu_pte_psize].enc;
318
319 if (book3e_htw_enabled) {
320 unsigned long start = address & PMD_MASK;
321 unsigned long end = address + PMD_SIZE;
322 unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift;
323
324 /* This isn't the most optimal, ideally we would factor out the
325 * while preempt & CPU mask mucking around, or even the IPI but
326 * it will do for now
327 */
328 while (start < end) {
329 __flush_tlb_page(tlb->mm, start, tsize, 1);
330 start += size;
331 }
332 } else {
333 unsigned long rmask = 0xf000000000000000ul;
334 unsigned long rid = (address & rmask) | 0x1000000000000000ul;
335 unsigned long vpte = address & ~rmask;
336
337#ifdef CONFIG_PPC_64K_PAGES
338 vpte = (vpte >> (PAGE_SHIFT - 4)) & ~0xfffful;
339#else
340 vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful;
341#endif
342 vpte |= rid;
343 __flush_tlb_page(tlb->mm, vpte, tsize, 0);
344 }
345}
346
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000347static void setup_page_sizes(void)
348{
Kumar Gala988cf862010-10-08 02:13:25 -0500349 unsigned int tlb0cfg;
350 unsigned int tlb0ps;
351 unsigned int eptcfg;
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000352 int i, psize;
353
Kumar Gala988cf862010-10-08 02:13:25 -0500354#ifdef CONFIG_PPC_FSL_BOOK3E
355 unsigned int mmucfg = mfspr(SPRN_MMUCFG);
356
357 if (((mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) &&
358 (mmu_has_feature(MMU_FTR_TYPE_FSL_E))) {
359 unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG);
360 unsigned int min_pg, max_pg;
361
362 min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT;
363 max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT;
364
365 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
366 struct mmu_psize_def *def;
367 unsigned int shift;
368
369 def = &mmu_psize_defs[psize];
370 shift = def->shift;
371
372 if (shift == 0)
373 continue;
374
375 /* adjust to be in terms of 4^shift Kb */
376 shift = (shift - 10) >> 1;
377
378 if ((shift >= min_pg) && (shift <= max_pg))
379 def->flags |= MMU_PAGE_SIZE_DIRECT;
380 }
381
382 goto no_indirect;
383 }
384#endif
385
386 tlb0cfg = mfspr(SPRN_TLB0CFG);
387 tlb0ps = mfspr(SPRN_TLB0PS);
388 eptcfg = mfspr(SPRN_EPTCFG);
389
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000390 /* Look for supported direct sizes */
391 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
392 struct mmu_psize_def *def = &mmu_psize_defs[psize];
393
394 if (tlb0ps & (1U << (def->shift - 10)))
395 def->flags |= MMU_PAGE_SIZE_DIRECT;
396 }
397
398 /* Indirect page sizes supported ? */
399 if ((tlb0cfg & TLBnCFG_IND) == 0)
400 goto no_indirect;
401
402 /* Now, we only deal with one IND page size for each
403 * direct size. Hopefully all implementations today are
404 * unambiguous, but we might want to be careful in the
405 * future.
406 */
407 for (i = 0; i < 3; i++) {
408 unsigned int ps, sps;
409
410 sps = eptcfg & 0x1f;
411 eptcfg >>= 5;
412 ps = eptcfg & 0x1f;
413 eptcfg >>= 5;
414 if (!ps || !sps)
415 continue;
416 for (psize = 0; psize < MMU_PAGE_COUNT; psize++) {
417 struct mmu_psize_def *def = &mmu_psize_defs[psize];
418
419 if (ps == (def->shift - 10))
420 def->flags |= MMU_PAGE_SIZE_INDIRECT;
421 if (sps == (def->shift - 10))
422 def->ind = ps + 10;
423 }
424 }
425 no_indirect:
426
427 /* Cleanup array and print summary */
428 pr_info("MMU: Supported page sizes\n");
429 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
430 struct mmu_psize_def *def = &mmu_psize_defs[psize];
431 const char *__page_type_names[] = {
432 "unsupported",
433 "direct",
434 "indirect",
435 "direct & indirect"
436 };
437 if (def->flags == 0) {
438 def->shift = 0;
439 continue;
440 }
441 pr_info(" %8ld KB as %s\n", 1ul << (def->shift - 10),
442 __page_type_names[def->flags & 0x3]);
443 }
444}
445
446static void setup_mmu_htw(void)
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000447{
448 extern unsigned int interrupt_base_book3e;
449 extern unsigned int exc_data_tlb_miss_htw_book3e;
450 extern unsigned int exc_instruction_tlb_miss_htw_book3e;
451
452 unsigned int *ibase = &interrupt_base_book3e;
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000453
454 /* Check if HW tablewalk is present, and if yes, enable it by:
455 *
456 * - patching the TLB miss handlers to branch to the
457 * one dedicates to it
458 *
459 * - setting the global book3e_htw_enabled
460 */
461 unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG);
462
463 if ((tlb0cfg & TLBnCFG_IND) &&
464 (tlb0cfg & TLBnCFG_PT)) {
465 /* Our exceptions vectors start with a NOP and -then- a branch
466 * to deal with single stepping from userspace which stops on
467 * the second instruction. Thus we need to patch the second
468 * instruction of the exception, not the first one
469 */
470 patch_branch(ibase + (0x1c0 / 4) + 1,
471 (unsigned long)&exc_data_tlb_miss_htw_book3e, 0);
472 patch_branch(ibase + (0x1e0 / 4) + 1,
473 (unsigned long)&exc_instruction_tlb_miss_htw_book3e, 0);
474 book3e_htw_enabled = 1;
475 }
Kumar Gala32d206e2011-05-19 20:09:28 +0000476 pr_info("MMU: Book3E HW tablewalk %s\n",
477 book3e_htw_enabled ? "enabled" : "not supported");
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000478}
479
480/*
481 * Early initialization of the MMU TLB code
482 */
483static void __early_init_mmu(int boot_cpu)
484{
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000485 unsigned int mas4;
486
487 /* XXX This will have to be decided at runtime, but right
Benjamin Herrenschmidt32a74942009-07-23 23:15:58 +0000488 * now our boot and TLB miss code hard wires it. Ideally
489 * we should find out a suitable page size and patch the
490 * TLB miss code (either that or use the PACA to store
491 * the value we want)
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000492 */
493 mmu_linear_psize = MMU_PAGE_1G;
494
Benjamin Herrenschmidt32a74942009-07-23 23:15:58 +0000495 /* XXX This should be decided at runtime based on supported
496 * page sizes in the TLB, but for now let's assume 16M is
497 * always there and a good fit (which it probably is)
498 */
499 mmu_vmemmap_psize = MMU_PAGE_16M;
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000500
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000501 /* XXX This code only checks for TLB 0 capabilities and doesn't
502 * check what page size combos are supported by the HW. It
503 * also doesn't handle the case where a separate array holds
504 * the IND entries from the array loaded by the PT.
505 */
506 if (boot_cpu) {
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000507 /* Look for supported page sizes */
508 setup_page_sizes();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000509
Benjamin Herrenschmidtf2b26c92010-07-09 14:57:43 +1000510 /* Look for HW tablewalk support */
511 setup_mmu_htw();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000512 }
513
514 /* Set MAS4 based on page table setting */
515
516 mas4 = 0x4 << MAS4_WIMGED_SHIFT;
517 if (book3e_htw_enabled) {
518 mas4 |= mas4 | MAS4_INDD;
519#ifdef CONFIG_PPC_64K_PAGES
520 mas4 |= BOOK3E_PAGESZ_256M << MAS4_TSIZED_SHIFT;
521 mmu_pte_psize = MMU_PAGE_256M;
522#else
523 mas4 |= BOOK3E_PAGESZ_1M << MAS4_TSIZED_SHIFT;
524 mmu_pte_psize = MMU_PAGE_1M;
525#endif
526 } else {
527#ifdef CONFIG_PPC_64K_PAGES
528 mas4 |= BOOK3E_PAGESZ_64K << MAS4_TSIZED_SHIFT;
529#else
530 mas4 |= BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT;
531#endif
532 mmu_pte_psize = mmu_virtual_psize;
533 }
534 mtspr(SPRN_MAS4, mas4);
535
536 /* Set the global containing the top of the linear mapping
537 * for use by the TLB miss code
538 */
Yinghai Lu95f72d12010-07-12 14:36:09 +1000539 linear_map_top = memblock_end_of_DRAM();
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000540
Kumar Gala55fd7662009-10-16 18:48:40 -0500541#ifdef CONFIG_PPC_FSL_BOOK3E
542 if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
543 unsigned int num_cams;
544
545 /* use a quarter of the TLBCAM for bolted linear map */
546 num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
547 linear_map_top = map_mem_in_cams(linear_map_top, num_cams);
548
549 /* limit memory so we dont have linear faults */
550 memblock_enforce_memory_limit(linear_map_top);
551 memblock_analyze();
552 }
553#endif
554
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000555 /* A sync won't hurt us after mucking around with
556 * the MMU configuration
557 */
558 mb();
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700559
560 memblock_set_current_limit(linear_map_top);
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000561}
562
563void __init early_init_mmu(void)
564{
565 __early_init_mmu(1);
566}
567
568void __cpuinit early_init_mmu_secondary(void)
569{
570 __early_init_mmu(0);
571}
572
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700573void setup_initial_memory_limit(phys_addr_t first_memblock_base,
574 phys_addr_t first_memblock_size)
575{
576 /* On Embedded 64-bit, we adjust the RMA size to match
577 * the bolted TLB entry. We know for now that only 1G
578 * entries are supported though that may eventually
579 * change. We crop it to the size of the first MEMBLOCK to
580 * avoid going over total available memory just in case...
581 */
582 ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
583
584 /* Finally limit subsequent allocations */
Kumar Gala4a892612010-11-10 12:29:49 +0000585 memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700586}
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000587#endif /* CONFIG_PPC64 */