[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/19] efi: mm: Extract function to add memory regions
From: |
Daniel Axtens |
Subject: |
[PATCH 11/19] efi: mm: Extract function to add memory regions |
Date: |
Tue, 12 Oct 2021 18:30:00 +1100 |
From: Patrick Steinhardt <ps@pks.im>
In preparation of support for runtime-allocating additional memory
region, this patch extracts the function to retrieve the EFI memory map
and add a subset of it to GRUB's own memory regions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
grub-core/kern/efi/mm.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 4d276bc87a4c..cfc6a67fc0cc 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -504,7 +504,7 @@ add_memory_regions (grub_efi_memory_descriptor_t
*memory_map,
addr = grub_efi_allocate_pages_real (start, pages,
GRUB_EFI_ALLOCATE_ADDRESS,
- GRUB_EFI_LOADER_CODE);
+ GRUB_EFI_LOADER_CODE);
if (! addr)
grub_fatal ("cannot allocate conventional memory %p with %u pages",
(void *) ((grub_addr_t) start),
@@ -556,8 +556,8 @@ print_memory_map (grub_efi_memory_descriptor_t *memory_map,
}
#endif
-void
-grub_efi_mm_init (void)
+static grub_err_t
+grub_efi_mm_add_regions (grub_efi_uint64_t required_bytes)
{
grub_efi_memory_descriptor_t *memory_map;
grub_efi_memory_descriptor_t *memory_map_end;
@@ -570,7 +570,7 @@ grub_efi_mm_init (void)
/* Prepare a memory region to store two memory maps. */
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES
(MEMORY_MAP_SIZE));
if (! memory_map)
- grub_fatal ("cannot allocate memory");
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory");
/* Obtain descriptors for available memory. */
map_size = MEMORY_MAP_SIZE;
@@ -588,14 +588,14 @@ grub_efi_mm_init (void)
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size));
if (! memory_map)
- grub_fatal ("cannot allocate memory");
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory");
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0,
&desc_size, 0);
}
if (mm_status < 0)
- grub_fatal ("cannot get memory map");
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot get memory map");
memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size);
@@ -610,7 +610,7 @@ grub_efi_mm_init (void)
/* Allocate memory regions for GRUB's memory management. */
add_memory_regions (filtered_memory_map, desc_size,
- filtered_memory_map_end, BYTES_TO_PAGES
(DEFAULT_HEAP_SIZE));
+ filtered_memory_map_end, BYTES_TO_PAGES (required_bytes));
#if 0
/* For debug. */
@@ -628,6 +628,15 @@ grub_efi_mm_init (void)
/* Release the memory maps. */
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
+
+ return GRUB_ERR_NONE;
+}
+
+void
+grub_efi_mm_init (void)
+{
+ if (grub_efi_mm_add_regions (DEFAULT_HEAP_SIZE) != GRUB_ERR_NONE)
+ grub_fatal ("%s", grub_errmsg);
}
#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
--
2.30.2
- Re: [PATCH 02/19] grub-shell: pseries: don't pass fw_opt to qemu, (continued)
- [PATCH 05/19] mm: when adding a region, merge with region after as well as before, Daniel Axtens, 2021/10/12
- [PATCH 06/19] configure: properly pass through MM_DEBUG, Daniel Axtens, 2021/10/12
- [PATCH 07/19] Add memtool module with memory allocation stress-test, Daniel Axtens, 2021/10/12
- [PATCH 08/19] mm: Drop unused unloading of modules on OOM, Daniel Axtens, 2021/10/12
- [PATCH 10/19] efi: mm: Always request a fixed number of pages on init, Daniel Axtens, 2021/10/12
- [PATCH 12/19] efi: mm: Pass up errors from `add_memory_regions ()`, Daniel Axtens, 2021/10/12
- [PATCH 09/19] mm: Allow dynamically requesting additional memory regions, Daniel Axtens, 2021/10/12
- [PATCH 11/19] efi: mm: Extract function to add memory regions,
Daniel Axtens <=
- [PATCH 13/19] efi: mm: Implement runtime addition of pages, Daniel Axtens, 2021/10/12
- [PATCH 15/19] ieee1275: drop len -= 1 quirk in heap_init, Daniel Axtens, 2021/10/12
- [PATCH 14/19] ieee1275: request memory with ibm, client-architecture-support, Daniel Axtens, 2021/10/12
- [PATCH 17/19] [not for merge] print more debug info in mm, Daniel Axtens, 2021/10/12
- [PATCH 16/19] ieee1275: support runtime memory claiming, Daniel Axtens, 2021/10/12
- [PATCH 18/19] [not for merge] ieee1275 debugging info, Daniel Axtens, 2021/10/12
- [PATCH 19/19] RFC: Ignore REGION_CONSECUTIVE, Daniel Axtens, 2021/10/12