From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Sun, 27 Aug 2017 00:53:21 +0200 Subject: [U-Boot] [PATCH 12/23] efi_loader: implement OpenProtocolInformation In-Reply-To: <20170826225328.7550-1-xypron.glpk@gmx.de> References: <20170826225110.7381-1-xypron.glpk@gmx.de> <20170826225328.7550-1-xypron.glpk@gmx.de> Message-ID: <20170826225328.7550-3-xypron.glpk@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de efi_open_protocol_information provides the agent and controller handles as well as the attributes and open count of an protocol on a handle. Cc: Rob Clark Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index c9aec597a2..23b8894e73 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -985,9 +985,62 @@ static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, struct efi_open_protocol_info_entry **entry_buffer, unsigned long *entry_count) { + unsigned long buffer_size; + unsigned long count; + struct efi_handler *handler; + size_t i; + efi_status_t r; + EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, entry_count); - return EFI_EXIT(EFI_NOT_FOUND); + + /* Check parameters */ + if (!handle || !protocol || !entry_buffer) { + r = EFI_INVALID_PARAMETER; + goto out; + } + + /* Find the protocol */ + r = efi_search_protocol(handle, protocol, &handler); + if (r != EFI_SUCCESS) + goto out; + + *entry_buffer = NULL; + + /* Count entries */ + count = 0; + for (i = 0; i < ARRAY_SIZE(handler->open_info); ++i) { + struct efi_open_protocol_info_entry *open_info = + &handler->open_info[i]; + + if (open_info->open_count) + ++count; + } + *entry_count = count; + if (!count) { + r = EFI_SUCCESS; + goto out; + } + + /* Copy entries */ + buffer_size = count * sizeof(struct efi_open_protocol_info_entry); + r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, + (void **)entry_buffer); + if (r != EFI_SUCCESS) + goto out; + count = 0; + for (i = 0; i < ARRAY_SIZE(handler->open_info); ++i) { + struct efi_open_protocol_info_entry *open_info = + &handler->open_info[i]; + + if (!open_info->open_count) + continue; + (*entry_buffer)[count] = *open_info; + ++count; + } + +out: + return EFI_EXIT(r); } static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, -- 2.14.1