From patchwork Tue Feb 28 22:35:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94667 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1528595qgi; Tue, 28 Feb 2017 14:38:26 -0800 (PST) X-Received: by 10.200.53.237 with SMTP id l42mr5802026qtb.264.1488321506950; Tue, 28 Feb 2017 14:38:26 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 93si2630276qkv.164.2017.02.28.14.38.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:38:26 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqPY-0007Sb-FT for patch@linaro.org; Tue, 28 Feb 2017 17:38:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqMx-0004qo-KY for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMw-0004YC-K1 for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:43 -0500 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:36450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMw-0004XH-Du for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:42 -0500 Received: by mail-wr0-x22d.google.com with SMTP id u108so18391597wrb.3 for ; Tue, 28 Feb 2017 14:35:40 -0800 (PST) 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; bh=XSOLKBaUhtn9O/vplOz1mskzWnFdB3dMvLkXx3NCJNw=; b=EwCs0oUFAGApdssGFcNyvh+ILhmDUCfn3ya96a2x7kSIRrXIWKsX+4gaRFmQol7tZm 7VhmjR8+npdgprg//GOXPdsCo2SwV7q+sm70I6qjdG263UBlon+k2EvE6vLc1Cr54vT3 SM61CYuiZPUVqADs8ZSgVyfDX3oI0pF+lQSuw= 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; bh=XSOLKBaUhtn9O/vplOz1mskzWnFdB3dMvLkXx3NCJNw=; b=BE3tdJV+/9Dkp0vMCi0FRou5sfreGSJaKZSPzbDswijxghpkeXEXAdppTd/PqFNtzV TeeA1U/8fWDp+QHGxtyKTfw0z/3xnViEwszwtVqRDFUoL7/mWrw/LxCOd58PGBk807jK ulX1v7tHO4bu0UX+rgE1EAQ9EpUVmneRGbeoXuHLbpW32Qd+Syzk7bKMiNtgO4TNLpic gogdQi21/pye4OoNPJHf3CwBNJO9yendCKx+MqOrEZTDQLeKQY0R3zD/jjznkShYUuwC cFRnfHbH1HVvyqtqZKKmeFr8N6HPwoXwY6yZ8upPkX/FdsqI6crRbaTeR94g19y7iVz1 kGSg== X-Gm-Message-State: AMke39lHCV7vdTQu+gFKVzXz8mLD2s0V0TFMY8Op23Jq4lEnQaXU2pnPLPFDsxTjbc8Is96y X-Received: by 10.223.168.43 with SMTP id l40mr4271396wrc.150.1488321339862; Tue, 28 Feb 2017 14:35:39 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:39 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm* Date: Tue, 28 Feb 2017 22:35:31 +0000 Message-Id: <20170228223537.9685-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Since ARM platforms do not have a common memory map, add a helper function that finds the lowest address region with the EFI_MEMORY_WB attribute set in the UEFI memory map. Required for the (32-bit) arm linux loader to restrict the initrd location to where it will be accessible by the kernel at runtime. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/grub/efi/efi.h | 1 + 2 files changed, 43 insertions(+) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 20a47aaf5..460a4b763 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -525,3 +525,45 @@ grub_efi_mm_init (void) grub_efi_free_pages ((grub_addr_t) memory_map, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } + +#if defined (__arm__) || defined (__aarch64__) +grub_err_t +grub_efi_get_dram_base(grub_addr_t *base_addr) +{ + grub_efi_memory_descriptor_t *memory_map; + grub_efi_memory_descriptor_t *desc; + grub_efi_uintn_t mmap_size; + grub_efi_uintn_t desc_size; + + mmap_size = (1 << GRUB_EFI_PAGE_SHIFT); + while (1) + { + int ret; + + memory_map = grub_malloc (mmap_size); + if (! memory_map) + return GRUB_ERR_OUT_OF_MEMORY; + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, + &desc_size, NULL); + if (ret > 0) + break; + + grub_free (memory_map); + if (ret == 0) + return GRUB_ERR_BUG; + + mmap_size += (1 << GRUB_EFI_PAGE_SHIFT); + } + + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) + { + if (desc->attribute & GRUB_EFI_MEMORY_WB) + if (desc->physical_start < *base_addr) + *base_addr = desc->physical_start; + } + + return GRUB_ERR_NONE; +} +#endif diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e9c601f34..845fc2438 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -83,6 +83,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, #if defined(__arm__) || defined(__aarch64__) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); +grub_err_t EXPORT_FUNC(grub_efi_get_dram_base)(grub_addr_t *); #endif grub_addr_t grub_efi_modules_addr (void);