git: 8bfd5cefbc71 - main - arm: switch to subr_efi_map.c
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 03 Mar 2025 16:12:26 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=8bfd5cefbc7143adffa34d74bc539802a01f0f26
commit 8bfd5cefbc7143adffa34d74bc539802a01f0f26
Author: Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2025-03-03 15:45:32 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2025-03-03 16:12:15 +0000
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
---
sys/arm/arm/machdep.c | 25 ++++++++---
sys/arm/arm/machdep_boot.c | 107 ---------------------------------------------
sys/conf/files.arm | 1 +
sys/kern/subr_efi_map.c | 4 +-
4 files changed, 21 insertions(+), 116 deletions(-)
diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c
index e45ef9834e81..31f888313d59 100644
--- a/sys/arm/arm/machdep.c
+++ b/sys/arm/arm/machdep.c
@@ -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));
}
diff --git a/sys/arm/arm/machdep_boot.c b/sys/arm/arm/machdep_boot.c
index e2416f86ad23..8a6c63af3c92 100644
--- a/sys/arm/arm/machdep_boot.c
+++ b/sys/arm/arm/machdep_boot.c
@@ -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 */
diff --git a/sys/conf/files.arm b/sys/conf/files.arm
index 5ada97ccad30..0188dda87c96 100644
--- a/sys/conf/files.arm
+++ b/sys/conf/files.arm
@@ -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
diff --git a/sys/kern/subr_efi_map.c b/sys/kern/subr_efi_map.c
index 29a94858f6c1..4085d7f1cdb9 100644
--- a/sys/kern/subr_efi_map.c
+++ b/sys/kern/subr_efi_map.c
@@ -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)