init_32.c 7.0 KB

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