From 3a989b2b1f34618a3c3d8e94d25aba0c5d2cf816 Mon Sep 17 00:00:00 2001 From: Youling Tang Date: Mon, 6 Feb 2023 09:49:14 +0800 Subject: [PATCH] LoongArch: Integrate initrd operation LoongArch inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I736HO -------------------------------- Integrate initrd operations to avoid reserving initrd space multiple times during kexec/kdump. Signed-off-by: Youling Tang Change-Id: Idb8a10c2143e7ff4682328f620de8d5b3e35b105 (cherry picked from commit 37b09006e621dce876410bb30540273c57a99656) --- arch/loongarch/kernel/legacy_boot.c | 91 +++-------------------------- arch/loongarch/kernel/legacy_boot.h | 2 + arch/loongarch/kernel/setup.c | 2 +- 3 files changed, 12 insertions(+), 83 deletions(-) diff --git a/arch/loongarch/kernel/legacy_boot.c b/arch/loongarch/kernel/legacy_boot.c index 93ce1a6a6a8c..15940f045dbe 100644 --- a/arch/loongarch/kernel/legacy_boot.c +++ b/arch/loongarch/kernel/legacy_boot.c @@ -303,79 +303,9 @@ int setup_legacy_IRQ(void) * Manage initrd */ #ifdef CONFIG_BLK_DEV_INITRD -static unsigned long init_initrd(unsigned long ps, unsigned long z) -{ - static int initalized; - - if (!ps || !z) - return 0; - - initrd_start = (unsigned long)__va(ps); - initrd_end = initrd_start + z; - /* - * Board specific code or command line parser should have - * already set up initrd_start and initrd_end. In these cases - * perfom sanity checks and use them if all looks good. - */ - if (initrd_start < PAGE_OFFSET || initrd_end <= initrd_start) { - pr_err("initrd start load address error!"); - goto disable; - } - - if (initrd_start & ~PAGE_MASK) { - pr_err("initrd start must be page aligned\n"); - goto disable; - } - - memblock_reserve(__pa(initrd_start), z); - initrd_below_start_ok = 1; - - if (!initalized) - pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n", - initrd_start, z); - initalized = 1; - - return 0; -disable: - printk(KERN_CONT " - disabling initrd\n"); - initrd_start = 0; - initrd_end = 0; - return 0; -} - -static int early_initrd(char *p) -{ - unsigned long start, size; - char *endp; - - if (!efi_bp) - return 0; - start = memparse(p, &endp); - if (*endp == ',') - size = memparse(endp + 1, NULL); - - if (start + size > PFN_PHYS(max_low_pfn)) { - pr_err(KERN_INFO "Initrd physical address is out of memory!"); - return 0; - } - - init_initrd(start, size); - - return 0; -} -early_param("initrd", early_initrd); - static int rd_start_early(char *p) { - unsigned long start; - - if (!efi_bp) - return 0; - - start = memparse(p, &p); - initrd_start = start; - initrd_end += start; - init_initrd(__pa(start), initrd_end - start); + phys_initrd_start = __pa(memparse(p, &p)); return 0; } @@ -383,24 +313,21 @@ early_param("rd_start", rd_start_early); static int rd_size_early(char *p) { - unsigned long size; - - if (!efi_bp) - return 0; - size = memparse(p, &p); - initrd_end += size; + phys_initrd_size = memparse(p, &p); - init_initrd(__pa(initrd_start), size); return 0; } early_param("rd_size", rd_size_early); +#endif -#else /* !CONFIG_BLK_DEV_INITRD */ -static unsigned long init_initrd(void) +void __init loongarch_reserve_initrd_mem(void) { - return 0; + /* The small fdt method should be skipped directly to avoid two reserved operations. */ + if (!fw_arg2) + return; + + reserve_initrd_mem(); } -#endif void fw_init_cmdline(unsigned long argc, unsigned long cmdp) { diff --git a/arch/loongarch/kernel/legacy_boot.h b/arch/loongarch/kernel/legacy_boot.h index 1d6b42a26460..b52d8aa262dc 100644 --- a/arch/loongarch/kernel/legacy_boot.h +++ b/arch/loongarch/kernel/legacy_boot.h @@ -87,4 +87,6 @@ extern int __init pch_msi_parse_madt(union acpi_subtable_headers *header, const unsigned long end); extern struct irq_domain *get_pchpic_irq_domain(void); + +extern void __init loongarch_reserve_initrd_mem(void); #endif diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index d19df19d67d5..9c2196e166d2 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -461,7 +461,7 @@ void __init setup_arch(char **cmdline_p) memblock_init(); pagetable_init(); parse_early_param(); - reserve_initrd_mem(); + loongarch_reserve_initrd_mem(); platform_init(); arch_mem_init(cmdline_p); -- GitLab