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>
21 /* Maximum physical address for 64-bit kernel with 4-level paging */
22 #define MAXMEM_X86_64_4LEVEL (1ull << 46)
24 const efi_system_table_t *efi_system_table;
25 const efi_dxe_services_table_t *efi_dxe_table;
26 extern u32 image_offset;
27 static efi_loaded_image_t *image = NULL;
30 preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
32 struct pci_setup_rom *rom = NULL;
39 * Some firmware images contain EFI function pointers at the place where
40 * the romimage and romsize fields are supposed to be. Typically the EFI
41 * code is mapped at high addresses, translating to an unrealistically
42 * large romsize. The UEFI spec limits the size of option ROMs to 16
43 * MiB so we reject any ROMs over 16 MiB in size to catch this.
45 romimage = efi_table_attr(pci, romimage);
46 romsize = efi_table_attr(pci, romsize);
47 if (!romimage || !romsize || romsize > SZ_16M)
48 return EFI_INVALID_PARAMETER;
50 size = romsize + sizeof(*rom);
52 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
54 if (status != EFI_SUCCESS) {
55 efi_err("Failed to allocate memory for 'rom'\n");
59 memset(rom, 0, sizeof(*rom));
61 rom->data.type = SETUP_PCI;
62 rom->data.len = size - sizeof(struct setup_data);
64 rom->pcilen = pci->romsize;
67 status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
68 PCI_VENDOR_ID, 1, &rom->vendor);
70 if (status != EFI_SUCCESS) {
71 efi_err("Failed to read rom->vendor\n");
75 status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16,
76 PCI_DEVICE_ID, 1, &rom->devid);
78 if (status != EFI_SUCCESS) {
79 efi_err("Failed to read rom->devid\n");
83 status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus,
84 &rom->device, &rom->function);
86 if (status != EFI_SUCCESS)
89 memcpy(rom->romdata, romimage, romsize);
93 efi_bs_call(free_pool, rom);
98 * There's no way to return an informative status from this function,
99 * because any analysis (and printing of error messages) needs to be
100 * done directly at the EFI function call-site.
102 * For example, EFI_INVALID_PARAMETER could indicate a bug or maybe we
103 * just didn't find any PCI devices, but there's no way to tell outside
104 * the context of the call.
106 static void setup_efi_pci(struct boot_params *params)
109 void **pci_handle = NULL;
110 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
111 unsigned long size = 0;
112 struct setup_data *data;
116 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
117 &pci_proto, NULL, &size, pci_handle);
119 if (status == EFI_BUFFER_TOO_SMALL) {
120 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
121 (void **)&pci_handle);
123 if (status != EFI_SUCCESS) {
124 efi_err("Failed to allocate memory for 'pci_handle'\n");
128 status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
129 &pci_proto, NULL, &size, pci_handle);
132 if (status != EFI_SUCCESS)
135 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
137 while (data && data->next)
138 data = (struct setup_data *)(unsigned long)data->next;
140 for_each_efi_handle(h, pci_handle, size, i) {
141 efi_pci_io_protocol_t *pci = NULL;
142 struct pci_setup_rom *rom;
144 status = efi_bs_call(handle_protocol, h, &pci_proto,
146 if (status != EFI_SUCCESS || !pci)
149 status = preserve_pci_rom_image(pci, &rom);
150 if (status != EFI_SUCCESS)
154 data->next = (unsigned long)rom;
156 params->hdr.setup_data = (unsigned long)rom;
158 data = (struct setup_data *)rom;
162 efi_bs_call(free_pool, pci_handle);
165 static void retrieve_apple_device_properties(struct boot_params *boot_params)
167 efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID;
168 struct setup_data *data, *new;
171 apple_properties_protocol_t *p;
173 status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&p);
174 if (status != EFI_SUCCESS)
177 if (efi_table_attr(p, version) != 0x10000) {
178 efi_err("Unsupported properties proto version\n");
182 efi_call_proto(p, get_all, NULL, &size);
187 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA,
188 size + sizeof(struct setup_data),
190 if (status != EFI_SUCCESS) {
191 efi_err("Failed to allocate memory for 'properties'\n");
195 status = efi_call_proto(p, get_all, new->data, &size);
197 if (status == EFI_BUFFER_TOO_SMALL)
198 efi_bs_call(free_pool, new);
199 } while (status == EFI_BUFFER_TOO_SMALL);
201 new->type = SETUP_APPLE_PROPERTIES;
205 data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
207 boot_params->hdr.setup_data = (unsigned long)new;
210 data = (struct setup_data *)(unsigned long)data->next;
211 data->next = (unsigned long)new;
216 adjust_memory_range_protection(unsigned long start, unsigned long size)
219 efi_gcd_memory_space_desc_t desc;
220 unsigned long end, next;
221 unsigned long rounded_start, rounded_end;
222 unsigned long unprotect_start, unprotect_size;
223 int has_system_memory = 0;
225 if (efi_dxe_table == NULL)
228 rounded_start = rounddown(start, EFI_PAGE_SIZE);
229 rounded_end = roundup(start + size, EFI_PAGE_SIZE);
232 * Don't modify memory region attributes, they are
233 * already suitable, to lower the possibility to
234 * encounter firmware bugs.
237 for (end = start + size; start < end; start = next) {
239 status = efi_dxe_call(get_memory_space_descriptor, start, &desc);
241 if (status != EFI_SUCCESS)
244 next = desc.base_address + desc.length;
247 * Only system memory is suitable for trampoline/kernel image placement,
248 * so only this type of memory needs its attributes to be modified.
251 if (desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory ||
252 (desc.attributes & (EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0)
255 unprotect_start = max(rounded_start, (unsigned long)desc.base_address);
256 unprotect_size = min(rounded_end, next) - unprotect_start;
258 status = efi_dxe_call(set_memory_space_attributes,
259 unprotect_start, unprotect_size,
262 if (status != EFI_SUCCESS) {
263 efi_warn("Unable to unprotect memory range [%08lx,%08lx]: %lx\n",
265 unprotect_start + unprotect_size,
272 * Trampoline takes 2 pages and can be loaded in first megabyte of memory
273 * with its end placed between 128k and 640k where BIOS might start.
274 * (see arch/x86/boot/compressed/pgtable_64.c)
276 * We cannot find exact trampoline placement since memory map
277 * can be modified by UEFI, and it can alter the computed address.
280 #define TRAMPOLINE_PLACEMENT_BASE ((128 - 8)*1024)
281 #define TRAMPOLINE_PLACEMENT_SIZE (640*1024 - (128 - 8)*1024)
283 void startup_32(struct boot_params *boot_params);
286 setup_memory_protection(unsigned long image_base, unsigned long image_size)
289 * Allow execution of possible trampoline used
290 * for switching between 4- and 5-level page tables
291 * and relocated kernel image.
294 adjust_memory_range_protection(TRAMPOLINE_PLACEMENT_BASE,
295 TRAMPOLINE_PLACEMENT_SIZE);
298 if (image_base != (unsigned long)startup_32)
299 adjust_memory_range_protection(image_base, image_size);
302 * Clear protection flags on a whole range of possible
303 * addresses used for KASLR. We don't need to do that
304 * on x86_64, since KASLR/extraction is performed after
305 * dedicated identity page tables are built and we only
306 * need to remove possible protection on relocated image
307 * itself disregarding further relocations.
309 adjust_memory_range_protection(LOAD_PHYSICAL_ADDR,
310 KERNEL_IMAGE_SIZE - LOAD_PHYSICAL_ADDR);
314 static const efi_char16_t apple[] = L"Apple";
316 static void setup_quirks(struct boot_params *boot_params,
317 unsigned long image_base,
318 unsigned long image_size)
320 efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long)
321 efi_table_attr(efi_system_table, fw_vendor);
323 if (!memcmp(fw_vendor, apple, sizeof(apple))) {
324 if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
325 retrieve_apple_device_properties(boot_params);
328 if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES))
329 setup_memory_protection(image_base, image_size);
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 struct boot_params *boot_params;
462 struct setup_header *hdr;
464 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
465 int options_size = 0;
469 efi_system_table = sys_table_arg;
471 /* Check if we were booted by the EFI firmware */
472 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
473 efi_exit(handle, EFI_INVALID_PARAMETER);
475 status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image);
476 if (status != EFI_SUCCESS) {
477 efi_err("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
478 efi_exit(handle, status);
481 image_base = efi_table_attr(image, image_base);
482 image_offset = (void *)startup_32 - image_base;
484 status = efi_allocate_pages(sizeof(struct boot_params),
485 (unsigned long *)&boot_params, ULONG_MAX);
486 if (status != EFI_SUCCESS) {
487 efi_err("Failed to allocate lowmem for boot params\n");
488 efi_exit(handle, status);
491 memset(boot_params, 0x0, sizeof(struct boot_params));
493 hdr = &boot_params->hdr;
495 /* Copy the setup header from the second sector to boot_params */
496 memcpy(&hdr->jump, image_base + 512,
497 sizeof(struct setup_header) - offsetof(struct setup_header, jump));
500 * Fill out some of the header fields ourselves because the
501 * EFI firmware loader doesn't load the first sector.
504 hdr->vid_mode = 0xffff;
505 hdr->boot_flag = 0xAA55;
507 hdr->type_of_loader = 0x21;
509 /* Convert unicode cmdline to ascii */
510 cmdline_ptr = efi_convert_cmdline(image, &options_size);
514 efi_set_u64_split((unsigned long)cmdline_ptr,
515 &hdr->cmd_line_ptr, &boot_params->ext_cmd_line_ptr);
517 hdr->ramdisk_image = 0;
518 hdr->ramdisk_size = 0;
520 efi_stub_entry(handle, sys_table_arg, boot_params);
524 efi_free(sizeof(struct boot_params), (unsigned long)boot_params);
526 efi_exit(handle, status);
529 static void add_e820ext(struct boot_params *params,
530 struct setup_data *e820ext, u32 nr_entries)
532 struct setup_data *data;
534 e820ext->type = SETUP_E820_EXT;
535 e820ext->len = nr_entries * sizeof(struct boot_e820_entry);
538 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
540 while (data && data->next)
541 data = (struct setup_data *)(unsigned long)data->next;
544 data->next = (unsigned long)e820ext;
546 params->hdr.setup_data = (unsigned long)e820ext;
550 setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_size)
552 struct boot_e820_entry *entry = params->e820_table;
553 struct efi_info *efi = ¶ms->efi_info;
554 struct boot_e820_entry *prev = NULL;
560 nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;
562 for (i = 0; i < nr_desc; i++) {
563 efi_memory_desc_t *d;
564 unsigned int e820_type = 0;
565 unsigned long m = efi->efi_memmap;
568 m |= (u64)efi->efi_memmap_hi << 32;
571 d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
573 case EFI_RESERVED_TYPE:
574 case EFI_RUNTIME_SERVICES_CODE:
575 case EFI_RUNTIME_SERVICES_DATA:
576 case EFI_MEMORY_MAPPED_IO:
577 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
579 e820_type = E820_TYPE_RESERVED;
582 case EFI_UNUSABLE_MEMORY:
583 e820_type = E820_TYPE_UNUSABLE;
586 case EFI_ACPI_RECLAIM_MEMORY:
587 e820_type = E820_TYPE_ACPI;
590 case EFI_LOADER_CODE:
591 case EFI_LOADER_DATA:
592 case EFI_BOOT_SERVICES_CODE:
593 case EFI_BOOT_SERVICES_DATA:
594 case EFI_CONVENTIONAL_MEMORY:
595 if (efi_soft_reserve_enabled() &&
596 (d->attribute & EFI_MEMORY_SP))
597 e820_type = E820_TYPE_SOFT_RESERVED;
599 e820_type = E820_TYPE_RAM;
602 case EFI_ACPI_MEMORY_NVS:
603 e820_type = E820_TYPE_NVS;
606 case EFI_PERSISTENT_MEMORY:
607 e820_type = E820_TYPE_PMEM;
614 /* Merge adjacent mappings */
615 if (prev && prev->type == e820_type &&
616 (prev->addr + prev->size) == d->phys_addr) {
617 prev->size += d->num_pages << 12;
621 if (nr_entries == ARRAY_SIZE(params->e820_table)) {
622 u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
623 sizeof(struct setup_data);
625 if (!e820ext || e820ext_size < need)
626 return EFI_BUFFER_TOO_SMALL;
628 /* boot_params map full, switch to e820 extended */
629 entry = (struct boot_e820_entry *)e820ext->data;
632 entry->addr = d->phys_addr;
633 entry->size = d->num_pages << PAGE_SHIFT;
634 entry->type = e820_type;
639 if (nr_entries > ARRAY_SIZE(params->e820_table)) {
640 u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table);
642 add_e820ext(params, e820ext, nr_e820ext);
643 nr_entries -= nr_e820ext;
646 params->e820_entries = (u8)nr_entries;
651 static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
657 size = sizeof(struct setup_data) +
658 sizeof(struct e820_entry) * nr_desc;
661 efi_bs_call(free_pool, *e820ext);
666 status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
668 if (status == EFI_SUCCESS)
669 *e820ext_size = size;
674 static efi_status_t allocate_e820(struct boot_params *params,
675 struct setup_data **e820ext,
678 unsigned long map_size, desc_size, map_key;
680 __u32 nr_desc, desc_version;
682 /* Only need the size of the mem map and size of each mem descriptor */
684 status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key,
685 &desc_size, &desc_version);
686 if (status != EFI_BUFFER_TOO_SMALL)
687 return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED;
689 nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS;
691 if (nr_desc > ARRAY_SIZE(params->e820_table)) {
692 u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table);
694 status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size);
695 if (status != EFI_SUCCESS)
702 struct exit_boot_struct {
703 struct boot_params *boot_params;
704 struct efi_info *efi;
707 static efi_status_t exit_boot_func(struct efi_boot_memmap *map,
710 const char *signature;
711 struct exit_boot_struct *p = priv;
713 signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE
714 : EFI32_LOADER_SIGNATURE;
715 memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));
717 efi_set_u64_split((unsigned long)efi_system_table,
718 &p->efi->efi_systab, &p->efi->efi_systab_hi);
719 p->efi->efi_memdesc_size = *map->desc_size;
720 p->efi->efi_memdesc_version = *map->desc_ver;
721 efi_set_u64_split((unsigned long)*map->map,
722 &p->efi->efi_memmap, &p->efi->efi_memmap_hi);
723 p->efi->efi_memmap_size = *map->map_size;
728 static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
730 unsigned long map_sz, key, desc_size, buff_size;
731 efi_memory_desc_t *mem_map;
732 struct setup_data *e820ext = NULL;
733 __u32 e820ext_size = 0;
736 struct efi_boot_memmap map;
737 struct exit_boot_struct priv;
740 map.map_size = &map_sz;
741 map.desc_size = &desc_size;
742 map.desc_ver = &desc_version;
744 map.buff_size = &buff_size;
745 priv.boot_params = boot_params;
746 priv.efi = &boot_params->efi_info;
748 status = allocate_e820(boot_params, &e820ext, &e820ext_size);
749 if (status != EFI_SUCCESS)
752 /* Might as well exit boot services now */
753 status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func);
754 if (status != EFI_SUCCESS)
758 boot_params->alt_mem_k = 32 * 1024;
760 status = setup_e820(boot_params, e820ext, e820ext_size);
761 if (status != EFI_SUCCESS)
768 * On success, we return the address of startup_32, which has potentially been
769 * relocated by efi_relocate_kernel.
770 * On failure, we exit to the firmware via efi_exit instead of returning.
772 unsigned long efi_main(efi_handle_t handle,
773 efi_system_table_t *sys_table_arg,
774 struct boot_params *boot_params)
776 unsigned long bzimage_addr = (unsigned long)startup_32;
777 unsigned long buffer_start, buffer_end;
778 struct setup_header *hdr = &boot_params->hdr;
779 unsigned long addr, size;
782 efi_system_table = sys_table_arg;
783 /* Check if we were booted by the EFI firmware */
784 if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
785 efi_exit(handle, EFI_INVALID_PARAMETER);
787 efi_dxe_table = get_efi_config_table(EFI_DXE_SERVICES_TABLE_GUID);
789 efi_dxe_table->hdr.signature != EFI_DXE_SERVICES_TABLE_SIGNATURE) {
790 efi_warn("Ignoring DXE services table: invalid signature\n");
791 efi_dxe_table = NULL;
795 * If the kernel isn't already loaded at a suitable address,
798 * It must be loaded above LOAD_PHYSICAL_ADDR.
800 * The maximum address for 64-bit is 1 << 46 for 4-level paging. This
801 * is defined as the macro MAXMEM, but unfortunately that is not a
802 * compile-time constant if 5-level paging is configured, so we instead
803 * define our own macro for use here.
805 * For 32-bit, the maximum address is complicated to figure out, for
806 * now use KERNEL_IMAGE_SIZE, which will be 512MiB, the same as what
809 * Also relocate it if image_offset is zero, i.e. the kernel wasn't
810 * loaded by LoadImage, but rather by a bootloader that called the
811 * handover entry. The reason we must always relocate in this case is
812 * to handle the case of systemd-boot booting a unified kernel image,
813 * which is a PE executable that contains the bzImage and an initrd as
814 * COFF sections. The initrd section is placed after the bzImage
815 * without ensuring that there are at least init_size bytes available
816 * for the bzImage, and thus the compressed kernel's startup code may
817 * overwrite the initrd unless it is moved out of the way.
820 buffer_start = ALIGN(bzimage_addr - image_offset,
821 hdr->kernel_alignment);
822 buffer_end = buffer_start + hdr->init_size;
824 if ((buffer_start < LOAD_PHYSICAL_ADDR) ||
825 (IS_ENABLED(CONFIG_X86_32) && buffer_end > KERNEL_IMAGE_SIZE) ||
826 (IS_ENABLED(CONFIG_X86_64) && buffer_end > MAXMEM_X86_64_4LEVEL) ||
827 (image_offset == 0)) {
830 status = efi_relocate_kernel(&bzimage_addr,
831 (unsigned long)_bss - bzimage_addr,
834 hdr->kernel_alignment,
836 if (status != EFI_SUCCESS) {
837 efi_err("efi_relocate_kernel() failed!\n");
841 * Now that we've copied the kernel elsewhere, we no longer
842 * have a set up block before startup_32(), so reset image_offset
843 * to zero in case it was set earlier.
848 #ifdef CONFIG_CMDLINE_BOOL
849 status = efi_parse_options(CONFIG_CMDLINE);
850 if (status != EFI_SUCCESS) {
851 efi_err("Failed to parse options\n");
855 if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
856 unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
857 ((u64)boot_params->ext_cmd_line_ptr << 32));
858 status = efi_parse_options((char *)cmdline_paddr);
859 if (status != EFI_SUCCESS) {
860 efi_err("Failed to parse options\n");
866 * At this point, an initrd may already have been loaded by the
867 * bootloader and passed via bootparams. We permit an initrd loaded
868 * from the LINUX_EFI_INITRD_MEDIA_GUID device path to supersede it.
870 * If the device path is not present, any command-line initrd=
871 * arguments will be processed only if image is not NULL, which will be
872 * the case only if we were loaded via the PE entry point.
874 status = efi_load_initrd(image, &addr, &size, hdr->initrd_addr_max,
876 if (status != EFI_SUCCESS)
879 efi_set_u64_split(addr, &hdr->ramdisk_image,
880 &boot_params->ext_ramdisk_image);
881 efi_set_u64_split(size, &hdr->ramdisk_size,
882 &boot_params->ext_ramdisk_size);
886 * If the boot loader gave us a value for secure_boot then we use that,
887 * otherwise we ask the BIOS.
889 if (boot_params->secure_boot == efi_secureboot_mode_unset)
890 boot_params->secure_boot = efi_get_secureboot();
892 /* Ask the firmware to clear memory on unclean shutdown */
893 efi_enable_reset_attack_mitigation();
895 efi_random_get_seed();
897 efi_retrieve_tpm2_eventlog();
899 setup_graphics(boot_params);
901 setup_efi_pci(boot_params);
903 setup_quirks(boot_params, bzimage_addr, buffer_end - buffer_start);
905 status = exit_boot(boot_params, handle);
906 if (status != EFI_SUCCESS) {
907 efi_err("exit_boot() failed!\n");
913 efi_err("efi_main() failed!\n");
915 efi_exit(handle, status);