From patchwork Tue Jul 11 20:06:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 786838 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3x6YB06Dn1z9s81 for ; Wed, 12 Jul 2017 06:11:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9F2D7C21E51; Tue, 11 Jul 2017 20:08:30 +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.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE 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 77A08C21EF0; Tue, 11 Jul 2017 20:07:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3F44BC21EC0; Tue, 11 Jul 2017 20:07:25 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lists.denx.de (Postfix) with ESMTPS id 4AAF2C21D63 for ; Tue, 11 Jul 2017 20:07:25 +0000 (UTC) Received: from workstation4.fritz.box ([88.152.145.149]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LaooK-1dxiLd11JI-00kS0A; Tue, 11 Jul 2017 22:06:37 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Tue, 11 Jul 2017 22:06:16 +0200 Message-Id: <20170711200625.7108-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170711200625.7108-1-xypron.glpk@gmx.de> References: <20170711200625.7108-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:WOR8n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cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 03/12] efi_loader: implement InstallProtocolInterface 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_install_protocol_interface up to now only returned an error code. The patch implements the UEFI specification for InstallProtocolInterface with the exception that it will not create new handles. Signed-off-by: Heinrich Schuchardt --- v2 Correctly check GUIDs. --- include/efi_api.h | 2 +- lib/efi_loader/efi_boottime.c | 54 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index f071b36b53..42cd47ff08 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -58,7 +58,7 @@ struct efi_boot_services { efi_status_t (EFIAPI *signal_event)(void *event); efi_status_t (EFIAPI *close_event)(void *event); efi_status_t (EFIAPI *check_event)(void *event); - +#define EFI_NATIVE_INTERFACE 0x00000000 efi_status_t (EFIAPI *install_protocol_interface)( void **handle, efi_guid_t *protocol, int protocol_interface_type, void *protocol_interface); diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index f11aa551d2..97b2dce8b3 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -304,10 +304,62 @@ static efi_status_t EFIAPI efi_install_protocol_interface(void **handle, efi_guid_t *protocol, int protocol_interface_type, void *protocol_interface) { + struct list_head *lhandle; + int i; + efi_status_t r; + EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type, protocol_interface); - return EFI_EXIT(EFI_OUT_OF_RESOURCES); + + if (!handle || !protocol || + protocol_interface_type != EFI_NATIVE_INTERFACE) { + r = EFI_INVALID_PARAMETER; + goto out; + } + + /* Create new handle if requested. */ + if (!*handle) { + r = EFI_OUT_OF_RESOURCES; + goto out; + } + /* Find object. */ + list_for_each(lhandle, &efi_obj_list) { + struct efi_object *efiobj; + efiobj = list_entry(lhandle, struct efi_object, link); + + if (efiobj->handle != *handle) + continue; + /* Check if protocol is already installed on the handle. */ + for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { + struct efi_handler *handler = &efiobj->protocols[i]; + + if (!handler->guid) + continue; + if (!guidcmp(handler->guid, protocol)) { + r = EFI_INVALID_PARAMETER; + goto out; + } + } + /* Install protocol in first empty slot. */ + for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { + struct efi_handler *handler = &efiobj->protocols[i]; + + if (handler->guid) + continue; + + handler->guid = protocol; + handler->protocol_interface = protocol_interface; + r = EFI_SUCCESS; + goto out; + } + r = EFI_OUT_OF_RESOURCES; + goto out; + } + r = EFI_INVALID_PARAMETER; +out: + return EFI_EXIT(r); } + static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle, efi_guid_t *protocol, void *old_interface, void *new_interface)