init_32.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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/lmb.h>
  43. #include <asm/sections.h>
  44. #include "mmu_decl.h"
  45. #if defined(CONFIG_KERNEL_START_BOOL) || defined(CONFIG_LOWMEM_SIZE_BOOL)
  46. /* The ammount of lowmem must be within 0xF0000000 - KERNELBASE. */
  47. #if (CONFIG_LOWMEM_SIZE > (0xF0000000 - KERNELBASE))
  48. #error "You must adjust CONFIG_LOWMEM_SIZE or CONFIG_START_KERNEL"
  49. #endif
  50. #endif
  51. #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE
  52. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  53. unsigned long total_memory;
  54. unsigned long total_lowmem;
  55. unsigned long ppc_memstart;
  56. unsigned long ppc_memoffset = PAGE_OFFSET;
  57. int boot_mapsize;
  58. #ifdef CONFIG_PPC_PMAC
  59. unsigned long agp_special_page;
  60. EXPORT_SYMBOL(agp_special_page);
  61. #endif
  62. #ifdef CONFIG_HIGHMEM
  63. pte_t *kmap_pte;
  64. pgprot_t kmap_prot;
  65. EXPORT_SYMBOL(kmap_prot);
  66. EXPORT_SYMBOL(kmap_pte);
  67. #endif
  68. void MMU_init(void);
  69. /* XXX should be in current.h -- paulus */
  70. extern struct task_struct *current_set[NR_CPUS];
  71. extern int init_bootmem_done;
  72. /*
  73. * this tells the system to map all of ram with the segregs
  74. * (i.e. page tables) instead of the bats.
  75. * -- Cort
  76. */
  77. int __map_without_bats;
  78. int __map_without_ltlbs;
  79. /* max amount of low RAM to map in */
  80. unsigned long __max_low_memory = MAX_LOW_MEM;
  81. /*
  82. * limit of what is accessible with initial MMU setup -
  83. * 256MB usually, but only 16MB on 601.
  84. */
  85. unsigned long __initial_memory_limit = 0x10000000;
  86. /*
  87. * Check for command-line options that affect what MMU_init will do.
  88. */
  89. void MMU_setup(void)
  90. {
  91. /* Check for nobats option (used in mapin_ram). */
  92. if (strstr(cmd_line, "nobats")) {
  93. __map_without_bats = 1;
  94. }
  95. if (strstr(cmd_line, "noltlbs")) {
  96. __map_without_ltlbs = 1;
  97. }
  98. #ifdef CONFIG_DEBUG_PAGEALLOC
  99. __map_without_bats = 1;
  100. __map_without_ltlbs = 1;
  101. #endif
  102. }
  103. /*
  104. * MMU_init sets up the basic memory mappings for the kernel,
  105. * including both RAM and possibly some I/O regions,
  106. * and sets up the page tables and the MMU hardware ready to go.
  107. */
  108. void __init MMU_init(void)
  109. {
  110. if (ppc_md.progress)
  111. ppc_md.progress("MMU:enter", 0x111);
  112. /* 601 can only access 16MB at the moment */
  113. if (PVR_VER(mfspr(SPRN_PVR)) == 1)
  114. __initial_memory_limit = 0x01000000;
  115. /* 8xx can only access 8MB at the moment */
  116. if (PVR_VER(mfspr(SPRN_PVR)) == 0x50)
  117. __initial_memory_limit = 0x00800000;
  118. /* parse args from command line */
  119. MMU_setup();
  120. if (lmb.memory.cnt > 1) {
  121. lmb.memory.cnt = 1;
  122. lmb_analyze();
  123. printk(KERN_WARNING "Only using first contiguous memory region");
  124. }
  125. total_memory = lmb_end_of_DRAM();
  126. total_lowmem = total_memory;
  127. #ifdef CONFIG_FSL_BOOKE
  128. /* Freescale Book-E parts expect lowmem to be mapped by fixed TLB
  129. * entries, so we need to adjust lowmem to match the amount we can map
  130. * in the fixed entries */
  131. adjust_total_lowmem();
  132. #endif /* CONFIG_FSL_BOOKE */
  133. if (total_lowmem > __max_low_memory) {
  134. total_lowmem = __max_low_memory;
  135. #ifndef CONFIG_HIGHMEM
  136. total_memory = total_lowmem;
  137. lmb_enforce_memory_limit(total_lowmem);
  138. lmb_analyze();
  139. #endif /* CONFIG_HIGHMEM */
  140. }
  141. /* Initialize the MMU hardware */
  142. if (ppc_md.progress)
  143. ppc_md.progress("MMU:hw init", 0x300);
  144. MMU_init_hw();
  145. /* Map in all of RAM starting at KERNELBASE */
  146. if (ppc_md.progress)
  147. ppc_md.progress("MMU:mapin", 0x301);
  148. mapin_ram();
  149. #ifdef CONFIG_HIGHMEM
  150. ioremap_base = PKMAP_BASE;
  151. #else
  152. ioremap_base = 0xfe000000UL; /* for now, could be 0xfffff000 */
  153. #endif /* CONFIG_HIGHMEM */
  154. ioremap_bot = ioremap_base;
  155. /* Map in I/O resources */
  156. if (ppc_md.progress)
  157. ppc_md.progress("MMU:setio", 0x302);
  158. if (ppc_md.setup_io_mappings)
  159. ppc_md.setup_io_mappings();
  160. /* Initialize the context management stuff */
  161. mmu_context_init();
  162. if (ppc_md.progress)
  163. ppc_md.progress("MMU:exit", 0x211);
  164. /* From now on, btext is no longer BAT mapped if it was at all */
  165. #ifdef CONFIG_BOOTX_TEXT
  166. btext_unmap();
  167. #endif
  168. }
  169. /* This is only called until mem_init is done. */
  170. void __init *early_get_page(void)
  171. {
  172. void *p;
  173. if (init_bootmem_done) {
  174. p = alloc_bootmem_pages(PAGE_SIZE);
  175. } else {
  176. p = __va(lmb_alloc_base(PAGE_SIZE, PAGE_SIZE,
  177. __initial_memory_limit));
  178. }
  179. return p;
  180. }
  181. /* Free up now-unused memory */
  182. static void free_sec(unsigned long start, unsigned long end, const char *name)
  183. {
  184. unsigned long cnt = 0;
  185. while (start < end) {
  186. ClearPageReserved(virt_to_page(start));
  187. init_page_count(virt_to_page(start));
  188. free_page(start);
  189. cnt++;
  190. start += PAGE_SIZE;
  191. }
  192. if (cnt) {
  193. printk(" %ldk %s", cnt << (PAGE_SHIFT - 10), name);
  194. totalram_pages += cnt;
  195. }
  196. }
  197. void free_initmem(void)
  198. {
  199. #define FREESEC(TYPE) \
  200. free_sec((unsigned long)(&__ ## TYPE ## _begin), \
  201. (unsigned long)(&__ ## TYPE ## _end), \
  202. #TYPE);
  203. printk ("Freeing unused kernel memory:");
  204. FREESEC(init);
  205. printk("\n");
  206. ppc_md.progress = NULL;
  207. #undef FREESEC
  208. }
  209. #ifdef CONFIG_BLK_DEV_INITRD
  210. void free_initrd_mem(unsigned long start, unsigned long end)
  211. {
  212. if (start < end)
  213. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  214. for (; start < end; start += PAGE_SIZE) {
  215. ClearPageReserved(virt_to_page(start));
  216. init_page_count(virt_to_page(start));
  217. free_page(start);
  218. totalram_pages++;
  219. }
  220. }
  221. #endif
  222. #ifdef CONFIG_PROC_KCORE
  223. static struct kcore_list kcore_vmem;
  224. static int __init setup_kcore(void)
  225. {
  226. int i;
  227. for (i = 0; i < lmb.memory.cnt; i++) {
  228. unsigned long base;
  229. unsigned long size;
  230. struct kcore_list *kcore_mem;
  231. base = lmb.memory.region[i].base;
  232. size = lmb.memory.region[i].size;
  233. kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
  234. if (!kcore_mem)
  235. panic("%s: kmalloc failed\n", __FUNCTION__);
  236. /* must stay under 32 bits */
  237. if ( 0xfffffffful - (unsigned long)__va(base) < size) {
  238. size = 0xfffffffful - (unsigned long)(__va(base));
  239. printk(KERN_DEBUG "setup_kcore: restrict size=%lx\n",
  240. size);
  241. }
  242. kclist_add(kcore_mem, __va(base), size);
  243. }
  244. kclist_add(&kcore_vmem, (void *)VMALLOC_START,
  245. VMALLOC_END-VMALLOC_START);
  246. return 0;
  247. }
  248. module_init(setup_kcore);
  249. #endif