20 #include <linux/kernel.h>
21 #include <linux/export.h>
22 #include <linux/errno.h>
26 #include <linux/mman.h>
35 #include <asm/sections.h>
36 #include <asm/setup.h>
37 #include <asm/sizes.h>
42 static unsigned long phys_initrd_start
__initdata = 0;
43 static unsigned long phys_initrd_size
__initdata = 0;
50 phys_initrd_start =
start;
51 phys_initrd_size = end -
start;
54 static int __init early_initrd(
char *
p)
63 phys_initrd_start =
start;
64 phys_initrd_size =
size;
70 #define MAX_DMA32_PFN ((4UL * 1024 * 1024 * 1024) >> PAGE_SHIFT)
72 static void __init zone_sizes_init(
unsigned long min,
unsigned long max)
74 struct memblock_region *
reg;
75 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
76 unsigned long max_dma32 =
min;
78 memset(zone_size, 0,
sizeof(zone_size));
80 #ifdef CONFIG_ZONE_DMA32
83 zone_size[ZONE_DMA32] =
max(min, max_dma32) -
min;
87 memcpy(zhole_size, zone_size,
sizeof(zhole_size));
89 for_each_memblock(
memory, reg) {
90 unsigned long start = memblock_region_memory_base_pfn(reg);
91 unsigned long end = memblock_region_memory_end_pfn(reg);
95 #ifdef CONFIG_ZONE_DMA32
96 if (start < max_dma32) {
97 unsigned long dma_end =
min(end, max_dma32);
98 zhole_size[ZONE_DMA32] -= dma_end -
start;
101 if (end > max_dma32) {
102 unsigned long normal_end =
min(end, max);
103 unsigned long normal_start =
max(start, max_dma32);
104 zhole_size[
ZONE_NORMAL] -= normal_end - normal_start;
111 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
119 #ifndef CONFIG_SPARSEMEM
120 static void arm64_memory_present(
void)
124 static void arm64_memory_present(
void)
126 struct memblock_region *
reg;
128 for_each_memblock(
memory, reg)
130 memblock_region_memory_end_pfn(reg));
140 #ifdef CONFIG_BLK_DEV_INITRD
141 if (phys_initrd_size) {
191 arm64_memory_present();
194 zone_sizes_init(min, max);
200 static inline int free_area(
unsigned long pfn,
unsigned long end,
char *
s)
204 for (; pfn <
end; pfn++) {
206 ClearPageReserved(page);
207 init_page_count(page);
213 pr_info(
"Freeing %s memory: %dK\n", s, size);
221 static inline void poison_init_mem(
void *s,
size_t count)
226 #ifndef CONFIG_SPARSEMEM_VMEMMAP
227 static inline void free_memmap(
unsigned long start_pfn,
unsigned long end_pfn)
229 struct page *start_pg, *end_pg;
230 unsigned long pg, pgend;
256 static void __init free_unused_memmap(
void)
258 unsigned long start, prev_end = 0;
259 struct memblock_region *
reg;
261 for_each_memblock(
memory, reg) {
264 #ifdef CONFIG_SPARSEMEM
269 start =
min(start,
ALIGN(prev_end, PAGES_PER_SECTION));
275 if (prev_end && prev_end < start)
276 free_memmap(prev_end, start);
287 #ifdef CONFIG_SPARSEMEM
289 free_memmap(prev_end,
ALIGN(prev_end, PAGES_PER_SECTION));
302 struct memblock_region *
reg;
308 #ifndef CONFIG_SPARSEMEM_VMEMMAP
310 free_unused_memmap();
315 reserved_pages = free_pages = 0;
317 for_each_memblock(
memory, reg) {
318 unsigned int pfn1, pfn2;
328 if (PageReserved(page))
330 else if (!page_count(page))
333 }
while (page < end);
342 for_each_memblock(
memory, reg) {
343 unsigned long pages = memblock_region_memory_end_pfn(reg) -
344 memblock_region_memory_base_pfn(reg);
350 pr_notice(
"Memory: %luk/%luk available, %luk reserved\n",
355 #define MLK(b, t) b, t, ((t) - (b)) >> 10
356 #define MLM(b, t) b, t, ((t) - (b)) >> 20
357 #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
359 pr_notice(
"Virtual kernel memory layout:\n"
360 " vmalloc : 0x%16lx - 0x%16lx (%6ld MB)\n"
361 #ifdef CONFIG_SPARSEMEM_VMEMMAP
362 " vmemmap : 0x%16lx - 0x%16lx (%6ld MB)\n"
364 " modules : 0x%16lx - 0x%16lx (%6ld MB)\n"
365 " memory : 0x%16lx - 0x%16lx (%6ld MB)\n"
366 " .init : 0x%p" " - 0x%p" " (%6ld kB)\n"
367 " .text : 0x%p" " - 0x%p" " (%6ld kB)\n"
368 " .data : 0x%p" " - 0x%p" " (%6ld kB)\n",
370 #ifdef CONFIG_SPARSEMEM_VMEMMAP
413 #ifdef CONFIG_BLK_DEV_INITRD
415 static int keep_initrd;
420 poison_init_mem((
void *)start,
PAGE_ALIGN(end) - start);
433 __setup(
"keepinitrd", keepinitrd_setup);