git: b538d4911004 - main - Add a new sysctl in order to diffrentiate UEFI architectures
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 20 Sep 2024 14:59:22 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b538d4911004ca541507166b8ec9689d2e87d1aa commit b538d4911004ca541507166b8ec9689d2e87d1aa Author: Ahmad Khalifa <ahmadkhalifa570@gmail.com> AuthorDate: 2024-06-03 01:40:43 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-09-20 14:45:09 +0000 Add a new sysctl in order to diffrentiate UEFI architectures With the new 32-bit UEFI loader, it's convenient to have a sysctl to figure out how we booted. Can be accessed at machdep.efi_arch Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1098 --- stand/efi/loader/bootinfo.c | 8 +++++++- sys/amd64/amd64/machdep.c | 21 +++++++++++++++++++++ sys/x86/include/metadata.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 5afb4c78353e..2961b8b97fb7 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -447,9 +447,15 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) module = *modulep; file_addmetadata(kfp, MODINFOMD_MODULEP, sizeof(module), &module); #endif -#if defined(EFI) && !defined(__i386__) +#ifdef EFI +#ifndef __i386__ file_addmetadata(kfp, MODINFOMD_FW_HANDLE, sizeof(ST), &ST); #endif +#if defined(__amd64__) || defined(__i386__) + file_addmetadata(kfp, MODINFOMD_EFI_ARCH, sizeof(MACHINE_ARCH), + MACHINE_ARCH); +#endif +#endif #ifdef LOADER_GELI_SUPPORT geli_export_key_metadata(kfp); #endif diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index f4b3b9702e00..5dbc41553452 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1689,6 +1689,27 @@ SYSCTL_PROC(_machdep, OID_AUTO, efi_map, efi_map_sysctl_handler, "S,efi_map_header", "Raw EFI Memory Map"); +static int +efi_arch_sysctl_handler(SYSCTL_HANDLER_ARGS) +{ + char *arch; + caddr_t kmdp; + + kmdp = preload_search_by_type("elf kernel"); + if (kmdp == NULL) + kmdp = preload_search_by_type("elf64 kernel"); + + arch = (char *)preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_EFI_ARCH); + if (arch == NULL) + return (0); + + return (SYSCTL_OUT_STR(req, arch)); +} +SYSCTL_PROC(_machdep, OID_AUTO, efi_arch, + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, + efi_arch_sysctl_handler, "A", "EFI Firmware Architecture"); + void spinlock_enter(void) { diff --git a/sys/x86/include/metadata.h b/sys/x86/include/metadata.h index dbc6d3275e53..b3eb4b16c1ba 100644 --- a/sys/x86/include/metadata.h +++ b/sys/x86/include/metadata.h @@ -34,6 +34,7 @@ #define MODINFOMD_EFI_FB 0x1005 #define MODINFOMD_MODULEP 0x1006 #define MODINFOMD_VBE_FB 0x1007 +#define MODINFOMD_EFI_ARCH 0x1008 struct efi_map_header { uint64_t memory_size;