This hypercall can be used to get the ESRT from the hypervisor. It returning successfully also indicates that Xen has reserved the ESRT and it can safely be parsed by dom0. --- xen/common/efi/boot.c | 15 ++++++++++----- xen/common/efi/efi.h | 2 ++ xen/common/efi/runtime.c | 14 ++++++++++++++ xen/include/public/platform.h | 7 +++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 31664818c1..01b2409c5e 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -567,8 +567,6 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image) } #endif -static UINTN __initdata esrt = EFI_INVALID_TABLE_ADDR; - static bool __init is_esrt_valid( const EFI_MEMORY_DESCRIPTOR *const desc) { @@ -594,9 +592,13 @@ static bool __init is_esrt_valid( esrt_ptr = (const ESRT *)esrt; if ( esrt_ptr->Version != 1 || !esrt_ptr->Count ) return false; - return esrt_ptr->Count <= - (available_len - sizeof(*esrt_ptr)) / - sizeof(esrt_ptr->Entries[0]); + if ( esrt_ptr->Count > + (available_len - sizeof(*esrt_ptr)) / + sizeof(esrt_ptr->Entries[0]) ) + return false; + esrt_size = sizeof(*esrt_ptr) + + esrt_ptr->Count * sizeof(esrt_ptr->Entries[0]); + return true; } /* @@ -1121,6 +1123,9 @@ static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste } } + if ( esrt_desc == (const EFI_MEMORY_DESCRIPTOR *)EFI_INVALID_TABLE_ADDR ) + esrt = EFI_INVALID_TABLE_ADDR; + efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size, efi_mdesc_size, mdesc_ver); diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 02f499071a..0736662ebc 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -46,6 +46,8 @@ extern const EFI_RUNTIME_SERVICES *efi_rs; extern UINTN efi_memmap_size, efi_mdesc_size; extern void *efi_memmap; extern const EFI_MEMORY_DESCRIPTOR *esrt_desc; +extern UINTN esrt; +extern UINTN esrt_size; #ifdef CONFIG_X86 extern mfn_t efi_l4_mfn; diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 0d09647952..4466d5379c 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -227,6 +227,12 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n) #endif /* COMPAT */ #ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ + +#ifndef COMPAT +UINTN esrt = EFI_INVALID_TABLE_ADDR; +UINTN esrt_size = 0; +#endif + int efi_get_info(uint32_t idx, union xenpf_efi_info *info) { unsigned int i, n; @@ -311,6 +317,14 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) info->apple_properties.size = efi_apple_properties_len; break; + case XEN_FW_EFI_ESRT: + if ( esrt_desc == (const EFI_MEMORY_DESCRIPTOR *)EFI_INVALID_TABLE_ADDR ) + return -ENODATA; + if ( info->esrt.size < esrt_size ) + return -ERANGE; + if ( copy_to_guest(info->esrt.table, (const ESRT *)esrt, esrt_size) ) + return -EFAULT; + break; default: return -EINVAL; } diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 8100133509..a848df2066 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -243,6 +243,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_efi_runtime_call_t); #define XEN_FW_EFI_RT_VERSION 4 #define XEN_FW_EFI_PCI_ROM 5 #define XEN_FW_EFI_APPLE_PROPERTIES 6 +#define XEN_FW_EFI_ESRT 7 #define XEN_FW_KBD_SHIFT_FLAGS 5 struct xenpf_firmware_info { /* IN variables. */ @@ -307,6 +308,12 @@ struct xenpf_firmware_info { uint64_t address; xen_ulong_t size; } apple_properties; + struct { + /* IN variables */ + uint64_t size; + /* OUT variables */ + XEN_GUEST_HANDLE(void) table; + } esrt; } efi_info; /* XEN_FW_EFI_INFO */ /* Int16, Fn02: Get keyboard shift flags. */ -- Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab