Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  PowerPC version
0004  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
0005  *
0006  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
0007  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
0008  *    Copyright (C) 1996 Paul Mackerras
0009  *  PPC44x/36-bit changes by Matt Porter (mporter@mvista.com)
0010  *
0011  *  Derived from "arch/i386/mm/init.c"
0012  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
0013  */
0014 
0015 #include <linux/module.h>
0016 #include <linux/sched.h>
0017 #include <linux/kernel.h>
0018 #include <linux/errno.h>
0019 #include <linux/string.h>
0020 #include <linux/types.h>
0021 #include <linux/mm.h>
0022 #include <linux/stddef.h>
0023 #include <linux/init.h>
0024 #include <linux/highmem.h>
0025 #include <linux/initrd.h>
0026 #include <linux/pagemap.h>
0027 #include <linux/memblock.h>
0028 #include <linux/gfp.h>
0029 #include <linux/slab.h>
0030 #include <linux/hugetlb.h>
0031 
0032 #include <asm/io.h>
0033 #include <asm/mmu.h>
0034 #include <asm/smp.h>
0035 #include <asm/machdep.h>
0036 #include <asm/btext.h>
0037 #include <asm/tlb.h>
0038 #include <asm/sections.h>
0039 #include <asm/hugetlb.h>
0040 #include <asm/kup.h>
0041 #include <asm/kasan.h>
0042 
0043 #include <mm/mmu_decl.h>
0044 
0045 #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
0046 /* The amount of lowmem must be within 0xF0000000 - KERNELBASE. */
0047 #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - PAGE_OFFSET))
0048 #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_KERNEL_START"
0049 #endif
0050 #endif
0051 #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
0052 
0053 phys_addr_t total_memory;
0054 phys_addr_t total_lowmem;
0055 
0056 #ifdef CONFIG_RELOCATABLE
0057 /* Used in __va()/__pa() */
0058 long long virt_phys_offset;
0059 EXPORT_SYMBOL(virt_phys_offset);
0060 #endif
0061 
0062 phys_addr_t lowmem_end_addr;
0063 
0064 int boot_mapsize;
0065 #ifdef CONFIG_PPC_PMAC
0066 unsigned long agp_special_page;
0067 EXPORT_SYMBOL(agp_special_page);
0068 #endif
0069 
0070 void MMU_init(void);
0071 
0072 /* max amount of low RAM to map in */
0073 unsigned long __max_low_memory = MAX_LOW_MEM;
0074 
0075 /*
0076  * MMU_init sets up the basic memory mappings for the kernel,
0077  * including both RAM and possibly some I/O regions,
0078  * and sets up the page tables and the MMU hardware ready to go.
0079  */
0080 void __init MMU_init(void)
0081 {
0082     if (ppc_md.progress)
0083         ppc_md.progress("MMU:enter", 0x111);
0084 
0085     /*
0086      * Reserve gigantic pages for hugetlb.  This MUST occur before
0087      * lowmem_end_addr is initialized below.
0088      */
0089     if (memblock.memory.cnt > 1) {
0090 #ifndef CONFIG_WII
0091         memblock_enforce_memory_limit(memblock.memory.regions[0].size);
0092         pr_warn("Only using first contiguous memory region\n");
0093 #else
0094         wii_memory_fixups();
0095 #endif
0096     }
0097 
0098     total_lowmem = total_memory = memblock_end_of_DRAM() - memstart_addr;
0099     lowmem_end_addr = memstart_addr + total_lowmem;
0100 
0101 #ifdef CONFIG_FSL_BOOKE
0102     /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
0103      * entries, so we need to adjust lowmem to match the amount we can map
0104      * in the fixed entries */
0105     adjust_total_lowmem();
0106 #endif /* CONFIG_FSL_BOOKE */
0107 
0108     if (total_lowmem > __max_low_memory) {
0109         total_lowmem = __max_low_memory;
0110         lowmem_end_addr = memstart_addr + total_lowmem;
0111 #ifndef CONFIG_HIGHMEM
0112         total_memory = total_lowmem;
0113         memblock_enforce_memory_limit(total_lowmem);
0114 #endif /* CONFIG_HIGHMEM */
0115     }
0116 
0117     /* Initialize the MMU hardware */
0118     if (ppc_md.progress)
0119         ppc_md.progress("MMU:hw init", 0x300);
0120     MMU_init_hw();
0121 
0122     /* Map in all of RAM starting at KERNELBASE */
0123     if (ppc_md.progress)
0124         ppc_md.progress("MMU:mapin", 0x301);
0125     mapin_ram();
0126 
0127     /* Initialize early top-down ioremap allocator */
0128     ioremap_bot = IOREMAP_TOP;
0129 
0130     if (ppc_md.progress)
0131         ppc_md.progress("MMU:exit", 0x211);
0132 
0133     /* From now on, btext is no longer BAT mapped if it was at all */
0134 #ifdef CONFIG_BOOTX_TEXT
0135     btext_unmap();
0136 #endif
0137 
0138     kasan_mmu_init();
0139 
0140     setup_kup();
0141 
0142     /* Shortly after that, the entire linear mapping will be available */
0143     memblock_set_current_limit(lowmem_end_addr);
0144 }