From patchwork Sat Aug 5 16:58:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 798273 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 3xPqp35Cs0z9t1K for ; Sun, 6 Aug 2017 03:01:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7630EC21F0F; Sat, 5 Aug 2017 17:00:43 +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, RCVD_IN_MSPIKE_H2 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 66661C21E6C; Sat, 5 Aug 2017 17:00:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2407AC21C2B; Sat, 5 Aug 2017 17:00:09 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lists.denx.de (Postfix) with ESMTPS id C3E65C21D82 for ; Sat, 5 Aug 2017 17:00:08 +0000 (UTC) Received: from workstation4.fritz.box ([84.118.154.110]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MZPer-1dwO8A3zED-00LBQj; Sat, 05 Aug 2017 19:00:08 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sat, 5 Aug 2017 18:58:51 +0200 Message-Id: <20170805165851.23461-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170805165851.23461-1-xypron.glpk@gmx.de> References: <20170805165851.23461-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:5NbfVtgssu+skeacWYo3pucuqEvXv9idoTgDDkbDsZTeILWuKnP CFC9GGtLG/cpYPnhPN4Wg6k6MrEMwdhlnWjPtDpU9IDRHCl7dgc6HqpTiRxAmOQw2Exm2ZG mGOfyW5f1UBbFJmfcek3Zh8L853UKtQvcAI4yf4q/JGHqHpqjrtRcps6HjfYIxGBRrJSq8z HZrsBcc93h/6wEv10X27A== X-UI-Out-Filterresults: notjunk:1; V01:K0:0nH0TuYD154=:tHxN/XnPgaaglvzZuBjdDQ H8wPCWiGjhugYg3Khc9cTAnfn8GD31OQUIttzV5/zQ29YWholZq3WgOS0DtzjO9TWi2k8O7Vl 8OsFVS6SAj+hI67n300lG+w5e6jVXR/jpZbCr2et/BwbC+SgFmt4VKMiGhW5W8hcemtVPJ3Jm 7vd3zcT+je0CUC/svg4A3GeXMnnc5qBgZ9mkP1Y+Zbq7fV4jSNIOUKF2DD8HrmfkFGL+1z2Th rYwG59KUflU01HIl5Gi4VmCVrpBBftPyr+8W9TrNlMqc/SU4bFQNyshJ9gxfgudkfJSNMKLJw psB98xJqmUYn2bHLcAxDlo4LS/cLUuDZK+8I2X4g66oE56LRv+0R14S9s5p5bjUJvKrJfFSzJ nrsKPF6ZgkvewkTiqwoEv88MjL0tIxBr0dIburW1IjUApQkFuztbjQKqvnfLRqrWjb3+4DGIO NUua8c2XqM1JtY4sElJTBiq1ISmchvar4Icwyts8sTtiT5ijXllLvk8mLnkXSBHmVHSZGGx80 6imRGNjp76ueDl/B42zS3AFRsyqVsqRMt7sNvP+Vo8U4h3iySOPmE+lhoVE5gcJaI/eJRai4r eGy5dGV4EMW+33oM+QRXuLYf/jhV0S1IWpd7YnCzLvp+uj2j/gm5RaPA61IVn4mgDsMcIiX0Y fUkuWzOS87fuFQOS5+q5cfA+rjUb7MyFP9nnd/d5j7XE0ZdBcqq7gs/cVVAF0caL4B+TAgKBP /R5knQvNqFDC5VET5sBh+ZNIJNYnnd5Lm6y+tAvF1lscGZrbZ1r7m0fOow3F24L64mN3eaUDE xJqfOS8TIr9IEX4hAMLtLpuBcWE9A== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 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. Signed-off-by: Heinrich Schuchardt --- v2: new patch --- lib/efi_loader/efi_boottime.c | 77 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 65a7a79dc1..941d07192d 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -984,14 +984,89 @@ 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; + struct list_head *lhandle; + 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(lhandle, &efi_obj_list) { + efiobj = list_entry(lhandle, struct efi_object, 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,