init.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <linux/dma-contiguous.h>
  29. #include <asm/bootparam.h>
  30. #include <asm/page.h>
  31. #include <asm/sections.h>
  32. #include <asm/sysmem.h>
  33. /*
  34. * Initialize the bootmem system and give it all low memory we have available.
  35. */
  36. void __init bootmem_init(void)
  37. {
  38. /* Reserve all memory below PHYS_OFFSET, as memory
  39. * accounting doesn't work for pages below that address.
  40. *
  41. * If PHYS_OFFSET is zero reserve page at address 0:
  42. * successfull allocations should never return NULL.
  43. */
  44. if (PHYS_OFFSET)
  45. memblock_reserve(0, PHYS_OFFSET);
  46. else
  47. memblock_reserve(0, 1);
  48. early_init_fdt_scan_reserved_mem();
  49. if (!memblock_phys_mem_size())
  50. panic("No memory found!\n");
  51. min_low_pfn = PFN_UP(memblock_start_of_DRAM());
  52. min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET));
  53. max_pfn = PFN_DOWN(memblock_end_of_DRAM());
  54. max_low_pfn = min(max_pfn, MAX_LOW_PFN);
  55. memblock_set_current_limit(PFN_PHYS(max_low_pfn));
  56. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  57. memblock_dump_all();
  58. }
  59. void __init zones_init(void)
  60. {
  61. /* All pages are DMA-able, so we put them all in the DMA zone. */
  62. unsigned long zones_size[MAX_NR_ZONES] = {
  63. [ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET,
  64. #ifdef CONFIG_HIGHMEM
  65. [ZONE_HIGHMEM] = max_pfn - max_low_pfn,
  66. #endif
  67. };
  68. free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
  69. }
  70. /*
  71. * Initialize memory pages.
  72. */
  73. void __init mem_init(void)
  74. {
  75. #ifdef CONFIG_HIGHMEM
  76. unsigned long tmp;
  77. reset_all_zones_managed_pages();
  78. for (tmp = max_low_pfn; tmp < max_pfn; tmp++)
  79. free_highmem_page(pfn_to_page(tmp));
  80. #endif
  81. max_mapnr = max_pfn - ARCH_PFN_OFFSET;
  82. high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
  83. free_all_bootmem();
  84. mem_init_print_info(NULL);
  85. pr_info("virtual kernel memory layout:\n"
  86. #ifdef CONFIG_HIGHMEM
  87. " pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
  88. " fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
  89. #endif
  90. #ifdef CONFIG_MMU
  91. " vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
  92. #endif
  93. " lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n",
  94. #ifdef CONFIG_HIGHMEM
  95. PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
  96. (LAST_PKMAP*PAGE_SIZE) >> 10,
  97. FIXADDR_START, FIXADDR_TOP,
  98. (FIXADDR_TOP - FIXADDR_START) >> 10,
  99. #endif
  100. #ifdef CONFIG_MMU
  101. VMALLOC_START, VMALLOC_END,
  102. (VMALLOC_END - VMALLOC_START) >> 20,
  103. PAGE_OFFSET, PAGE_OFFSET +
  104. (max_low_pfn - min_low_pfn) * PAGE_SIZE,
  105. #else
  106. min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE,
  107. #endif
  108. ((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20);
  109. }
  110. #ifdef CONFIG_BLK_DEV_INITRD
  111. extern int initrd_is_mapped;
  112. void free_initrd_mem(unsigned long start, unsigned long end)
  113. {
  114. if (initrd_is_mapped)
  115. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  116. }
  117. #endif
  118. void free_initmem(void)
  119. {
  120. free_initmem_default(-1);
  121. }
  122. static void __init parse_memmap_one(char *p)
  123. {
  124. char *oldp;
  125. unsigned long start_at, mem_size;
  126. if (!p)
  127. return;
  128. oldp = p;
  129. mem_size = memparse(p, &p);
  130. if (p == oldp)
  131. return;
  132. switch (*p) {
  133. case '@':
  134. start_at = memparse(p + 1, &p);
  135. memblock_add(start_at, mem_size);
  136. break;
  137. case '$':
  138. start_at = memparse(p + 1, &p);
  139. memblock_reserve(start_at, mem_size);
  140. break;
  141. case 0:
  142. memblock_reserve(mem_size, -mem_size);
  143. break;
  144. default:
  145. pr_warn("Unrecognized memmap syntax: %s\n", p);
  146. break;
  147. }
  148. }
  149. static int __init parse_memmap_opt(char *str)
  150. {
  151. while (str) {
  152. char *k = strchr(str, ',');
  153. if (k)
  154. *k++ = 0;
  155. parse_memmap_one(str);
  156. str = k;
  157. }
  158. return 0;
  159. }
  160. early_param("memmap", parse_memmap_opt);