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