init.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. /* References to section boundaries */
  31. extern char _text, _etext, _edata;
  32. extern char __init_begin, __init_end;
  33. pgd_t swapper_pg_dir[1024];
  34. /*
  35. * Cache of MMU context last used.
  36. */
  37. #ifndef CONFIG_SMP
  38. unsigned long mmu_context_cache_dat;
  39. #else
  40. unsigned long mmu_context_cache_dat[NR_CPUS];
  41. #endif
  42. static unsigned long hole_pages;
  43. /*
  44. * function prototype
  45. */
  46. void __init paging_init(void);
  47. void __init mem_init(void);
  48. void free_initmem(void);
  49. #ifdef CONFIG_BLK_DEV_INITRD
  50. void free_initrd_mem(unsigned long, unsigned long);
  51. #endif
  52. /* It'd be good if these lines were in the standard header file. */
  53. #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
  54. #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
  55. #ifndef CONFIG_DISCONTIGMEM
  56. unsigned long __init zone_sizes_init(void)
  57. {
  58. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  59. unsigned long max_dma;
  60. unsigned long low;
  61. unsigned long start_pfn;
  62. #ifdef CONFIG_MMU
  63. start_pfn = START_PFN(0);
  64. max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  65. low = MAX_LOW_PFN(0);
  66. if (low < max_dma){
  67. zones_size[ZONE_DMA] = low - start_pfn;
  68. zones_size[ZONE_NORMAL] = 0;
  69. } else {
  70. zones_size[ZONE_DMA] = low - start_pfn;
  71. zones_size[ZONE_NORMAL] = low - max_dma;
  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. return 0;
  80. }
  81. #else /* CONFIG_DISCONTIGMEM */
  82. extern unsigned long zone_sizes_init(void);
  83. #endif /* CONFIG_DISCONTIGMEM */
  84. /*======================================================================*
  85. * paging_init() : sets up the page tables
  86. *======================================================================*/
  87. void __init paging_init(void)
  88. {
  89. #ifdef CONFIG_MMU
  90. int i;
  91. pgd_t *pg_dir;
  92. /* We don't need kernel mapping as hardware support that. */
  93. pg_dir = swapper_pg_dir;
  94. for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
  95. pgd_val(pg_dir[i]) = 0;
  96. #endif /* CONFIG_MMU */
  97. hole_pages = zone_sizes_init();
  98. }
  99. int __init reservedpages_count(void)
  100. {
  101. int reservedpages, nid, i;
  102. reservedpages = 0;
  103. for_each_online_node(nid) {
  104. unsigned long flags;
  105. pgdat_resize_lock(NODE_DATA(nid), &flags);
  106. for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++)
  107. if (PageReserved(nid_page_nr(nid, i)))
  108. reservedpages++;
  109. pgdat_resize_unlock(NODE_DATA(nid), &flags);
  110. }
  111. return reservedpages;
  112. }
  113. /*======================================================================*
  114. * mem_init() :
  115. * orig : arch/sh/mm/init.c
  116. *======================================================================*/
  117. void __init mem_init(void)
  118. {
  119. int codesize, reservedpages, datasize, initsize;
  120. int nid;
  121. #ifndef CONFIG_MMU
  122. extern unsigned long memory_end;
  123. #endif
  124. num_physpages = 0;
  125. for_each_online_node(nid)
  126. num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1;
  127. num_physpages -= hole_pages;
  128. #ifndef CONFIG_DISCONTIGMEM
  129. max_mapnr = num_physpages;
  130. #endif /* CONFIG_DISCONTIGMEM */
  131. #ifdef CONFIG_MMU
  132. high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
  133. #else
  134. high_memory = (void *)(memory_end & PAGE_MASK);
  135. #endif /* CONFIG_MMU */
  136. /* clear the zero-page */
  137. memset(empty_zero_page, 0, PAGE_SIZE);
  138. /* this will put all low memory onto the freelists */
  139. for_each_online_node(nid)
  140. totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
  141. reservedpages = reservedpages_count() - hole_pages;
  142. codesize = (unsigned long) &_etext - (unsigned long)&_text;
  143. datasize = (unsigned long) &_edata - (unsigned long)&_etext;
  144. initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin;
  145. printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
  146. "%dk reserved, %dk data, %dk init)\n",
  147. nr_free_pages() << (PAGE_SHIFT-10),
  148. num_physpages << (PAGE_SHIFT-10),
  149. codesize >> 10,
  150. reservedpages << (PAGE_SHIFT-10),
  151. datasize >> 10,
  152. initsize >> 10);
  153. }
  154. /*======================================================================*
  155. * free_initmem() :
  156. * orig : arch/sh/mm/init.c
  157. *======================================================================*/
  158. void free_initmem(void)
  159. {
  160. unsigned long addr;
  161. addr = (unsigned long)(&__init_begin);
  162. for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
  163. ClearPageReserved(virt_to_page(addr));
  164. init_page_count(virt_to_page(addr));
  165. free_page(addr);
  166. totalram_pages++;
  167. }
  168. printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", \
  169. (int)(&__init_end - &__init_begin) >> 10);
  170. }
  171. #ifdef CONFIG_BLK_DEV_INITRD
  172. /*======================================================================*
  173. * free_initrd_mem() :
  174. * orig : arch/sh/mm/init.c
  175. *======================================================================*/
  176. void free_initrd_mem(unsigned long start, unsigned long end)
  177. {
  178. unsigned long p;
  179. for (p = start; p < end; p += PAGE_SIZE) {
  180. ClearPageReserved(virt_to_page(p));
  181. init_page_count(virt_to_page(p));
  182. free_page(p);
  183. totalram_pages++;
  184. }
  185. printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  186. }
  187. #endif