From patchwork Fri Apr 6 07:42:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 132901 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp465801ljb; Fri, 6 Apr 2018 00:42:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+PEMw/15A5KvxJgycS6jKO1bYMmZk2WXpJKf5SBHMdc2tXE3CAeWNqd2Rn/VHkSJw2XOll X-Received: by 10.80.141.134 with SMTP id r6mr5584240edh.228.1523000576777; Fri, 06 Apr 2018 00:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523000576; cv=none; d=google.com; s=arc-20160816; b=jvgwudMRISOQvIF6n/f/9T6EKuQTrAYggFGg99/VC1hbBBar2ikFwYZ9RbFzjUQDc+ apm5JS+6Rx+nRhbai7XdAjWuafW84GD/AFoZFeBC7ngIgTgC12xYFbg/ZhawzYXRm/EC n/QLdUf6e+L7JwhfBves9D0wsQYFUrU/RQb7VxBL0mBso8vGAxOr/FC2UjZFXyGfLZv7 +cOJ3IYcV3tsKJRzJjWnep9SH2YMB2Q6K1xTnjtmNE23zvPZvgAQgvT2u+Tl2WaJMoxQ Y4Zj8/FbXmRnE2q53BYvP7eF+0Fy9egRX5fI+9Xp9QXXw1SlSI+0Z7344KD7E1XwJIb/ XQjg== 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 :arc-authentication-results; bh=QTjU8YvCXR8Ur0mNCr2/myiyIKu3L60CyVXYSuWmpis=; b=fo3weQB46ghDD/Eew69FAJJ8Mja8M3HtA0El73u2bbbF8HJldXFh3k66PidNUDL0Uy HqQajhNFOm+hO+lc7g4hOEYYeEy0U+xK2KrQPVYBKMVI4hWNIvs3q0k9e9d9HSlWFGlU uQwUhTP6UfrHVZ6eek1ouC08O2b8NnAcHzRlJE5zmR1qKPtF0KGIgWwvKKj18C8k66/J Fkv7QQfsTWDCsPPqL0LCjG+GNaThdV63CMCJARxp6CpB/k+yz3HZT082Q3Uy61uUJBuH Lw6hOYnkwGC2BFjAoicyDA8fcPfMj/nF/+NGTWcFFoZrK1sSrwDvgH0ItaY4vAQPkQ8k QLuQ== 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 32si4561283edy.432.2018.04.06.00.42.56; Fri, 06 Apr 2018 00:42:56 -0700 (PDT) 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 EAD94C21DD4; Fri, 6 Apr 2018 07:42:51 +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 C50C8C21C2F; Fri, 6 Apr 2018 07:42:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8E65EC21C2F; Fri, 6 Apr 2018 07:42:48 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 424F0C21C29 for ; Fri, 6 Apr 2018 07:42:48 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EEBC4AE38; Fri, 6 Apr 2018 07:42:47 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 6 Apr 2018 09:42:47 +0200 Message-Id: <20180406074247.76733-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt , afaerber@suse.de Subject: [U-Boot] [PATCH] efi_loader: Respect DT reserved regions 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" With legacy boot (booti, bootz), people can declare memory regions as reserved using device tree memory reservations. This feature is some times used to indicate memory regions that should not be touched. Since in a UEFI world, the DT memory reservations do not get honored, let's copy them into the UEFI memory map so everyone has a coherent view of the world and we give people the chance to add reservations on demand. Signed-off-by: Alexander Graf --- cmd/bootefi.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 2a31a914cd..5a2a81005f 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -178,6 +178,27 @@ static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)( } #endif +/* Carve out DT reserved memory ranges */ +static efi_status_t efi_carve_out_dt_rsv(void *fdt) +{ + int nr_rsv, i; + uint64_t addr, size, pages; + + nr_rsv = fdt_num_mem_rsv(fdt); + + /* Look for an existing entry and add it to the efi mem map. */ + for (i = 0; i < nr_rsv; i++) { + if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0) + continue; + + pages = ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT; + efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, + false); + } + + return EFI_SUCCESS; +} + static efi_status_t efi_install_fdt(void *fdt) { bootm_headers_t img = { 0 }; @@ -199,6 +220,11 @@ static efi_status_t efi_install_fdt(void *fdt) return EFI_LOAD_ERROR; } + if (efi_carve_out_dt_rsv(fdt) != EFI_SUCCESS) { + printf("ERROR: failed to carve out memory\n"); + return EFI_LOAD_ERROR; + } + /* Link to it in the efi tables */ ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS)