init.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Memory subsystem initialization for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/mm.h>
  22. #include <linux/bootmem.h>
  23. #include <asm/atomic.h>
  24. #include <linux/highmem.h>
  25. #include <asm/tlb.h>
  26. #include <asm/sections.h>
  27. #include <asm/vm_mmu.h>
  28. /*
  29. * Define a startpg just past the end of the kernel image and a lastpg
  30. * that corresponds to the end of real or simulated platform memory.
  31. */
  32. #define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET))
  33. unsigned long bootmem_lastpg; /* Should be set by platform code */
  34. /* Set as variable to limit PMD copies */
  35. int max_kernel_seg = 0x303;
  36. /* think this should be (page_size-1) the way it's used...*/
  37. unsigned long zero_page_mask;
  38. /* indicate pfn's of high memory */
  39. unsigned long highstart_pfn, highend_pfn;
  40. /* struct mmu_gather defined in asm-generic.h; */
  41. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  42. /* Default cache attribute for newly created page tables */
  43. unsigned long _dflt_cache_att = CACHEDEF;
  44. /*
  45. * The current "generation" of kernel map, which should not roll
  46. * over until Hell freezes over. Actual bound in years needs to be
  47. * calculated to confirm.
  48. */
  49. DEFINE_SPINLOCK(kmap_gen_lock);
  50. /* checkpatch says don't init this to 0. */
  51. unsigned long long kmap_generation;
  52. /*
  53. * mem_init - initializes memory
  54. *
  55. * Frees up bootmem
  56. * Fixes up more stuff for HIGHMEM
  57. * Calculates and displays memory available/used
  58. */
  59. void __init mem_init(void)
  60. {
  61. /* No idea where this is actually declared. Seems to evade LXR. */
  62. totalram_pages += free_all_bootmem();
  63. num_physpages = bootmem_lastpg; /* seriously, what? */
  64. printk(KERN_INFO "totalram_pages = %ld\n", totalram_pages);
  65. /*
  66. * To-Do: someone somewhere should wipe out the bootmem map
  67. * after we're done?
  68. */
  69. /*
  70. * This can be moved to some more virtual-memory-specific
  71. * initialization hook at some point. Set the init_mm
  72. * descriptors "context" value to point to the initial
  73. * kernel segment table's physical address.
  74. */
  75. init_mm.context.ptbase = __pa(init_mm.pgd);
  76. }
  77. /*
  78. * free_initmem - frees memory used by stuff declared with __init
  79. *
  80. * Todo: free pages between __init_begin and __init_end; possibly
  81. * some devtree related stuff as well.
  82. */
  83. void __init_refok free_initmem(void)
  84. {
  85. }
  86. /*
  87. * free_initrd_mem - frees... initrd memory.
  88. * @start - start of init memory
  89. * @end - end of init memory
  90. *
  91. * Apparently has to be passed the address of the initrd memory.
  92. *
  93. * Wrapped by #ifdef CONFIG_BLKDEV_INITRD
  94. */
  95. void free_initrd_mem(unsigned long start, unsigned long end)
  96. {
  97. }
  98. void sync_icache_dcache(pte_t pte)
  99. {
  100. unsigned long addr;
  101. struct page *page;
  102. page = pte_page(pte);
  103. addr = (unsigned long) page_address(page);
  104. __vmcache_idsync(addr, PAGE_SIZE);
  105. }
  106. /*
  107. * In order to set up page allocator "nodes",
  108. * somebody has to call free_area_init() for UMA.
  109. *
  110. * In this mode, we only have one pg_data_t
  111. * structure: contig_mem_data.
  112. */
  113. void __init paging_init(void)
  114. {
  115. unsigned long zones_sizes[MAX_NR_ZONES] = {0, };
  116. /*
  117. * This is not particularly well documented anywhere, but
  118. * give ZONE_NORMAL all the memory, including the big holes
  119. * left by the kernel+bootmem_map which are already left as reserved
  120. * in the bootmem_map; free_area_init should see those bits and
  121. * adjust accordingly.
  122. */
  123. zones_sizes[ZONE_NORMAL] = max_low_pfn;
  124. free_area_init(zones_sizes); /* sets up the zonelists and mem_map */
  125. /*
  126. * Start of high memory area. Will probably need something more
  127. * fancy if we... get more fancy.
  128. */
  129. high_memory = (void *)((bootmem_lastpg + 1) << PAGE_SHIFT);
  130. }
  131. #ifndef DMA_RESERVE
  132. #define DMA_RESERVE (4)
  133. #endif
  134. #define DMA_CHUNKSIZE (1<<22)
  135. #define DMA_RESERVED_BYTES (DMA_RESERVE * DMA_CHUNKSIZE)
  136. /*
  137. * Pick out the memory size. We look for mem=size,
  138. * where size is "size[KkMm]"
  139. */
  140. static int __init early_mem(char *p)
  141. {
  142. unsigned long size;
  143. char *endp;
  144. size = memparse(p, &endp);
  145. bootmem_lastpg = PFN_DOWN(size);
  146. return 0;
  147. }
  148. early_param("mem", early_mem);
  149. size_t hexagon_coherent_pool_size = (size_t) (DMA_RESERVE << 22);
  150. void __init setup_arch_memory(void)
  151. {
  152. int bootmap_size;
  153. /* XXX Todo: this probably should be cleaned up */
  154. u32 *segtable = (u32 *) &swapper_pg_dir[0];
  155. u32 *segtable_end;
  156. /*
  157. * Set up boot memory allocator
  158. *
  159. * The Gorman book also talks about these functions.
  160. * This needs to change for highmem setups.
  161. */
  162. /* Memory size needs to be a multiple of 16M */
  163. bootmem_lastpg = PFN_DOWN((bootmem_lastpg << PAGE_SHIFT) &
  164. ~((BIG_KERNEL_PAGE_SIZE) - 1));
  165. /*
  166. * Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
  167. * memory allocation
  168. */
  169. bootmap_size = init_bootmem(bootmem_startpg, bootmem_lastpg -
  170. PFN_DOWN(DMA_RESERVED_BYTES));
  171. printk(KERN_INFO "bootmem_startpg: 0x%08lx\n", bootmem_startpg);
  172. printk(KERN_INFO "bootmem_lastpg: 0x%08lx\n", bootmem_lastpg);
  173. printk(KERN_INFO "bootmap_size: %d\n", bootmap_size);
  174. printk(KERN_INFO "max_low_pfn: 0x%08lx\n", max_low_pfn);
  175. /*
  176. * The default VM page tables (will be) populated with
  177. * VA=PA+PAGE_OFFSET mapping. We go in and invalidate entries
  178. * higher than what we have memory for.
  179. */
  180. /* this is pointer arithmetic; each entry covers 4MB */
  181. segtable = segtable + (PAGE_OFFSET >> 22);
  182. /* this actually only goes to the end of the first gig */
  183. segtable_end = segtable + (1<<(30-22));
  184. /* Move forward to the start of empty pages */
  185. segtable += bootmem_lastpg >> (22-PAGE_SHIFT);
  186. {
  187. int i;
  188. for (i = 1 ; i <= DMA_RESERVE ; i++)
  189. segtable[-i] = ((segtable[-i] & __HVM_PTE_PGMASK_4MB)
  190. | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X
  191. | __HEXAGON_C_UNC << 6
  192. | __HVM_PDE_S_4MB);
  193. }
  194. printk(KERN_INFO "clearing segtable from %p to %p\n", segtable,
  195. segtable_end);
  196. while (segtable < (segtable_end-8))
  197. *(segtable++) = __HVM_PDE_S_INVALID;
  198. /* stop the pointer at the device I/O 4MB page */
  199. printk(KERN_INFO "segtable = %p (should be equal to _K_io_map)\n",
  200. segtable);
  201. #if 0
  202. /* Other half of the early device table from vm_init_segtable. */
  203. printk(KERN_INFO "&_K_init_devicetable = 0x%08x\n",
  204. (unsigned long) _K_init_devicetable-PAGE_OFFSET);
  205. *segtable = ((u32) (unsigned long) _K_init_devicetable-PAGE_OFFSET) |
  206. __HVM_PDE_S_4KB;
  207. printk(KERN_INFO "*segtable = 0x%08x\n", *segtable);
  208. #endif
  209. /*
  210. * Free all the memory that wasn't taken up by the bootmap, the DMA
  211. * reserve, or kernel itself.
  212. */
  213. free_bootmem(PFN_PHYS(bootmem_startpg)+bootmap_size,
  214. PFN_PHYS(bootmem_lastpg - bootmem_startpg) - bootmap_size -
  215. DMA_RESERVED_BYTES);
  216. /*
  217. * The bootmem allocator seemingly just lives to feed memory
  218. * to the paging system
  219. */
  220. printk(KERN_INFO "PAGE_SIZE=%lu\n", PAGE_SIZE);
  221. paging_init(); /* See Gorman Book, 2.3 */
  222. /*
  223. * At this point, the page allocator is kind of initialized, but
  224. * apparently no pages are available (just like with the bootmem
  225. * allocator), and need to be freed themselves via mem_init(),
  226. * which is called by start_kernel() later on in the process
  227. */
  228. }