init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* init.c: memory initialisation for FRV
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Derived from:
  12. * - linux/arch/m68knommu/mm/init.c
  13. * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, Kenneth Albanowski <kjahds@kjahds.com>,
  14. * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
  15. * - linux/arch/m68k/mm/init.c
  16. * - Copyright (C) 1995 Hamish Macdonald
  17. */
  18. #include <linux/signal.h>
  19. #include <linux/sched.h>
  20. #include <linux/pagemap.h>
  21. #include <linux/gfp.h>
  22. #include <linux/swap.h>
  23. #include <linux/mm.h>
  24. #include <linux/kernel.h>
  25. #include <linux/string.h>
  26. #include <linux/types.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/highmem.h>
  29. #include <linux/module.h>
  30. #include <asm/setup.h>
  31. #include <asm/segment.h>
  32. #include <asm/page.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/system.h>
  35. #include <asm/mmu_context.h>
  36. #include <asm/virtconvert.h>
  37. #include <asm/sections.h>
  38. #include <asm/tlb.h>
  39. #undef DEBUG
  40. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  41. /*
  42. * BAD_PAGE is the page that is used for page faults when linux
  43. * is out-of-memory. Older versions of linux just did a
  44. * do_exit(), but using this instead means there is less risk
  45. * for a process dying in kernel mode, possibly leaving a inode
  46. * unused etc..
  47. *
  48. * BAD_PAGETABLE is the accompanying page-table: it is initialized
  49. * to point to BAD_PAGE entries.
  50. *
  51. * ZERO_PAGE is a special page that is used for zero-initialized
  52. * data and COW.
  53. */
  54. static unsigned long empty_bad_page_table;
  55. static unsigned long empty_bad_page;
  56. unsigned long empty_zero_page;
  57. EXPORT_SYMBOL(empty_zero_page);
  58. /*****************************************************************************/
  59. /*
  60. * paging_init() continues the virtual memory environment setup which
  61. * was begun by the code in arch/head.S.
  62. * The parameters are pointers to where to stick the starting and ending
  63. * addresses of available kernel virtual memory.
  64. */
  65. void __init paging_init(void)
  66. {
  67. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  68. /* allocate some pages for kernel housekeeping tasks */
  69. empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  70. empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  71. empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  72. memset((void *) empty_zero_page, 0, PAGE_SIZE);
  73. #ifdef CONFIG_HIGHMEM
  74. if (num_physpages - num_mappedpages) {
  75. pgd_t *pge;
  76. pud_t *pue;
  77. pmd_t *pme;
  78. pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
  79. pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
  80. pue = pud_offset(pge, PKMAP_BASE);
  81. pme = pmd_offset(pue, PKMAP_BASE);
  82. __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
  83. }
  84. #endif
  85. /* distribute the allocatable pages across the various zones and pass them to the allocator
  86. */
  87. zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
  88. #ifdef CONFIG_HIGHMEM
  89. zones_size[ZONE_HIGHMEM] = num_physpages - num_mappedpages;
  90. #endif
  91. free_area_init(zones_size);
  92. #ifdef CONFIG_MMU
  93. /* initialise init's MMU context */
  94. init_new_context(&init_task, &init_mm);
  95. #endif
  96. } /* end paging_init() */
  97. /*****************************************************************************/
  98. /*
  99. *
  100. */
  101. void __init mem_init(void)
  102. {
  103. unsigned long npages = (memory_end - memory_start) >> PAGE_SHIFT;
  104. unsigned long tmp;
  105. #ifdef CONFIG_MMU
  106. unsigned long loop, pfn;
  107. int datapages = 0;
  108. #endif
  109. int codek = 0, datak = 0;
  110. /* this will put all memory onto the freelists */
  111. totalram_pages = free_all_bootmem();
  112. #ifdef CONFIG_MMU
  113. for (loop = 0 ; loop < npages ; loop++)
  114. if (PageReserved(&mem_map[loop]))
  115. datapages++;
  116. #ifdef CONFIG_HIGHMEM
  117. for (pfn = num_physpages - 1; pfn >= num_mappedpages; pfn--) {
  118. struct page *page = &mem_map[pfn];
  119. ClearPageReserved(page);
  120. init_page_count(page);
  121. __free_page(page);
  122. totalram_pages++;
  123. }
  124. #endif
  125. codek = ((unsigned long) &_etext - (unsigned long) &_stext) >> 10;
  126. datak = datapages << (PAGE_SHIFT - 10);
  127. #else
  128. codek = (_etext - _stext) >> 10;
  129. datak = 0; //(_ebss - _sdata) >> 10;
  130. #endif
  131. tmp = nr_free_pages() << PAGE_SHIFT;
  132. printk("Memory available: %luKiB/%luKiB RAM, %luKiB/%luKiB ROM (%dKiB kernel code, %dKiB data)\n",
  133. tmp >> 10,
  134. npages << (PAGE_SHIFT - 10),
  135. (rom_length > 0) ? ((rom_length >> 10) - codek) : 0,
  136. rom_length >> 10,
  137. codek,
  138. datak
  139. );
  140. } /* end mem_init() */
  141. /*****************************************************************************/
  142. /*
  143. * free the memory that was only required for initialisation
  144. */
  145. void free_initmem(void)
  146. {
  147. #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
  148. unsigned long start, end, addr;
  149. start = PAGE_ALIGN((unsigned long) &__init_begin); /* round up */
  150. end = ((unsigned long) &__init_end) & PAGE_MASK; /* round down */
  151. /* next to check that the page we free is not a partial page */
  152. for (addr = start; addr < end; addr += PAGE_SIZE) {
  153. ClearPageReserved(virt_to_page(addr));
  154. init_page_count(virt_to_page(addr));
  155. free_page(addr);
  156. totalram_pages++;
  157. }
  158. printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
  159. (end - start) >> 10, start, end);
  160. #endif
  161. } /* end free_initmem() */
  162. /*****************************************************************************/
  163. /*
  164. * free the initial ramdisk memory
  165. */
  166. #ifdef CONFIG_BLK_DEV_INITRD
  167. void __init free_initrd_mem(unsigned long start, unsigned long end)
  168. {
  169. int pages = 0;
  170. for (; start < end; start += PAGE_SIZE) {
  171. ClearPageReserved(virt_to_page(start));
  172. init_page_count(virt_to_page(start));
  173. free_page(start);
  174. totalram_pages++;
  175. pages++;
  176. }
  177. printk("Freeing initrd memory: %dKiB freed\n", (pages * PAGE_SIZE) >> 10);
  178. } /* end free_initrd_mem() */
  179. #endif