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@xxxxxxxxxxxxxx> --- efi/payload/Makefile | 2 ++ efi/payload/early-mem.c | 32 +++++++++++++++++++++++++++ efi/payload/entry-single.c | 45 ++++++++++++++++++++++++++++++++++++++ efi/payload/init.c | 45 -------------------------------------- include/efi/efi-payload.h | 3 +++ 5 files changed, 82 insertions(+), 45 deletions(-) create mode 100644 efi/payload/early-mem.c create mode 100644 efi/payload/entry-single.c diff --git a/efi/payload/Makefile b/efi/payload/Makefile index eeed046b0045..71305bee7006 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 000000000000..24bc1d34cc51 --- /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 000000000000..cb7981e03060 --- /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 9bc0741e044b..d5ec86fafe1a 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 3713ef359228..774c069229ab 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 -- 2.39.2