init_32.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PowerPC version
  4. * Copyright (C) 1995-1996 Gary Thomas ([email protected])
  5. *
  6. * Modifications by Paul Mackerras (PowerMac) ([email protected])
  7. * and Cort Dougan (PReP) ([email protected])
  8. * Copyright (C) 1996 Paul Mackerras
  9. * PPC44x/36-bit changes by Matt Porter ([email protected])
  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 <mm/mmu_decl.h>
  41. #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
  42. /* The amount of lowmem must be within 0xF0000000 - KERNELBASE. */
  43. #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - PAGE_OFFSET))
  44. #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_KERNEL_START"
  45. #endif
  46. #endif
  47. #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
  48. phys_addr_t total_memory;
  49. phys_addr_t total_lowmem;
  50. #ifdef CONFIG_RELOCATABLE
  51. /* Used in __va()/__pa() */
  52. long long virt_phys_offset;
  53. EXPORT_SYMBOL(virt_phys_offset);
  54. #endif
  55. phys_addr_t lowmem_end_addr;
  56. int boot_mapsize;
  57. #ifdef CONFIG_PPC_PMAC
  58. unsigned long agp_special_page;
  59. EXPORT_SYMBOL(agp_special_page);
  60. #endif
  61. void MMU_init(void);
  62. /* max amount of low RAM to map in */
  63. unsigned long __max_low_memory = MAX_LOW_MEM;
  64. /*
  65. * MMU_init sets up the basic memory mappings for the kernel,
  66. * including both RAM and possibly some I/O regions,
  67. * and sets up the page tables and the MMU hardware ready to go.
  68. */
  69. void __init MMU_init(void)
  70. {
  71. if (ppc_md.progress)
  72. ppc_md.progress("MMU:enter", 0x111);
  73. total_lowmem = total_memory = memblock_end_of_DRAM() - memstart_addr;
  74. lowmem_end_addr = memstart_addr + total_lowmem;
  75. #ifdef CONFIG_PPC_85xx
  76. /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
  77. * entries, so we need to adjust lowmem to match the amount we can map
  78. * in the fixed entries */
  79. adjust_total_lowmem();
  80. #endif /* CONFIG_PPC_85xx */
  81. if (total_lowmem > __max_low_memory) {
  82. total_lowmem = __max_low_memory;
  83. lowmem_end_addr = memstart_addr + total_lowmem;
  84. #ifndef CONFIG_HIGHMEM
  85. total_memory = total_lowmem;
  86. memblock_enforce_memory_limit(total_lowmem);
  87. #endif /* CONFIG_HIGHMEM */
  88. }
  89. /* Initialize the MMU hardware */
  90. if (ppc_md.progress)
  91. ppc_md.progress("MMU:hw init", 0x300);
  92. MMU_init_hw();
  93. /* Map in all of RAM starting at KERNELBASE */
  94. if (ppc_md.progress)
  95. ppc_md.progress("MMU:mapin", 0x301);
  96. mapin_ram();
  97. /* Initialize early top-down ioremap allocator */
  98. ioremap_bot = IOREMAP_TOP;
  99. if (ppc_md.progress)
  100. ppc_md.progress("MMU:exit", 0x211);
  101. /* From now on, btext is no longer BAT mapped if it was at all */
  102. #ifdef CONFIG_BOOTX_TEXT
  103. btext_unmap();
  104. #endif
  105. kasan_mmu_init();
  106. setup_kup();
  107. /* Shortly after that, the entire linear mapping will be available */
  108. memblock_set_current_limit(lowmem_end_addr);
  109. }