From: Leif Lindholm <leif.lindholm@linaro.org>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>
Subject: [PATCH v2 04/14] efi: add grub_efi_get_ram_base() function for arm*
Date: Thu, 3 Aug 2017 11:04:22 +0100 [thread overview]
Message-ID: <20170803100432.29913-5-leif.lindholm@linaro.org> (raw)
In-Reply-To: <20170803100432.29913-1-leif.lindholm@linaro.org>
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 <leif.lindholm@linaro.org>
---
grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++
include/grub/efi/efi.h | 3 +++
2 files changed, 39 insertions(+)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 31ca703ec..8413c19e5 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -569,3 +569,39 @@ grub_efi_mm_init (void)
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
}
+
+#if defined (__aarch64__)
+grub_err_t
+grub_efi_get_ram_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;
+ int ret;
+
+ mmap_size = grub_efi_find_mmap_size();
+
+ 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 < 1)
+ return GRUB_ERR_BUG;
+
+ 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;
+ }
+
+ grub_free(memory_map);
+
+ return GRUB_ERR_NONE;
+}
+#endif
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index 3984de083..80ab56795 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -85,6 +85,9 @@ 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);
#endif
+#if defined(__aarch64__)
+grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
+#endif
grub_addr_t grub_efi_modules_addr (void);
--
2.11.0
next prev parent reply other threads:[~2017-08-03 10:06 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 10:04 [PATCH v2 00/14] efi: improved correctness, arm unification, and cleanup Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 01/14] arm64/efi: move EFI_PAGE definitions to efi/memory.h Leif Lindholm
2017-08-03 15:18 ` Vladimir 'phcoder' Serbinenko
2017-08-04 9:11 ` Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 02/14] efi: add central copy of grub_efi_find_mmap_size Leif Lindholm
2017-08-03 15:19 ` Vladimir 'phcoder' Serbinenko
2017-08-08 15:56 ` Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 03/14] loader: drop local implementations of find_efi_mmap_size Leif Lindholm
2017-08-03 15:20 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` Leif Lindholm [this message]
2017-08-03 15:30 ` [PATCH v2 04/14] efi: add grub_efi_get_ram_base() function for arm* Vladimir 'phcoder' Serbinenko
2017-08-08 16:04 ` Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 05/14] efi: refactor grub_efi_allocate_pages Leif Lindholm
2017-08-03 15:37 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 06/14] efi: move fdt helper library Leif Lindholm
2017-08-03 15:38 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 07/14] efi: Add GRUB_PE32_MAGIC definition Leif Lindholm
2017-08-03 16:35 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 08/14] arm64 linux loader: improve type portability Leif Lindholm
2017-08-03 16:41 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 09/14] arm64 linux loader: rename functions and macros and move to common headers Leif Lindholm
2017-08-03 16:44 ` Vladimir 'phcoder' Serbinenko
2017-08-03 16:46 ` Vladimir 'phcoder' Serbinenko
2017-09-04 14:29 ` Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 10/14] loader: switch arm/linux to grub_linux_kernel_header struct Leif Lindholm
2017-08-07 14:07 ` Vladimir 'phcoder' Serbinenko
2017-09-04 14:31 ` Leif Lindholm
2017-09-04 14:35 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 11/14] arm/efi: switch to arm64 linux loader Leif Lindholm
2017-08-07 14:08 ` Vladimir 'phcoder' Serbinenko
2017-09-04 14:35 ` Leif Lindholm
2017-08-03 10:04 ` [PATCH v2 12/14] arm: delete unused efi support from loader/arm Leif Lindholm
2017-08-07 14:09 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 13/14] efi: restrict arm/arm64 linux loader initrd placement Leif Lindholm
2017-08-07 14:10 ` Vladimir 'phcoder' Serbinenko
2017-08-03 10:04 ` [PATCH v2 14/14] efi: change heap allocation type to GRUB_EFI_LOADER_CODE Leif Lindholm
2017-08-07 14:11 ` Vladimir 'phcoder' Serbinenko
2017-08-07 16:18 ` Konrad Rzeszutek Wilk
2017-08-07 16:22 ` Vladimir 'phcoder' Serbinenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170803100432.29913-5-leif.lindholm@linaro.org \
--to=leif.lindholm@linaro.org \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).