init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 max_dma;
  57. unsigned long low;
  58. unsigned long start_pfn;
  59. #ifdef CONFIG_MMU
  60. start_pfn = START_PFN(0);
  61. max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  62. low = MAX_LOW_PFN(0);
  63. if (low < max_dma){
  64. zones_size[ZONE_DMA] = low - start_pfn;
  65. zones_size[ZONE_NORMAL] = 0;
  66. } else {
  67. zones_size[ZONE_DMA] = low - start_pfn;
  68. zones_size[ZONE_NORMAL] = low - max_dma;
  69. }
  70. #else
  71. zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
  72. zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
  73. start_pfn = __MEMORY_START >> PAGE_SHIFT;
  74. #endif /* CONFIG_MMU */
  75. free_area_init_node(0, zones_size, start_pfn, 0);
  76. }
  77. #else /* CONFIG_DISCONTIGMEM */
  78. extern void zone_sizes_init(void);
  79. #endif /* CONFIG_DISCONTIGMEM */
  80. /*======================================================================*
  81. * paging_init() : sets up the page tables
  82. *======================================================================*/
  83. void __init paging_init(void)
  84. {
  85. #ifdef CONFIG_MMU
  86. int i;
  87. pgd_t *pg_dir;
  88. /* We don't need kernel mapping as hardware support that. */
  89. pg_dir = swapper_pg_dir;
  90. for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
  91. pgd_val(pg_dir[i]) = 0;
  92. #endif /* CONFIG_MMU */
  93. zone_sizes_init();
  94. }
  95. /*======================================================================*
  96. * mem_init() :
  97. * orig : arch/sh/mm/init.c
  98. *======================================================================*/
  99. void __init mem_init(void)
  100. {
  101. #ifndef CONFIG_MMU
  102. extern unsigned long memory_end;
  103. high_memory = (void *)(memory_end & PAGE_MASK);
  104. #else
  105. high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
  106. #endif /* CONFIG_MMU */
  107. /* clear the zero-page */
  108. memset(empty_zero_page, 0, PAGE_SIZE);
  109. set_max_mapnr(get_num_physpages());
  110. free_all_bootmem();
  111. mem_init_print_info(NULL);
  112. }
  113. /*======================================================================*
  114. * free_initmem() :
  115. * orig : arch/sh/mm/init.c
  116. *======================================================================*/
  117. void free_initmem(void)
  118. {
  119. free_initmem_default(-1);
  120. }
  121. #ifdef CONFIG_BLK_DEV_INITRD
  122. /*======================================================================*
  123. * free_initrd_mem() :
  124. * orig : arch/sh/mm/init.c
  125. *======================================================================*/
  126. void free_initrd_mem(unsigned long start, unsigned long end)
  127. {
  128. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  129. }
  130. #endif