init_32.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  6. * and Cort Dougan (PReP) (cort@cs.nmt.edu)
  7. * Copyright (C) 1996 Paul Mackerras
  8. * PPC44x/36-bit changes by Matt Porter (mporter@mvista.com)
  9. *
  10. * Derived from "arch/i386/mm/init.c"
  11. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/sched.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/types.h>
  25. #include <linux/mm.h>
  26. #include <linux/stddef.h>
  27. #include <linux/init.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/highmem.h>
  30. #include <linux/initrd.h>
  31. #include <linux/pagemap.h>
  32. #include <asm/pgalloc.h>
  33. #include <asm/prom.h>
  34. #include <asm/io.h>
  35. #include <asm/mmu_context.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/mmu.h>
  38. #include <asm/smp.h>
  39. #include <asm/machdep.h>
  40. #include <asm/btext.h>
  41. #include <asm/tlb.h>
  42. #include <asm/prom.h>
  43. #include <asm/lmb.h>
  44. #include <asm/sections.h>
  45. #include "mmu_decl.h"
  46. #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
  47. /* The ammount of lowmem must be within 0xF0000000 - KERNELBASE. */
  48. #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - KERNELBASE))
  49. #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_START_KERNEL"
  50. #endif
  51. #endif
  52. #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
  53. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  54. unsigned long total_memory;
  55. unsigned long total_lowmem;
  56. unsigned long ppc_memstart;
  57. unsigned long ppc_memoffset = PAGE_OFFSET;
  58. int boot_mapsize;
  59. #ifdef CONFIG_PPC_PMAC
  60. unsigned long agp_special_page;
  61. EXPORT_SYMBOL(agp_special_page);
  62. #endif
  63. #ifdef CONFIG_HIGHMEM
  64. pte_t *kmap_pte;
  65. pgprot_t kmap_prot;
  66. EXPORT_SYMBOL(kmap_prot);
  67. EXPORT_SYMBOL(kmap_pte);
  68. #endif
  69. void MMU_init(void);
  70. /* XXX should be in current.h -- paulus */
  71. extern struct task_struct *current_set[NR_CPUS];
  72. extern int init_bootmem_done;
  73. /*
  74. * this tells the system to map all of ram with the segregs
  75. * (i.e. page tables) instead of the bats.
  76. * -- Cort
  77. */
  78. int __map_without_bats;
  79. int __map_without_ltlbs;
  80. /* max amount of low RAM to map in */
  81. unsigned long __max_low_memory = MAX_LOW_MEM;
  82. /*
  83. * limit of what is accessible with initial MMU setup -
  84. * 256MB usually, but only 16MB on 601.
  85. */
  86. unsigned long __initial_memory_limit = 0x10000000;
  87. /*
  88. * Check for command-line options that affect what MMU_init will do.
  89. */
  90. void MMU_setup(void)
  91. {
  92. /* Check for nobats option (used in mapin_ram). */
  93. if (strstr(cmd_line, "nobats")) {
  94. __map_without_bats = 1;
  95. }
  96. if (strstr(cmd_line, "noltlbs")) {
  97. __map_without_ltlbs = 1;
  98. }
  99. #ifdef CONFIG_DEBUG_PAGEALLOC
  100. __map_without_bats = 1;
  101. __map_without_ltlbs = 1;
  102. #endif
  103. }
  104. /*
  105. * MMU_init sets up the basic memory mappings for the kernel,
  106. * including both RAM and possibly some I/O regions,
  107. * and sets up the page tables and the MMU hardware ready to go.
  108. */
  109. void __init MMU_init(void)
  110. {
  111. if (ppc_md.progress)
  112. ppc_md.progress("MMU:enter", 0x111);
  113. /* 601 can only access 16MB at the moment */
  114. if (PVR_VER(mfspr(SPRN_PVR)) == 1)
  115. __initial_memory_limit = 0x01000000;
  116. /* parse args from command line */
  117. MMU_setup();
  118. if (lmb.memory.cnt > 1) {
  119. lmb.memory.cnt = 1;
  120. lmb_analyze();
  121. printk(KERN_WARNING "Only using first contiguous memory region");
  122. }
  123. total_memory = lmb_end_of_DRAM();
  124. total_lowmem = total_memory;
  125. #ifdef CONFIG_FSL_BOOKE
  126. /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
  127. * entries, so we need to adjust lowmem to match the amount we can map
  128. * in the fixed entries */
  129. adjust_total_lowmem();
  130. #endif /* CONFIG_FSL_BOOKE */
  131. if (total_lowmem > __max_low_memory) {
  132. total_lowmem = __max_low_memory;
  133. #ifndef CONFIG_HIGHMEM
  134. total_memory = total_lowmem;
  135. lmb_enforce_memory_limit(total_lowmem);
  136. lmb_analyze();
  137. #endif /* CONFIG_HIGHMEM */
  138. }
  139. /* Initialize the MMU hardware */
  140. if (ppc_md.progress)
  141. ppc_md.progress("MMU:hw init", 0x300);
  142. MMU_init_hw();
  143. /* Map in all of RAM starting at KERNELBASE */
  144. if (ppc_md.progress)
  145. ppc_md.progress("MMU:mapin", 0x301);
  146. mapin_ram();
  147. #ifdef CONFIG_HIGHMEM
  148. ioremap_base = PKMAP_BASE;
  149. #else
  150. ioremap_base = 0xfe000000UL; /* for now, could be 0xfffff000 */
  151. #endif /* CONFIG_HIGHMEM */
  152. ioremap_bot = ioremap_base;
  153. /* Map in I/O resources */
  154. if (ppc_md.progress)
  155. ppc_md.progress("MMU:setio", 0x302);
  156. if (ppc_md.setup_io_mappings)
  157. ppc_md.setup_io_mappings();
  158. /* Initialize the context management stuff */
  159. mmu_context_init();
  160. if (ppc_md.progress)
  161. ppc_md.progress("MMU:exit", 0x211);
  162. /* From now on, btext is no longer BAT mapped if it was at all */
  163. #ifdef CONFIG_BOOTX_TEXT
  164. btext_unmap();
  165. #endif
  166. }
  167. /* This is only called until mem_init is done. */
  168. void __init *early_get_page(void)
  169. {
  170. void *p;
  171. if (init_bootmem_done) {
  172. p = alloc_bootmem_pages(PAGE_SIZE);
  173. } else {
  174. p = __va(lmb_alloc_base(PAGE_SIZE, PAGE_SIZE,
  175. __initial_memory_limit));
  176. }
  177. return p;
  178. }
  179. /* Free up now-unused memory */
  180. static void free_sec(unsigned long start, unsigned long end, const char *name)
  181. {
  182. unsigned long cnt = 0;
  183. while (start < end) {
  184. ClearPageReserved(virt_to_page(start));
  185. init_page_count(virt_to_page(start));
  186. free_page(start);
  187. cnt++;
  188. start += PAGE_SIZE;
  189. }
  190. if (cnt) {
  191. printk(" %ldk %s", cnt << (PAGE_SHIFT - 10), name);
  192. totalram_pages += cnt;
  193. }
  194. }
  195. void free_initmem(void)
  196. {
  197. #define FREESEC(TYPE) \
  198. free_sec((unsigned long)(&__ ## TYPE ## _begin), \
  199. (unsigned long)(&__ ## TYPE ## _end), \
  200. #TYPE);
  201. printk ("Freeing unused kernel memory:");
  202. FREESEC(init);
  203. printk("\n");
  204. ppc_md.progress = NULL;
  205. #undef FREESEC
  206. }
  207. #ifdef CONFIG_BLK_DEV_INITRD
  208. void free_initrd_mem(unsigned long start, unsigned long end)
  209. {
  210. if (start < end)
  211. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  212. for (; start < end; start += PAGE_SIZE) {
  213. ClearPageReserved(virt_to_page(start));
  214. init_page_count(virt_to_page(start));
  215. free_page(start);
  216. totalram_pages++;
  217. }
  218. }
  219. #endif