init.c 3.8 KB

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