init_32.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PowerPC version
  4. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  5. *
  6. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  7. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  8. * Copyright (C) 1996 Paul Mackerras
  9. * PPC44x/36-bit changes by Matt Porter (mporter@mvista.com)
  10. *
  11. * Derived from "arch/i386/mm/init.c"
  12. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  13. */
  14. #include <linux/module.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/types.h>
  20. #include <linux/mm.h>
  21. #include <linux/stddef.h>
  22. #include <linux/init.h>
  23. #include <linux/highmem.h>
  24. #include <linux/initrd.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/memblock.h>
  27. #include <linux/gfp.h>
  28. #include <linux/slab.h>
  29. #include <linux/hugetlb.h>
  30. #include <asm/io.h>
  31. #include <asm/mmu.h>
  32. #include <asm/smp.h>
  33. #include <asm/machdep.h>
  34. #include <asm/btext.h>
  35. #include <asm/tlb.h>
  36. #include <asm/sections.h>
  37. #include <asm/hugetlb.h>
  38. #include <asm/kup.h>
  39. #include <asm/kasan.h>
  40. #include <asm/fixmap.h>
  41. #include <mm/mmu_decl.h>
  42. #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
  43. /* The amount of lowmem must be within 0xF0000000 - KERNELBASE. */
  44. #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - PAGE_OFFSET))
  45. #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_KERNEL_START"
  46. #endif
  47. #endif
  48. #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
  49. phys_addr_t total_memory;
  50. phys_addr_t total_lowmem;
  51. #ifdef CONFIG_RELOCATABLE
  52. /* Used in __va()/__pa() */
  53. long long virt_phys_offset;
  54. EXPORT_SYMBOL(virt_phys_offset);
  55. #endif
  56. phys_addr_t lowmem_end_addr;
  57. int boot_mapsize;
  58. #ifdef CONFIG_PPC_PMAC
  59. unsigned long agp_special_page;
  60. EXPORT_SYMBOL(agp_special_page);
  61. #endif
  62. void MMU_init(void);
  63. /* max amount of low RAM to map in */
  64. unsigned long __max_low_memory = MAX_LOW_MEM;
  65. /*
  66. * MMU_init sets up the basic memory mappings for the kernel,
  67. * including both RAM and possibly some I/O regions,
  68. * and sets up the page tables and the MMU hardware ready to go.
  69. */
  70. void __init MMU_init(void)
  71. {
  72. if (ppc_md.progress)
  73. ppc_md.progress("MMU:enter", 0x111);
  74. total_lowmem = total_memory = memblock_end_of_DRAM() - memstart_addr;
  75. lowmem_end_addr = memstart_addr + total_lowmem;
  76. #ifdef CONFIG_PPC_85xx
  77. /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
  78. * entries, so we need to adjust lowmem to match the amount we can map
  79. * in the fixed entries */
  80. adjust_total_lowmem();
  81. #endif /* CONFIG_PPC_85xx */
  82. if (total_lowmem > __max_low_memory) {
  83. total_lowmem = __max_low_memory;
  84. lowmem_end_addr = memstart_addr + total_lowmem;
  85. #ifndef CONFIG_HIGHMEM
  86. total_memory = total_lowmem;
  87. memblock_enforce_memory_limit(total_lowmem);
  88. #endif /* CONFIG_HIGHMEM */
  89. }
  90. /* Initialize the MMU hardware */
  91. if (ppc_md.progress)
  92. ppc_md.progress("MMU:hw init", 0x300);
  93. MMU_init_hw();
  94. /* Map in all of RAM starting at KERNELBASE */
  95. if (ppc_md.progress)
  96. ppc_md.progress("MMU:mapin", 0x301);
  97. mapin_ram();
  98. /* Initialize early top-down ioremap allocator */
  99. ioremap_bot = IOREMAP_TOP;
  100. if (ppc_md.progress)
  101. ppc_md.progress("MMU:exit", 0x211);
  102. /* From now on, btext is no longer BAT mapped if it was at all */
  103. #ifdef CONFIG_BOOTX_TEXT
  104. btext_unmap();
  105. #endif
  106. kasan_mmu_init();
  107. setup_kup();
  108. update_mmu_feature_fixups(MMU_FTR_KUAP);
  109. /* Shortly after that, the entire linear mapping will be available */
  110. memblock_set_current_limit(lowmem_end_addr);
  111. }