xref: /openbmc/linux/arch/powerpc/mm/init_32.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
270d64ceaSPaul Mackerras /*
370d64ceaSPaul Mackerras  *  PowerPC version
470d64ceaSPaul Mackerras  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
570d64ceaSPaul Mackerras  *
670d64ceaSPaul Mackerras  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
770d64ceaSPaul Mackerras  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
870d64ceaSPaul Mackerras  *    Copyright (C) 1996 Paul Mackerras
970d64ceaSPaul Mackerras  *  PPC44x/36-bit changes by Matt Porter (mporter@mvista.com)
1070d64ceaSPaul Mackerras  *
1170d64ceaSPaul Mackerras  *  Derived from "arch/i386/mm/init.c"
1270d64ceaSPaul Mackerras  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
1370d64ceaSPaul Mackerras  */
1470d64ceaSPaul Mackerras 
1570d64ceaSPaul Mackerras #include <linux/module.h>
1670d64ceaSPaul Mackerras #include <linux/sched.h>
1770d64ceaSPaul Mackerras #include <linux/kernel.h>
1870d64ceaSPaul Mackerras #include <linux/errno.h>
1970d64ceaSPaul Mackerras #include <linux/string.h>
2070d64ceaSPaul Mackerras #include <linux/types.h>
2170d64ceaSPaul Mackerras #include <linux/mm.h>
2270d64ceaSPaul Mackerras #include <linux/stddef.h>
2370d64ceaSPaul Mackerras #include <linux/init.h>
2470d64ceaSPaul Mackerras #include <linux/highmem.h>
2570d64ceaSPaul Mackerras #include <linux/initrd.h>
2670d64ceaSPaul Mackerras #include <linux/pagemap.h>
2795f72d1eSYinghai Lu #include <linux/memblock.h>
285a0e3ad6STejun Heo #include <linux/gfp.h>
2941151e77SBecky Bruce #include <linux/slab.h>
3041151e77SBecky Bruce #include <linux/hugetlb.h>
3170d64ceaSPaul Mackerras 
3270d64ceaSPaul Mackerras #include <asm/io.h>
3370d64ceaSPaul Mackerras #include <asm/mmu.h>
3470d64ceaSPaul Mackerras #include <asm/smp.h>
3570d64ceaSPaul Mackerras #include <asm/machdep.h>
3670d64ceaSPaul Mackerras #include <asm/btext.h>
3770d64ceaSPaul Mackerras #include <asm/tlb.h>
3870d64ceaSPaul Mackerras #include <asm/sections.h>
3941151e77SBecky Bruce #include <asm/hugetlb.h>
4069795cabSChristophe Leroy #include <asm/kup.h>
412edb16efSChristophe Leroy #include <asm/kasan.h>
4270d64ceaSPaul Mackerras 
439d9f2cccSChristophe Leroy #include <mm/mmu_decl.h>
4470d64ceaSPaul Mackerras 
4570d64ceaSPaul Mackerras #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
469ddc5b6fSUwe Kleine-König /* The amount of lowmem must be within 0xF0000000 - KERNELBASE. */
47ccdcef72SDale Farnsworth #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - PAGE_OFFSET))
48b615f4b3SPaul Bolle #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_KERNEL_START"
4970d64ceaSPaul Mackerras #endif
5070d64ceaSPaul Mackerras #endif
5170d64ceaSPaul Mackerras #define MAX_LOW_MEM	CONFIG_LOWMEM_SIZE
5270d64ceaSPaul Mackerras 
532bf3016fSStefan Roese phys_addr_t total_memory;
542bf3016fSStefan Roese phys_addr_t total_lowmem;
5570d64ceaSPaul Mackerras 
5627d11496SKevin Hao #ifdef CONFIG_RELOCATABLE
57368ff8f1SSuzuki Poulose /* Used in __va()/__pa() */
58368ff8f1SSuzuki Poulose long long virt_phys_offset;
59368ff8f1SSuzuki Poulose EXPORT_SYMBOL(virt_phys_offset);
60368ff8f1SSuzuki Poulose #endif
61368ff8f1SSuzuki Poulose 
6299c62dd7SKumar Gala phys_addr_t lowmem_end_addr;
6370d64ceaSPaul Mackerras 
6470d64ceaSPaul Mackerras int boot_mapsize;
6570d64ceaSPaul Mackerras #ifdef CONFIG_PPC_PMAC
6670d64ceaSPaul Mackerras unsigned long agp_special_page;
675c8c56ebSPaul Mackerras EXPORT_SYMBOL(agp_special_page);
6870d64ceaSPaul Mackerras #endif
6970d64ceaSPaul Mackerras 
7070d64ceaSPaul Mackerras void MMU_init(void);
7170d64ceaSPaul Mackerras 
7270d64ceaSPaul Mackerras /* max amount of low RAM to map in */
7370d64ceaSPaul Mackerras unsigned long __max_low_memory = MAX_LOW_MEM;
7470d64ceaSPaul Mackerras 
7570d64ceaSPaul Mackerras /*
7670d64ceaSPaul Mackerras  * MMU_init sets up the basic memory mappings for the kernel,
7770d64ceaSPaul Mackerras  * including both RAM and possibly some I/O regions,
7870d64ceaSPaul Mackerras  * and sets up the page tables and the MMU hardware ready to go.
7970d64ceaSPaul Mackerras  */
MMU_init(void)8070d64ceaSPaul Mackerras void __init MMU_init(void)
8170d64ceaSPaul Mackerras {
8270d64ceaSPaul Mackerras 	if (ppc_md.progress)
8370d64ceaSPaul Mackerras 		ppc_md.progress("MMU:enter", 0x111);
8470d64ceaSPaul Mackerras 
8595f72d1eSYinghai Lu 	total_lowmem = total_memory = memblock_end_of_DRAM() - memstart_addr;
86d7917ba7SKumar Gala 	lowmem_end_addr = memstart_addr + total_lowmem;
8770d64ceaSPaul Mackerras 
88dfc3095cSChristophe Leroy #ifdef CONFIG_PPC_85xx
8970d64ceaSPaul Mackerras 	/* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
9070d64ceaSPaul Mackerras 	 * entries, so we need to adjust lowmem to match the amount we can map
9170d64ceaSPaul Mackerras 	 * in the fixed entries */
9270d64ceaSPaul Mackerras 	adjust_total_lowmem();
93dfc3095cSChristophe Leroy #endif /* CONFIG_PPC_85xx */
94fa39dc43SPaul Mackerras 
9570d64ceaSPaul Mackerras 	if (total_lowmem > __max_low_memory) {
9670d64ceaSPaul Mackerras 		total_lowmem = __max_low_memory;
97d7917ba7SKumar Gala 		lowmem_end_addr = memstart_addr + total_lowmem;
9870d64ceaSPaul Mackerras #ifndef CONFIG_HIGHMEM
9970d64ceaSPaul Mackerras 		total_memory = total_lowmem;
1006dd22700SScott Wood 		memblock_enforce_memory_limit(total_lowmem);
10170d64ceaSPaul Mackerras #endif /* CONFIG_HIGHMEM */
10270d64ceaSPaul Mackerras 	}
10370d64ceaSPaul Mackerras 
10470d64ceaSPaul Mackerras 	/* Initialize the MMU hardware */
10570d64ceaSPaul Mackerras 	if (ppc_md.progress)
10670d64ceaSPaul Mackerras 		ppc_md.progress("MMU:hw init", 0x300);
10770d64ceaSPaul Mackerras 	MMU_init_hw();
10870d64ceaSPaul Mackerras 
10970d64ceaSPaul Mackerras 	/* Map in all of RAM starting at KERNELBASE */
11070d64ceaSPaul Mackerras 	if (ppc_md.progress)
11170d64ceaSPaul Mackerras 		ppc_md.progress("MMU:mapin", 0x301);
11270d64ceaSPaul Mackerras 	mapin_ram();
11370d64ceaSPaul Mackerras 
114f637a49eSBenjamin Herrenschmidt 	/* Initialize early top-down ioremap allocator */
115f637a49eSBenjamin Herrenschmidt 	ioremap_bot = IOREMAP_TOP;
11670d64ceaSPaul Mackerras 
11770d64ceaSPaul Mackerras 	if (ppc_md.progress)
11870d64ceaSPaul Mackerras 		ppc_md.progress("MMU:exit", 0x211);
11951d3082fSBenjamin Herrenschmidt 
12051d3082fSBenjamin Herrenschmidt 	/* From now on, btext is no longer BAT mapped if it was at all */
12151d3082fSBenjamin Herrenschmidt #ifdef CONFIG_BOOTX_TEXT
12251d3082fSBenjamin Herrenschmidt 	btext_unmap();
12351d3082fSBenjamin Herrenschmidt #endif
124e63075a3SBenjamin Herrenschmidt 
125b506923eSChristophe Leroy 	kasan_mmu_init();
126b506923eSChristophe Leroy 
12769795cabSChristophe Leroy 	setup_kup();
12869795cabSChristophe Leroy 
129*26e04120SChristophe Leroy 	update_mmu_feature_fixups(MMU_FTR_KUAP);
130*26e04120SChristophe Leroy 
131e63075a3SBenjamin Herrenschmidt 	/* Shortly after that, the entire linear mapping will be available */
132e63075a3SBenjamin Herrenschmidt 	memblock_set_current_limit(lowmem_end_addr);
13370d64ceaSPaul Mackerras }
134