]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
lmb: move lmb_map_update_notify() to EFI
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 16 Feb 2025 11:12:40 +0000 (12:12 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 20 Feb 2025 10:09:33 +0000 (11:09 +0100)
When building with qemu_arm64_defconfig with CONFIG_CC_OPTIMIZE_FOR_DEBUG=y
and CONFIG_EFI_LOADER=n an error undefined reference to efi_add_memory_map_pg
occurs.

Move the EFI dependent part of lmb_map_update_notify() to the EFI
sub-system.

Reported-by: Liya Huang <1425075683@qq.com>
Acked-by: Liya Huang <1425075683@qq.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
include/efi_loader.h
lib/efi_loader/efi_memory.c
lib/lmb.c

index dcae6a731a07fd71f382e2c8be1d75875b8de148..db3d20fd75389d0ab49c1da64f5e3aff0a60fbc1 100644 (file)
@@ -1263,6 +1263,21 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int
  */
 void efi_add_known_memory(void);
 
+/**
+ * efi_map_update_notify() - notify EFI of memory map changes
+ *
+ * @addr:      start of memory area
+ * @size:      size of memory area
+ * @op:                type of change
+ * Return:     0 if change could be processed
+ */
+#ifdef CONFIG_EFI_LOADER
+int efi_map_update_notify(phys_addr_t addr, phys_size_t size,
+                         enum lmb_map_op op);
+#else
+#define efi_map_update_notify(addr, size, op) (0)
+#endif
+
 /**
  * efi_load_option_dp_join() - join device-paths for load option
  *
index 1212772471e36ba9f6bdda5f74a9eb8c9c0f43dc..11d092dc289f4dddc3100fa6b7665a2231255378 100644 (file)
@@ -865,3 +865,30 @@ int efi_memory_init(void)
 
        return 0;
 }
+
+int efi_map_update_notify(phys_addr_t addr, phys_size_t size,
+                         enum lmb_map_op op)
+{
+       u64 efi_addr;
+       u64 pages;
+       efi_status_t status;
+
+       efi_addr = (uintptr_t)map_sysmem(addr, 0);
+       pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK));
+       efi_addr &= ~EFI_PAGE_MASK;
+
+       status = efi_add_memory_map_pg(efi_addr, pages,
+                                      op == LMB_MAP_OP_RESERVE ?
+                                      EFI_BOOT_SERVICES_DATA :
+                                      EFI_CONVENTIONAL_MEMORY,
+                                      false);
+       if (status != EFI_SUCCESS) {
+               log_err("LMB Map notify failure %lu\n",
+                       status & ~EFI_ERROR_MASK);
+               return -1;
+       }
+       unmap_sysmem((void *)(uintptr_t)efi_addr);
+
+       return 0;
+}
+
index 7534a231c993eff63214710ed643354f4c419115..93fc1bea07cd93cc26df9ec701b213812ee89cf0 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -426,37 +426,12 @@ long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size)
 
 static struct lmb lmb;
 
-static bool lmb_should_notify(u32 flags)
-{
-       return !lmb.test && !(flags & LMB_NONOTIFY) &&
-               CONFIG_IS_ENABLED(EFI_LOADER);
-}
-
 static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size,
                                 enum lmb_map_op op, u32 flags)
 {
-       u64 efi_addr;
-       u64 pages;
-       efi_status_t status;
-
-       if (!lmb_should_notify(flags))
-               return 0;
-
-       efi_addr = (uintptr_t)map_sysmem(addr, 0);
-       pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK));
-       efi_addr &= ~EFI_PAGE_MASK;
-
-       status = efi_add_memory_map_pg(efi_addr, pages,
-                                      op == LMB_MAP_OP_RESERVE ?
-                                      EFI_BOOT_SERVICES_DATA :
-                                      EFI_CONVENTIONAL_MEMORY,
-                                      false);
-       if (status != EFI_SUCCESS) {
-               log_err("%s: LMB Map notify failure %lu\n", __func__,
-                       status & ~EFI_ERROR_MASK);
-               return -1;
-       }
-       unmap_sysmem((void *)(uintptr_t)efi_addr);
+       if (CONFIG_IS_ENABLED(EFI_LOADER) &&
+           !lmb.test && !(flags & LMB_NONOTIFY))
+               return efi_map_update_notify(addr, size, op);
 
        return 0;
 }