arm: switch to subr_efi_map.c

Reduce code duplication by switching to the new shared interface.
Practically, the kernel may lose a few pages to (unused) EFI runtime
services.

Reviewed by:	andrew
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D49132
This commit is contained in:
Mitchell Horne 2025-03-03 11:45:32 -04:00
parent cb0fb28129
commit 8bfd5cefbc
4 changed files with 21 additions and 116 deletions

View file

@ -56,6 +56,7 @@
#include <sys/cpu.h>
#include <sys/devmap.h>
#include <sys/efi.h>
#include <sys/efi_map.h>
#include <sys/imgact.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
@ -462,20 +463,22 @@ initarm(struct arm_boot_params *abp)
efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp,
MODINFO_METADATA | MODINFOMD_EFI_MAP);
if (efihdr != NULL) {
arm_add_efi_map_entries(efihdr, mem_regions, &mem_regions_sz);
efi_map_add_entries(efihdr);
efi_map_exclude_entries(efihdr);
} else
#endif
{
/* Grab physical memory regions information from device tree. */
if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,NULL) != 0)
panic("Cannot get physical memory regions");
}
physmem_hardware_regions(mem_regions, mem_regions_sz);
/* Grab reserved memory regions information from device tree. */
if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
physmem_exclude_regions(mem_regions, mem_regions_sz,
EXFLAG_NODUMP | EXFLAG_NOALLOC);
physmem_hardware_regions(mem_regions, mem_regions_sz);
/* Grab reserved memory regions information from device tree. */
if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
physmem_exclude_regions(mem_regions, mem_regions_sz,
EXFLAG_NODUMP | EXFLAG_NOALLOC);
}
/*
* Set TEX remapping registers.
@ -632,6 +635,14 @@ initarm(struct arm_boot_params *abp)
arm_kdb_init();
/* Apply possible BP hardening. */
cpuinfo_init_bp_hardening();
#ifdef EFI
if (boothowto & RB_VERBOSE) {
if (efihdr != NULL)
efi_map_print_entries(efihdr);
}
#endif
return ((void *)STACKALIGN(thread0.td_pcb));
}

View file

@ -389,110 +389,3 @@ fake_preload_metadata(struct arm_boot_params *abp __unused, void *dtb_ptr,
return (lastaddr);
}
#ifdef EFI
void
arm_add_efi_map_entries(struct efi_map_header *efihdr, struct mem_region *mr,
int *mrcnt)
{
struct efi_md *map, *p;
const char *type;
size_t efisz;
int ndesc, i, j;
static const char *types[] = {
"Reserved",
"LoaderCode",
"LoaderData",
"BootServicesCode",
"BootServicesData",
"RuntimeServicesCode",
"RuntimeServicesData",
"ConventionalMemory",
"UnusableMemory",
"ACPIReclaimMemory",
"ACPIMemoryNVS",
"MemoryMappedIO",
"MemoryMappedIOPortSpace",
"PalCode",
"PersistentMemory"
};
*mrcnt = 0;
/*
* Memory map data provided by UEFI via the GetMemoryMap
* Boot Services API.
*/
efisz = roundup2(sizeof(struct efi_map_header), 0x10);
map = (struct efi_md *)((uint8_t *)efihdr + efisz);
if (efihdr->descriptor_size == 0)
return;
ndesc = efihdr->memory_size / efihdr->descriptor_size;
if (boothowto & RB_VERBOSE)
printf("%23s %12s %12s %8s %4s\n",
"Type", "Physical", "Virtual", "#Pages", "Attr");
for (i = 0, j = 0, p = map; i < ndesc; i++,
p = efi_next_descriptor(p, efihdr->descriptor_size)) {
if (boothowto & RB_VERBOSE) {
if (p->md_type < nitems(types))
type = types[p->md_type];
else
type = "<INVALID>";
printf("%23s %012llx %012llx %08llx ", type, p->md_phys,
p->md_virt, p->md_pages);
if (p->md_attr & EFI_MD_ATTR_UC)
printf("UC ");
if (p->md_attr & EFI_MD_ATTR_WC)
printf("WC ");
if (p->md_attr & EFI_MD_ATTR_WT)
printf("WT ");
if (p->md_attr & EFI_MD_ATTR_WB)
printf("WB ");
if (p->md_attr & EFI_MD_ATTR_UCE)
printf("UCE ");
if (p->md_attr & EFI_MD_ATTR_WP)
printf("WP ");
if (p->md_attr & EFI_MD_ATTR_RP)
printf("RP ");
if (p->md_attr & EFI_MD_ATTR_XP)
printf("XP ");
if (p->md_attr & EFI_MD_ATTR_NV)
printf("NV ");
if (p->md_attr & EFI_MD_ATTR_MORE_RELIABLE)
printf("MORE_RELIABLE ");
if (p->md_attr & EFI_MD_ATTR_RO)
printf("RO ");
if (p->md_attr & EFI_MD_ATTR_RT)
printf("RUNTIME");
printf("\n");
}
switch (p->md_type) {
case EFI_MD_TYPE_CODE:
case EFI_MD_TYPE_DATA:
case EFI_MD_TYPE_BS_CODE:
case EFI_MD_TYPE_BS_DATA:
case EFI_MD_TYPE_FREE:
/*
* We're allowed to use any entry with these types.
*/
break;
default:
continue;
}
j++;
if (j >= FDT_MEM_REGIONS)
break;
mr[j].mr_start = p->md_phys;
mr[j].mr_size = p->md_pages * EFI_PAGE_SIZE;
}
*mrcnt = j;
}
#endif /* EFI */

View file

@ -108,6 +108,7 @@ kern/msi_if.m optional intrng
kern/pic_if.m optional intrng
kern/subr_busdma_bufalloc.c standard
kern/subr_devmap.c standard
kern/subr_efi_map.c optional efi
kern/subr_physmem.c standard
kern/subr_sfbuf.c standard
libkern/arm/aeabi_unwind.c standard

View file

@ -139,8 +139,8 @@ print_efi_map_entry(struct efi_md *p, void *argp __unused)
type = types[p->md_type];
else
type = "<INVALID>";
printf("%23s %012lx %012lx %08lx ", type, p->md_phys,
p->md_virt, p->md_pages);
printf("%23s %012jx %012jx %08jx ", type, (uintmax_t)p->md_phys,
(uintmax_t)p->md_virt, (uintmax_t)p->md_pages);
if (p->md_attr & EFI_MD_ATTR_UC)
printf("UC ");
if (p->md_attr & EFI_MD_ATTR_WC)