init.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/mm.h>
  10. #include <linux/bootmem.h>
  11. #include <linux/memblock.h>
  12. #ifdef CONFIG_BLOCK_DEV_RAM
  13. #include <linux/blk.h>
  14. #endif
  15. #include <linux/swap.h>
  16. #include <linux/module.h>
  17. #include <asm/page.h>
  18. #include <asm/pgalloc.h>
  19. #include <asm/sections.h>
  20. #include <asm/arcregs.h>
  21. pgd_t swapper_pg_dir[PTRS_PER_PGD] __aligned(PAGE_SIZE);
  22. char empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
  23. EXPORT_SYMBOL(empty_zero_page);
  24. /* Default tot mem from .config */
  25. static unsigned long arc_mem_sz = CONFIG_ARC_PLAT_SDRAM_SIZE;
  26. /* User can over-ride above with "mem=nnn[KkMm]" in cmdline */
  27. static int __init setup_mem_sz(char *str)
  28. {
  29. arc_mem_sz = memparse(str, NULL) & PAGE_MASK;
  30. /* early console might not be setup yet - it will show up later */
  31. pr_info("\"mem=%s\": mem sz set to %ldM\n", str, TO_MB(arc_mem_sz));
  32. return 0;
  33. }
  34. early_param("mem", setup_mem_sz);
  35. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  36. {
  37. pr_err("%s(%llx, %llx)\n", __func__, base, size);
  38. }
  39. /*
  40. * First memory setup routine called from setup_arch()
  41. * 1. setup swapper's mm @init_mm
  42. * 2. Count the pages we have and setup bootmem allocator
  43. * 3. zone setup
  44. */
  45. void __init setup_arch_memory(void)
  46. {
  47. unsigned long zones_size[MAX_NR_ZONES] = { 0, 0 };
  48. unsigned long end_mem = CONFIG_LINUX_LINK_BASE + arc_mem_sz;
  49. init_mm.start_code = (unsigned long)_text;
  50. init_mm.end_code = (unsigned long)_etext;
  51. init_mm.end_data = (unsigned long)_edata;
  52. init_mm.brk = (unsigned long)_end;
  53. /*
  54. * We do it here, so that memory is correctly instantiated
  55. * even if "mem=xxx" cmline over-ride is not given
  56. */
  57. memblock_add(CONFIG_LINUX_LINK_BASE, arc_mem_sz);
  58. /*------------- externs in mm need setting up ---------------*/
  59. /* first page of system - kernel .vector starts here */
  60. min_low_pfn = PFN_DOWN(CONFIG_LINUX_LINK_BASE);
  61. /* Last usable page of low mem (no HIGHMEM yet for ARC port) */
  62. max_low_pfn = max_pfn = PFN_DOWN(end_mem);
  63. max_mapnr = num_physpages = max_low_pfn - min_low_pfn;
  64. /*------------- reserve kernel image -----------------------*/
  65. memblock_reserve(CONFIG_LINUX_LINK_BASE,
  66. __pa(_end) - CONFIG_LINUX_LINK_BASE);
  67. memblock_dump_all();
  68. /*-------------- node setup --------------------------------*/
  69. memset(zones_size, 0, sizeof(zones_size));
  70. zones_size[ZONE_NORMAL] = num_physpages;
  71. /*
  72. * We can't use the helper free_area_init(zones[]) because it uses
  73. * PAGE_OFFSET to compute the @min_low_pfn which would be wrong
  74. * when our kernel doesn't start at PAGE_OFFSET, i.e.
  75. * PAGE_OFFSET != CONFIG_LINUX_LINK_BASE
  76. */
  77. free_area_init_node(0, /* node-id */
  78. zones_size, /* num pages per zone */
  79. min_low_pfn, /* first pfn of node */
  80. NULL); /* NO holes */
  81. }
  82. /*
  83. * mem_init - initializes memory
  84. *
  85. * Frees up bootmem
  86. * Calculates and displays memory available/used
  87. */
  88. void __init mem_init(void)
  89. {
  90. int codesize, datasize, initsize, reserved_pages, free_pages;
  91. int tmp;
  92. high_memory = (void *)(CONFIG_LINUX_LINK_BASE + arc_mem_sz);
  93. totalram_pages = free_all_bootmem();
  94. /* count all reserved pages [kernel code/data/mem_map..] */
  95. reserved_pages = 0;
  96. for (tmp = 0; tmp < max_mapnr; tmp++)
  97. if (PageReserved(mem_map + tmp))
  98. reserved_pages++;
  99. /* XXX: nr_free_pages() is equivalent */
  100. free_pages = max_mapnr - reserved_pages;
  101. /*
  102. * For the purpose of display below, split the "reserve mem"
  103. * kernel code/data is already shown explicitly,
  104. * Show any other reservations (mem_map[ ] et al)
  105. */
  106. reserved_pages -= (((unsigned int)_end - CONFIG_LINUX_LINK_BASE) >>
  107. PAGE_SHIFT);
  108. codesize = _etext - _text;
  109. datasize = _end - _etext;
  110. initsize = __init_end - __init_begin;
  111. pr_info("Memory Available: %dM / %ldM (%dK code, %dK data, %dK init, %dK reserv)\n",
  112. PAGES_TO_MB(free_pages),
  113. TO_MB(arc_mem_sz),
  114. TO_KB(codesize), TO_KB(datasize), TO_KB(initsize),
  115. PAGES_TO_KB(reserved_pages));
  116. }
  117. static void __init free_init_pages(const char *what, unsigned long begin,
  118. unsigned long end)
  119. {
  120. unsigned long addr;
  121. pr_info("Freeing %s: %ldk [%lx] to [%lx]\n",
  122. what, TO_KB(end - begin), begin, end);
  123. /* need to check that the page we free is not a partial page */
  124. for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
  125. ClearPageReserved(virt_to_page(addr));
  126. init_page_count(virt_to_page(addr));
  127. free_page(addr);
  128. totalram_pages++;
  129. }
  130. }
  131. /*
  132. * free_initmem: Free all the __init memory.
  133. */
  134. void __init_refok free_initmem(void)
  135. {
  136. free_init_pages("unused kernel memory",
  137. (unsigned long)__init_begin,
  138. (unsigned long)__init_end);
  139. }
  140. #ifdef CONFIG_BLK_DEV_INITRD
  141. void __init free_initrd_mem(unsigned long start, unsigned long end)
  142. {
  143. free_init_pages("initrd memory", start, end);
  144. }
  145. #endif
  146. #ifdef CONFIG_OF_FLATTREE
  147. void __init early_init_dt_setup_initrd_arch(unsigned long start,
  148. unsigned long end)
  149. {
  150. pr_err("%s(%lx, %lx)\n", __func__, start, end);
  151. }
  152. #endif /* CONFIG_OF_FLATTREE */