summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 20:00:08 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:06 +0100
commitc6d2ed6850eeba71f3913904ccb6a45442177a06 (patch)
treedff7ab154f38f2297ca4114f861776d4b1d92e84
parent158ca31e5619cec2c006ad981cdd8e2633232bdf (diff)
downloadbarebox-c6d2ed6850eeba71f3913904ccb6a45442177a06.tar.gz
barebox-c6d2ed6850eeba71f3913904ccb6a45442177a06.tar.xz
efi: payload: factor C efi_main into dedicated file
For barebox as EFI payload on ARM, we will not call start_barebox() ourselves as we will be using PBL, which we don't on x86 yet. Therefore move that code out of the common init.c into a new entry-single.c and early-mem.c that can be used as needed. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-84-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--efi/payload/Makefile2
-rw-r--r--efi/payload/early-mem.c32
-rw-r--r--efi/payload/entry-single.c45
-rw-r--r--efi/payload/init.c45
-rw-r--r--include/efi/efi-payload.h3
5 files changed, 82 insertions, 45 deletions
diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index eeed046b00..71305bee70 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -5,3 +5,5 @@ obj-y += image.o
obj-$(CONFIG_OFTREE) += fdt.o
bbenv-y += env-efi
obj-$(CONFIG_CMD_IOMEM) += iomem.o
+obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o
+obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
new file mode 100644
index 0000000000..24bc1d34cc
--- /dev/null
+++ b/efi/payload/early-mem.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/kernel.h>
+#include <linux/sizes.h>
+#include <efi.h>
+#include <efi/efi-payload.h>
+#include <linux/pagemap.h>
+
+efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
+ size_t *memsize)
+{
+ struct efi_boot_services *bs = sys_table->boottime;
+ efi_physical_addr_t mem;
+ efi_status_t efiret;
+
+ mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
+ for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
+ efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
+ EFI_LOADER_DATA,
+ *memsize/PAGE_SIZE, &mem);
+ if (!EFI_ERROR(efiret))
+ break;
+ if (efiret != EFI_OUT_OF_RESOURCES)
+ panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+ }
+ if (EFI_ERROR(efiret))
+ panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+
+ return mem;
+}
diff --git a/efi/payload/entry-single.c b/efi/payload/entry-single.c
new file mode 100644
index 0000000000..cb7981e030
--- /dev/null
+++ b/efi/payload/entry-single.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifdef CONFIG_DEBUG_LL
+#define DEBUG
+#endif
+
+#include <linux/kernel.h>
+#include <linux/sizes.h>
+#include <efi.h>
+#include <efi/efi-payload.h>
+#include <memory.h>
+#include <common.h>
+
+/**
+ * efi-main - Entry point for EFI images
+ */
+void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
+{
+ efi_status_t efiret;
+ size_t memsize;
+ efi_physical_addr_t mem;
+
+#ifdef DEBUG
+ sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
+#endif
+
+ BS = sys_table->boottime;
+
+ efi_parent_image = image;
+ efi_sys_table = sys_table;
+ RT = sys_table->runtime;
+
+ efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
+ (void **)&efi_loaded_image,
+ efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (!EFI_ERROR(efiret))
+ BS->handle_protocol(efi_loaded_image->device_handle,
+ &efi_device_path_protocol_guid, (void **)&efi_device_path);
+
+ mem = efi_earlymem_alloc(sys_table, &memsize);
+
+ mem_malloc_init((void *)mem, (void *)mem + memsize - 1);
+
+ start_barebox();
+}
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 9bc0741e04..d5ec86fafe 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -267,51 +267,6 @@ static int efi_init(void)
}
device_efi_initcall(efi_init);
-/**
- * efi-main - Entry point for EFI images
- */
-void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
-{
- efi_physical_addr_t mem;
- size_t memsize;
- efi_status_t efiret;
-
-#ifdef DEBUG
- sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
-#endif
-
- BS = sys_table->boottime;
-
- efi_parent_image = image;
- efi_sys_table = sys_table;
- RT = sys_table->runtime;
-
- efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
- (void **)&efi_loaded_image,
- efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (!EFI_ERROR(efiret))
- BS->handle_protocol(efi_loaded_image->device_handle,
- &efi_device_path_protocol_guid, (void **)&efi_device_path);
-
- mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
- for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
- efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
- EFI_LOADER_DATA,
- memsize/PAGE_SIZE, &mem);
- if (!EFI_ERROR(efiret))
- break;
- if (efiret != EFI_OUT_OF_RESOURCES)
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- }
- if (EFI_ERROR(efiret))
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- mem_malloc_init((void *)mem, (void *)mem + memsize - 1);
-
- start_barebox();
-}
-
static int efi_core_init(void)
{
struct device *dev;
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 3713ef3592..774c069229 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -25,4 +25,7 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
void *buf, unsigned long size);
int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
+efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
+ size_t *memsize);
+
#endif