init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/m32r/mm/init.c
  4. *
  5. * Copyright (c) 2001, 2002 Hitoshi Yamamoto
  6. *
  7. * Some code taken from sh version.
  8. * Copyright (C) 1999 Niibe Yutaka
  9. * Based on linux/arch/i386/mm/init.c:
  10. * Copyright (C) 1995 Linus Torvalds
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/pagemap.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/swap.h>
  18. #include <linux/highmem.h>
  19. #include <linux/bitops.h>
  20. #include <linux/nodemask.h>
  21. #include <linux/pfn.h>
  22. #include <linux/gfp.h>
  23. #include <asm/types.h>
  24. #include <asm/processor.h>
  25. #include <asm/page.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/pgalloc.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/setup.h>
  30. #include <asm/tlb.h>
  31. #include <asm/sections.h>
  32. pgd_t swapper_pg_dir[1024];
  33. /*
  34. * Cache of MMU context last used.
  35. */
  36. #ifndef CONFIG_SMP
  37. unsigned long mmu_context_cache_dat;
  38. #else
  39. unsigned long mmu_context_cache_dat[NR_CPUS];
  40. #endif
  41. /*
  42. * function prototype
  43. */
  44. void __init paging_init(void);
  45. void __init mem_init(void);
  46. void free_initmem(void);
  47. #ifdef CONFIG_BLK_DEV_INITRD
  48. void free_initrd_mem(unsigned long, unsigned long);
  49. #endif
  50. /* It'd be good if these lines were in the standard header file. */
  51. #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
  52. #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
  53. #ifndef CONFIG_DISCONTIGMEM
  54. void __init zone_sizes_init(void)
  55. {
  56. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  57. unsigned long start_pfn;
  58. #ifdef CONFIG_MMU
  59. {
  60. unsigned long low;
  61. unsigned long max_dma;
  62. start_pfn = START_PFN(0);
  63. max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  64. low = MAX_LOW_PFN(0);
  65. if (low < max_dma) {
  66. zones_size[ZONE_DMA] = low - start_pfn;
  67. zones_size[ZONE_NORMAL] = 0;
  68. } else {
  69. zones_size[ZONE_DMA] = low - start_pfn;
  70. zones_size[ZONE_NORMAL] = low - max_dma;
  71. }
  72. }
  73. #else
  74. zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
  75. zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
  76. start_pfn = __MEMORY_START >> PAGE_SHIFT;
  77. #endif /* CONFIG_MMU */
  78. free_area_init_node(0, zones_size, start_pfn, 0);
  79. }
  80. #else /* CONFIG_DISCONTIGMEM */
  81. extern void zone_sizes_init(void);
  82. #endif /* CONFIG_DISCONTIGMEM */
  83. /*======================================================================*
  84. * paging_init() : sets up the page tables
  85. *======================================================================*/
  86. void __init paging_init(void)
  87. {
  88. #ifdef CONFIG_MMU
  89. int i;
  90. pgd_t *pg_dir;
  91. /* We don't need kernel mapping as hardware support that. */
  92. pg_dir = swapper_pg_dir;
  93. for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
  94. pgd_val(pg_dir[i]) = 0;
  95. #endif /* CONFIG_MMU */
  96. zone_sizes_init();
  97. }
  98. /*======================================================================*
  99. * mem_init() :
  100. * orig : arch/sh/mm/init.c
  101. *======================================================================*/
  102. void __init mem_init(void)
  103. {
  104. #ifndef CONFIG_MMU
  105. extern unsigned long memory_end;
  106. high_memory = (void *)(memory_end & PAGE_MASK);
  107. #else
  108. high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
  109. #endif /* CONFIG_MMU */
  110. /* clear the zero-page */
  111. memset(empty_zero_page, 0, PAGE_SIZE);
  112. set_max_mapnr(get_num_physpages());
  113. free_all_bootmem();
  114. mem_init_print_info(NULL);
  115. }
  116. /*======================================================================*
  117. * free_initmem() :
  118. * orig : arch/sh/mm/init.c
  119. *======================================================================*/
  120. void free_initmem(void)
  121. {
  122. free_initmem_default(-1);
  123. }
  124. #ifdef CONFIG_BLK_DEV_INITRD
  125. /*======================================================================*
  126. * free_initrd_mem() :
  127. * orig : arch/sh/mm/init.c
  128. *======================================================================*/
  129. void free_initrd_mem(unsigned long start, unsigned long end)
  130. {
  131. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  132. }
  133. #endif