[PATCH v8 11/25] efi: Share struct efi_priv between the app and stub code
Heinrich Schuchardt
xypron.glpk at gmx.de
Fri Dec 31 06:11:32 CET 2021
On 12/29/21 19:57, Simon Glass wrote:
> At present each of these has its own static variable and helper functions.
> Move them into a shared file.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
> include/efi.h | 21 +++++++++++++++++++++
> lib/efi/efi.c | 29 +++++++++++++++++++++++++++++
> lib/efi/efi_app.c | 21 ++-------------------
> lib/efi/efi_stub.c | 7 ++++---
> 4 files changed, 56 insertions(+), 22 deletions(-)
>
> diff --git a/include/efi.h b/include/efi.h
> index 57ca2f424ab..d4785478585 100644
> --- a/include/efi.h
> +++ b/include/efi.h
> @@ -474,6 +474,27 @@ extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
> EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
> EFI_VARIABLE_APPEND_WRITE)
>
> +/**
> + * efi_get_priv() - Get access to the EFI-private information
> + *
> + * This struct it used by both the stub and the app to record things about the
> + * EFI environment. It is not available in U-Boot proper after the stub has
> + * jumped there. Use efi_info_get() to obtain info in that case.
> + *
> + * @return pointer to private info
%s/@return/Return:/
See
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
I will correct this when merging.
Best regards
Heinrich
> + */
> +struct efi_priv *efi_get_priv(void);
> +
> +/**
> + * efi_set_priv() - Set up a pointer to the EFI-private information
> + *
> + * This is called in the stub and app to record the location of this
> + * information.
> + *
> + * @priv: New location of private data
> + */
> +void efi_set_priv(struct efi_priv *priv);
> +
> /**
> * efi_get_sys_table() - Get access to the main EFI system table
> *
> diff --git a/lib/efi/efi.c b/lib/efi/efi.c
> index 69e52e45748..cd6bf47b180 100644
> --- a/lib/efi/efi.c
> +++ b/lib/efi/efi.c
> @@ -1,5 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0+
> /*
> + * Functions shared by the app and stub
> + *
> * Copyright (c) 2015 Google, Inc
> *
> * EFI information obtained here:
> @@ -17,6 +19,33 @@
> #include <efi.h>
> #include <efi_api.h>
>
> +static struct efi_priv *global_priv;
> +
> +struct efi_priv *efi_get_priv(void)
> +{
> + return global_priv;
> +}
> +
> +void efi_set_priv(struct efi_priv *priv)
> +{
> + global_priv = priv;
> +}
> +
> +struct efi_system_table *efi_get_sys_table(void)
> +{
> + return global_priv->sys_table;
> +}
> +
> +struct efi_boot_services *efi_get_boot(void)
> +{
> + return global_priv->boot;
> +}
> +
> +unsigned long efi_get_ram_base(void)
> +{
> + return global_priv->ram_base;
> +}
> +
> /*
> * Global declaration of gd.
> *
> diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
> index 852cf3679d6..2f1feda1b1e 100644
> --- a/lib/efi/efi_app.c
> +++ b/lib/efi/efi_app.c
> @@ -27,23 +27,6 @@
>
> DECLARE_GLOBAL_DATA_PTR;
>
> -static struct efi_priv *global_priv;
> -
> -struct efi_system_table *efi_get_sys_table(void)
> -{
> - return global_priv->sys_table;
> -}
> -
> -struct efi_boot_services *efi_get_boot(void)
> -{
> - return global_priv->boot;
> -}
> -
> -unsigned long efi_get_ram_base(void)
> -{
> - return global_priv->ram_base;
> -}
> -
> int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
> {
> return -ENOSYS;
> @@ -318,7 +301,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
> /* Set up access to EFI data structures */
> efi_init(priv, "App", image, sys_table);
>
> - global_priv = priv;
> + efi_set_priv(priv);
>
> /*
> * Set up the EFI debug UART so that printf() works. This is
> @@ -344,7 +327,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
>
> static void efi_exit(void)
> {
> - struct efi_priv *priv = global_priv;
> + struct efi_priv *priv = efi_get_priv();
>
> free_memory(priv);
> printf("U-Boot EFI exiting\n");
> diff --git a/lib/efi/efi_stub.c b/lib/efi/efi_stub.c
> index 31f1e1a72a1..c89ae7c9072 100644
> --- a/lib/efi/efi_stub.c
> +++ b/lib/efi/efi_stub.c
> @@ -31,7 +31,6 @@
> #error "This file needs to be ported for use on architectures"
> #endif
>
> -static struct efi_priv *global_priv;
> static bool use_uart;
>
> struct __packed desctab_info {
> @@ -63,6 +62,8 @@ void _debug_uart_init(void)
>
> void putc(const char ch)
> {
> + struct efi_priv *priv = efi_get_priv();
> +
> if (ch == '\n')
> putc('\r');
>
> @@ -73,7 +74,7 @@ void putc(const char ch)
> ;
> outb(ch, (ulong)&com_port->thr);
> } else {
> - efi_putc(global_priv, ch);
> + efi_putc(priv, ch);
> }
> }
>
> @@ -320,7 +321,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
> puts(" efi_init() failed\n");
> return ret;
> }
> - global_priv = priv;
> + efi_set_priv(priv);
>
> cs32 = get_codeseg32();
> if (cs32 < 0)
More information about the U-Boot
mailing list