efi: Use EVT_RESERVE_BOARD to reserve memory for efi_priv

Use the EVT_RESERVE_BOARD event handler to allocate the efi_priv struct
in the normal memory area. This avoids the caller needing to keep it on
the stack.

Copy the struct to the new place and start using it there.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-11-01 18:23:09 +01:00
parent 7477fe4d9b
commit 89611203f0
3 changed files with 50 additions and 0 deletions

View File

@@ -621,6 +621,16 @@ struct efi_priv *efi_get_priv(void);
*/ */
void efi_set_priv(struct efi_priv *priv); void efi_set_priv(struct efi_priv *priv);
/**
* efi_move_priv() - Move EFI-private information to a new location
*
* Copies the existing EFI-private data to a new location and updates the
* global pointer. If there is no existing data, just sets the pointer.
*
* @new_priv: New location for private data
*/
void efi_move_priv(struct efi_priv *new_priv);
/** /**
* efi_get_sys_table() - Get access to the main EFI system table * efi_get_sys_table() - Get access to the main EFI system table
* *

View File

@@ -57,6 +57,12 @@ void efi_set_priv(struct efi_priv *priv)
global_priv = priv; global_priv = priv;
} }
void efi_move_priv(struct efi_priv *new_priv)
{
*new_priv = *global_priv;
global_priv = new_priv;
}
struct efi_system_table *efi_get_sys_table(void) struct efi_system_table *efi_get_sys_table(void)
{ {
return global_priv->sys_table; return global_priv->sys_table;

View File

@@ -33,6 +33,7 @@
#include <dm/lists.h> #include <dm/lists.h>
#include <dm/root.h> #include <dm/root.h>
#include <mapmem.h> #include <mapmem.h>
#include <event.h>
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
@@ -389,6 +390,39 @@ U_BOOT_DRIVER(efi_sysreset) = {
.ops = &efi_sysreset_ops, .ops = &efi_sysreset_ops,
}; };
/**
* efi_reserve_priv() - Event handler to reserve memory for struct efi_priv
*
* This handler is called during EVT_RESERVE_BOARD event to reserve memory
* for the efi_priv structure before other reservations.
*
* @ctx: Event context (unused)
* @event: Event information containing reserve_board data
* Return: 0 on success
*/
static int efi_reserve_priv(void *ctx, struct event *event)
{
struct event_reserve_board *reserve = &event->data.reserve_board;
struct efi_priv *priv;
ulong addr;
/* Reserve memory for efi_priv using the provided stack pointer */
addr = ALIGN_DOWN(reserve->start_addr_sp - sizeof(struct efi_priv), 16);
priv = map_sysmem(addr, sizeof(struct efi_priv));
/* Update stack pointer for next reservation */
reserve->start_addr_sp = addr;
/* Move existing priv data (from stack) to reserved location */
efi_move_priv(priv);
log_debug("Reserving %zu bytes for EFI priv at: %08lx\n",
sizeof(struct efi_priv), addr);
return 0;
}
EVENT_SPY_FULL(EVT_RESERVE_BOARD, efi_reserve_priv);
efi_status_t efi_startup(efi_handle_t image, struct efi_system_table *systab) efi_status_t efi_startup(efi_handle_t image, struct efi_system_table *systab)
{ {
struct efi_priv local_priv, *priv = &local_priv; struct efi_priv local_priv, *priv = &local_priv;