Commit 6abec12c authored by Hari Bathini's avatar Hari Bathini Committed by Michael Ellerman

powerpc/fadump: improve fadump_reserve_mem()

Some code clean-up like using minimal assignments and updating printk
messages. Also, add an 'error_out' label for handling error cleanup
at one place.
Signed-off-by: default avatarHari Bathini <hbathini@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/156821343485.5656.10202857091553646948.stgit@hbathini.in.ibm.com
parent 41df5928
...@@ -338,16 +338,15 @@ static void __init fadump_reserve_crash_area(unsigned long base, ...@@ -338,16 +338,15 @@ static void __init fadump_reserve_crash_area(unsigned long base,
int __init fadump_reserve_mem(void) int __init fadump_reserve_mem(void)
{ {
unsigned long base, size, memory_boundary; u64 base, size, mem_boundary;
int ret = 1;
if (!fw_dump.fadump_enabled) if (!fw_dump.fadump_enabled)
return 0; return 0;
if (!fw_dump.fadump_supported) { if (!fw_dump.fadump_supported) {
printk(KERN_INFO "Firmware-assisted dump is not supported on" pr_info("Firmware-Assisted Dump is not supported on this hardware\n");
" this hardware\n"); goto error_out;
fw_dump.fadump_enabled = 0;
return 0;
} }
/* /*
* Initialize boot memory size * Initialize boot memory size
...@@ -355,7 +354,8 @@ int __init fadump_reserve_mem(void) ...@@ -355,7 +354,8 @@ int __init fadump_reserve_mem(void)
* first kernel. * first kernel.
*/ */
if (!fw_dump.dump_active) { if (!fw_dump.dump_active) {
fw_dump.boot_memory_size = fadump_calculate_reserve_size(); fw_dump.boot_memory_size =
PAGE_ALIGN(fadump_calculate_reserve_size());
#ifdef CONFIG_CMA #ifdef CONFIG_CMA
if (!fw_dump.nocma) if (!fw_dump.nocma)
fw_dump.boot_memory_size = fw_dump.boot_memory_size =
...@@ -381,10 +381,11 @@ int __init fadump_reserve_mem(void) ...@@ -381,10 +381,11 @@ int __init fadump_reserve_mem(void)
" dump, now %#016llx\n", memory_limit); " dump, now %#016llx\n", memory_limit);
} }
if (memory_limit) if (memory_limit)
memory_boundary = memory_limit; mem_boundary = memory_limit;
else else
memory_boundary = memblock_end_of_DRAM(); mem_boundary = memblock_end_of_DRAM();
base = fw_dump.boot_memory_size;
size = get_fadump_area_size(); size = get_fadump_area_size();
fw_dump.reserve_dump_area_size = size; fw_dump.reserve_dump_area_size = size;
if (fw_dump.dump_active) { if (fw_dump.dump_active) {
...@@ -404,8 +405,7 @@ int __init fadump_reserve_mem(void) ...@@ -404,8 +405,7 @@ int __init fadump_reserve_mem(void)
* dump is written to disk by userspace tool. This memory * dump is written to disk by userspace tool. This memory
* will be released for general use once the dump is saved. * will be released for general use once the dump is saved.
*/ */
base = fw_dump.boot_memory_size; size = mem_boundary - base;
size = memory_boundary - base;
fadump_reserve_crash_area(base, size); fadump_reserve_crash_area(base, size);
pr_debug("fadumphdr_addr = %#016lx\n", fw_dump.fadumphdr_addr); pr_debug("fadumphdr_addr = %#016lx\n", fw_dump.fadumphdr_addr);
...@@ -418,29 +418,31 @@ int __init fadump_reserve_mem(void) ...@@ -418,29 +418,31 @@ int __init fadump_reserve_mem(void)
* use memblock_find_in_range() here since it doesn't allocate * use memblock_find_in_range() here since it doesn't allocate
* from bottom to top. * from bottom to top.
*/ */
for (base = fw_dump.boot_memory_size; while (base <= (mem_boundary - size)) {
base <= (memory_boundary - size);
base += size) {
if (memblock_is_region_memory(base, size) && if (memblock_is_region_memory(base, size) &&
!memblock_is_region_reserved(base, size)) !memblock_is_region_reserved(base, size))
break; break;
base += size;
} }
if ((base > (memory_boundary - size)) ||
if ((base > (mem_boundary - size)) ||
memblock_reserve(base, size)) { memblock_reserve(base, size)) {
pr_err("Failed to reserve memory\n"); pr_err("Failed to reserve memory!\n");
return 0; goto error_out;
} }
pr_info("Reserved %ldMB of memory at %ldMB for firmware-" pr_info("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n",
"assisted dump (System RAM: %ldMB)\n", (size >> 20), base, (memblock_phys_mem_size() >> 20));
(unsigned long)(size >> 20),
(unsigned long)(base >> 20),
(unsigned long)(memblock_phys_mem_size() >> 20));
fw_dump.reserve_dump_area_start = base; fw_dump.reserve_dump_area_start = base;
return fadump_cma_init(); ret = fadump_cma_init();
} }
return 1;
return ret;
error_out:
fw_dump.fadump_enabled = 0;
return 0;
} }
unsigned long __init arch_reserved_kernel_pages(void) unsigned long __init arch_reserved_kernel_pages(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment