init.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * arch/score/mm/init.c
  3. *
  4. * Score Processor version.
  5. *
  6. * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
  7. * Lennox Wu <lennox.wu@sunplusct.com>
  8. * Chen Liqin <liqin.chen@sunplusct.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, see the file COPYING, or write
  22. * to the Free Software Foundation, Inc.,
  23. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. #include <linux/errno.h>
  26. #include <linux/bootmem.h>
  27. #include <linux/kernel.h>
  28. #include <linux/gfp.h>
  29. #include <linux/init.h>
  30. #include <linux/mm.h>
  31. #include <linux/mman.h>
  32. #include <linux/pagemap.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/sched.h>
  35. #include <linux/initrd.h>
  36. #include <asm/sections.h>
  37. #include <asm/tlb.h>
  38. unsigned long empty_zero_page;
  39. EXPORT_SYMBOL_GPL(empty_zero_page);
  40. static struct kcore_list kcore_mem, kcore_vmalloc;
  41. static unsigned long setup_zero_page(void)
  42. {
  43. struct page *page;
  44. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
  45. if (!empty_zero_page)
  46. panic("Oh boy, that early out of memory?");
  47. page = virt_to_page((void *) empty_zero_page);
  48. SetPageReserved(page);
  49. return 1UL;
  50. }
  51. #ifndef CONFIG_NEED_MULTIPLE_NODES
  52. int page_is_ram(unsigned long pagenr)
  53. {
  54. if (pagenr >= min_low_pfn && pagenr < max_low_pfn)
  55. return 1;
  56. else
  57. return 0;
  58. }
  59. void __init paging_init(void)
  60. {
  61. unsigned long max_zone_pfns[MAX_NR_ZONES];
  62. unsigned long lastpfn;
  63. pagetable_init();
  64. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  65. lastpfn = max_low_pfn;
  66. free_area_init_nodes(max_zone_pfns);
  67. }
  68. void __init mem_init(void)
  69. {
  70. unsigned long codesize, reservedpages, datasize, initsize;
  71. unsigned long tmp, ram = 0;
  72. high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
  73. totalram_pages += free_all_bootmem();
  74. totalram_pages -= setup_zero_page(); /* Setup zeroed pages. */
  75. reservedpages = 0;
  76. for (tmp = 0; tmp < max_low_pfn; tmp++)
  77. if (page_is_ram(tmp)) {
  78. ram++;
  79. if (PageReserved(pfn_to_page(tmp)))
  80. reservedpages++;
  81. }
  82. num_physpages = ram;
  83. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  84. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  85. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  86. printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
  87. "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
  88. (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
  89. ram << (PAGE_SHIFT-10), codesize >> 10,
  90. reservedpages << (PAGE_SHIFT-10), datasize >> 10,
  91. initsize >> 10,
  92. totalhigh_pages << (PAGE_SHIFT-10));
  93. }
  94. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  95. static void free_init_pages(const char *what, unsigned long begin, unsigned long end)
  96. {
  97. unsigned long pfn;
  98. for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) {
  99. struct page *page = pfn_to_page(pfn);
  100. void *addr = phys_to_virt(PFN_PHYS(pfn));
  101. ClearPageReserved(page);
  102. init_page_count(page);
  103. memset(addr, POISON_FREE_INITMEM, PAGE_SIZE);
  104. __free_page(page);
  105. totalram_pages++;
  106. }
  107. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  108. }
  109. #ifdef CONFIG_BLK_DEV_INITRD
  110. void free_initrd_mem(unsigned long start, unsigned long end)
  111. {
  112. free_init_pages("initrd memory",
  113. virt_to_phys((void *) start),
  114. virt_to_phys((void *) end));
  115. }
  116. #endif
  117. void __init_refok free_initmem(void)
  118. {
  119. free_init_pages("unused kernel memory",
  120. __pa(&__init_begin),
  121. __pa(&__init_end));
  122. }
  123. unsigned long pgd_current;
  124. #define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order)))
  125. /*
  126. * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER
  127. * are constants. So we use the variants from asm-offset.h until that gcc
  128. * will officially be retired.
  129. */
  130. pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER);
  131. pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);