efi_loader: internal CloseProtocol

Allow avoiding using EFI_CALL() when closing a protocol by providing an
internal function.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Heinrich Schuchardt 2022-10-07 15:18:15 +02:00
parent 56c9f0c44e
commit ef1857641b
2 changed files with 67 additions and 44 deletions

View File

@ -661,9 +661,8 @@ efi_status_t EFIAPI efi_locate_handle_buffer(
enum efi_locate_search_type search_type, enum efi_locate_search_type search_type,
const efi_guid_t *protocol, void *search_key, const efi_guid_t *protocol, void *search_key,
efi_uintn_t *no_handles, efi_handle_t **buffer); efi_uintn_t *no_handles, efi_handle_t **buffer);
/* Close an previously opened protocol interface */ /* Close a previously opened protocol interface */
efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, efi_status_t efi_close_protocol(efi_handle_t handle, const efi_guid_t *protocol,
const efi_guid_t *protocol,
efi_handle_t agent_handle, efi_handle_t agent_handle,
efi_handle_t controller_handle); efi_handle_t controller_handle);
/* Open a protocol interface */ /* Open a protocol interface */

View File

@ -1993,7 +1993,7 @@ efi_status_t efi_load_image_from_path(bool boot_policy,
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
efi_free_pages(addr, pages); efi_free_pages(addr, pages);
out: out:
EFI_CALL(efi_close_protocol(device, guid, efi_root, NULL)); efi_close_protocol(device, guid, efi_root, NULL);
if (ret == EFI_SUCCESS) { if (ret == EFI_SUCCESS) {
*buffer = (void *)(uintptr_t)addr; *buffer = (void *)(uintptr_t)addr;
*size = buffer_size; *size = buffer_size;
@ -2290,6 +2290,49 @@ static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
* @agent_handle: handle of the driver * @agent_handle: handle of the driver
* @controller_handle: handle of the controller * @controller_handle: handle of the controller
* *
* This is the function implementing the CloseProtocol service is for internal
* usage in U-Boot. For API usage wrapper efi_close_protocol_ext() is provided.
*
* See the Unified Extensible Firmware Interface (UEFI) specification for
* details.
*
* Return: status code
*/
efi_status_t efi_close_protocol(efi_handle_t handle, const efi_guid_t *protocol,
efi_handle_t agent_handle,
efi_handle_t controller_handle)
{
struct efi_handler *handler;
struct efi_open_protocol_info_item *item;
struct efi_open_protocol_info_item *pos;
efi_status_t ret;
if (!efi_search_obj(agent_handle) ||
(controller_handle && !efi_search_obj(controller_handle)))
return EFI_INVALID_PARAMETER;
ret = efi_search_protocol(handle, protocol, &handler);
if (ret != EFI_SUCCESS)
return ret;
ret = EFI_NOT_FOUND;
list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
if (item->info.agent_handle == agent_handle &&
item->info.controller_handle == controller_handle) {
efi_delete_open_info(item);
ret = EFI_SUCCESS;
}
}
return ret;
}
/**
* efi_close_protocol_ext() - close a protocol
* @handle: handle on which the protocol shall be closed
* @protocol: GUID of the protocol to close
* @agent_handle: handle of the driver
* @controller_handle: handle of the controller
*
* This function implements the CloseProtocol service. * This function implements the CloseProtocol service.
* *
* See the Unified Extensible Firmware Interface (UEFI) specification for * See the Unified Extensible Firmware Interface (UEFI) specification for
@ -2297,38 +2340,20 @@ static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
* *
* Return: status code * Return: status code
*/ */
efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, static efi_status_t EFIAPI
const efi_guid_t *protocol, efi_close_protocol_ext(efi_handle_t handle, const efi_guid_t *protocol,
efi_handle_t agent_handle, efi_handle_t agent_handle,
efi_handle_t controller_handle) efi_handle_t controller_handle)
{ {
struct efi_handler *handler; efi_status_t ret;
struct efi_open_protocol_info_item *item;
struct efi_open_protocol_info_item *pos;
efi_status_t r;
EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, agent_handle, EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, agent_handle,
controller_handle); controller_handle);
if (!efi_search_obj(agent_handle) || ret = efi_close_protocol(handle, protocol,
(controller_handle && !efi_search_obj(controller_handle))) { agent_handle, controller_handle);
r = EFI_INVALID_PARAMETER;
goto out;
}
r = efi_search_protocol(handle, protocol, &handler);
if (r != EFI_SUCCESS)
goto out;
r = EFI_NOT_FOUND; return EFI_EXIT(ret);
list_for_each_entry_safe(item, pos, &handler->open_infos, link) {
if (item->info.agent_handle == agent_handle &&
item->info.controller_handle == controller_handle) {
efi_delete_open_info(item);
r = EFI_SUCCESS;
}
}
out:
return EFI_EXIT(r);
} }
/** /**
@ -3213,11 +3238,10 @@ close_next:
if (info->info.agent_handle != if (info->info.agent_handle !=
(efi_handle_t)image_obj) (efi_handle_t)image_obj)
continue; continue;
r = EFI_CALL(efi_close_protocol r = efi_close_protocol(
(efiobj, &protocol->guid, efiobj, &protocol->guid,
info->info.agent_handle, info->info.agent_handle,
info->info.controller_handle info->info.controller_handle);
));
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
ret = r; ret = r;
/* /*
@ -3481,9 +3505,9 @@ static efi_status_t efi_bind_controller(
r = EFI_CALL(binding_protocol->start(binding_protocol, r = EFI_CALL(binding_protocol->start(binding_protocol,
controller_handle, controller_handle,
remain_device_path)); remain_device_path));
EFI_CALL(efi_close_protocol(driver_image_handle, efi_close_protocol(driver_image_handle,
&efi_guid_driver_binding_protocol, &efi_guid_driver_binding_protocol,
driver_image_handle, NULL)); driver_image_handle, NULL);
return r; return r;
} }
@ -3834,9 +3858,9 @@ static efi_status_t EFIAPI efi_disconnect_controller(
goto out; goto out;
} }
} }
EFI_CALL(efi_close_protocol(driver_image_handle, efi_close_protocol(driver_image_handle,
&efi_guid_driver_binding_protocol, &efi_guid_driver_binding_protocol,
driver_image_handle, NULL)); driver_image_handle, NULL);
r = EFI_SUCCESS; r = EFI_SUCCESS;
out: out:
if (!child_handle) if (!child_handle)
@ -3883,7 +3907,7 @@ static struct efi_boot_services efi_boot_services = {
.connect_controller = efi_connect_controller, .connect_controller = efi_connect_controller,
.disconnect_controller = efi_disconnect_controller, .disconnect_controller = efi_disconnect_controller,
.open_protocol = efi_open_protocol, .open_protocol = efi_open_protocol,
.close_protocol = efi_close_protocol, .close_protocol = efi_close_protocol_ext,
.open_protocol_information = efi_open_protocol_information, .open_protocol_information = efi_open_protocol_information,
.protocols_per_handle = efi_protocols_per_handle, .protocols_per_handle = efi_protocols_per_handle,
.locate_handle_buffer = efi_locate_handle_buffer, .locate_handle_buffer = efi_locate_handle_buffer,