init.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Memory subsystem initialization for Hexagon
  3. *
  4. * Copyright (c) 2010-2013, 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 + PHYS_OFFSET))
  33. unsigned long bootmem_lastpg; /* Should be set by platform code */
  34. unsigned long __phys_offset; /* physical kernel offset >> 12 */
  35. /* Set as variable to limit PMD copies */
  36. int max_kernel_seg = 0x303;
  37. /* think this should be (page_size-1) the way it's used...*/
  38. unsigned long zero_page_mask;
  39. /* indicate pfn's of high memory */
  40. unsigned long highstart_pfn, highend_pfn;
  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. free_all_bootmem();
  63. mem_init_print_info(NULL);
  64. /*
  65. * To-Do: someone somewhere should wipe out the bootmem map
  66. * after we're done?
  67. */
  68. /*
  69. * This can be moved to some more virtual-memory-specific
  70. * initialization hook at some point. Set the init_mm
  71. * descriptors "context" value to point to the initial
  72. * kernel segment table's physical address.
  73. */
  74. init_mm.context.ptbase = __pa(init_mm.pgd);
  75. }
  76. /*
  77. * free_initmem - frees memory used by stuff declared with __init
  78. *
  79. * Todo: free pages between __init_begin and __init_end; possibly
  80. * some devtree related stuff as well.
  81. */
  82. void __ref free_initmem(void)
  83. {
  84. }
  85. /*
  86. * free_initrd_mem - frees... initrd memory.
  87. * @start - start of init memory
  88. * @end - end of init memory
  89. *
  90. * Apparently has to be passed the address of the initrd memory.
  91. *
  92. * Wrapped by #ifdef CONFIG_BLKDEV_INITRD
  93. */
  94. void free_initrd_mem(unsigned long start, unsigned long end)
  95. {
  96. }
  97. void sync_icache_dcache(pte_t pte)
  98. {
  99. unsigned long addr;
  100. struct page *page;
  101. page = pte_page(pte);
  102. addr = (unsigned long) page_address(page);
  103. __vmcache_idsync(addr, PAGE_SIZE);
  104. }
  105. /*
  106. * In order to set up page allocator "nodes",
  107. * somebody has to call free_area_init() for UMA.
  108. *
  109. * In this mode, we only have one pg_data_t
  110. * structure: contig_mem_data.
  111. */
  112. void __init paging_init(void)
  113. {
  114. unsigned long zones_sizes[MAX_NR_ZONES] = {0, };
  115. /*
  116. * This is not particularly well documented anywhere, but
  117. * give ZONE_NORMAL all the memory, including the big holes
  118. * left by the kernel+bootmem_map which are already left as reserved
  119. * in the bootmem_map; free_area_init should see those bits and
  120. * adjust accordingly.
  121. */
  122. zones_sizes[ZONE_NORMAL] = max_low_pfn;
  123. free_area_init(zones_sizes); /* sets up the zonelists and mem_map */
  124. /*
  125. * Start of high memory area. Will probably need something more
  126. * fancy if we... get more fancy.
  127. */
  128. high_memory = (void *)((bootmem_lastpg + 1) << PAGE_SHIFT);
  129. }
  130. #ifndef DMA_RESERVE
  131. #define DMA_RESERVE (4)
  132. #endif
  133. #define DMA_CHUNKSIZE (1<<22)
  134. #define DMA_RESERVED_BYTES (DMA_RESERVE * DMA_CHUNKSIZE)
  135. /*
  136. * Pick out the memory size. We look for mem=size,
  137. * where size is "size[KkMm]"
  138. */
  139. static int __init early_mem(char *p)
  140. {
  141. unsigned long size;
  142. char *endp;
  143. size = memparse(p, &endp);
  144. bootmem_lastpg = PFN_DOWN(size);
  145. return 0;
  146. }
  147. early_param("mem", early_mem);
  148. size_t hexagon_coherent_pool_size = (size_t) (DMA_RESERVE << 22);
  149. void __init setup_arch_memory(void)
  150. {
  151. int bootmap_size;
  152. /* XXX Todo: this probably should be cleaned up */
  153. u32 *segtable = (u32 *) &swapper_pg_dir[0];
  154. u32 *segtable_end;
  155. /*
  156. * Set up boot memory allocator
  157. *
  158. * The Gorman book also talks about these functions.
  159. * This needs to change for highmem setups.
  160. */
  161. /* Prior to this, bootmem_lastpg is actually mem size */
  162. bootmem_lastpg += ARCH_PFN_OFFSET;
  163. /* Memory size needs to be a multiple of 16M */
  164. bootmem_lastpg = PFN_DOWN((bootmem_lastpg << PAGE_SHIFT) &
  165. ~((BIG_KERNEL_PAGE_SIZE) - 1));
  166. /*
  167. * Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
  168. * memory allocation
  169. */
  170. max_low_pfn = bootmem_lastpg - PFN_DOWN(DMA_RESERVED_BYTES);
  171. min_low_pfn = ARCH_PFN_OFFSET;
  172. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmem_startpg, min_low_pfn, max_low_pfn);
  173. printk(KERN_INFO "bootmem_startpg: 0x%08lx\n", bootmem_startpg);
  174. printk(KERN_INFO "bootmem_lastpg: 0x%08lx\n", bootmem_lastpg);
  175. printk(KERN_INFO "bootmap_size: %d\n", bootmap_size);
  176. printk(KERN_INFO "min_low_pfn: 0x%08lx\n", min_low_pfn);
  177. printk(KERN_INFO "max_low_pfn: 0x%08lx\n", max_low_pfn);
  178. /*
  179. * The default VM page tables (will be) populated with
  180. * VA=PA+PAGE_OFFSET mapping. We go in and invalidate entries
  181. * higher than what we have memory for.
  182. */
  183. /* this is pointer arithmetic; each entry covers 4MB */
  184. segtable = segtable + (PAGE_OFFSET >> 22);
  185. /* this actually only goes to the end of the first gig */
  186. segtable_end = segtable + (1<<(30-22));
  187. /*
  188. * Move forward to the start of empty pages; take into account
  189. * phys_offset shift.
  190. */
  191. segtable += (bootmem_lastpg-ARCH_PFN_OFFSET)>>(22-PAGE_SHIFT);
  192. {
  193. int i;
  194. for (i = 1 ; i <= DMA_RESERVE ; i++)
  195. segtable[-i] = ((segtable[-i] & __HVM_PTE_PGMASK_4MB)
  196. | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X
  197. | __HEXAGON_C_UNC << 6
  198. | __HVM_PDE_S_4MB);
  199. }
  200. printk(KERN_INFO "clearing segtable from %p to %p\n", segtable,
  201. segtable_end);
  202. while (segtable < (segtable_end-8))
  203. *(segtable++) = __HVM_PDE_S_INVALID;
  204. /* stop the pointer at the device I/O 4MB page */
  205. printk(KERN_INFO "segtable = %p (should be equal to _K_io_map)\n",
  206. segtable);
  207. #if 0
  208. /* Other half of the early device table from vm_init_segtable. */
  209. printk(KERN_INFO "&_K_init_devicetable = 0x%08x\n",
  210. (unsigned long) _K_init_devicetable-PAGE_OFFSET);
  211. *segtable = ((u32) (unsigned long) _K_init_devicetable-PAGE_OFFSET) |
  212. __HVM_PDE_S_4KB;
  213. printk(KERN_INFO "*segtable = 0x%08x\n", *segtable);
  214. #endif
  215. /*
  216. * Free all the memory that wasn't taken up by the bootmap, the DMA
  217. * reserve, or kernel itself.
  218. */
  219. free_bootmem(PFN_PHYS(bootmem_startpg) + bootmap_size,
  220. PFN_PHYS(bootmem_lastpg - bootmem_startpg) - bootmap_size -
  221. DMA_RESERVED_BYTES);
  222. /*
  223. * The bootmem allocator seemingly just lives to feed memory
  224. * to the paging system
  225. */
  226. printk(KERN_INFO "PAGE_SIZE=%lu\n", PAGE_SIZE);
  227. paging_init(); /* See Gorman Book, 2.3 */
  228. /*
  229. * At this point, the page allocator is kind of initialized, but
  230. * apparently no pages are available (just like with the bootmem
  231. * allocator), and need to be freed themselves via mem_init(),
  232. * which is called by start_kernel() later on in the process
  233. */
  234. }