1 // SPDX-License-Identifier: GPL-2.0-only
3 /* -----------------------------------------------------------------------
5 * Copyright 2011 Intel Corporation; author Matt Fleming
7 * ----------------------------------------------------------------------- */
10 #include <linux/pci.h>
11 #include <linux/stddef.h>
14 #include <asm/e820/types.h>
15 #include <asm/setup.h>
18 #include <asm/kaslr.h>
24 const efi_system_table_t *efi_system_table;
25 const efi_dxe_services_table_t *efi_dxe_table;
26 static efi_loaded_image_t *image = NULL;
27 static efi_memory_attribute_protocol_t *memattr;
29 typedef union sev_memory_acceptance_protocol sev_memory_acceptance_protocol_t;
30 union sev_memory_acceptance_protocol {
32 efi_status_t (__efiapi * allow_unaccepted_memory)(
33 sev_memory_acceptance_protocol_t *);
36 u32 allow_unaccepted_memory;
41 preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
43 struct pci_setup_rom *rom = NULL;
50 * Some firmware images contain EFI function pointers at the place where
51 * the romimage and romsize fields are supposed to be. Typically the EFI
52 * code is mapped at high addresses, translating to an unrealistically
53 * large romsize. The UEFI spec limits the size of option ROMs to 16
54 * MiB so we reject any ROMs over 16 MiB in size to catch this.
56 romimage = efi_table_attr(pci, romimage);
57 romsize = efi_table_attr(pci, romsize);
58 if (!romimage || !romsize || romsize > SZ_16M)
59 return EFI_INVALID_PARAMETER;
61 size = romsize + sizeof(*rom);
63 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
65 if (status != EFI_SUCCESS) {
66 efi_err("Failed to allocate memory for 'rom'\n");
70 memset(rom, 0, sizeof(*rom));
72 rom->data.type = SETUP_PCI;
73 rom->data.len = size - sizeof(struct setup_data);
75 rom->pcilen = romsize;
78 status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
79 PCI_VENDOR_ID, 1, &rom->vendor);
81 if (status != EFI_SUCCESS) {
82 efi_err("Failed to read rom->vendor\n");
86 status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
87 PCI_DEVICE_ID, 1, &rom->devid);
89 if (status != EFI_SUCCESS) {
90 efi_err("Failed to read rom->devid\n");
94 status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus,
95 &rom->device, &rom->function);
97 if (status != EFI_SUCCESS)
100 memcpy(rom->romdata, romimage, romsize);
104 efi_bs_call(free_pool, rom);
109 * There's no way to return an informative status from this function,
110 * because any analysis (and printing of error messages) needs to be
111 * done directly at the EFI function call-site.
113 * For example, EFI_INVALID_PARAMETER could indicate a bug or maybe we
114 * just didn't find any PCI devices, but there's no way to tell outside
115 * the context of the call.
117 static void setup_efi_pci(struct boot_params *params)
120 void **pci_handle = NULL;
121 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
122 unsigned long size = 0;
123 struct setup_data *data;
127 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
128 &pci_proto, NULL, &size, pci_handle);
130 if (status == EFI_BUFFER_TOO_SMALL) {
131 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
132 (void **)&pci_handle);
134 if (status != EFI_SUCCESS) {
135 efi_err("Failed to allocate memory for 'pci_handle'\n");
139 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
140 &pci_proto, NULL, &size, pci_handle);
143 if (status != EFI_SUCCESS)
146 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
148 while (data && data->next)
149 data = (struct setup_data *)(unsigned long)data->next;
151 for_each_efi_handle(h, pci_handle, size, i) {
152 efi_pci_io_protocol_t *pci = NULL;
153 struct pci_setup_rom *rom;
155 status = efi_bs_call(handle_protocol, h, &pci_proto,
157 if (status != EFI_SUCCESS || !pci)
160 status = preserve_pci_rom_image(pci, &rom);
161 if (status != EFI_SUCCESS)
165 data->next = (unsigned long)rom;
167 params->hdr.setup_data = (unsigned long)rom;
169 data = (struct setup_data *)rom;
173 efi_bs_call(free_pool, pci_handle);
176 static void retrieve_apple_device_properties(struct boot_params *boot_params)
178 efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID;
179 struct setup_data *data, *new;
182 apple_properties_protocol_t *p;
184 status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&p);
185 if (status != EFI_SUCCESS)
188 if (efi_table_attr(p, version) != 0x10000) {
189 efi_err("Unsupported properties proto version\n");
193 efi_call_proto(p, get_all, NULL, &size);
198 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA,
199 size + sizeof(struct setup_data),
201 if (status != EFI_SUCCESS) {
202 efi_err("Failed to allocate memory for 'properties'\n");
206 status = efi_call_proto(p, get_all, new->data, &size);
208 if (status == EFI_BUFFER_TOO_SMALL)
209 efi_bs_call(free_pool, new);
210 } while (status == EFI_BUFFER_TOO_SMALL);
212 new->type = SETUP_APPLE_PROPERTIES;
216 data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
218 boot_params->hdr.setup_data = (unsigned long)new;
221 data = (struct setup_data *)(unsigned long)data->next;
222 data->next = (unsigned long)new;
226 efi_status_t efi_adjust_memory_range_protection(unsigned long start,
230 efi_gcd_memory_space_desc_t desc;
231 unsigned long end, next;
232 unsigned long rounded_start, rounded_end;
233 unsigned long unprotect_start, unprotect_size;
235 rounded_start = rounddown(start, EFI_PAGE_SIZE);
236 rounded_end = roundup(start + size, EFI_PAGE_SIZE);
238 if (memattr != NULL) {
239 status = efi_call_proto(memattr, clear_memory_attributes,
241 rounded_end - rounded_start,
243 if (status != EFI_SUCCESS)
244 efi_warn("Failed to clear EFI_MEMORY_XP attribute\n");
248 if (efi_dxe_table == NULL)
252 * Don't modify memory region attributes, they are
253 * already suitable, to lower the possibility to
254 * encounter firmware bugs.
257 for (end = start + size; start < end; start = next) {
259 status = efi_dxe_call(get_memory_space_descriptor, start, &desc);
261 if (status != EFI_SUCCESS)
264 next = desc.base_address + desc.length;
267 * Only system memory is suitable for trampoline/kernel image placement,
268 * so only this type of memory needs its attributes to be modified.
271 if (desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory ||
272 (desc.attributes & (EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0)
275 unprotect_start = max(rounded_start, (unsigned long)desc.base_address);
276 unprotect_size = min(rounded_end, next) - unprotect_start;
278 status = efi_dxe_call(set_memory_space_attributes,
279 unprotect_start, unprotect_size,
282 if (status != EFI_SUCCESS) {
283 efi_warn("Unable to unprotect memory range [%08lx,%08lx]: %lx\n",
285 unprotect_start + unprotect_size,
293 static void setup_unaccepted_memory(void)
295 efi_guid_t mem_acceptance_proto = OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID;
296 sev_memory_acceptance_protocol_t *proto;
299 if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY))
303 * Enable unaccepted memory before calling exit boot services in order
304 * for the UEFI to not accept all memory on EBS.
306 status = efi_bs_call(locate_protocol, &mem_acceptance_proto, NULL,
308 if (status != EFI_SUCCESS)
311 status = efi_call_proto(proto, allow_unaccepted_memory);
312 if (status != EFI_SUCCESS)
313 efi_err("Memory acceptance protocol failed\n");
316 static efi_char16_t *efistub_fw_vendor(void)
318 unsigned long vendor = efi_table_attr(efi_system_table, fw_vendor);
320 return (efi_char16_t *)vendor;
323 static const efi_char16_t apple[] = L"Apple";
325 static void setup_quirks(struct boot_params *boot_params)
327 if (IS_ENABLED(CONFIG_APPLE_PROPERTIES) &&
328 !memcmp(efistub_fw_vendor(), apple, sizeof(apple)))
329 retrieve_apple_device_properties(boot_params);
333 * See if we have Universal Graphics Adapter (UGA) protocol
336 setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size)
340 void **uga_handle = NULL;
341 efi_uga_draw_protocol_t *uga = NULL, *first_uga;
345 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
346 (void **)&uga_handle);
347 if (status != EFI_SUCCESS)
350 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
351 uga_proto, NULL, &size, uga_handle);
352 if (status != EFI_SUCCESS)
359 for_each_efi_handle(handle, uga_handle, size, i) {
360 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
361 u32 w, h, depth, refresh;
364 status = efi_bs_call(handle_protocol, handle, uga_proto,
366 if (status != EFI_SUCCESS)
370 efi_bs_call(handle_protocol, handle, &pciio_proto, &pciio);
372 status = efi_call_proto(uga, get_mode, &w, &h, &depth, &refresh);
373 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
378 * Once we've found a UGA supporting PCIIO,
379 * don't bother looking any further.
388 if (!width && !height)
391 /* EFI framebuffer */
392 si->orig_video_isVGA = VIDEO_TYPE_EFI;
395 si->lfb_width = width;
396 si->lfb_height = height;
408 efi_bs_call(free_pool, uga_handle);
413 static void setup_graphics(struct boot_params *boot_params)
415 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
416 struct screen_info *si;
417 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
420 void **gop_handle = NULL;
421 void **uga_handle = NULL;
423 si = &boot_params->screen_info;
424 memset(si, 0, sizeof(*si));
427 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
428 &graphics_proto, NULL, &size, gop_handle);
429 if (status == EFI_BUFFER_TOO_SMALL)
430 status = efi_setup_gop(si, &graphics_proto, size);
432 if (status != EFI_SUCCESS) {
434 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
435 &uga_proto, NULL, &size, uga_handle);
436 if (status == EFI_BUFFER_TOO_SMALL)
437 setup_uga(si, &uga_proto, size);
442 static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status)
444 efi_bs_call(exit, handle, status, 0, NULL);
449 void __noreturn efi_stub_entry(efi_handle_t handle,
450 efi_system_table_t *sys_table_arg,
451 struct boot_params *boot_params);
454 * Because the x86 boot code expects to be passed a boot_params we
455 * need to create one ourselves (usually the bootloader would create
458 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
459 efi_system_table_t *sys_table_arg)
461 static struct boot_params boot_params __page_aligned_bss;
462 struct setup_header *hdr = &boot_params.hdr;
463 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
464 int options_size = 0;
468 efi_system_table = sys_table_arg;
470 /* Check if we were booted by the EFI firmware */
471 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
472 efi_exit(handle, EFI_INVALID_PARAMETER);
474 status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image);
475 if (status != EFI_SUCCESS) {
476 efi_err("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
477 efi_exit(handle, status);
480 /* Assign the setup_header fields that the kernel actually cares about */
482 hdr->vid_mode = 0xffff;
484 hdr->type_of_loader = 0x21;
486 /* Convert unicode cmdline to ascii */
487 cmdline_ptr = efi_convert_cmdline(image, &options_size);
491 efi_set_u64_split((unsigned long)cmdline_ptr, &hdr->cmd_line_ptr,
492 &boot_params.ext_cmd_line_ptr);
494 efi_stub_entry(handle, sys_table_arg, &boot_params);
498 efi_exit(handle, status);
501 static void add_e820ext(struct boot_params *params,
502 struct setup_data *e820ext, u32 nr_entries)
504 struct setup_data *data;
506 e820ext->type = SETUP_E820_EXT;
507 e820ext->len = nr_entries * sizeof(struct boot_e820_entry);
510 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
512 while (data && data->next)
513 data = (struct setup_data *)(unsigned long)data->next;
516 data->next = (unsigned long)e820ext;
518 params->hdr.setup_data = (unsigned long)e820ext;
522 setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_size)
524 struct boot_e820_entry *entry = params->e820_table;
525 struct efi_info *efi = ¶ms->efi_info;
526 struct boot_e820_entry *prev = NULL;
532 nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;
534 for (i = 0; i < nr_desc; i++) {
535 efi_memory_desc_t *d;
536 unsigned int e820_type = 0;
537 unsigned long m = efi->efi_memmap;
540 m |= (u64)efi->efi_memmap_hi << 32;
543 d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
545 case EFI_RESERVED_TYPE:
546 case EFI_RUNTIME_SERVICES_CODE:
547 case EFI_RUNTIME_SERVICES_DATA:
548 case EFI_MEMORY_MAPPED_IO:
549 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
551 e820_type = E820_TYPE_RESERVED;
554 case EFI_UNUSABLE_MEMORY:
555 e820_type = E820_TYPE_UNUSABLE;
558 case EFI_ACPI_RECLAIM_MEMORY:
559 e820_type = E820_TYPE_ACPI;
562 case EFI_LOADER_CODE:
563 case EFI_LOADER_DATA:
564 case EFI_BOOT_SERVICES_CODE:
565 case EFI_BOOT_SERVICES_DATA:
566 case EFI_CONVENTIONAL_MEMORY:
567 if (efi_soft_reserve_enabled() &&
568 (d->attribute & EFI_MEMORY_SP))
569 e820_type = E820_TYPE_SOFT_RESERVED;
571 e820_type = E820_TYPE_RAM;
574 case EFI_ACPI_MEMORY_NVS:
575 e820_type = E820_TYPE_NVS;
578 case EFI_PERSISTENT_MEMORY:
579 e820_type = E820_TYPE_PMEM;
582 case EFI_UNACCEPTED_MEMORY:
583 if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY))
585 e820_type = E820_TYPE_RAM;
586 process_unaccepted_memory(d->phys_addr,
587 d->phys_addr + PAGE_SIZE * d->num_pages);
593 /* Merge adjacent mappings */
594 if (prev && prev->type == e820_type &&
595 (prev->addr + prev->size) == d->phys_addr) {
596 prev->size += d->num_pages << 12;
600 if (nr_entries == ARRAY_SIZE(params->e820_table)) {
601 u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
602 sizeof(struct setup_data);
604 if (!e820ext || e820ext_size < need)
605 return EFI_BUFFER_TOO_SMALL;
607 /* boot_params map full, switch to e820 extended */
608 entry = (struct boot_e820_entry *)e820ext->data;
611 entry->addr = d->phys_addr;
612 entry->size = d->num_pages << PAGE_SHIFT;
613 entry->type = e820_type;
618 if (nr_entries > ARRAY_SIZE(params->e820_table)) {
619 u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table);
621 add_e820ext(params, e820ext, nr_e820ext);
622 nr_entries -= nr_e820ext;
625 params->e820_entries = (u8)nr_entries;
630 static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
636 size = sizeof(struct setup_data) +
637 sizeof(struct e820_entry) * nr_desc;
640 efi_bs_call(free_pool, *e820ext);
645 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
647 if (status == EFI_SUCCESS)
648 *e820ext_size = size;
653 static efi_status_t allocate_e820(struct boot_params *params,
654 struct setup_data **e820ext,
657 struct efi_boot_memmap *map;
661 status = efi_get_memory_map(&map, false);
662 if (status != EFI_SUCCESS)
665 nr_desc = map->map_size / map->desc_size;
666 if (nr_desc > ARRAY_SIZE(params->e820_table) - EFI_MMAP_NR_SLACK_SLOTS) {
667 u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table) +
668 EFI_MMAP_NR_SLACK_SLOTS;
670 status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size);
673 if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY) && status == EFI_SUCCESS)
674 status = allocate_unaccepted_bitmap(nr_desc, map);
676 efi_bs_call(free_pool, map);
680 struct exit_boot_struct {
681 struct boot_params *boot_params;
682 struct efi_info *efi;
685 static efi_status_t exit_boot_func(struct efi_boot_memmap *map,
688 const char *signature;
689 struct exit_boot_struct *p = priv;
691 signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE
692 : EFI32_LOADER_SIGNATURE;
693 memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));
695 efi_set_u64_split((unsigned long)efi_system_table,
696 &p->efi->efi_systab, &p->efi->efi_systab_hi);
697 p->efi->efi_memdesc_size = map->desc_size;
698 p->efi->efi_memdesc_version = map->desc_ver;
699 efi_set_u64_split((unsigned long)map->map,
700 &p->efi->efi_memmap, &p->efi->efi_memmap_hi);
701 p->efi->efi_memmap_size = map->map_size;
706 static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
708 struct setup_data *e820ext = NULL;
709 __u32 e820ext_size = 0;
711 struct exit_boot_struct priv;
713 priv.boot_params = boot_params;
714 priv.efi = &boot_params->efi_info;
716 status = allocate_e820(boot_params, &e820ext, &e820ext_size);
717 if (status != EFI_SUCCESS)
720 /* Might as well exit boot services now */
721 status = efi_exit_boot_services(handle, &priv, exit_boot_func);
722 if (status != EFI_SUCCESS)
726 boot_params->alt_mem_k = 32 * 1024;
728 status = setup_e820(boot_params, e820ext, e820ext_size);
729 if (status != EFI_SUCCESS)
735 static bool have_unsupported_snp_features(void)
739 unsupported = snp_get_unsupported_features(sev_get_status());
741 efi_err("Unsupported SEV-SNP features detected: 0x%llx\n",
748 static void efi_get_seed(void *seed, int size)
750 efi_get_random_bytes(size, seed);
753 * This only updates seed[0] when running on 32-bit, but in that case,
754 * seed[1] is not used anyway, as there is no virtual KASLR on 32-bit.
756 *(unsigned long *)seed ^= kaslr_get_random_long("EFI");
759 static void error(char *str)
761 efi_warn("Decompression failed: %s\n", str);
764 static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
766 unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
767 unsigned long addr, alloc_size, entry;
771 /* determine the required size of the allocation */
772 alloc_size = ALIGN(max_t(unsigned long, output_len, kernel_total_size),
775 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) {
776 u64 range = KERNEL_IMAGE_SIZE - LOAD_PHYSICAL_ADDR - kernel_total_size;
777 static const efi_char16_t ami[] = L"American Megatrends";
779 efi_get_seed(seed, sizeof(seed));
781 virt_addr += (range * seed[1]) >> 32;
782 virt_addr &= ~(CONFIG_PHYSICAL_ALIGN - 1);
785 * Older Dell systems with AMI UEFI firmware v2.0 may hang
786 * while decompressing the kernel if physical address
787 * randomization is enabled.
789 * https://bugzilla.kernel.org/show_bug.cgi?id=218173
791 if (efi_system_table->hdr.revision <= EFI_2_00_SYSTEM_TABLE_REVISION &&
792 !memcmp(efistub_fw_vendor(), ami, sizeof(ami))) {
793 efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n");
797 boot_params_ptr->hdr.loadflags |= KASLR_FLAG;
800 status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,
801 seed[0], EFI_LOADER_CODE,
802 EFI_X86_KERNEL_ALLOC_LIMIT);
803 if (status != EFI_SUCCESS)
806 entry = decompress_kernel((void *)addr, virt_addr, error);
807 if (entry == ULONG_MAX) {
808 efi_free(alloc_size, addr);
809 return EFI_LOAD_ERROR;
812 *kernel_entry = addr + entry;
814 return efi_adjust_memory_range_protection(addr, kernel_total_size);
817 static void __noreturn enter_kernel(unsigned long kernel_addr,
818 struct boot_params *boot_params)
820 /* enter decompressed kernel with boot_params pointer in RSI/ESI */
821 asm("jmp *%0"::"r"(kernel_addr), "S"(boot_params));
827 * On success, this routine will jump to the relocated image directly and never
828 * return. On failure, it will exit to the firmware via efi_exit() instead of
831 void __noreturn efi_stub_entry(efi_handle_t handle,
832 efi_system_table_t *sys_table_arg,
833 struct boot_params *boot_params)
835 efi_guid_t guid = EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID;
836 struct setup_header *hdr = &boot_params->hdr;
837 const struct linux_efi_initrd *initrd = NULL;
838 unsigned long kernel_entry;
841 boot_params_ptr = boot_params;
843 efi_system_table = sys_table_arg;
844 /* Check if we were booted by the EFI firmware */
845 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
846 efi_exit(handle, EFI_INVALID_PARAMETER);
848 if (have_unsupported_snp_features())
849 efi_exit(handle, EFI_UNSUPPORTED);
851 if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES)) {
852 efi_dxe_table = get_efi_config_table(EFI_DXE_SERVICES_TABLE_GUID);
854 efi_dxe_table->hdr.signature != EFI_DXE_SERVICES_TABLE_SIGNATURE) {
855 efi_warn("Ignoring DXE services table: invalid signature\n");
856 efi_dxe_table = NULL;
860 /* grab the memory attributes protocol if it exists */
861 efi_bs_call(locate_protocol, &guid, NULL, (void **)&memattr);
863 status = efi_setup_5level_paging();
864 if (status != EFI_SUCCESS) {
865 efi_err("efi_setup_5level_paging() failed!\n");
869 #ifdef CONFIG_CMDLINE_BOOL
870 status = efi_parse_options(CONFIG_CMDLINE);
871 if (status != EFI_SUCCESS) {
872 efi_err("Failed to parse options\n");
876 if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
877 unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
878 ((u64)boot_params->ext_cmd_line_ptr << 32));
879 status = efi_parse_options((char *)cmdline_paddr);
880 if (status != EFI_SUCCESS) {
881 efi_err("Failed to parse options\n");
886 status = efi_decompress_kernel(&kernel_entry);
887 if (status != EFI_SUCCESS) {
888 efi_err("Failed to decompress kernel\n");
893 * At this point, an initrd may already have been loaded by the
894 * bootloader and passed via bootparams. We permit an initrd loaded
895 * from the LINUX_EFI_INITRD_MEDIA_GUID device path to supersede it.
897 * If the device path is not present, any command-line initrd=
898 * arguments will be processed only if image is not NULL, which will be
899 * the case only if we were loaded via the PE entry point.
901 status = efi_load_initrd(image, hdr->initrd_addr_max, ULONG_MAX,
903 if (status != EFI_SUCCESS)
905 if (initrd && initrd->size > 0) {
906 efi_set_u64_split(initrd->base, &hdr->ramdisk_image,
907 &boot_params->ext_ramdisk_image);
908 efi_set_u64_split(initrd->size, &hdr->ramdisk_size,
909 &boot_params->ext_ramdisk_size);
914 * If the boot loader gave us a value for secure_boot then we use that,
915 * otherwise we ask the BIOS.
917 if (boot_params->secure_boot == efi_secureboot_mode_unset)
918 boot_params->secure_boot = efi_get_secureboot();
920 /* Ask the firmware to clear memory on unclean shutdown */
921 efi_enable_reset_attack_mitigation();
923 efi_random_get_seed();
925 efi_retrieve_tpm2_eventlog();
927 setup_graphics(boot_params);
929 setup_efi_pci(boot_params);
931 setup_quirks(boot_params);
933 setup_unaccepted_memory();
935 status = exit_boot(boot_params, handle);
936 if (status != EFI_SUCCESS) {
937 efi_err("exit_boot() failed!\n");
942 * Call the SEV init code while still running with the firmware's
943 * GDT/IDT, so #VC exceptions will be handled by EFI.
945 sev_enable(boot_params);
949 enter_kernel(kernel_entry, boot_params);
951 efi_err("efi_stub_entry() failed!\n");
953 efi_exit(handle, status);
956 #ifdef CONFIG_EFI_HANDOVER_PROTOCOL
957 void efi_handover_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
958 struct boot_params *boot_params)
960 extern char _bss[], _ebss[];
962 memset(_bss, 0, _ebss - _bss);
963 efi_stub_entry(handle, sys_table_arg, boot_params);
966 #ifndef CONFIG_EFI_MIXED
967 extern __alias(efi_handover_entry)
968 void efi32_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
969 struct boot_params *boot_params);
971 extern __alias(efi_handover_entry)
972 void efi64_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
973 struct boot_params *boot_params);