From patchwork Fri Nov 30 20:24:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 152588 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4087070ljp; Fri, 30 Nov 2018 12:25:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/VtdfCgkLRjPkejXxE/EPCZn8CalmaleeDgDp2225FdyaAfV2JcSZy8+4IYz9Nnp0oVI4ti X-Received: by 2002:aa7:db0e:: with SMTP id t14mr6490067eds.292.1543609507546; Fri, 30 Nov 2018 12:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543609507; cv=none; d=google.com; s=arc-20160816; b=iktqFEhsJ/u0HKNlYdUy1+z+3/pp2+9LqOFNHLPQZ0qGPfiwEksN0+5tq/5AbTpRdt L6fXOczHQMQNGv7E3dgpEiGKmI8K44fu8Kx/snMZRWO/jLIGUsKZbsQJwqJr0vRJjYxu 320XPPGczuL3CcEF5CnffQUFyao5uHXXY3HEwL3bhQiQSjFXzacJIT17qrBVyek4YI57 Y1O88FH0kK8UpKVnf0x6LZiJ6mnbLK1ueGLfajyjm5Qg/fqot4joggREs4HI2Kcsiq6/ TQIafpJ0fm5FZHOu7DxAX6cXBgoqkG81yBfqNUDcM14MTmu7pvdnXulLlHTcTS8d9O+g DYdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from; bh=apOiTV7Pdg5CfhQuidAZnBFHrdolSYNyjnPwN++3+K4=; b=JhDpNGiFql0U6V5DhWNMBcgGoZaWGqt9A8y8njFfCrlbPoGEYB1XERClK6DhnEcuIK YZHvHvV9VT5FMcrSEqWlxVhVSsZkVQk9Wwr1oFDGj5/TxnfZvVMJ5S2ym1qFOrl4xaLS cJYi6R7EJSJuNco3zIaaAD4OiDnVVhn93JNWs2qsULUhLpQdPl7KX+DUacykJOOT4cde bXt6C/M+crS5sCKRGkIVzVRCcqXbffnmhSYPONChSE6fF9vp3SaActNbM3FPKX2habGP xXCYD7FfOp/6q7j4sYbnieVY5iuRTmtWH2G3U2YZpd/NOnhWkuseOd/B0sx01dkarwCN CcLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w5-v6si2422285eja.270.2018.11.30.12.25.07; Fri, 30 Nov 2018 12:25:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 1505AC22559; Fri, 30 Nov 2018 20:25:02 +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=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 7B1DFC22090; Fri, 30 Nov 2018 20:25:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 332BBC22090; Fri, 30 Nov 2018 20:24:59 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id B66F2C2203F for ; Fri, 30 Nov 2018 20:24:58 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F2834AC3E; Fri, 30 Nov 2018 20:24:57 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 30 Nov 2018 21:24:56 +0100 Message-Id: <20181130202456.87452-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Baruch Siach , Prafulla Wadaskar , Luka Perkov , Heinrich Schuchardt , Yazan Shhady , Stefan Roese Subject: [U-Boot] [PATCH v3] efi_loader: Reserve unaccessible memory 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" On some systems, not all RAM may be usable within U-Boot. Maybe the memory maps are incomplete, maybe it's used as workaround for broken DMA. But whatever the reason may be, a platform can say that it does not wish to have its RAM accessed above a certain address by defining board_get_usable_ram_top(). In the efi_loader world, we ignored that hint, mostly because very few boards actually have real restrictions around this. So let's honor the board's wish to not access high addresses during boot time. The best way to do so is by indicating the respective pages as "allocated by firmware". That way, Operating Systems will still use the pages after boot, but before boot no allocation will use them. Reported-by: Baruch Siach Signed-off-by: Alexander Graf Reviewed-by: Stephen Warren Reviewed-by: Heinrich Schuchardt Tested-by: Baruch Siach --- v1 -> v2: - Reserve banks that start above ram_top - Improve inline comments - Fix 32bit target with ram_top = 0 (>=4G) v2 -> v3: - Fix 32bit target with ram_top = 0 for real (map to 1<<32 rather than 1<<32-1) --- include/common.h | 11 +++++++++++ lib/efi_loader/efi_memory.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/common.h b/include/common.h index 3f69943887..8f295c2f30 100644 --- a/include/common.h +++ b/include/common.h @@ -106,6 +106,17 @@ int mdm_init(void); void board_show_dram(phys_size_t size); /** + * Get the uppermost pointer that is valid to access + * + * Some systems may not map all of their address space. This function allows + * boards to indicate what their highest support pointer value is for DRAM + * access. + * + * @param total_size Size of U-Boot (unused?) + */ +ulong board_get_usable_ram_top(ulong total_size); + +/** * arch_fixup_fdt() - Write arch-specific information to fdt * * Defined in arch/$(ARCH)/lib/bootm-fdt.c diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index f225a9028c..73bfbb65c4 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -551,8 +551,13 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, __weak void efi_add_known_memory(void) { + u64 ram_top = board_get_usable_ram_top(0) & ~EFI_PAGE_MASK; int i; + /* Fix for 32bit targets with ram_top at 4G */ + if (!ram_top) + ram_top = 0x100000000ULL; + /* Add RAM */ for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { u64 ram_end, ram_start, pages; @@ -564,11 +569,32 @@ __weak void efi_add_known_memory(void) ram_end &= ~EFI_PAGE_MASK; ram_start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; - if (ram_end > ram_start) { - pages = (ram_end - ram_start) >> EFI_PAGE_SHIFT; + if (ram_end <= ram_start) { + /* Invalid mapping, keep going. */ + continue; + } + + pages = (ram_end - ram_start) >> EFI_PAGE_SHIFT; + efi_add_memory_map(ram_start, pages, + EFI_CONVENTIONAL_MEMORY, false); + + /* + * Boards may indicate to the U-Boot memory core that they + * can not support memory above ram_top. Let's honor this + * in the efi_loader subsystem too by declaring any memory + * above ram_top as "already occupied by firmware". + */ + if (ram_top < ram_start) { + /* ram_top is before this region, reserve all */ efi_add_memory_map(ram_start, pages, - EFI_CONVENTIONAL_MEMORY, false); + EFI_BOOT_SERVICES_DATA, true); + } else if ((ram_top >= ram_start) && (ram_top < ram_end)) { + /* ram_top is inside this region, reserve parts */ + pages = (ram_end - ram_top) >> EFI_PAGE_SHIFT; + + efi_add_memory_map(ram_top, pages, + EFI_BOOT_SERVICES_DATA, true); } } }