efi: Provide a way to sync EFI reserved-memory to fdt

When booting Linux with EFI the devicetree memory-map is ignored and
Linux calls through EFI to obtain the real memory map.

When booting Linux from the EFI app, without EFI, we must pass the
reserved memory onto Linux using the devicetree.

Add a function to support this. It reads the EFI memory-map and adds any
missing regions to the reserved-memory node.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-27 15:42:18 -06:00
parent 0dc72120b7
commit eb85d76a42
3 changed files with 274 additions and 0 deletions

View File

@@ -794,6 +794,23 @@ static inline bool efi_mem_is_boot_services(int type)
*/
const char *efi_mem_type_name(enum efi_memory_type type);
/**
* efi_mem_reserved_sync() - Sync EFI memory map with DT reserved-memory nodes
*
* Compares the EFI memory map with the device tree's reserved-memory nodes and
* adds regions to the devicetree that are reserved in EFI but not mentioned in
* the devicetree's '/reserved-memory' node. This ensures that memory regions
* which EFI considers reserved are not used by the OS, e.g. because a
* hypervisor may be in use..
*
* Note: This only works with #address-cells and #size-cells of 2
*
* @fdt: Pointer to the devicetree blob
* @verbose: If true, show detailed output; if false, only show errors
* Return: Number of regions synced, or -ve on error
*/
int efi_mem_reserved_sync(void *fdt, bool verbose);
/**
* efi_dump_mem_table() - Dump out the EFI memory map
*