init.c 5.4 KB

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