init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/mm/init.c
  7. *
  8. * Copyright (C) 2000, 2001 Paolo Alberelli
  9. * Copyright (C) 2003, 2004 Paul Mundt
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/rwsem.h>
  14. #include <linux/mm.h>
  15. #include <linux/swap.h>
  16. #include <linux/bootmem.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/page.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/tlb.h>
  22. #ifdef CONFIG_BLK_DEV_INITRD
  23. #include <linux/blk.h>
  24. #endif
  25. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  26. /*
  27. * Cache of MMU context last used.
  28. */
  29. unsigned long mmu_context_cache;
  30. pgd_t * mmu_pdtp_cache;
  31. int after_bootmem = 0;
  32. /*
  33. * BAD_PAGE is the page that is used for page faults when linux
  34. * is out-of-memory. Older versions of linux just did a
  35. * do_exit(), but using this instead means there is less risk
  36. * for a process dying in kernel mode, possibly leaving an inode
  37. * unused etc..
  38. *
  39. * BAD_PAGETABLE is the accompanying page-table: it is initialized
  40. * to point to BAD_PAGE entries.
  41. *
  42. * ZERO_PAGE is a special page that is used for zero-initialized
  43. * data and COW.
  44. */
  45. extern unsigned char empty_zero_page[PAGE_SIZE];
  46. extern unsigned char empty_bad_page[PAGE_SIZE];
  47. extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
  48. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  49. extern char _text, _etext, _edata, __bss_start, _end;
  50. extern char __init_begin, __init_end;
  51. /* It'd be good if these lines were in the standard header file. */
  52. #define START_PFN (NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
  53. #define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn)
  54. void show_mem(void)
  55. {
  56. int i, total = 0, reserved = 0;
  57. int shared = 0, cached = 0;
  58. printk("Mem-info:\n");
  59. show_free_areas();
  60. printk("Free swap: %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
  61. i = max_mapnr;
  62. while (i-- > 0) {
  63. total++;
  64. if (PageReserved(mem_map+i))
  65. reserved++;
  66. else if (PageSwapCache(mem_map+i))
  67. cached++;
  68. else if (page_count(mem_map+i))
  69. shared += page_count(mem_map+i) - 1;
  70. }
  71. printk("%d pages of RAM\n",total);
  72. printk("%d reserved pages\n",reserved);
  73. printk("%d pages shared\n",shared);
  74. printk("%d pages swap cached\n",cached);
  75. printk("%ld pages in page table cache\n",pgtable_cache_size);
  76. }
  77. /*
  78. * paging_init() sets up the page tables.
  79. *
  80. * head.S already did a lot to set up address translation for the kernel.
  81. * Here we comes with:
  82. * . MMU enabled
  83. * . ASID set (SR)
  84. * . some 512MB regions being mapped of which the most relevant here is:
  85. * . CACHED segment (ASID 0 [irrelevant], shared AND NOT user)
  86. * . possible variable length regions being mapped as:
  87. * . UNCACHED segment (ASID 0 [irrelevant], shared AND NOT user)
  88. * . All of the memory regions are placed, independently from the platform
  89. * on high addresses, above 0x80000000.
  90. * . swapper_pg_dir is already cleared out by the .space directive
  91. * in any case swapper does not require a real page directory since
  92. * it's all kernel contained.
  93. *
  94. * Those pesky NULL-reference errors in the kernel are then
  95. * dealt with by not mapping address 0x00000000 at all.
  96. *
  97. */
  98. void __init paging_init(void)
  99. {
  100. unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
  101. pgd_init((unsigned long)swapper_pg_dir);
  102. pgd_init((unsigned long)swapper_pg_dir +
  103. sizeof(pgd_t) * USER_PTRS_PER_PGD);
  104. mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;
  105. /*
  106. * All memory is good as ZONE_NORMAL (fall-through) and ZONE_DMA.
  107. */
  108. zones_size[ZONE_DMA] = MAX_LOW_PFN - START_PFN;
  109. NODE_DATA(0)->node_mem_map = NULL;
  110. free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0);
  111. }
  112. void __init mem_init(void)
  113. {
  114. int codesize, reservedpages, datasize, initsize;
  115. int tmp;
  116. max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
  117. high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE);
  118. /*
  119. * Clear the zero-page.
  120. * This is not required but we might want to re-use
  121. * this very page to pass boot parameters, one day.
  122. */
  123. memset(empty_zero_page, 0, PAGE_SIZE);
  124. /* this will put all low memory onto the freelists */
  125. totalram_pages += free_all_bootmem_node(NODE_DATA(0));
  126. reservedpages = 0;
  127. for (tmp = 0; tmp < num_physpages; tmp++)
  128. /*
  129. * Only count reserved RAM pages
  130. */
  131. if (PageReserved(mem_map+tmp))
  132. reservedpages++;
  133. after_bootmem = 1;
  134. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  135. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  136. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  137. printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
  138. (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
  139. max_mapnr << (PAGE_SHIFT-10),
  140. codesize >> 10,
  141. reservedpages << (PAGE_SHIFT-10),
  142. datasize >> 10,
  143. initsize >> 10);
  144. }
  145. void free_initmem(void)
  146. {
  147. unsigned long addr;
  148. addr = (unsigned long)(&__init_begin);
  149. for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
  150. ClearPageReserved(virt_to_page(addr));
  151. set_page_count(virt_to_page(addr), 1);
  152. free_page(addr);
  153. totalram_pages++;
  154. }
  155. printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end - &__init_begin) >> 10);
  156. }
  157. #ifdef CONFIG_BLK_DEV_INITRD
  158. void free_initrd_mem(unsigned long start, unsigned long end)
  159. {
  160. unsigned long p;
  161. for (p = start; p < end; p += PAGE_SIZE) {
  162. ClearPageReserved(virt_to_page(p));
  163. set_page_count(virt_to_page(p), 1);
  164. free_page(p);
  165. totalram_pages++;
  166. }
  167. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  168. }
  169. #endif