init.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * arch/xtensa/mm/init.c
  3. *
  4. * Derived from MIPS, PPC.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2001 - 2005 Tensilica Inc.
  11. * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
  12. *
  13. * Chris Zankel <chris@zankel.net>
  14. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  15. * Marc Gauthier
  16. * Kevin Chea
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/errno.h>
  20. #include <linux/bootmem.h>
  21. #include <linux/gfp.h>
  22. #include <linux/highmem.h>
  23. #include <linux/swap.h>
  24. #include <linux/mman.h>
  25. #include <linux/nodemask.h>
  26. #include <linux/mm.h>
  27. #include <linux/of_fdt.h>
  28. #include <asm/bootparam.h>
  29. #include <asm/page.h>
  30. #include <asm/sections.h>
  31. #include <asm/sysmem.h>
  32. /*
  33. * Initialize the bootmem system and give it all low memory we have available.
  34. */
  35. void __init bootmem_init(void)
  36. {
  37. /* Reserve all memory below PHYS_OFFSET, as memory
  38. * accounting doesn't work for pages below that address.
  39. *
  40. * If PHYS_OFFSET is zero reserve page at address 0:
  41. * successfull allocations should never return NULL.
  42. */
  43. if (PHYS_OFFSET)
  44. memblock_reserve(0, PHYS_OFFSET);
  45. else
  46. memblock_reserve(0, 1);
  47. early_init_fdt_scan_reserved_mem();
  48. if (!memblock_phys_mem_size())
  49. panic("No memory found!\n");
  50. min_low_pfn = PFN_UP(memblock_start_of_DRAM());
  51. min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET));
  52. max_pfn = PFN_DOWN(memblock_end_of_DRAM());
  53. max_low_pfn = min(max_pfn, MAX_LOW_PFN);
  54. memblock_set_current_limit(PFN_PHYS(max_low_pfn));
  55. memblock_dump_all();
  56. }
  57. void __init zones_init(void)
  58. {
  59. /* All pages are DMA-able, so we put them all in the DMA zone. */
  60. unsigned long zones_size[MAX_NR_ZONES] = {
  61. [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET,
  62. #ifdef CONFIG_HIGHMEM
  63. [ZONE_HIGHMEM] = max_pfn - max_low_pfn,
  64. #endif
  65. };
  66. free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
  67. }
  68. /*
  69. * Initialize memory pages.
  70. */
  71. void __init mem_init(void)
  72. {
  73. #ifdef CONFIG_HIGHMEM
  74. unsigned long tmp;
  75. reset_all_zones_managed_pages();
  76. for (tmp = max_low_pfn; tmp < max_pfn; tmp++)
  77. free_highmem_page(pfn_to_page(tmp));
  78. #endif
  79. max_mapnr = max_pfn - ARCH_PFN_OFFSET;
  80. high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
  81. free_all_bootmem();
  82. mem_init_print_info(NULL);
  83. pr_info("virtual kernel memory layout:\n"
  84. #ifdef CONFIG_HIGHMEM
  85. " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
  86. " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
  87. #endif
  88. #ifdef CONFIG_MMU
  89. " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
  90. #endif
  91. " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n",
  92. #ifdef CONFIG_HIGHMEM
  93. PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
  94. (LAST_PKMAP*PAGE_SIZE) >> 10,
  95. FIXADDR_START, FIXADDR_TOP,
  96. (FIXADDR_TOP - FIXADDR_START) >> 10,
  97. #endif
  98. #ifdef CONFIG_MMU
  99. VMALLOC_START, VMALLOC_END,
  100. (VMALLOC_END - VMALLOC_START) >> 20,
  101. PAGE_OFFSET, PAGE_OFFSET +
  102. (max_low_pfn - min_low_pfn) * PAGE_SIZE,
  103. #else
  104. min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE,
  105. #endif
  106. ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20);
  107. }
  108. #ifdef CONFIG_BLK_DEV_INITRD
  109. extern int initrd_is_mapped;
  110. void free_initrd_mem(unsigned long start, unsigned long end)
  111. {
  112. if (initrd_is_mapped)
  113. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  114. }
  115. #endif
  116. void free_initmem(void)
  117. {
  118. free_initmem_default(-1);
  119. }
  120. static void __init parse_memmap_one(char *p)
  121. {
  122. char *oldp;
  123. unsigned long start_at, mem_size;
  124. if (!p)
  125. return;
  126. oldp = p;
  127. mem_size = memparse(p, &p);
  128. if (p == oldp)
  129. return;
  130. switch (*p) {
  131. case '@':
  132. start_at = memparse(p + 1, &p);
  133. memblock_add(start_at, mem_size);
  134. break;
  135. case '$':
  136. start_at = memparse(p + 1, &p);
  137. memblock_reserve(start_at, mem_size);
  138. break;
  139. case 0:
  140. memblock_reserve(mem_size, -mem_size);
  141. break;
  142. default:
  143. pr_warn("Unrecognized memmap syntax: %s\n", p);
  144. break;
  145. }
  146. }
  147. static int __init parse_memmap_opt(char *str)
  148. {
  149. while (str) {
  150. char *k = strchr(str, ',');
  151. if (k)
  152. *k++ = 0;
  153. parse_memmap_one(str);
  154. str = k;
  155. }
  156. return 0;
  157. }
  158. early_param("memmap", parse_memmap_opt);