142c8ea3dSArd Biesheuvel // SPDX-License-Identifier: GPL-2.0-only 242c8ea3dSArd Biesheuvel 342c8ea3dSArd Biesheuvel #include <linux/efi.h> 442c8ea3dSArd Biesheuvel #include <asm/efi.h> 542c8ea3dSArd Biesheuvel 642c8ea3dSArd Biesheuvel #include "efistub.h" 742c8ea3dSArd Biesheuvel 8*fc3608aaSArd Biesheuvel static unsigned long screen_info_offset; 9*fc3608aaSArd Biesheuvel 10*fc3608aaSArd Biesheuvel struct screen_info *alloc_screen_info(void) 11*fc3608aaSArd Biesheuvel { 12*fc3608aaSArd Biesheuvel if (IS_ENABLED(CONFIG_ARM)) 13*fc3608aaSArd Biesheuvel return __alloc_screen_info(); 14*fc3608aaSArd Biesheuvel return (void *)&screen_info + screen_info_offset; 15*fc3608aaSArd Biesheuvel } 16*fc3608aaSArd Biesheuvel 1742c8ea3dSArd Biesheuvel /* 1842c8ea3dSArd Biesheuvel * EFI entry point for the generic EFI stub used by ARM, arm64, RISC-V and 1942c8ea3dSArd Biesheuvel * LoongArch. This is the entrypoint that is described in the PE/COFF header 2042c8ea3dSArd Biesheuvel * of the core kernel. 2142c8ea3dSArd Biesheuvel */ 2242c8ea3dSArd Biesheuvel efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, 2342c8ea3dSArd Biesheuvel efi_system_table_t *systab) 2442c8ea3dSArd Biesheuvel { 2542c8ea3dSArd Biesheuvel efi_loaded_image_t *image; 2642c8ea3dSArd Biesheuvel efi_status_t status; 2742c8ea3dSArd Biesheuvel unsigned long image_addr; 2842c8ea3dSArd Biesheuvel unsigned long image_size = 0; 2942c8ea3dSArd Biesheuvel /* addr/point and size pairs for memory management*/ 3042c8ea3dSArd Biesheuvel char *cmdline_ptr = NULL; 3142c8ea3dSArd Biesheuvel efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID; 3242c8ea3dSArd Biesheuvel unsigned long reserve_addr = 0; 3342c8ea3dSArd Biesheuvel unsigned long reserve_size = 0; 3442c8ea3dSArd Biesheuvel 3542c8ea3dSArd Biesheuvel WRITE_ONCE(efi_system_table, systab); 3642c8ea3dSArd Biesheuvel 3742c8ea3dSArd Biesheuvel /* Check if we were booted by the EFI firmware */ 3842c8ea3dSArd Biesheuvel if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 3942c8ea3dSArd Biesheuvel return EFI_INVALID_PARAMETER; 4042c8ea3dSArd Biesheuvel 4142c8ea3dSArd Biesheuvel /* 4242c8ea3dSArd Biesheuvel * Get a handle to the loaded image protocol. This is used to get 4342c8ea3dSArd Biesheuvel * information about the running image, such as size and the command 4442c8ea3dSArd Biesheuvel * line. 4542c8ea3dSArd Biesheuvel */ 4642c8ea3dSArd Biesheuvel status = efi_bs_call(handle_protocol, handle, &loaded_image_proto, 4742c8ea3dSArd Biesheuvel (void *)&image); 4842c8ea3dSArd Biesheuvel if (status != EFI_SUCCESS) { 4942c8ea3dSArd Biesheuvel efi_err("Failed to get loaded image protocol\n"); 5042c8ea3dSArd Biesheuvel return status; 5142c8ea3dSArd Biesheuvel } 5242c8ea3dSArd Biesheuvel 5342c8ea3dSArd Biesheuvel status = efi_handle_cmdline(image, &cmdline_ptr); 5442c8ea3dSArd Biesheuvel if (status != EFI_SUCCESS) 5542c8ea3dSArd Biesheuvel return status; 5642c8ea3dSArd Biesheuvel 5742c8ea3dSArd Biesheuvel efi_info("Booting Linux Kernel...\n"); 5842c8ea3dSArd Biesheuvel 5942c8ea3dSArd Biesheuvel status = handle_kernel_image(&image_addr, &image_size, 6042c8ea3dSArd Biesheuvel &reserve_addr, 6142c8ea3dSArd Biesheuvel &reserve_size, 6242c8ea3dSArd Biesheuvel image, handle); 6342c8ea3dSArd Biesheuvel if (status != EFI_SUCCESS) { 6442c8ea3dSArd Biesheuvel efi_err("Failed to relocate kernel\n"); 6542c8ea3dSArd Biesheuvel return status; 6642c8ea3dSArd Biesheuvel } 6742c8ea3dSArd Biesheuvel 68*fc3608aaSArd Biesheuvel screen_info_offset = image_addr - (unsigned long)image->image_base; 69*fc3608aaSArd Biesheuvel 7042c8ea3dSArd Biesheuvel status = efi_stub_common(handle, image, image_addr, cmdline_ptr); 7142c8ea3dSArd Biesheuvel 7242c8ea3dSArd Biesheuvel efi_free(image_size, image_addr); 7342c8ea3dSArd Biesheuvel efi_free(reserve_size, reserve_addr); 7442c8ea3dSArd Biesheuvel 7542c8ea3dSArd Biesheuvel return status; 7642c8ea3dSArd Biesheuvel } 77