init.c 7.7 KB

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