From: Leif Lindholm <leif.lindholm@linaro.org>
To: grub-devel@gnu.org
Cc: Daniel Kiper <daniel.kiper@oracle.com>
Subject: [PATCH v4 1/6] efi: add central copy of grub_efi_find_mmap_size
Date: Mon, 9 Jul 2018 18:33:00 +0100 [thread overview]
Message-ID: <20180709173305.17588-2-leif.lindholm@linaro.org> (raw)
In-Reply-To: <20180709173305.17588-1-leif.lindholm@linaro.org>
There are several implementations of this function in the tree.
Add a central version in grub-core/efi/mm.c.
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
---
grub-core/kern/efi/mm.c | 20 ++++++++++++++++++++
include/grub/efi/efi.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index c48e9b5c7..fd39d23b4 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -286,6 +286,26 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
return GRUB_ERR_NONE;
}
+/* To obtain the UEFI memory map, we must pass a buffer of sufficient size
+ to hold the entire map. This function returns a sane start value for
+ buffer size. */
+grub_efi_uintn_t
+grub_efi_find_mmap_size (void)
+{
+ grub_efi_uintn_t mmap_size = 0;
+ grub_efi_uintn_t desc_size;
+
+ if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0)
+ {
+ grub_error (GRUB_ERR_IO, "cannot get EFI memory map size");
+ return 0;
+ }
+
+ /* Add an extra page, since UEFI can alter the memory map itself on
+ callbacks or explicit calls, including console output. */
+ return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_SIZE);
+}
+
/* Get the memory map as defined in the EFI spec. Return 1 if successful,
return 0 if partial, or return -1 if an error occurs. */
int
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index c996913e5..1021273c1 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -49,6 +49,7 @@ void *
EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
grub_efi_uintn_t pages);
+grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);
int
EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size,
grub_efi_memory_descriptor_t *memory_map,
--
2.11.0
next prev parent reply other threads:[~2018-07-09 17:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 17:32 [PATCH v4 0/6] efi: arm linux loader unification and correctness Leif Lindholm
2018-07-09 17:33 ` Leif Lindholm [this message]
2018-07-09 17:33 ` [PATCH v4 2/6] efi: add grub_efi_get_ram_base() function for arm64 Leif Lindholm
2018-07-09 17:33 ` [PATCH v4 3/6] arm64 linux loader: rename functions and macros and move to common headers Leif Lindholm
2018-07-09 17:33 ` [PATCH v4 4/6] arm/efi: switch to arm64 linux loader Leif Lindholm
2018-07-09 17:33 ` [PATCH v4 5/6] arm: delete unused efi support from loader/arm Leif Lindholm
2018-07-09 17:33 ` [PATCH v4 6/6] efi: restrict arm/arm64 linux loader initrd placement Leif Lindholm
2018-07-10 12:20 ` [PATCH v4 0/6] efi: arm linux loader unification and correctness Daniel Kiper
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=20180709173305.17588-2-leif.lindholm@linaro.org \
--to=leif.lindholm@linaro.org \
--cc=daniel.kiper@oracle.com \
--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).