init.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/sched/task.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/gfp.h>
  23. #include <linux/swap.h>
  24. #include <linux/mm.h>
  25. #include <linux/kernel.h>
  26. #include <linux/string.h>
  27. #include <linux/types.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/highmem.h>
  30. #include <linux/module.h>
  31. #include <asm/setup.h>
  32. #include <asm/segment.h>
  33. #include <asm/page.h>
  34. #include <asm/pgtable.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. /*
  41. * BAD_PAGE is the page that is used for page faults when linux
  42. * is out-of-memory. Older versions of linux just did a
  43. * do_exit(), but using this instead means there is less risk
  44. * for a process dying in kernel mode, possibly leaving a inode
  45. * unused etc..
  46. *
  47. * BAD_PAGETABLE is the accompanying page-table: it is initialized
  48. * to point to BAD_PAGE entries.
  49. *
  50. * ZERO_PAGE is a special page that is used for zero-initialized
  51. * data and COW.
  52. */
  53. static unsigned long empty_bad_page_table;
  54. static unsigned long empty_bad_page;
  55. unsigned long empty_zero_page;
  56. EXPORT_SYMBOL(empty_zero_page);
  57. /*****************************************************************************/
  58. /*
  59. * paging_init() continues the virtual memory environment setup which
  60. * was begun by the code in arch/head.S.
  61. * The parameters are pointers to where to stick the starting and ending
  62. * addresses of available kernel virtual memory.
  63. */
  64. void __init paging_init(void)
  65. {
  66. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  67. /* allocate some pages for kernel housekeeping tasks */
  68. empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  69. empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  70. empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  71. memset((void *) empty_zero_page, 0, PAGE_SIZE);
  72. #ifdef CONFIG_HIGHMEM
  73. if (get_num_physpages() - num_mappedpages) {
  74. pgd_t *pge;
  75. pud_t *pue;
  76. pmd_t *pme;
  77. pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
  78. pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
  79. pue = pud_offset(pge, PKMAP_BASE);
  80. pme = pmd_offset(pue, PKMAP_BASE);
  81. __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
  82. }
  83. #endif
  84. /* distribute the allocatable pages across the various zones and pass them to the allocator
  85. */
  86. zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
  87. #ifdef CONFIG_HIGHMEM
  88. zones_size[ZONE_HIGHMEM] = get_num_physpages() - num_mappedpages;
  89. #endif
  90. free_area_init(zones_size);
  91. #ifdef CONFIG_MMU
  92. /* initialise init's MMU context */
  93. init_new_context(&init_task, &init_mm);
  94. #endif
  95. } /* end paging_init() */
  96. /*****************************************************************************/
  97. /*
  98. *
  99. */
  100. void __init mem_init(void)
  101. {
  102. unsigned long code_size = _etext - _stext;
  103. /* this will put all low memory onto the freelists */
  104. free_all_bootmem();
  105. #if defined(CONFIG_MMU) && defined(CONFIG_HIGHMEM)
  106. {
  107. unsigned long pfn;
  108. for (pfn = get_num_physpages() - 1;
  109. pfn >= num_mappedpages; pfn--)
  110. free_highmem_page(&mem_map[pfn]);
  111. }
  112. #endif
  113. mem_init_print_info(NULL);
  114. if (rom_length > 0 && rom_length >= code_size)
  115. printk("Memory available: %luKiB/%luKiB ROM\n",
  116. (rom_length - code_size) >> 10, rom_length >> 10);
  117. } /* end mem_init() */
  118. /*****************************************************************************/
  119. /*
  120. * free the memory that was only required for initialisation
  121. */
  122. void free_initmem(void)
  123. {
  124. #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
  125. free_initmem_default(-1);
  126. #endif
  127. } /* end free_initmem() */
  128. /*****************************************************************************/
  129. /*
  130. * free the initial ramdisk memory
  131. */
  132. #ifdef CONFIG_BLK_DEV_INITRD
  133. void __init free_initrd_mem(unsigned long start, unsigned long end)
  134. {
  135. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  136. } /* end free_initrd_mem() */
  137. #endif