[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 03/14] loader: drop local implementations of find_efi_mmap_siz
From: |
Leif Lindholm |
Subject: |
[PATCH v2 03/14] loader: drop local implementations of find_efi_mmap_size |
Date: |
Thu, 3 Aug 2017 11:04:21 +0100 |
Now we have a grub_efi_find_mmap_size, replace near-identical implementations
in i386/linux and mbi2 loaders with calls to that one.
Signed-off-by: Leif Lindholm <address@hidden>
---
grub-core/loader/i386/linux.c | 51 +--------------------------------------
grub-core/loader/multiboot_mbi2.c | 38 +----------------------------
2 files changed, 2 insertions(+), 87 deletions(-)
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 083f9417c..dfd50472f 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -101,55 +101,6 @@ page_align (grub_size_t size)
return (size + (1 << 12) - 1) & (~((1 << 12) - 1));
}
-#ifdef GRUB_MACHINE_EFI
-/* Find the optimal number of pages for the memory map. Is it better to
- move this code to efi/mm.c? */
-static grub_efi_uintn_t
-find_efi_mmap_size (void)
-{
- static grub_efi_uintn_t mmap_size = 0;
-
- if (mmap_size != 0)
- return mmap_size;
-
- mmap_size = (1 << 12);
- while (1)
- {
- int ret;
- grub_efi_memory_descriptor_t *mmap;
- grub_efi_uintn_t desc_size;
- grub_efi_uintn_t cur_mmap_size = mmap_size;
-
- mmap = grub_malloc (cur_mmap_size);
- if (! mmap)
- return 0;
-
- ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0);
- grub_free (mmap);
-
- if (ret < 0)
- {
- grub_error (GRUB_ERR_IO, "cannot get memory map");
- return 0;
- }
- else if (ret > 0)
- break;
-
- if (mmap_size < cur_mmap_size)
- mmap_size = cur_mmap_size;
- mmap_size += (1 << 12);
- }
-
- /* Increase the size a bit for safety, because GRUB allocates more on
- later, and EFI itself may allocate more. */
- mmap_size += (3 << 12);
-
- mmap_size = page_align (mmap_size);
- return mmap_size;
-}
-
-#endif
-
/* Helper for find_mmap_size. */
static int
count_hook (grub_uint64_t addr __attribute__ ((unused)),
@@ -560,7 +511,7 @@ grub_linux_boot (void)
ctx.real_size = ALIGN_UP (cl_offset + maximal_cmdline_size, 4096);
#ifdef GRUB_MACHINE_EFI
- efi_mmap_size = find_efi_mmap_size ();
+ efi_mmap_size = grub_efi_find_mmap_size ();
if (efi_mmap_size == 0)
return grub_errno;
#endif
diff --git a/grub-core/loader/multiboot_mbi2.c
b/grub-core/loader/multiboot_mbi2.c
index b0679a9f6..b5f961494 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -407,42 +407,6 @@ acpiv2_size (void)
static grub_efi_uintn_t efi_mmap_size = 0;
-/* Find the optimal number of pages for the memory map. Is it better to
- move this code to efi/mm.c? */
-static void
-find_efi_mmap_size (void)
-{
- efi_mmap_size = (1 << 12);
- while (1)
- {
- int ret;
- grub_efi_memory_descriptor_t *mmap;
- grub_efi_uintn_t desc_size;
- grub_efi_uintn_t cur_mmap_size = efi_mmap_size;
-
- mmap = grub_malloc (cur_mmap_size);
- if (! mmap)
- return;
-
- ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0);
- grub_free (mmap);
-
- if (ret < 0)
- return;
- else if (ret > 0)
- break;
-
- if (efi_mmap_size < cur_mmap_size)
- efi_mmap_size = cur_mmap_size;
- efi_mmap_size += (1 << 12);
- }
-
- /* Increase the size a bit for safety, because GRUB allocates more on
- later, and EFI itself may allocate more. */
- efi_mmap_size += (3 << 12);
-
- efi_mmap_size = ALIGN_UP (efi_mmap_size, 4096);
-}
#endif
static grub_size_t
@@ -463,7 +427,7 @@ grub_multiboot_get_mbi_size (void)
{
#ifdef GRUB_MACHINE_EFI
if (!keep_bs && !efi_mmap_size)
- find_efi_mmap_size ();
+ efi_mmap_size = grub_efi_find_mmap_size ();
#endif
return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
+ sizeof (struct multiboot_tag)
--
2.11.0
- [PATCH v2 00/14] efi: improved correctness, arm unification, and cleanup, Leif Lindholm, 2017/08/03
- [PATCH v2 01/14] arm64/efi: move EFI_PAGE definitions to efi/memory.h, Leif Lindholm, 2017/08/03
- [PATCH v2 04/14] efi: add grub_efi_get_ram_base() function for arm*, Leif Lindholm, 2017/08/03
- [PATCH v2 02/14] efi: add central copy of grub_efi_find_mmap_size, Leif Lindholm, 2017/08/03
- [PATCH v2 03/14] loader: drop local implementations of find_efi_mmap_size,
Leif Lindholm <=
- [PATCH v2 06/14] efi: move fdt helper library, Leif Lindholm, 2017/08/03
- [PATCH v2 05/14] efi: refactor grub_efi_allocate_pages, Leif Lindholm, 2017/08/03
- [PATCH v2 07/14] efi: Add GRUB_PE32_MAGIC definition, Leif Lindholm, 2017/08/03
- [PATCH v2 11/14] arm/efi: switch to arm64 linux loader, Leif Lindholm, 2017/08/03
- [PATCH v2 08/14] arm64 linux loader: improve type portability, Leif Lindholm, 2017/08/03