Path: blob/master/drivers/firmware/efi/libstub/efi-stub-entry.c
51913 views
// SPDX-License-Identifier: GPL-2.0-only12#include <linux/efi.h>3#include <linux/sysfb.h>45#include <asm/efi.h>67#include "efistub.h"89static unsigned long kernel_image_offset;1011static void *kernel_image_addr(void *addr)12{13return addr + kernel_image_offset;14}1516struct sysfb_display_info *alloc_primary_display(void)17{18if (IS_ENABLED(CONFIG_ARM))19return __alloc_primary_display();2021if (IS_ENABLED(CONFIG_X86) ||22IS_ENABLED(CONFIG_EFI_EARLYCON) ||23IS_ENABLED(CONFIG_SYSFB))24return kernel_image_addr(&sysfb_primary_display);2526return NULL;27}2829/*30* EFI entry point for the generic EFI stub used by ARM, arm64, RISC-V and31* LoongArch. This is the entrypoint that is described in the PE/COFF header32* of the core kernel.33*/34efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,35efi_system_table_t *systab)36{37efi_loaded_image_t *image;38efi_status_t status;39unsigned long image_addr;40unsigned long image_size = 0;41/* addr/point and size pairs for memory management*/42char *cmdline_ptr = NULL;43efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID;44unsigned long reserve_addr = 0;45unsigned long reserve_size = 0;4647WRITE_ONCE(efi_system_table, systab);4849/* Check if we were booted by the EFI firmware */50if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)51return EFI_INVALID_PARAMETER;5253/*54* Get a handle to the loaded image protocol. This is used to get55* information about the running image, such as size and the command56* line.57*/58status = efi_bs_call(handle_protocol, handle, &loaded_image_proto,59(void *)&image);60if (status != EFI_SUCCESS) {61efi_err("Failed to get loaded image protocol\n");62return status;63}6465status = efi_handle_cmdline(image, &cmdline_ptr);66if (status != EFI_SUCCESS)67return status;6869efi_info("Booting Linux Kernel...\n");7071status = handle_kernel_image(&image_addr, &image_size,72&reserve_addr,73&reserve_size,74image, handle);75if (status != EFI_SUCCESS) {76efi_err("Failed to relocate kernel\n");77return status;78}7980kernel_image_offset = image_addr - (unsigned long)image->image_base;8182status = efi_stub_common(handle, image, image_addr, cmdline_ptr);8384efi_free(image_size, image_addr);85efi_free(reserve_size, reserve_addr);8687return status;88}899091