From patchwork Sat Aug 5 20:32:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 798305 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xPwZ366ttz9sNc for ; Sun, 6 Aug 2017 06:36:43 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8B559C21C72; Sat, 5 Aug 2017 20:35:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_LOW autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DD5D1C21F29; Sat, 5 Aug 2017 20:34:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E7591C21D82; Sat, 5 Aug 2017 20:34:31 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 9BBA6C21C72 for ; Sat, 5 Aug 2017 20:34:31 +0000 (UTC) Received: from workstation4.fritz.box ([84.118.154.110]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MUpI8-1eA2N03PsS-00Y6s3; Sat, 05 Aug 2017 22:34:30 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sat, 5 Aug 2017 22:32:30 +0200 Message-Id: <20170805203230.19796-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170805203230.19796-1-xypron.glpk@gmx.de> References: <20170805203230.19796-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:ONzP6ii34iSxvmHfQWYaiLFN2c5EBVKvozxvS8ao9GZhbPSievM rGft90mXkglfwop74r7CzVNiNg40iPIVfg9ocpCBqtlEnxgp40WyX8ZfTc0+JbcUw9rIA2I s8Uk3H7CGdsYJiZ0LAIv6D9+miRBGRO1uIQDjXQjhJmzjVAgN8GAHtVO+GT2wpc8LbWTnKk J+8OnqRXvZCeEFnPNT8Tw== X-UI-Out-Filterresults: notjunk:1; V01:K0:eSc9437vnvM=:8ffFJCHWSs5zjrTAmg/rkE HEAkhcNOkPM3EnIfvXKTc+sa+/QUYBgORPlOPp/hjhWcWfPX5ibvh1WNJwiiR4Liym4RypYFL oCCHezvFquM/pkF8VWRk4GjAkaOmiAZzVASjc5ExF9GpQdBDsovqO47x0rCAPbg/xL6W0cGAv vIt0ei0NbTOj3xUjwZcpHhkOtJ9sRYO+ewy570o5Nq8hlJZp9x2nm+B5XnwSPTFtLCVKaEwUA Jn8PDfh5VbBUHzlsQHRvSzVMrNH+RDI3YQkSeiQzepM9cBBOUb0t/ziY6q1XIbc9r0OpBn2vE 5oDjmmXJbJH/xnrsYBhm4uDuDgVrjXAcsfz78UniGVYqXePt6C5nnJ8jo6dXKcNniCos2Bla3 CB33d3jOYVsgD6HRvtvJRfIAnXrYPD6yhtxPNbfc1uPKAZcr8QEYn/wLYzERYtMt9UoEhRspk rWRXdPSge9IF5eyBPtFwKJ5d03kh8xFCjQ1YCbAHC8OBIxkHcs0HLuDN7uJkEnIQt4MP1J67k W4vQRFT2OFB6sAO2I1WdnOjAv2nFqs5ceOXjRmEw5iyvIwzCQQ/uul3X0PKaJ6mKDskUSWyyE uhC5fOc6VH9FwBuEcdw5j4B3hartvyDoeX744ItZ7TyZ5txoqq7od3hoaWR8jHlel/uAUw6od 0o5YA59ZO5iNGvsD8WykpdhDSK/WxC01NxWMdfFijqJmqwQkjQCrXxu9abJag+ECIO4MyQ3OM Qv3iRaEE5a6Zj8BJKXVMSVFyyzUjmTbFLb29Ivbt1fxwrbAFdEmmRo0dRMtIrnG/ItHJVVX2G FvQJvj5A4r4R7hTwRBLE+cCNPVxcA== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v3 3/3] efi_loader: implement OpenProtocolInformation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- v3: use list_for_each_entry correct indention v2: new patch --- lib/efi_loader/efi_boottime.c | 74 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 65a7a79dc1..fa9b74d465 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -984,14 +984,86 @@ out: return EFI_EXIT(r); } +static efi_status_t efi_copy_open_protocol_information( + struct efi_handler *protocol, + struct efi_open_protocol_info_entry **entry_buffer, + unsigned long *entry_count) +{ + unsigned long buffer_size; + unsigned long count = 0; + size_t i; + efi_status_t r; + + *entry_buffer = NULL; + + /* Count entries */ + for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) { + struct efi_open_protocol_info_entry *open_info = + &protocol->open_info[i]; + + if (open_info->open_count) + ++count; + } + *entry_count = count; + if (!count) + return EFI_SUCCESS; + + /* 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) + return r; + count = 0; + for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) { + struct efi_open_protocol_info_entry *open_info = + &protocol->open_info[i]; + + if (!open_info->open_count) + continue; + (*entry_buffer)[count] = *open_info; + ++count; + } + + return EFI_SUCCESS; +} + static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, efi_guid_t *protocol, struct efi_open_protocol_info_entry **entry_buffer, unsigned long *entry_count) { + struct efi_object *efiobj; + size_t i; + efi_status_t r = EFI_NOT_FOUND; + EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, entry_count); - return EFI_EXIT(EFI_NOT_FOUND); + + if (!handle || !protocol || !entry_buffer) + EFI_EXIT(EFI_INVALID_PARAMETER); + + EFI_PRINT_GUID("protocol:", protocol); + + list_for_each_entry(efiobj, &efi_obj_list, link) { + if (efiobj->handle != handle) + continue; + + for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { + struct efi_handler *handler = &efiobj->protocols[i]; + const efi_guid_t *hprotocol = handler->guid; + if (!hprotocol) + continue; + if (!guidcmp(hprotocol, protocol)) { + r = efi_copy_open_protocol_information( + handler, entry_buffer, entry_count); + goto out; + } + } + goto out; + } +out: + return EFI_EXIT(r); } static efi_status_t EFIAPI efi_protocols_per_handle(void *handle,