init.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* MN10300 Memory management initialisation
  2. *
  3. * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Modified by David Howells (dhowells@redhat.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #include <linux/signal.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/types.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/mman.h>
  20. #include <linux/slab.h>
  21. #include <linux/fs.h>
  22. #include <linux/mm.h>
  23. #include <linux/swap.h>
  24. #include <linux/smp.h>
  25. #include <linux/init.h>
  26. #include <linux/initrd.h>
  27. #include <linux/highmem.h>
  28. #include <linux/pagemap.h>
  29. #include <linux/bootmem.h>
  30. #include <asm/processor.h>
  31. #include <asm/system.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/pgalloc.h>
  35. #include <asm/dma.h>
  36. #include <asm/tlb.h>
  37. #include <asm/sections.h>
  38. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  39. unsigned long highstart_pfn, highend_pfn;
  40. /*
  41. * set up paging
  42. */
  43. void __init paging_init(void)
  44. {
  45. unsigned long zones_size[MAX_NR_ZONES] = {0,};
  46. pte_t *ppte;
  47. int loop;
  48. /* main kernel space -> RAM mapping is handled as 1:1 transparent by
  49. * the MMU */
  50. memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
  51. memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes));
  52. /* load the VMALLOC area PTE table addresses into the kernel PGD */
  53. ppte = kernel_vmalloc_ptes;
  54. for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE);
  55. loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE);
  56. loop++
  57. ) {
  58. set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE));
  59. ppte += PAGE_SIZE / sizeof(pte_t);
  60. }
  61. /* declare the sizes of the RAM zones (only use the normal zone) */
  62. zones_size[ZONE_NORMAL] =
  63. contig_page_data.bdata->node_low_pfn -
  64. contig_page_data.bdata->node_min_pfn;
  65. /* pass the memory from the bootmem allocator to the main allocator */
  66. free_area_init(zones_size);
  67. __flush_tlb_all();
  68. }
  69. /*
  70. * transfer all the memory from the bootmem allocator to the runtime allocator
  71. */
  72. void __init mem_init(void)
  73. {
  74. int codesize, reservedpages, datasize, initsize;
  75. int tmp;
  76. if (!mem_map)
  77. BUG();
  78. #define START_PFN (contig_page_data.bdata->node_min_pfn)
  79. #define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn)
  80. max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
  81. high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE);
  82. /* clear the zero-page */
  83. memset(empty_zero_page, 0, PAGE_SIZE);
  84. /* this will put all low memory onto the freelists */
  85. totalram_pages += free_all_bootmem();
  86. reservedpages = 0;
  87. for (tmp = 0; tmp < num_physpages; tmp++)
  88. if (PageReserved(&mem_map[tmp]))
  89. reservedpages++;
  90. codesize = (unsigned long) &_etext - (unsigned long) &_stext;
  91. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  92. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  93. printk(KERN_INFO
  94. "Memory: %luk/%luk available"
  95. " (%dk kernel code, %dk reserved, %dk data, %dk init,"
  96. " %ldk highmem)\n",
  97. nr_free_pages() << (PAGE_SHIFT - 10),
  98. max_mapnr << (PAGE_SHIFT - 10),
  99. codesize >> 10,
  100. reservedpages << (PAGE_SHIFT - 10),
  101. datasize >> 10,
  102. initsize >> 10,
  103. (unsigned long) (totalhigh_pages << (PAGE_SHIFT - 10))
  104. );
  105. }
  106. /*
  107. *
  108. */
  109. void free_init_pages(char *what, unsigned long begin, unsigned long end)
  110. {
  111. unsigned long addr;
  112. for (addr = begin; addr < end; addr += PAGE_SIZE) {
  113. ClearPageReserved(virt_to_page(addr));
  114. init_page_count(virt_to_page(addr));
  115. memset((void *) addr, 0xcc, PAGE_SIZE);
  116. free_page(addr);
  117. totalram_pages++;
  118. }
  119. printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
  120. }
  121. /*
  122. * recycle memory containing stuff only required for initialisation
  123. */
  124. void free_initmem(void)
  125. {
  126. free_init_pages("unused kernel memory",
  127. (unsigned long) &__init_begin,
  128. (unsigned long) &__init_end);
  129. }
  130. /*
  131. * dispose of the memory on which the initial ramdisk resided
  132. */
  133. #ifdef CONFIG_BLK_DEV_INITRD
  134. void free_initrd_mem(unsigned long start, unsigned long end)
  135. {
  136. free_init_pages("initrd memory", start, end);
  137. }
  138. #endif