From patchwork Mon Jun 12 14:53:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 103629 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp232963qgd; Mon, 12 Jun 2017 07:57:07 -0700 (PDT) X-Received: by 10.55.54.7 with SMTP id d7mr29386077qka.258.1497279427244; Mon, 12 Jun 2017 07:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497279427; cv=none; d=google.com; s=arc-20160816; b=pBJ7RE5uiBIrviNxGGkCWHmnXSytuYZmMg9fVtJMAXu2fuuL2gJ/U1LQ/4uMyzQn7X ZWkKzY1KZ62c9Pg1WkD5zPm6rUdShhOwUaW/mp94qeeeu90z/Kab/UQp7pwyZEdSeyKC sKSxAGE2RGJ5KKsND+77GUO/vISARNbXAzMrKkkyntO8cWB7ie2wiUq72hWZsUdCUOo7 OKGDHlEbcZZCN7ivuSGx8wn3+XaS9jSGRZcq75JxkvgAo9BavPAApriFAkTH5R/NmgVp enEOYrGCzll2to7oBz5AJuuR2w05RXguJY8mUKlPcSTnr/7pvvih8HtU62318S81peaD 2M6g== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:arc-authentication-results; bh=7FYIBIuViySTPiaXi5H/eO1iU3PRJZlF4R7+dINk76Y=; b=mhnA8FyonfSxpkiGIsdv0rQlTLRDtJ7Ns9Vpii6dkOFGC5l6hcJjwyCSBTuDF40YCx LtKCuQEMPx8C0VHdHjJuE+4AErTLwNNz71GnAVlTOKTTg9Xq0ismqvPqg6hFmc7zz4Ns Zj4HX1k/GLH9W1zL5hfDqP3NDSbzwr8OCcZPchkah3RrDZv27/aQQcLykkeUu+AegGQt bQgtHS4zjyi3b4xaHej/7GBGLXdA4Wg4FigXS6UdrVQm47i+5NL+5RJ3Li+f3a6wlNyP 5KahZkMGG6V7VMAUUx+fC3QV1Z+1hLOuUPqeDqMN1RIPHdPSTPzk6Z3HdPZbSsGqAyJX 5hKg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s37si8776810qte.104.2017.06.12.07.57.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 12 Jun 2017 07:57:07 -0700 (PDT) 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]:38516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQm8-0000wf-Ot for patch@linaro.org; Mon, 12 Jun 2017 10:57:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQky-0000tz-9G for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKQkw-0000uW-RS for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:52 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:34081) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKQkw-0000uF-JS for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:50 -0400 Received: by mail-wr0-x230.google.com with SMTP id g76so98958289wrd.1 for ; Mon, 12 Jun 2017 07:55:50 -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; bh=FmPKJ6T6RMiB7ad1iiASLo3pTNH6PHIoIgPwTf6I7iI=; b=hiF6eJ6m1VxDBbCQytP88I/FIB7CJyHRQEcUYxhViQZvDkwhRtrlZiZKdko6NMQVEa TNIpU9VGFqNyXpuYMZei1aYnJ72QuWgzEnAChLxALy4QkHAF9i1oXKI/FoFYWpVTIBU+ qF6XgOKiDufrl5i8UsHUPwkrqmhb1+OeJoZHw= 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=FmPKJ6T6RMiB7ad1iiASLo3pTNH6PHIoIgPwTf6I7iI=; b=SvmvuIxKO8B8pyGxUMuELAd0kI3BrHwbqpfwv5mtW3AEJoV6LqNyzeZ2WwFJUa8B+z 89jlLsGLfYIy0+G1bOeiqdEx4DcW7cd+/xZiF7WiS9ZMicTeBW/wO8bdP3TO0sJv+WQr SS7K+gU1C/DX6JmnHGVl6wNm6Mne1KOm/a6G6opAmD6WZC8WC3PK9miL+oURZhwFgF3I dDvbRYCi6febEBjQC/+fuUHTJ6t1khNlPAggJDhw7OvFK8KuxN52JKKsPUYWBA/o4CwB 1YacG8FdTz/m56S8D0174/cC99g2mJsx5U3Qqb8bBFvogglTnE9M7LO/6am6w7Y8Wbjy bi5Q== X-Gm-Message-State: AKS2vOxcES5olbTOsYX95AMR9PjwBaBQ/ILI8d2h8cenUwbuZTarpG5l ccmabRiA4RsHMfxvX32ADw== X-Received: by 10.223.169.203 with SMTP id b69mr8521361wrd.1.1497279344453; Mon, 12 Jun 2017 07:55:44 -0700 (PDT) Received: from mohikan.hemma.eciton.net (cpc92316-cmbg19-2-0-cust118.5-4.cable.virginm.net. [82.12.0.119]) by smtp.gmail.com with ESMTPSA id s140sm7722wmd.1.2017.06.12.07.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 07:55:43 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm* Date: Mon, 12 Jun 2017 15:53:35 +0100 Message-Id: <20170612145341.3351-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612145341.3351-1-leif.lindholm@linaro.org> References: <20170612145341.3351-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::230 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: ard.biesheuvel@linaro.org, lersek@redhat.com, agraf@suse.de, kraxel@redhat.com 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 arm/arm64 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);