[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm*
From: |
Leif Lindholm |
Subject: |
[PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm* |
Date: |
Mon, 12 Jun 2017 15:53:35 +0100 |
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 <address@hidden>
---
grub-core/kern/efi/mm.c | 42 ++++++++++++++++++++++++++++++++++++++++++
include/grub/efi/efi.h | 1 +
2 files changed, 43 insertions(+)
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);
--
2.11.0
- [PATCH 0/7] efi: improved correctness, arm unification, and cleanup, Leif Lindholm, 2017/06/12
- [PATCH 1/7] efi: add grub_efi_get_dram_base() function for arm*,
Leif Lindholm <=
- [PATCH 3/7] efi: move fdt helper library, Leif Lindholm, 2017/06/12
- [PATCH 2/7] efi: refactor grub_efi_allocate_pages, Leif Lindholm, 2017/06/12
- [PATCH 7/7] efi: change heap allocation type to GRUB_EFI_LOADER_CODE, Leif Lindholm, 2017/06/12
- [PATCH 6/7] efi: restrict arm/arm64 linux loader initrd placement, Leif Lindholm, 2017/06/12
- [PATCH 5/7] arm: reuse arm64 linux loader on efi systems, Leif Lindholm, 2017/06/12
- [PATCH 4/7] arm64: make efi linux loader more generic, Leif Lindholm, 2017/06/12
- Re: [PATCH 0/7] efi: improved correctness, arm unification, and cleanup, Daniel Kiper, 2017/06/20