Skip to content

Commit d1552ce

Browse files
committed
of/fdt: move memreserve and dtb memory reservations into core
Move the /memreserve/ processing and dtb memory reservations into early_init_fdt_scan_reserved_mem. This converts arm, arm64, and powerpc as they are the only users of early_init_fdt_scan_reserved_mem. memblock_reserve is safe to call on the same region twice, so the reservation check for the dtb in powerpc 32-bit reservations is safe to remove. Signed-off-by: Rob Herring <[email protected]> Tested-by: Michal Simek <[email protected]> Cc: Russell King <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Paul Mackerras <[email protected]> Tested-by: Grant Likely <[email protected]> Tested-by: Stephen Chivers <[email protected]>
1 parent b0a6fb3 commit d1552ce

File tree

6 files changed

+16
-73
lines changed

6 files changed

+16
-73
lines changed

arch/arm/include/asm/prom.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifdef CONFIG_OF
1515

1616
extern const struct machine_desc *setup_machine_fdt(unsigned int dt_phys);
17-
extern void arm_dt_memblock_reserve(void);
1817
extern void __init arm_dt_init_cpu_maps(void);
1918

2019
#else /* CONFIG_OF */
@@ -24,7 +23,6 @@ static inline const struct machine_desc *setup_machine_fdt(unsigned int dt_phys)
2423
return NULL;
2524
}
2625

27-
static inline void arm_dt_memblock_reserve(void) { }
2826
static inline void arm_dt_init_cpu_maps(void) { }
2927

3028
#endif /* CONFIG_OF */

arch/arm/kernel/devtree.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,6 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size)
3232
arm_add_memory(base, size);
3333
}
3434

35-
void __init arm_dt_memblock_reserve(void)
36-
{
37-
u64 *reserve_map, base, size;
38-
39-
if (!initial_boot_params)
40-
return;
41-
42-
/* Reserve the dtb region */
43-
memblock_reserve(virt_to_phys(initial_boot_params),
44-
be32_to_cpu(initial_boot_params->totalsize));
45-
46-
/*
47-
* Process the reserve map. This will probably overlap the initrd
48-
* and dtb locations which are already reserved, but overlaping
49-
* doesn't hurt anything
50-
*/
51-
reserve_map = ((void*)initial_boot_params) +
52-
be32_to_cpu(initial_boot_params->off_mem_rsvmap);
53-
while (1) {
54-
base = be64_to_cpup(reserve_map++);
55-
size = be64_to_cpup(reserve_map++);
56-
if (!size)
57-
break;
58-
memblock_reserve(base, size);
59-
}
60-
}
61-
6235
#ifdef CONFIG_SMP
6336
extern struct of_cpu_method __cpu_method_of_table_begin[];
6437
extern struct of_cpu_method __cpu_method_of_table_end[];

arch/arm/mm/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ void __init arm_memblock_init(struct meminfo *mi,
317317
#endif
318318

319319
arm_mm_memblock_reserve();
320-
arm_dt_memblock_reserve();
321320

322321
/* reserve any platform specific memblock areas */
323322
if (mdesc->reserve)

arch/arm64/mm/init.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ static void arm64_memory_present(void)
126126

127127
void __init arm64_memblock_init(void)
128128
{
129-
u64 *reserve_map, base, size;
130-
131129
/* Register the kernel text, kernel data and initrd with memblock */
132130
memblock_reserve(__pa(_text), _end - _text);
133131
#ifdef CONFIG_BLK_DEV_INITRD
@@ -142,25 +140,6 @@ void __init arm64_memblock_init(void)
142140
memblock_reserve(__pa(swapper_pg_dir), SWAPPER_DIR_SIZE);
143141
memblock_reserve(__pa(idmap_pg_dir), IDMAP_DIR_SIZE);
144142

145-
/* Reserve the dtb region */
146-
memblock_reserve(virt_to_phys(initial_boot_params),
147-
be32_to_cpu(initial_boot_params->totalsize));
148-
149-
/*
150-
* Process the reserve map. This will probably overlap the initrd
151-
* and dtb locations which are already reserved, but overlapping
152-
* doesn't hurt anything
153-
*/
154-
reserve_map = ((void*)initial_boot_params) +
155-
be32_to_cpu(initial_boot_params->off_mem_rsvmap);
156-
while (1) {
157-
base = be64_to_cpup(reserve_map++);
158-
size = be64_to_cpup(reserve_map++);
159-
if (!size)
160-
break;
161-
memblock_reserve(base, size);
162-
}
163-
164143
early_init_fdt_scan_reserved_mem();
165144
dma_contiguous_reserve(0);
166145

arch/powerpc/kernel/prom.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,11 @@ static void __init early_reserve_mem_dt(void)
596596

597597
static void __init early_reserve_mem(void)
598598
{
599-
u64 base, size;
600599
__be64 *reserve_map;
601-
unsigned long self_base;
602-
unsigned long self_size;
603600

604601
reserve_map = (__be64 *)(((unsigned long)initial_boot_params) +
605602
be32_to_cpu(initial_boot_params->off_mem_rsvmap));
606603

607-
/* before we do anything, lets reserve the dt blob */
608-
self_base = __pa((unsigned long)initial_boot_params);
609-
self_size = be32_to_cpu(initial_boot_params->totalsize);
610-
memblock_reserve(self_base, self_size);
611-
612604
/* Look for the new "reserved-regions" property in the DT */
613605
early_reserve_mem_dt();
614606

@@ -637,26 +629,12 @@ static void __init early_reserve_mem(void)
637629
size_32 = be32_to_cpup(reserve_map_32++);
638630
if (size_32 == 0)
639631
break;
640-
/* skip if the reservation is for the blob */
641-
if (base_32 == self_base && size_32 == self_size)
642-
continue;
643632
DBG("reserving: %x -> %x\n", base_32, size_32);
644633
memblock_reserve(base_32, size_32);
645634
}
646635
return;
647636
}
648637
#endif
649-
DBG("Processing reserve map\n");
650-
651-
/* Handle the reserve map in the fdt blob if it exists */
652-
while (1) {
653-
base = be64_to_cpup(reserve_map++);
654-
size = be64_to_cpup(reserve_map++);
655-
if (size == 0)
656-
break;
657-
DBG("reserving: %llx -> %llx\n", base, size);
658-
memblock_reserve(base, size);
659-
}
660638
}
661639

662640
void __init early_init_devtree(void *params)

drivers/of/fdt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,25 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname,
492492
*/
493493
void __init early_init_fdt_scan_reserved_mem(void)
494494
{
495+
int n;
496+
u64 base, size;
497+
495498
if (!initial_boot_params)
496499
return;
497500

501+
/* Reserve the dtb region */
502+
early_init_dt_reserve_memory_arch(__pa(initial_boot_params),
503+
fdt_totalsize(initial_boot_params),
504+
0);
505+
506+
/* Process header /memreserve/ fields */
507+
for (n = 0; ; n++) {
508+
fdt_get_mem_rsv(initial_boot_params, n, &base, &size);
509+
if (!size)
510+
break;
511+
early_init_dt_reserve_memory_arch(base, size, 0);
512+
}
513+
498514
of_scan_flat_dt(__fdt_scan_reserved_mem, NULL);
499515
fdt_init_reserved_mem();
500516
}

0 commit comments

Comments
 (0)