From patchwork Wed Jun 5 04:21:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1110295 X-Patchwork-Delegate: xypron.glpk@gmx.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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tTcvn58R"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45JbHz5tZ1z9s3Z for ; Wed, 5 Jun 2019 14:23:11 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7C06FC21C3F; Wed, 5 Jun 2019 04:22:33 +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=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID 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 7CA25C21DF9; Wed, 5 Jun 2019 04:21:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B4BCEC21DD4; Wed, 5 Jun 2019 04:21:06 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id C3E07C21DA2 for ; Wed, 5 Jun 2019 04:21:03 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id v11so11649186pgl.5 for ; Tue, 04 Jun 2019 21:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rgYo04PIrTb5mkCktON7TVufFICJqtEwGY/zjOIGiwU=; b=tTcvn58RHBPfPSdn+0VtGWV+FseMR1cCDuRAu9frDP83kiBW+Qf51OVpUadhyrWu01 W50cIfLvlcs+GkdqmCT6Hgieb3rROZwRPn0wCuvl/6uFvLt9te4NYaOuQEStKrO6gFlK 9bQ6BBsI/NaeGnb7rgFCUD10Z1OMXnJDo64T0fwVuz5lEgCcaHVHPuFU6URFe3Qx8xV4 /jikY8PqEYmfo7aEi3dFlv03Q2dhdXPo0AYV+ojrrXb339tvIh0Fw2oM78/TQ8x7lK3R 5iG/O1oQ1/ye2PaGjQrozfckkve6uy51zilyUv3tzUpKW5Wu6zb95DGw/cxNcd5kufNQ sYEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rgYo04PIrTb5mkCktON7TVufFICJqtEwGY/zjOIGiwU=; b=GbDktIncs0K08OySEvadtq5s3y5HO5Of/45aYKJpZmiBYAy+ElJexXMvspEHI6AyXd dav9opQGWJS6kE9ttJrl+StwL1UBa8lJVWaRqzlB2vfKshHnfUo+n4ZzxmYOZ7J2MrzI TrMO9zpPPL8bgAA8qYo9p4BAkqslBPmNwu7HqntrpV6o9GvvXyzPXjCoSjvvIH9sAFF0 sByAEgNZ/6LT2EYf314s+cO5QsbkcUjcgsI/HSuFH/yFbY5x1vyuBSTXCUb+QsctKhJh El+J6qLdNrkqu30qIAjfIg/GYnpl/leRrf6IjHBadim0UicHQy0cWaZU6MmuKm6yH+c0 C6pg== X-Gm-Message-State: APjAAAW1q5+hVCR95hhJV4XtD38Loj5898UHHGws3+MsYhPtGrOzgcP4 EoZoW1Cx9BFAOZEOHATEqqNEJg== X-Google-Smtp-Source: APXvYqzpHt1o82gAEG1vqBRbt5xS631EylDcOrIzEaxnvSBLJP6SleiBfj8eYHEJK02ZvqMYx62dkg== X-Received: by 2002:a65:51cb:: with SMTP id i11mr1544848pgq.390.1559708462458; Tue, 04 Jun 2019 21:21:02 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e6sm14467070pfi.42.2019.06.04.21.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 21:21:02 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Wed, 5 Jun 2019 13:21:39 +0900 Message-Id: <20190605042142.15113-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190605042142.15113-1-takahiro.akashi@linaro.org> References: <20190605042142.15113-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 3/6] efi_loader: support convert_pointer at runtime 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" With this patch, ConvertPointer runtime service is enabled. This function will be useful only after SetVirtualAddressMap is called and before it exits according to UEFI specification. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/Kconfig | 8 ++++ lib/efi_loader/efi_runtime.c | 81 ++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index bb9c7582b14d..e2ef43157568 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -51,6 +51,14 @@ config EFI_RUNTIME_SET_VIRTUAL_ADDRESS_MAP Enable SetVirtualAddressMap runtime service. This API will be called by OS just before it enters into virtual address mode. +config EFI_RUNTIME_CONVERT_POINTER + bool "runtime service: ConvertPointer" + default n + help + Enable ConvertPointer runtime service. This API will be expected + to be called by UEFI drivers in relocating themselves to virtual + address space. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index cf202bb9ec07..ff3684a4b692 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -27,7 +27,6 @@ LIST_HEAD(efi_runtime_mmio); static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void); static efi_status_t __efi_runtime EFIAPI efi_device_error(void); -static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void); /* * TODO(sjg@chromium.org): These defines and structures should come from the ELF @@ -108,6 +107,10 @@ efi_status_t efi_init_runtime_supported(void) efi_runtime_services_supported |= EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP; #endif +#ifdef CONFIG_EFI_RUNTIME_CONVERT_POINTER + efi_runtime_services_supported |= + EFI_RT_SUPPORTED_CONVERT_POINTER; +#endif return EFI_CALL(efi_set_variable(L"RuntimeServicesSupported", &efi_global_variable_guid, @@ -392,6 +395,39 @@ efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time) return EFI_UNSUPPORTED; } +#ifdef CONFIG_EFI_RUNTIME_CONVERT_POINTER +static struct efi_mem_desc *efi_virtmap __efi_runtime_data; +static int efi_virtmap_num __efi_runtime_data; + +static efi_status_t __efi_runtime EFIAPI efi_convert_pointer(unsigned long dbg, + void **address) +{ + struct efi_mem_desc *map; + efi_physical_addr_t addr; + int i; + + if (!efi_virtmap) + return EFI_UNSUPPORTED; + + if (!address) + return EFI_INVALID_PARAMETER; + + for (i = 0, map = efi_virtmap; i < efi_virtmap_num; i++, map++) { + addr = (efi_physical_addr_t)*address; + if (addr >= map->physical_start && + (addr < (map->physical_start + + (map->num_pages << EFI_PAGE_SHIFT)))) { + *address = (void *)map->virtual_start; + *address += addr - map->physical_start; + + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} +#endif + struct efi_runtime_detach_list_struct { void *ptr; void *patchto; @@ -599,6 +635,10 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( return EFI_EXIT(EFI_INVALID_PARAMETER); } + efi_virtmap = virtmap; + efi_virtmap_num = n; + +#if 0 /* FIXME: This code is fragile as calloc is used in add_runtime_mmio */ /* Rebind mmio pointers */ for (i = 0; i < n; i++) { struct efi_mem_desc *map = (void*)virtmap + @@ -622,14 +662,14 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( *lmmio->ptr = (void *)new_addr; } } - if ((map_start <= (uintptr_t)systab.tables) && - (map_end >= (uintptr_t)systab.tables)) { - char *ptr = (char *)systab.tables; - - ptr += off; - systab.tables = (struct efi_configuration_table *)ptr; - } } +#endif + + /* FIXME */ + efi_convert_pointer(0, (void **)&systab.tables); + + /* All fixes must be done before this line */ + efi_virtmap = NULL; /* Move the actual runtime code over */ for (i = 0; i < n; i++) { @@ -644,6 +684,11 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( /* Once we're virtual, we can no longer handle complex callbacks */ efi_runtime_detach(new_offset); + + /* + * FIXME: + * We can no longer update RuntimeServicesSupported. + */ return EFI_EXIT(EFI_SUCCESS); } } @@ -733,20 +778,6 @@ static efi_status_t __efi_runtime EFIAPI efi_device_error(void) return EFI_DEVICE_ERROR; } -/** - * efi_invalid_parameter() - replacement function, returns EFI_INVALID_PARAMETER - * - * This function is used after SetVirtualAddressMap() is called as replacement - * for services that are not available anymore due to constraints of the U-Boot - * implementation. - * - * Return: EFI_INVALID_PARAMETER - */ -static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void) -{ - return EFI_INVALID_PARAMETER; -} - /** * efi_update_capsule() - process information from operating system * @@ -833,7 +864,11 @@ struct efi_runtime_services __efi_runtime_data efi_runtime_services = { #else .set_virtual_address_map = (void *)&efi_unimplemented, #endif - .convert_pointer = (void *)&efi_invalid_parameter, +#ifdef CONFIG_EFI_RUNTIME_CONVERT_POINTER + .convert_pointer = &efi_convert_pointer, +#else + .convert_pointer = (void *)&efi_unimplemented, +#endif .get_variable = efi_get_variable, .get_next_variable_name = efi_get_next_variable_name, .set_variable = efi_set_variable,