diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c index b132af112664bcc029b4b3540791dba48b7ea42d..140b43d3f18254e2841a04649901eb6765e6f6fc 100644 --- a/arch/loongarch/kernel/efi.c +++ b/arch/loongarch/kernel/efi.c @@ -69,8 +69,10 @@ static int __init efimap_populate_hugepages( if (pud_none(*pud)) { void *p = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!p) + if (!p) { + pr_err("can not alloc efimap huge pages!\n"); return -1; + } pmd_init(p); pud_populate(&init_mm, pud, p); } @@ -88,7 +90,8 @@ static void __init efi_map_pgt(void) { unsigned long node; unsigned long start, end; - unsigned long start_pfn, end_pfn; + efi_memory_desc_t *md; + u32 mem_type; pgd_efi = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); if (!pgd_efi) { @@ -105,13 +108,33 @@ static void __init efi_map_pgt(void) /* MMIO Registers, Uncached */ efimap_populate_hugepages(SZ_256M | (node << 44), SZ_512M | (node << 44), PAGE_KERNEL_SUC); + } - get_pfn_range_for_nid(node, &start_pfn, &end_pfn); - start = ALIGN_DOWN(start_pfn << PAGE_SHIFT, PMD_SIZE); - end = ALIGN(end_pfn << PAGE_SHIFT, PMD_SIZE); - - /* System memory, Cached */ - efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL); + /* Parse memory information */ + for_each_efi_memory_desc(md) { + mem_type = md->type; + start = ALIGN_DOWN(md->phys_addr, PMD_SIZE); + end = ALIGN(start + (md->num_pages << EFI_PAGE_SHIFT), PMD_SIZE); + node = start >> 44; + + switch (mem_type) { + case EFI_LOADER_CODE: + case EFI_LOADER_DATA: + case EFI_BOOT_SERVICES_CODE: + case EFI_BOOT_SERVICES_DATA: + case EFI_PAL_CODE: + case EFI_UNUSABLE_MEMORY: + case EFI_ACPI_RECLAIM_MEMORY: + case EFI_RESERVED_TYPE: + case EFI_RUNTIME_SERVICES_CODE: + case EFI_RUNTIME_SERVICES_DATA: + efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL); + break; + case EFI_MEMORY_MAPPED_IO: + case EFI_MEMORY_MAPPED_IO_PORT_SPACE: + efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL_SUC); + break; + } } } diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index bfe1f05b279d56150ec5278d55894db2c01ce0d4..80874fa75337fad79d76527987a7592935f52360 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -69,8 +69,6 @@ EXPORT_SYMBOL(cpu_data); struct loongson_board_info b_info; static const char dmi_empty_string[] = " "; -static phys_addr_t crashmem_start, crashmem_size; - /* * Setup information * @@ -208,15 +206,6 @@ static int __init early_parse_mem(char *p) return -EINVAL; } - start = 0; - size = memparse(p, &p); - if (*p == '@') - start = memparse(p + 1, &p); - else { - pr_err("Invalid format!\n"); - return -EINVAL; - } - /* * If a user specifies memory size, we * blow away any automatically generated @@ -224,14 +213,16 @@ static int __init early_parse_mem(char *p) */ if (usermem == 0) { usermem = 1; - if (!strstr(boot_command_line, "elfcorehdr")) { - memblock_remove(memblock_start_of_DRAM(), - memblock_end_of_DRAM() - memblock_start_of_DRAM()); - } else { - crashmem_start = start; - crashmem_size = size; - return 0; - } + memblock_remove(memblock_start_of_DRAM(), + memblock_end_of_DRAM() - memblock_start_of_DRAM()); + } + start = 0; + size = memparse(p, &p); + if (*p == '@') + start = memparse(p + 1, &p); + else { + pr_err("Invalid format!\n"); + return -EINVAL; } if (!IS_ENABLED(CONFIG_NUMA)) @@ -378,59 +369,11 @@ static void __init bootcmdline_init(char **cmdline_p) *cmdline_p = boot_command_line; } -/* - * After the kdump operation is performed to enter the capture kernel, the - * memory area used by the previous production kernel should be reserved to - * avoid destroy to the captured data. - */ -static void reserve_oldmem_region(int node, unsigned long s0, unsigned long e0) -{ -#ifdef CONFIG_CRASH_DUMP - unsigned long s1, e1; - - if (!is_kdump_kernel()) - return; - - if ((e0 - s0) > (SZ_1G >> PAGE_SHIFT)) - e0 = e0 - (SZ_512M >> PAGE_SHIFT); - - /* crashmem_start is crashk_res reserved by primary production kernel */ - s1 = PFN_UP(crashmem_start); - e1 = PFN_DOWN(crashmem_start + crashmem_size); - - if (s1 == 0) - return; - - if (node == 0) { - memblock_reserve(PFN_PHYS(s0), (s1 - s0) << PAGE_SHIFT); - memblock_reserve(PFN_PHYS(e1), (e0 - e1) << PAGE_SHIFT); - } else { - memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); - } -#endif -} - -/* Traditionally, LoongArch's contiguous low memory is 256M, so crashkernel=X@Y is - * unable to be large enough in some cases. Thus, if the total memory of a node - * is more than 1GB, we reserve the top 512MB for the capture kernel - */ -static void reserve_crashm_region(int node, unsigned long s0, unsigned long e0) -{ -#ifdef CONFIG_KEXEC - if (crashk_res.start == crashk_res.end) - return; - - if ((e0 - s0) <= (SZ_1G >> PAGE_SHIFT)) - return; - - s0 = e0 - (SZ_512M >> PAGE_SHIFT); - - memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); -#endif -} - void __init platform_init(void) { + arch_reserve_vmcore(); + arch_parse_crashkernel(); + #ifdef CONFIG_ACPI_TABLE_UPGRADE acpi_table_upgrade(); #endif @@ -468,17 +411,6 @@ static void __init check_kernel_sections_mem(void) */ static void __init arch_mem_init(char **cmdline_p) { - unsigned int node; - unsigned long start_pfn, end_pfn; - - arch_reserve_vmcore(); - arch_parse_crashkernel(); - for_each_online_node(node) { - get_pfn_range_for_nid(node, &start_pfn, &end_pfn); - reserve_crashm_region(node, start_pfn, end_pfn); - reserve_oldmem_region(node, start_pfn, end_pfn); - } - if (usermem) pr_info("User-defined physical RAM map overwrite\n");