Skip to content

Commit

Permalink
LoongArch: fix efi map page table error
Browse files Browse the repository at this point in the history
Fixes: d7aad0c ("LoongArch: add kernel setvirtmap for runtime")
Signed-off-by: Yun Liu <[email protected]>
Signed-off-by: Hongchen Zhang <[email protected]>
Signed-off-by: Yanteng Si <[email protected]>
  • Loading branch information
Yanteng Si committed Jun 13, 2024
1 parent 16b46d9 commit a74a325
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions arch/loongarch/kernel/efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit a74a325

Please sign in to comment.