efi-stub-entry.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/efi.h>
  3. #include <linux/screen_info.h>
  4. #include <asm/efi.h>
  5. #include "efistub.h"
  6. static unsigned long screen_info_offset;
  7. struct screen_info *alloc_screen_info(void)
  8. {
  9. if (IS_ENABLED(CONFIG_ARM))
  10. return __alloc_screen_info();
  11. if (IS_ENABLED(CONFIG_X86) ||
  12. IS_ENABLED(CONFIG_EFI_EARLYCON) ||
  13. IS_ENABLED(CONFIG_SYSFB))
  14. return (void *)&screen_info + screen_info_offset;
  15. return NULL;
  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. WRITE_ONCE(efi_system_table, systab);
  35. /* Check if we were booted by the EFI firmware */
  36. if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
  37. return EFI_INVALID_PARAMETER;
  38. /*
  39. * Get a handle to the loaded image protocol. This is used to get
  40. * information about the running image, such as size and the command
  41. * line.
  42. */
  43. status = efi_bs_call(handle_protocol, handle, &loaded_image_proto,
  44. (void *)&image);
  45. if (status != EFI_SUCCESS) {
  46. efi_err("Failed to get loaded image protocol\n");
  47. return status;
  48. }
  49. status = efi_handle_cmdline(image, &cmdline_ptr);
  50. if (status != EFI_SUCCESS)
  51. return status;
  52. efi_info("Booting Linux Kernel...\n");
  53. status = handle_kernel_image(&image_addr, &image_size,
  54. &reserve_addr,
  55. &reserve_size,
  56. image, handle);
  57. if (status != EFI_SUCCESS) {
  58. efi_err("Failed to relocate kernel\n");
  59. return status;
  60. }
  61. screen_info_offset = image_addr - (unsigned long)image->image_base;
  62. status = efi_stub_common(handle, image, image_addr, cmdline_ptr);
  63. efi_free(image_size, image_addr);
  64. efi_free(reserve_size, reserve_addr);
  65. return status;
  66. }