From 39434a9b25dcfc0f6b5aba59e9b6d691468891a4 Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Wed, 5 Oct 2022 13:18:35 +0100 Subject: efi: Add string conversion helper Signed-off-by: Paul Barker Reviewed-by: Heinrich Schuchardt --- include/efi_loader.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/efi_loader.h b/include/efi_loader.h index ad01395b39c..8c45e3ee259 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -1014,9 +1014,10 @@ struct pkcs7_message *efi_parse_pkcs7_header(const void *buf, /* runtime implementation of memcpy() */ void efi_memcpy_runtime(void *dest, const void *src, size_t n); -/* commonly used helper function */ +/* commonly used helper functions */ u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name, unsigned int index); +efi_string_t efi_convert_string(const char *str); extern const struct efi_firmware_management_protocol efi_fmp_fit; extern const struct efi_firmware_management_protocol efi_fmp_raw; -- cgit v1.2.3 From 16b27b67c5002c13d84bdf68727954ec765f0731 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 3 Oct 2022 09:47:51 +0200 Subject: efi_loader: function to unlink udevice and handle When deleting a device or a handle we must remove the link between the two to avoid dangling references. Provide function efi_unlink_dev() for this purpose. Signed-off-by: Heinrich Schuchardt --- include/efi_loader.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/efi_loader.h b/include/efi_loader.h index 8c45e3ee259..6f78f774047 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -708,6 +708,7 @@ const char *guid_to_sha_str(const efi_guid_t *guid); int algo_to_len(const char *algo); int efi_link_dev(efi_handle_t handle, struct udevice *dev); +int efi_unlink_dev(efi_handle_t handle); /** * efi_size_in_pages() - convert size in bytes to size in pages -- cgit v1.2.3 From 43a5891c66c8fe961999415b051c827ce1b543c4 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 3 Oct 2022 10:35:35 +0200 Subject: efi_driver: fix error handling If creating the block device fails, * delete all created objects and references * close the protocol interface on the controller Signed-off-by: Heinrich Schuchardt --- include/efi_driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/efi_driver.h b/include/efi_driver.h index 2b62219c5bf..dc0c1c7ac07 100644 --- a/include/efi_driver.h +++ b/include/efi_driver.h @@ -25,7 +25,7 @@ struct efi_driver_ops { const efi_guid_t *protocol; const efi_guid_t *child_protocol; - int (*bind)(efi_handle_t handle, void *interface); + efi_status_t (*bind)(efi_handle_t handle, void *interface); }; /* -- cgit v1.2.3 From df31fedd3929c18bd64192d1ec9b839b6295efd6 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 4 Oct 2022 18:28:24 +0200 Subject: doc: documentation of EFI driver binding protocol * Convert code comments in include/efi_driver.h to Sphinx style. * Add include/efi_driver.h to the HTML documentation. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- include/efi_driver.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/efi_driver.h b/include/efi_driver.h index dc0c1c7ac07..de38abe83bd 100644 --- a/include/efi_driver.h +++ b/include/efi_driver.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * EFI application loader + * Internal structures for the EFI driver binding protocol * * Copyright (c) 2017 Heinrich Schuchardt */ @@ -10,16 +10,16 @@ #include -/* - * Operations supported by an EFI driver with respect to the EFI uclass +/** + * struct efi_driver_ops - operations support by an EFI driver * - * @protocol The GUID of the protocol which is consumed by the + * @protocol: The GUID of the protocol which is consumed by the * driver. This GUID is used by the EFI uclass in the * supports() and start() methods of the * EFI_DRIVER_BINDING_PROTOCOL. - * @child_protocol Protocol supported by the child handles generated by + * @child_protocol: Protocol supported by the child handles generated by * the EFI driver. - * @bind Function called by the EFI uclass to attach the + * @bind: Function called by the EFI uclass to attach the * driver to EFI driver to a handle. */ struct efi_driver_ops { @@ -28,8 +28,13 @@ struct efi_driver_ops { efi_status_t (*bind)(efi_handle_t handle, void *interface); }; -/* +/** + * struct efi_driver_binding_extended_protocol - extended driver binding protocol + * * This structure adds internal fields to the driver binding protocol. + * + * @bp: driver binding protocol + * @ops: operations supported by the driver */ struct efi_driver_binding_extended_protocol { struct efi_driver_binding_protocol bp; -- cgit v1.2.3 From ec4f675f9ebec2535f2cd050aed7f9c106a5bee9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 4 Oct 2022 19:12:59 +0200 Subject: efi_driver: provide driver binding protocol to bind function DisconnectController() is based on the open protocol information created when the driver opens a protocol with BY_CHILD_CONTROLLER or BY_DRIVER. To create an open protocol information it is required to supply the handle of the driver as agent handle. This information is available as field DriverBindingHandle in the driver binding protocol. Signed-off-by: Heinrich Schuchardt --- include/efi_driver.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/efi_driver.h b/include/efi_driver.h index de38abe83bd..71e0d3194ea 100644 --- a/include/efi_driver.h +++ b/include/efi_driver.h @@ -10,6 +10,19 @@ #include +/** + * struct efi_driver_binding_extended_protocol - extended driver binding protocol + * + * This structure adds internal fields to the driver binding protocol. + * + * @bp: driver binding protocol + * @ops: operations supported by the driver + */ +struct efi_driver_binding_extended_protocol { + struct efi_driver_binding_protocol bp; + const struct efi_driver_ops *ops; +}; + /** * struct efi_driver_ops - operations support by an EFI driver * @@ -25,20 +38,8 @@ struct efi_driver_ops { const efi_guid_t *protocol; const efi_guid_t *child_protocol; - efi_status_t (*bind)(efi_handle_t handle, void *interface); -}; - -/** - * struct efi_driver_binding_extended_protocol - extended driver binding protocol - * - * This structure adds internal fields to the driver binding protocol. - * - * @bp: driver binding protocol - * @ops: operations supported by the driver - */ -struct efi_driver_binding_extended_protocol { - struct efi_driver_binding_protocol bp; - const struct efi_driver_ops *ops; + efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this, + efi_handle_t handle, void *interface); }; #endif /* _EFI_DRIVER_H */ -- cgit v1.2.3 From 8f8fe1d458664aaa15fa82de78dfdb0eca74b2ca Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 5 Oct 2022 11:28:47 +0200 Subject: efi_driver: add init function to EFI block driver For handling added and removed block devices we need to register events which has to be done when the driver is installed. This patch only creates an empty init function that will be filled with code later on. The function needs to be called before any EFI block devices are used. Move the efi_driver_init() call to early init. Signed-off-by: Heinrich Schuchardt --- include/efi_driver.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/efi_driver.h b/include/efi_driver.h index 71e0d3194ea..63a95e4cf80 100644 --- a/include/efi_driver.h +++ b/include/efi_driver.h @@ -32,12 +32,15 @@ struct efi_driver_binding_extended_protocol { * EFI_DRIVER_BINDING_PROTOCOL. * @child_protocol: Protocol supported by the child handles generated by * the EFI driver. + * @init: Function called by the EFI uclass after installing the + * driver binding protocol. * @bind: Function called by the EFI uclass to attach the * driver to EFI driver to a handle. */ struct efi_driver_ops { const efi_guid_t *protocol; const efi_guid_t *child_protocol; + efi_status_t (*init)(struct efi_driver_binding_extended_protocol *this); efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this, efi_handle_t handle, void *interface); }; -- cgit v1.2.3 From f05911a126bd6b8536c8d43fd6c1d837008fcda1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 6 Oct 2022 07:29:41 +0200 Subject: efi_driver: move event registration to driver Move the registration of events for the addition and removal of block devices to the block device driver. Here we can add a reference to the EFI Driver Binding protocol as context. Signed-off-by: Heinrich Schuchardt --- include/efi_loader.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/efi_loader.h b/include/efi_loader.h index 6f78f774047..15e7680af95 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -544,8 +545,6 @@ void efi_carve_out_dt_rsv(void *fdt); void efi_try_purge_kaslr_seed(void *fdt); /* Called by bootefi to make console interface available */ efi_status_t efi_console_register(void); -/* Called by efi_init_early() to add block devices when probed */ -efi_status_t efi_disk_init(void); /* Called by efi_init_obj_list() to proble all block devices */ efi_status_t efi_disks_register(void); /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */ @@ -749,6 +748,10 @@ efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end, /* Called by board init to initialize the EFI drivers */ efi_status_t efi_driver_init(void); +/* Called when a block device is added */ +int efi_disk_probe(void *ctx, struct event *event); +/* Called when a block device is removed */ +int efi_disk_remove(void *ctx, struct event *event); /* Called by board init to initialize the EFI memory map */ int efi_memory_init(void); /* Adds new or overrides configuration table entry to the system table */ -- cgit v1.2.3 From 05c4c9e21ae6f45ba1091917fc55f3ebc3916909 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Thu, 6 Oct 2022 16:08:46 +0300 Subject: efi_loader: define internal implementations of install/uninstallmultiple A following patch is cleaning up the core EFI code trying to remove sequences of efi_create_handle, efi_add_protocol. Although this works fine there's a problem with the latter since it is usually combined with efi_delete_handle() which blindly removes all protocols on a handle and deletes the handle. We should try to adhere to the EFI spec which only deletes a handle if the last instance of a protocol has been removed. Another problem is that efi_delete_handle() never checks for opened protocols, but the EFI spec defines that the caller is responsible for ensuring that there are no references to a protocol interface that is going to be removed. So let's fix this by replacing all callsites of efi_create_handle(), efi_add_protocol() , efi_delete_handle() with Install/UninstallMultipleProtocol. In order to do that redefine functions that can be used by the U-Boot proper internally and add '_ext' variants that will be used from the EFI API Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- include/efi.h | 2 ++ include/efi_loader.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/efi.h b/include/efi.h index 6159f34ad2b..42f4e58a917 100644 --- a/include/efi.h +++ b/include/efi.h @@ -37,12 +37,14 @@ #define EFIAPI __attribute__((ms_abi)) #define efi_va_list __builtin_ms_va_list #define efi_va_start __builtin_ms_va_start +#define efi_va_copy __builtin_ms_va_copy #define efi_va_arg __builtin_va_arg #define efi_va_end __builtin_ms_va_end #else #define EFIAPI asmlinkage #define efi_va_list va_list #define efi_va_start va_start +#define efi_va_copy va_copy #define efi_va_arg va_arg #define efi_va_end va_end #endif /* __x86_64__ */ diff --git a/include/efi_loader.h b/include/efi_loader.h index 15e7680af95..69d6d004f4d 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -654,8 +654,10 @@ efi_status_t efi_remove_protocol(const efi_handle_t handle, /* Delete all protocols from a handle */ efi_status_t efi_remove_all_protocols(const efi_handle_t handle); /* Install multiple protocol interfaces */ -efi_status_t EFIAPI efi_install_multiple_protocol_interfaces - (efi_handle_t *handle, ...); +efi_status_t EFIAPI +efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...); +efi_status_t EFIAPI +efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...); /* Get handles that support a given protocol */ efi_status_t EFIAPI efi_locate_handle_buffer( enum efi_locate_search_type search_type, -- cgit v1.2.3