1 // SPDX-License-Identifier: GPL-2.0-only 2 3 #include <linux/efi.h> 4 #include <asm/efi.h> 5 6 #include "efistub.h" 7 8 static unsigned long screen_info_offset; 9 10 struct screen_info *alloc_screen_info(void) 11 { 12 if (IS_ENABLED(CONFIG_ARM)) 13 return __alloc_screen_info(); 14 return (void *)&screen_info + screen_info_offset; 15 } 16 17 /* 18 * EFI entry point for the generic EFI stub used by ARM, arm64, RISC-V and 19 * LoongArch. This is the entrypoint that is described in the PE/COFF header 20 * of the core kernel. 21 */ 22 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, 23 efi_system_table_t *systab) 24 { 25 efi_loaded_image_t *image; 26 efi_status_t status; 27 unsigned long image_addr; 28 unsigned long image_size = 0; 29 /* addr/point and size pairs for memory management*/ 30 char *cmdline_ptr = NULL; 31 efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID; 32 unsigned long reserve_addr = 0; 33 unsigned long reserve_size = 0; 34 35 WRITE_ONCE(efi_system_table, systab); 36 37 /* Check if we were booted by the EFI firmware */ 38 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 39 return EFI_INVALID_PARAMETER; 40 41 /* 42 * Get a handle to the loaded image protocol. This is used to get 43 * information about the running image, such as size and the command 44 * line. 45 */ 46 status = efi_bs_call(handle_protocol, handle, &loaded_image_proto, 47 (void *)&image); 48 if (status != EFI_SUCCESS) { 49 efi_err("Failed to get loaded image protocol\n"); 50 return status; 51 } 52 53 status = efi_handle_cmdline(image, &cmdline_ptr); 54 if (status != EFI_SUCCESS) 55 return status; 56 57 efi_info("Booting Linux Kernel...\n"); 58 59 status = handle_kernel_image(&image_addr, &image_size, 60 &reserve_addr, 61 &reserve_size, 62 image, handle); 63 if (status != EFI_SUCCESS) { 64 efi_err("Failed to relocate kernel\n"); 65 return status; 66 } 67 68 screen_info_offset = image_addr - (unsigned long)image->image_base; 69 70 status = efi_stub_common(handle, image, image_addr, cmdline_ptr); 71 72 efi_free(image_size, image_addr); 73 efi_free(reserve_size, reserve_addr); 74 75 return status; 76 } 77