From patchwork Mon Jun 18 14:08:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 930918 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 418YGp5phKz9ryk for ; Tue, 19 Jun 2018 00:23:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0FBD0C21EE7; Mon, 18 Jun 2018 14:16:39 +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 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 6AEA8C21E79; Mon, 18 Jun 2018 14:15:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 05391C21E15; Mon, 18 Jun 2018 14:09:54 +0000 (UTC) Received: from mail-vk0-f73.google.com (mail-vk0-f73.google.com [209.85.213.73]) by lists.denx.de (Postfix) with ESMTPS id 4BE44C21DFF for ; Mon, 18 Jun 2018 14:09:51 +0000 (UTC) Received: by mail-vk0-f73.google.com with SMTP id d204-v6so7025965vka.23 for ; Mon, 18 Jun 2018 07:09:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=idE97fmVOLJaLGfL/GB43zllAGkh87McF1M1YKoQFgo=; b=qeVUpiXNl03qbtkjy2MHGigo+hHAUFfZgvLEotfZXgorHaGtshrxmRUlzVWDvzFXRP 2ALkARsugZG2Yla8t7z880abeoVpwz0Hx4QGDR/Rhc1JjfUr7M1y6y90PQp+pPA4WUyB w/s9qxZofFgV4BRe11ITIIsBmD0Qn7jiKHZQZuVJsXREF8Hv64wQKQoaQoJgUmU01d1D BQQCRFH0lXduPWRhQDFCQsiK8xxj2wBJIXvYjc38/w6VL0ooXm2UCaGgRiTn12PDM8r3 FhmQZmWDsxvryfvR5OH9xZa0a3fDa68YEOX6jdIkf9PKsHH5mfr+JJtElSDcBgO/IjZa p3dA== X-Gm-Message-State: APt69E3DTzzOnSwsFXxr5l6yJekmI5dY/1abzMRoHGhYDEOph5JaI6gV elmfiEINMg4v7nVfo6B4rRCZgqk= X-Google-Smtp-Source: ADUXVKK6rzvAHj8wOLL7VaSMO+Wv2Jh6Bu7HqWyMSTJTe7TX7frZbfRxQNQnk5E3OpTve6XoFTKOhOE= MIME-Version: 1.0 X-Received: by 2002:ab0:1268:: with SMTP id s40-v6mr5285032uac.41.1529330990364; Mon, 18 Jun 2018 07:09:50 -0700 (PDT) Date: Mon, 18 Jun 2018 08:08:29 -0600 In-Reply-To: <20180618140835.195901-1-sjg@chromium.org> Message-Id: <20180618140835.195901-25-sjg@chromium.org> References: <20180618140835.195901-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v8 24/30] efi: Adjust memory handling to support sandbox 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" Sandbox does not support direct casts between addresses and pointers, since it uses an emulated RAM buffer rather than directly using host RAM. The current EFI code uses an integer type for addresses, but treats them like pointers. Update the code to maintain a (reasonably) clear separation between the two, so that sandbox can work. Unfortunately there remains an inconsistency between the arguments of allocate_pages() and allocate_pool(). One takes an address and one takes a pointer. Partly this seems to be defined by the boot services API itself but it would be fairly easy to update the functions in efi_memory.c to be consistent. However, this is a larger change and needs discussion. Signed-off-by: Simon Glass --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None lib/efi_loader/efi_boottime.c | 13 +++++++++++-- lib/efi_loader/efi_image_loader.c | 3 ++- lib/efi_loader/efi_memory.c | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 50d311548e..aefafc3fba 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -14,6 +14,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -305,9 +306,17 @@ static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, uint64_t *memory) { efi_status_t r; + uint64_t addr; EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory); - r = efi_allocate_pages(type, memory_type, pages, memory); + if (memory_type == EFI_ALLOCATE_MAX_ADDRESS || + memory_type == EFI_ALLOCATE_ADDRESS) + addr = *memory == -1ULL ? *memory : + map_to_sysmem((void *)(uintptr_t)*memory); + else + addr = 0; + r = efi_allocate_pages(type, memory_type, pages, &addr); + *memory = (uintptr_t)map_sysmem(addr, pages << EFI_PAGE_SHIFT); return EFI_EXIT(r); } @@ -328,7 +337,7 @@ static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, efi_status_t r; EFI_ENTRY("%" PRIx64 ", 0x%zx", memory, pages); - r = efi_free_pages(memory, pages); + r = efi_free_pages(map_to_sysmem((void *)memory), pages); return EFI_EXIT(r); } diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index ecdb77e5b6..d5dd8864d7 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -9,6 +9,7 @@ #include #include +#include #include const efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; @@ -301,7 +302,7 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) /* Run through relocations */ if (efi_loader_relocate(rel, rel_size, efi_reloc, (unsigned long)image_base) != EFI_SUCCESS) { - efi_free_pages((uintptr_t) efi_reloc, + efi_free_pages(map_to_sysmem(efi_reloc), (virt_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT); return NULL; } diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index c6410613c7..ad61b723e6 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -345,7 +345,7 @@ void *efi_alloc(uint64_t len, int memory_type) r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, memory_type, pages, &ret); if (r == EFI_SUCCESS) - return (void*)(uintptr_t)ret; + return map_sysmem(ret, len); return NULL; } @@ -412,15 +412,17 @@ efi_status_t efi_free_pool(void *buffer) { efi_status_t r; struct efi_pool_allocation *alloc; + uintptr_t addr; if (buffer == NULL) return EFI_INVALID_PARAMETER; alloc = container_of(buffer, struct efi_pool_allocation, data); /* Sanity check, was the supplied address returned by allocate_pool */ - assert(((uintptr_t)alloc & EFI_PAGE_MASK) == 0); + addr = map_to_sysmem(alloc); + assert((addr & EFI_PAGE_MASK) == 0); - r = efi_free_pages((uintptr_t)alloc, alloc->num_pages); + r = efi_free_pages(addr, alloc->num_pages); return r; } @@ -471,7 +473,14 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, struct efi_mem_list *lmem; lmem = list_entry(lhandle, struct efi_mem_list, link); - *memory_map = lmem->desc; + memory_map->type = lmem->desc.type; + memory_map->reserved = 0; + memory_map->physical_start = (uintptr_t)map_sysmem( + lmem->desc.physical_start, + memory_map->num_pages << EFI_PAGE_SHIFT); + memory_map->virtual_start = memory_map->physical_start; + memory_map->num_pages = lmem->desc.num_pages; + memory_map->attribute = lmem->desc.attribute; memory_map--; } }