Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'efi-next' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into efi/core

Pull EFI updates for v5.7 from Ard Biesheuvel:

This time, the set of changes for the EFI subsystem is much larger than
usual. The main reasons are:

- Get things cleaned up before EFI support for RISC-V arrives, which will
increase the size of the validation matrix, and therefore the threshold to
making drastic changes,

- After years of defunct maintainership, the GRUB project has finally started
to consider changes from the distros regarding UEFI boot, some of which are
highly specific to the way x86 does UEFI secure boot and measured boot,
based on knowledge of both shim internals and the layout of bootparams and
the x86 setup header. Having this maintenance burden on other architectures
(which don't need shim in the first place) is hard to justify, so instead,
we are introducing a generic Linux/UEFI boot protocol.

Summary of changes:

- Boot time GDT handling changes (Arvind)

- Simplify handling of EFI properties table on arm64

- Generic EFI stub cleanups, to improve command line handling, file I/O,
memory allocation, etc.

- Introduce a generic initrd loading method based on calling back into
the firmware, instead of relying on the x86 EFI handover protocol or
device tree.

- Introduce a mixed mode boot method that does not rely on the x86 EFI
handover protocol either, and could potentially be adopted by other
architectures (if another one ever surfaces where one execution mode
is a superset of another)

- Clean up the contents of struct efi, and move out everything that
doesn't need to be stored there.

- Incorporate support for UEFI spec v2.8A changes that permit firmware
implementations to return EFI_UNSUPPORTED from UEFI runtime services at
OS runtime, and expose a mask of which ones are supported or unsupported
via a configuration table.

- Various documentation updates and minor code cleanups (Heinrich)

- Partial fix for the lack of by-VA cache maintenance in the decompressor
on 32-bit ARM. Note that these patches were deliberately put at the
beginning so they can be used as a stable branch that will be shared with
a PR containing the complete fix, which I will send to the ARM tree.

Signed-off-by: Ingo Molnar <mingo@kernel.org>

+2732 -2652
+2 -6
Documentation/x86/boot.rst
··· 490 490 kernel) to not write early messages that require 491 491 accessing the display hardware directly. 492 492 493 - Bit 6 (write): KEEP_SEGMENTS 493 + Bit 6 (obsolete): KEEP_SEGMENTS 494 494 495 495 Protocol: 2.07+ 496 496 497 - - If 0, reload the segment registers in the 32bit entry point. 498 - - If 1, do not reload the segment registers in the 32bit entry point. 499 - 500 - Assume that %cs %ds %ss %es are all set to flat segments with 501 - a base of 0 (or the equivalent for their environment). 497 + - This flag is obsolete. 502 498 503 499 Bit 7 (write): CAN_USE_HEAP 504 500
+3 -3
arch/arm/boot/compressed/efi-header.S
··· 60 60 .long __pecoff_code_size @ SizeOfCode 61 61 .long __pecoff_data_size @ SizeOfInitializedData 62 62 .long 0 @ SizeOfUninitializedData 63 - .long efi_stub_entry - start @ AddressOfEntryPoint 63 + .long efi_entry - start @ AddressOfEntryPoint 64 64 .long start_offset @ BaseOfCode 65 65 .long __pecoff_data_start - start @ BaseOfData 66 66 ··· 70 70 .long SZ_512 @ FileAlignment 71 71 .short 0 @ MajorOsVersion 72 72 .short 0 @ MinorOsVersion 73 - .short 0 @ MajorImageVersion 74 - .short 0 @ MinorImageVersion 73 + .short LINUX_EFISTUB_MAJOR_VERSION @ MajorImageVersion 74 + .short LINUX_EFISTUB_MINOR_VERSION @ MinorImageVersion 75 75 .short 0 @ MajorSubsystemVersion 76 76 .short 0 @ MinorSubsystemVersion 77 77 .long 0 @ Win32VersionValue
+24 -34
arch/arm/boot/compressed/head.S
··· 1437 1437 reloc_code_end: 1438 1438 1439 1439 #ifdef CONFIG_EFI_STUB 1440 - .align 2 1441 - _start: .long start - . 1440 + ENTRY(efi_enter_kernel) 1441 + mov r7, r0 @ preserve image base 1442 + mov r4, r1 @ preserve DT pointer 1442 1443 1443 - ENTRY(efi_stub_entry) 1444 - @ allocate space on stack for passing current zImage address 1445 - @ and for the EFI stub to return of new entry point of 1446 - @ zImage, as EFI stub may copy the kernel. Pointer address 1447 - @ is passed in r2. r0 and r1 are passed through from the 1448 - @ EFI firmware to efi_entry 1449 - adr ip, _start 1450 - ldr r3, [ip] 1451 - add r3, r3, ip 1452 - stmfd sp!, {r3, lr} 1453 - mov r2, sp @ pass zImage address in r2 1454 - bl efi_entry 1455 - 1456 - @ Check for error return from EFI stub. r0 has FDT address 1457 - @ or error code. 1458 - cmn r0, #1 1459 - beq efi_load_fail 1460 - 1461 - @ Preserve return value of efi_entry() in r4 1462 - mov r4, r0 1444 + mov r0, r4 @ DT start 1445 + add r1, r4, r2 @ DT end 1463 1446 bl cache_clean_flush 1447 + 1448 + mov r0, r7 @ relocated zImage 1449 + ldr r1, =_edata @ size of zImage 1450 + add r1, r1, r0 @ end of zImage 1451 + bl cache_clean_flush 1452 + 1453 + @ The PE/COFF loader might not have cleaned the code we are 1454 + @ running beyond the PoU, and so calling cache_off below from 1455 + @ inside the PE/COFF loader allocated region is unsafe. Let's 1456 + @ assume our own zImage relocation code did a better job, and 1457 + @ jump into its version of this routine before proceeding. 1458 + ldr r1, .Ljmp 1459 + sub r1, r7, r1 1460 + mov pc, r1 @ no mode switch 1461 + 0: 1464 1462 bl cache_off 1465 1463 1466 1464 @ Set parameters for booting zImage according to boot protocol ··· 1467 1469 mov r0, #0 1468 1470 mov r1, #0xFFFFFFFF 1469 1471 mov r2, r4 1470 - 1471 - @ Branch to (possibly) relocated zImage that is in [sp] 1472 - ldr lr, [sp] 1473 - ldr ip, =start_offset 1474 - add lr, lr, ip 1475 - mov pc, lr @ no mode switch 1476 - 1477 - efi_load_fail: 1478 - @ Return EFI_LOAD_ERROR to EFI firmware on error. 1479 - ldr r0, =0x80000001 1480 - ldmfd sp!, {ip, pc} 1481 - ENDPROC(efi_stub_entry) 1472 + b __efi_start 1473 + ENDPROC(efi_enter_kernel) 1474 + .align 2 1475 + .Ljmp: .long start - 0b 1482 1476 #endif 1483 1477 1484 1478 .align
-10
arch/arm64/include/asm/efi.h
··· 58 58 /* arch specific definitions used by the stub code */ 59 59 60 60 /* 61 - * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from 62 - * start of kernel and may not cross a 2MiB boundary. We set alignment to 63 - * 2MiB so we know it won't cross a 2MiB boundary. 64 - */ 65 - #define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ 66 - 67 - /* 68 61 * In some configurations (e.g. VMAP_STACK && 64K pages), stacks built into the 69 62 * kernel need greater alignment than we require the segments to be padded to. 70 63 */ ··· 99 106 static inline void free_screen_info(struct screen_info *si) 100 107 { 101 108 } 102 - 103 - /* redeclare as 'hidden' so the compiler will generate relative references */ 104 - extern struct screen_info screen_info __attribute__((__visibility__("hidden"))); 105 109 106 110 static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt) 107 111 {
+17 -69
arch/arm64/kernel/efi-entry.S
··· 10 10 11 11 #include <asm/assembler.h> 12 12 13 - #define EFI_LOAD_ERROR 0x8000000000000001 14 - 15 13 __INIT 16 14 17 - /* 18 - * We arrive here from the EFI boot manager with: 19 - * 20 - * * CPU in little-endian mode 21 - * * MMU on with identity-mapped RAM 22 - * * Icache and Dcache on 23 - * 24 - * We will most likely be running from some place other than where 25 - * we want to be. The kernel image wants to be placed at TEXT_OFFSET 26 - * from start of RAM. 27 - */ 28 - ENTRY(entry) 29 - /* 30 - * Create a stack frame to save FP/LR with extra space 31 - * for image_addr variable passed to efi_entry(). 32 - */ 33 - stp x29, x30, [sp, #-32]! 34 - mov x29, sp 35 - 36 - /* 37 - * Call efi_entry to do the real work. 38 - * x0 and x1 are already set up by firmware. Current runtime 39 - * address of image is calculated and passed via *image_addr. 40 - * 41 - * unsigned long efi_entry(void *handle, 42 - * efi_system_table_t *sys_table, 43 - * unsigned long *image_addr) ; 44 - */ 45 - adr_l x8, _text 46 - add x2, sp, 16 47 - str x8, [x2] 48 - bl efi_entry 49 - cmn x0, #1 50 - b.eq efi_load_fail 51 - 15 + ENTRY(efi_enter_kernel) 52 16 /* 53 17 * efi_entry() will have copied the kernel image if necessary and we 54 - * return here with device tree address in x0 and the kernel entry 55 - * point stored at *image_addr. Save those values in registers which 56 - * are callee preserved. 18 + * end up here with device tree address in x1 and the kernel entry 19 + * point stored in x0. Save those values in registers which are 20 + * callee preserved. 57 21 */ 58 - mov x20, x0 // DTB address 59 - ldr x0, [sp, #16] // relocated _text address 60 - ldr w21, =stext_offset 61 - add x21, x0, x21 62 - 63 - /* 64 - * Calculate size of the kernel Image (same for original and copy). 65 - */ 66 - adr_l x1, _text 67 - adr_l x2, _edata 68 - sub x1, x2, x1 22 + mov x19, x0 // relocated Image address 23 + mov x20, x1 // DTB address 69 24 70 25 /* 71 26 * Flush the copied Image to the PoC, and ensure it is not shadowed by 72 27 * stale icache entries from before relocation. 73 28 */ 29 + ldr w1, =kernel_size 74 30 bl __flush_dcache_area 75 31 ic ialluis 32 + dsb sy 76 33 77 34 /* 78 - * Ensure that the rest of this function (in the original Image) is 79 - * visible when the caches are disabled. The I-cache can't have stale 80 - * entries for the VA range of the current image, so no maintenance is 81 - * necessary. 35 + * Jump across, into the copy of the image that we just cleaned 36 + * to the PoC, so that we can safely disable the MMU and caches. 82 37 */ 83 - adr x0, entry 84 - adr x1, entry_end 85 - sub x1, x1, x0 86 - bl __flush_dcache_area 87 - 38 + ldr w0, .Ljmp 39 + sub x0, x19, w0, sxtw 40 + br x0 41 + 0: 88 42 /* Turn off Dcache and MMU */ 89 43 mrs x0, CurrentEL 90 44 cmp x0, #CurrentEL_EL2 ··· 63 109 mov x1, xzr 64 110 mov x2, xzr 65 111 mov x3, xzr 66 - br x21 67 - 68 - efi_load_fail: 69 - mov x0, #EFI_LOAD_ERROR 70 - ldp x29, x30, [sp], #32 71 - ret 72 - 73 - entry_end: 74 - ENDPROC(entry) 112 + b stext 113 + ENDPROC(efi_enter_kernel) 114 + .Ljmp: .long _text - 0b
+3 -3
arch/arm64/kernel/efi-header.S
··· 27 27 .long __initdata_begin - efi_header_end // SizeOfCode 28 28 .long __pecoff_data_size // SizeOfInitializedData 29 29 .long 0 // SizeOfUninitializedData 30 - .long __efistub_entry - _head // AddressOfEntryPoint 30 + .long __efistub_efi_entry - _head // AddressOfEntryPoint 31 31 .long efi_header_end - _head // BaseOfCode 32 32 33 33 extra_header_fields: ··· 36 36 .long PECOFF_FILE_ALIGNMENT // FileAlignment 37 37 .short 0 // MajorOperatingSystemVersion 38 38 .short 0 // MinorOperatingSystemVersion 39 - .short 0 // MajorImageVersion 40 - .short 0 // MinorImageVersion 39 + .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion 40 + .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion 41 41 .short 0 // MajorSubsystemVersion 42 42 .short 0 // MinorSubsystemVersion 43 43 .long 0 // Win32VersionValue
+4 -1
arch/arm64/kernel/image-vars.h
··· 12 12 13 13 #ifdef CONFIG_EFI 14 14 15 - __efistub_stext_offset = stext - _text; 15 + __efistub_kernel_size = _edata - _text; 16 + 16 17 17 18 /* 18 19 * The EFI stub has its own symbol namespace prefixed by __efistub_, to ··· 43 42 #endif 44 43 45 44 __efistub__text = _text; 45 + __efistub_stext = stext; 46 46 __efistub__end = _end; 47 47 __efistub__edata = _edata; 48 48 __efistub_screen_info = screen_info; 49 + __efistub__ctype = _ctype; 49 50 50 51 #endif 51 52
+30 -25
arch/ia64/kernel/efi.c
··· 45 45 46 46 #define EFI_DEBUG 0 47 47 48 + #define ESI_TABLE_GUID \ 49 + EFI_GUID(0x43EA58DC, 0xCF28, 0x4b06, 0xB3, \ 50 + 0x91, 0xB7, 0x50, 0x59, 0x34, 0x2B, 0xD4) 51 + 52 + static unsigned long mps_phys = EFI_INVALID_TABLE_ADDR; 48 53 static __initdata unsigned long palo_phys; 49 54 55 + unsigned long __initdata esi_phys = EFI_INVALID_TABLE_ADDR; 56 + unsigned long hcdp_phys = EFI_INVALID_TABLE_ADDR; 50 57 unsigned long sal_systab_phys = EFI_INVALID_TABLE_ADDR; 51 58 52 - static __initdata efi_config_table_type_t arch_tables[] = { 59 + static const efi_config_table_type_t arch_tables[] __initconst = { 60 + {ESI_TABLE_GUID, "ESI", &esi_phys}, 61 + {HCDP_TABLE_GUID, "HCDP", &hcdp_phys}, 62 + {MPS_TABLE_GUID, "MPS", &mps_phys}, 53 63 {PROCESSOR_ABSTRACTION_LAYER_OVERWRITE_GUID, "PALO", &palo_phys}, 54 64 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &sal_systab_phys}, 55 65 {NULL_GUID, NULL, 0}, ··· 484 474 void __init 485 475 efi_init (void) 486 476 { 477 + const efi_system_table_t *efi_systab; 487 478 void *efi_map_start, *efi_map_end; 488 - efi_char16_t *c16; 489 479 u64 efi_desc_size; 490 - char *cp, vendor[100] = "unknown"; 491 - int i; 480 + char *cp; 492 481 493 482 set_bit(EFI_BOOT, &efi.flags); 494 483 set_bit(EFI_64BIT, &efi.flags); ··· 517 508 printk(KERN_INFO "Ignoring memory above %lluMB\n", 518 509 max_addr >> 20); 519 510 520 - efi.systab = __va(ia64_boot_param->efi_systab); 511 + efi_systab = __va(ia64_boot_param->efi_systab); 521 512 522 513 /* 523 514 * Verify the EFI Table 524 515 */ 525 - if (efi.systab == NULL) 516 + if (efi_systab == NULL) 526 517 panic("Whoa! Can't find EFI system table.\n"); 527 - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 518 + if (efi_systab_check_header(&efi_systab->hdr, 1)) 528 519 panic("Whoa! EFI system table signature incorrect\n"); 529 - if ((efi.systab->hdr.revision >> 16) == 0) 530 - printk(KERN_WARNING "Warning: EFI system table version " 531 - "%d.%02d, expected 1.00 or greater\n", 532 - efi.systab->hdr.revision >> 16, 533 - efi.systab->hdr.revision & 0xffff); 534 520 535 - /* Show what we know for posterity */ 536 - c16 = __va(efi.systab->fw_vendor); 537 - if (c16) { 538 - for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i) 539 - vendor[i] = *c16++; 540 - vendor[i] = '\0'; 541 - } 542 - 543 - printk(KERN_INFO "EFI v%u.%.02u by %s:", 544 - efi.systab->hdr.revision >> 16, 545 - efi.systab->hdr.revision & 0xffff, vendor); 521 + efi_systab_report_header(&efi_systab->hdr, efi_systab->fw_vendor); 546 522 547 523 palo_phys = EFI_INVALID_TABLE_ADDR; 548 524 549 - if (efi_config_init(arch_tables) != 0) 525 + if (efi_config_parse_tables(__va(efi_systab->tables), 526 + efi_systab->nr_tables, 527 + arch_tables) != 0) 550 528 return; 551 529 552 530 if (palo_phys != EFI_INVALID_TABLE_ADDR) 553 531 handle_palo(palo_phys); 554 532 555 - runtime = __va(efi.systab->runtime); 533 + runtime = __va(efi_systab->runtime); 556 534 efi.get_time = phys_get_time; 557 535 efi.set_time = phys_set_time; 558 536 efi.get_wakeup_time = phys_get_wakeup_time; ··· 1347 1351 return ret; 1348 1352 } 1349 1353 #endif 1354 + 1355 + char *efi_systab_show_arch(char *str) 1356 + { 1357 + if (mps_phys != EFI_INVALID_TABLE_ADDR) 1358 + str += sprintf(str, "MPS=0x%lx\n", mps_phys); 1359 + if (hcdp_phys != EFI_INVALID_TABLE_ADDR) 1360 + str += sprintf(str, "HCDP=0x%lx\n", hcdp_phys); 1361 + return str; 1362 + }
+4 -17
arch/ia64/kernel/esi.c
··· 19 19 20 20 #define MODULE_NAME "esi" 21 21 22 - #define ESI_TABLE_GUID \ 23 - EFI_GUID(0x43EA58DC, 0xCF28, 0x4b06, 0xB3, \ 24 - 0x91, 0xB7, 0x50, 0x59, 0x34, 0x2B, 0xD4) 25 - 26 22 enum esi_systab_entry_type { 27 23 ESI_DESC_ENTRY_POINT = 0 28 24 }; ··· 44 48 45 49 static struct ia64_sal_systab *esi_systab; 46 50 51 + extern unsigned long esi_phys; 52 + 47 53 static int __init esi_init (void) 48 54 { 49 - efi_config_table_t *config_tables; 50 55 struct ia64_sal_systab *systab; 51 - unsigned long esi = 0; 52 56 char *p; 53 57 int i; 54 58 55 - config_tables = __va(efi.systab->tables); 56 - 57 - for (i = 0; i < (int) efi.systab->nr_tables; ++i) { 58 - if (efi_guidcmp(config_tables[i].guid, ESI_TABLE_GUID) == 0) { 59 - esi = config_tables[i].table; 60 - break; 61 - } 62 - } 63 - 64 - if (!esi) 59 + if (esi_phys == EFI_INVALID_TABLE_ADDR) 65 60 return -ENODEV; 66 61 67 - systab = __va(esi); 62 + systab = __va(esi_phys); 68 63 69 64 if (strncmp(systab->signature, "ESIT", 4) != 0) { 70 65 printk(KERN_ERR "bad signature in ESI system table!");
+1 -1
arch/x86/boot/Makefile
··· 88 88 89 89 SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) 90 90 91 - sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p' 91 + sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|efi32_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p' 92 92 93 93 quiet_cmd_zoffset = ZOFFSET $@ 94 94 cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
+1 -4
arch/x86/boot/compressed/Makefile
··· 87 87 88 88 vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o 89 89 90 - $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone 91 - 92 - vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o \ 93 - $(objtree)/drivers/firmware/efi/libstub/lib.a 90 + vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a 94 91 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o 95 92 96 93 # The compressed kernel is built with -fPIC/-fPIE so that a boot loader
+87 -169
arch/x86/boot/compressed/eboot.c drivers/firmware/efi/libstub/x86-stub.c
··· 6 6 * 7 7 * ----------------------------------------------------------------------- */ 8 8 9 - #pragma GCC visibility push(hidden) 10 - 11 9 #include <linux/efi.h> 12 10 #include <linux/pci.h> 13 11 ··· 15 17 #include <asm/desc.h> 16 18 #include <asm/boot.h> 17 19 18 - #include "../string.h" 19 - #include "eboot.h" 20 + #include "efistub.h" 20 21 21 22 static efi_system_table_t *sys_table; 22 23 extern const bool efi_is64; ··· 312 315 return status; 313 316 } 314 317 315 - void setup_graphics(struct boot_params *boot_params) 318 + static void setup_graphics(struct boot_params *boot_params) 316 319 { 317 320 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; 318 321 struct screen_info *si; ··· 340 343 } 341 344 } 342 345 346 + 347 + static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status) 348 + { 349 + efi_bs_call(exit, handle, status, 0, NULL); 350 + unreachable(); 351 + } 352 + 343 353 void startup_32(struct boot_params *boot_params); 344 354 345 355 void __noreturn efi_stub_entry(efi_handle_t handle, ··· 362 358 efi_system_table_t *sys_table_arg) 363 359 { 364 360 struct boot_params *boot_params; 365 - struct apm_bios_info *bi; 366 361 struct setup_header *hdr; 367 362 efi_loaded_image_t *image; 368 363 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; ··· 370 367 char *cmdline_ptr; 371 368 unsigned long ramdisk_addr; 372 369 unsigned long ramdisk_size; 370 + bool above4g; 373 371 374 372 sys_table = sys_table_arg; 375 373 376 374 /* Check if we were booted by the EFI firmware */ 377 375 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 378 - return EFI_INVALID_PARAMETER; 376 + efi_exit(handle, EFI_INVALID_PARAMETER); 379 377 380 378 status = efi_bs_call(handle_protocol, handle, &proto, (void *)&image); 381 379 if (status != EFI_SUCCESS) { 382 380 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); 383 - return status; 381 + efi_exit(handle, status); 384 382 } 385 383 386 - status = efi_low_alloc(0x4000, 1, (unsigned long *)&boot_params); 384 + hdr = &((struct boot_params *)efi_table_attr(image, image_base))->hdr; 385 + above4g = hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G; 386 + 387 + status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params, 388 + above4g ? ULONG_MAX : UINT_MAX); 387 389 if (status != EFI_SUCCESS) { 388 390 efi_printk("Failed to allocate lowmem for boot params\n"); 389 - return status; 391 + efi_exit(handle, status); 390 392 } 391 393 392 394 memset(boot_params, 0x0, 0x4000); 393 395 394 396 hdr = &boot_params->hdr; 395 - bi = &boot_params->apm_bios_info; 396 397 397 398 /* Copy the second sector to boot_params */ 398 - memcpy(&hdr->jump, image->image_base + 512, 512); 399 + memcpy(&hdr->jump, efi_table_attr(image, image_base) + 512, 512); 399 400 400 401 /* 401 402 * Fill out some of the header fields ourselves because the ··· 412 405 hdr->type_of_loader = 0x21; 413 406 414 407 /* Convert unicode cmdline to ascii */ 415 - cmdline_ptr = efi_convert_cmdline(image, &options_size); 408 + cmdline_ptr = efi_convert_cmdline(image, &options_size, 409 + above4g ? ULONG_MAX : UINT_MAX); 416 410 if (!cmdline_ptr) 417 411 goto fail; 418 412 ··· 424 416 hdr->ramdisk_image = 0; 425 417 hdr->ramdisk_size = 0; 426 418 427 - /* Clear APM BIOS info */ 428 - memset(bi, 0, sizeof(*bi)); 419 + if (efi_is_native()) { 420 + status = efi_parse_options(cmdline_ptr); 421 + if (status != EFI_SUCCESS) 422 + goto fail2; 429 423 430 - status = efi_parse_options(cmdline_ptr); 431 - if (status != EFI_SUCCESS) 432 - goto fail2; 433 - 434 - status = handle_cmdline_files(image, 435 - (char *)(unsigned long)hdr->cmd_line_ptr, 436 - "initrd=", hdr->initrd_addr_max, 437 - &ramdisk_addr, &ramdisk_size); 438 - 439 - if (status != EFI_SUCCESS && 440 - hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) { 441 - efi_printk("Trying to load files to higher address\n"); 442 - status = handle_cmdline_files(image, 443 - (char *)(unsigned long)hdr->cmd_line_ptr, 444 - "initrd=", -1UL, 445 - &ramdisk_addr, &ramdisk_size); 424 + if (!noinitrd()) { 425 + status = efi_load_initrd(image, &ramdisk_addr, 426 + &ramdisk_size, 427 + hdr->initrd_addr_max, 428 + above4g ? ULONG_MAX 429 + : hdr->initrd_addr_max); 430 + if (status != EFI_SUCCESS) 431 + goto fail2; 432 + hdr->ramdisk_image = ramdisk_addr & 0xffffffff; 433 + hdr->ramdisk_size = ramdisk_size & 0xffffffff; 434 + boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; 435 + boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; 436 + } 446 437 } 447 - 448 - if (status != EFI_SUCCESS) 449 - goto fail2; 450 - hdr->ramdisk_image = ramdisk_addr & 0xffffffff; 451 - hdr->ramdisk_size = ramdisk_size & 0xffffffff; 452 - boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; 453 - boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; 454 - 455 - hdr->code32_start = (u32)(unsigned long)startup_32; 456 438 457 439 efi_stub_entry(handle, sys_table, boot_params); 458 440 /* not reached */ 459 441 460 442 fail2: 461 - efi_free(options_size, hdr->cmd_line_ptr); 443 + efi_free(options_size, (unsigned long)cmdline_ptr); 462 444 fail: 463 445 efi_free(0x4000, (unsigned long)boot_params); 464 446 465 - return status; 447 + efi_exit(handle, status); 466 448 } 467 449 468 450 static void add_e820ext(struct boot_params *params, ··· 710 712 efi_system_table_t *sys_table_arg, 711 713 struct boot_params *boot_params) 712 714 { 713 - struct desc_ptr *gdt = NULL; 715 + unsigned long bzimage_addr = (unsigned long)startup_32; 714 716 struct setup_header *hdr = &boot_params->hdr; 715 717 efi_status_t status; 716 - struct desc_struct *desc; 717 718 unsigned long cmdline_paddr; 718 719 719 720 sys_table = sys_table_arg; 720 721 721 722 /* Check if we were booted by the EFI firmware */ 722 723 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 723 - goto fail; 724 + efi_exit(handle, EFI_INVALID_PARAMETER); 724 725 725 726 /* 726 - * make_boot_params() may have been called before efi_main(), in which 727 + * If the kernel isn't already loaded at the preferred load 728 + * address, relocate it. 729 + */ 730 + if (bzimage_addr != hdr->pref_address) { 731 + status = efi_relocate_kernel(&bzimage_addr, 732 + hdr->init_size, hdr->init_size, 733 + hdr->pref_address, 734 + hdr->kernel_alignment, 735 + LOAD_PHYSICAL_ADDR); 736 + if (status != EFI_SUCCESS) { 737 + efi_printk("efi_relocate_kernel() failed!\n"); 738 + goto fail; 739 + } 740 + } 741 + hdr->code32_start = (u32)bzimage_addr; 742 + 743 + /* 744 + * efi_pe_entry() may have been called before efi_main(), in which 727 745 * case this is the second time we parse the cmdline. This is ok, 728 746 * parsing the cmdline multiple times does not have side-effects. 729 747 */ 730 748 cmdline_paddr = ((u64)hdr->cmd_line_ptr | 731 749 ((u64)boot_params->ext_cmd_line_ptr << 32)); 732 750 efi_parse_options((char *)cmdline_paddr); 751 + 752 + /* 753 + * At this point, an initrd may already have been loaded, either by 754 + * the bootloader and passed via bootparams, or loaded from a initrd= 755 + * command line option by efi_pe_entry() above. In either case, we 756 + * permit an initrd loaded from the LINUX_EFI_INITRD_MEDIA_GUID device 757 + * path to supersede it. 758 + */ 759 + if (!noinitrd()) { 760 + unsigned long addr, size; 761 + unsigned long max_addr = hdr->initrd_addr_max; 762 + 763 + if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) 764 + max_addr = ULONG_MAX; 765 + 766 + status = efi_load_initrd_dev_path(&addr, &size, max_addr); 767 + if (status == EFI_SUCCESS) { 768 + hdr->ramdisk_image = (u32)addr; 769 + hdr->ramdisk_size = (u32)size; 770 + boot_params->ext_ramdisk_image = (u64)addr >> 32; 771 + boot_params->ext_ramdisk_size = (u64)size >> 32; 772 + } else if (status != EFI_NOT_FOUND) { 773 + efi_printk("efi_load_initrd_dev_path() failed!\n"); 774 + goto fail; 775 + } 776 + } 733 777 734 778 /* 735 779 * If the boot loader gave us a value for secure_boot then we use that, ··· 793 753 794 754 setup_quirks(boot_params); 795 755 796 - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*gdt), 797 - (void **)&gdt); 798 - if (status != EFI_SUCCESS) { 799 - efi_printk("Failed to allocate memory for 'gdt' structure\n"); 800 - goto fail; 801 - } 802 - 803 - gdt->size = 0x800; 804 - status = efi_low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); 805 - if (status != EFI_SUCCESS) { 806 - efi_printk("Failed to allocate memory for 'gdt'\n"); 807 - goto fail; 808 - } 809 - 810 - /* 811 - * If the kernel isn't already loaded at the preferred load 812 - * address, relocate it. 813 - */ 814 - if (hdr->pref_address != hdr->code32_start) { 815 - unsigned long bzimage_addr = hdr->code32_start; 816 - status = efi_relocate_kernel(&bzimage_addr, 817 - hdr->init_size, hdr->init_size, 818 - hdr->pref_address, 819 - hdr->kernel_alignment, 820 - LOAD_PHYSICAL_ADDR); 821 - if (status != EFI_SUCCESS) { 822 - efi_printk("efi_relocate_kernel() failed!\n"); 823 - goto fail; 824 - } 825 - 826 - hdr->pref_address = hdr->code32_start; 827 - hdr->code32_start = bzimage_addr; 828 - } 829 - 830 756 status = exit_boot(boot_params, handle); 831 757 if (status != EFI_SUCCESS) { 832 758 efi_printk("exit_boot() failed!\n"); 833 759 goto fail; 834 760 } 835 761 836 - memset((char *)gdt->address, 0x0, gdt->size); 837 - desc = (struct desc_struct *)gdt->address; 838 - 839 - /* The first GDT is a dummy. */ 840 - desc++; 841 - 842 - if (IS_ENABLED(CONFIG_X86_64)) { 843 - /* __KERNEL32_CS */ 844 - desc->limit0 = 0xffff; 845 - desc->base0 = 0x0000; 846 - desc->base1 = 0x0000; 847 - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; 848 - desc->s = DESC_TYPE_CODE_DATA; 849 - desc->dpl = 0; 850 - desc->p = 1; 851 - desc->limit1 = 0xf; 852 - desc->avl = 0; 853 - desc->l = 0; 854 - desc->d = SEG_OP_SIZE_32BIT; 855 - desc->g = SEG_GRANULARITY_4KB; 856 - desc->base2 = 0x00; 857 - 858 - desc++; 859 - } else { 860 - /* Second entry is unused on 32-bit */ 861 - desc++; 862 - } 863 - 864 - /* __KERNEL_CS */ 865 - desc->limit0 = 0xffff; 866 - desc->base0 = 0x0000; 867 - desc->base1 = 0x0000; 868 - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; 869 - desc->s = DESC_TYPE_CODE_DATA; 870 - desc->dpl = 0; 871 - desc->p = 1; 872 - desc->limit1 = 0xf; 873 - desc->avl = 0; 874 - 875 - if (IS_ENABLED(CONFIG_X86_64)) { 876 - desc->l = 1; 877 - desc->d = 0; 878 - } else { 879 - desc->l = 0; 880 - desc->d = SEG_OP_SIZE_32BIT; 881 - } 882 - desc->g = SEG_GRANULARITY_4KB; 883 - desc->base2 = 0x00; 884 - desc++; 885 - 886 - /* __KERNEL_DS */ 887 - desc->limit0 = 0xffff; 888 - desc->base0 = 0x0000; 889 - desc->base1 = 0x0000; 890 - desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; 891 - desc->s = DESC_TYPE_CODE_DATA; 892 - desc->dpl = 0; 893 - desc->p = 1; 894 - desc->limit1 = 0xf; 895 - desc->avl = 0; 896 - desc->l = 0; 897 - desc->d = SEG_OP_SIZE_32BIT; 898 - desc->g = SEG_GRANULARITY_4KB; 899 - desc->base2 = 0x00; 900 - desc++; 901 - 902 - if (IS_ENABLED(CONFIG_X86_64)) { 903 - /* Task segment value */ 904 - desc->limit0 = 0x0000; 905 - desc->base0 = 0x0000; 906 - desc->base1 = 0x0000; 907 - desc->type = SEG_TYPE_TSS; 908 - desc->s = 0; 909 - desc->dpl = 0; 910 - desc->p = 1; 911 - desc->limit1 = 0x0; 912 - desc->avl = 0; 913 - desc->l = 0; 914 - desc->d = 0; 915 - desc->g = SEG_GRANULARITY_4KB; 916 - desc->base2 = 0x00; 917 - desc++; 918 - } 919 - 920 - asm volatile("cli"); 921 - asm volatile ("lgdt %0" : : "m" (*gdt)); 922 - 923 762 return boot_params; 924 763 fail: 925 764 efi_printk("efi_main() failed!\n"); 926 765 927 - for (;;) 928 - asm("hlt"); 766 + efi_exit(handle, status); 929 767 }
-31
arch/x86/boot/compressed/eboot.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef BOOT_COMPRESSED_EBOOT_H 3 - #define BOOT_COMPRESSED_EBOOT_H 4 - 5 - #define SEG_TYPE_DATA (0 << 3) 6 - #define SEG_TYPE_READ_WRITE (1 << 1) 7 - #define SEG_TYPE_CODE (1 << 3) 8 - #define SEG_TYPE_EXEC_READ (1 << 1) 9 - #define SEG_TYPE_TSS ((1 << 3) | (1 << 0)) 10 - #define SEG_OP_SIZE_32BIT (1 << 0) 11 - #define SEG_GRANULARITY_4KB (1 << 0) 12 - 13 - #define DESC_TYPE_CODE_DATA (1 << 0) 14 - 15 - typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t; 16 - 17 - union efi_uga_draw_protocol { 18 - struct { 19 - efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *, 20 - u32*, u32*, u32*, u32*); 21 - void *set_mode; 22 - void *blt; 23 - }; 24 - struct { 25 - u32 get_mode; 26 - u32 set_mode; 27 - u32 blt; 28 - } mixed_mode; 29 - }; 30 - 31 - #endif /* BOOT_COMPRESSED_EBOOT_H */
+24 -5
arch/x86/boot/compressed/efi_thunk_64.S
··· 54 54 * Switch to gdt with 32-bit segments. This is the firmware GDT 55 55 * that was installed when the kernel started executing. This 56 56 * pointer was saved at the EFI stub entry point in head_64.S. 57 + * 58 + * Pass the saved DS selector to the 32-bit code, and use far return to 59 + * restore the saved CS selector. 57 60 */ 58 61 leaq efi32_boot_gdt(%rip), %rax 59 62 lgdt (%rax) 60 63 61 - pushq $__KERNEL_CS 64 + movzwl efi32_boot_ds(%rip), %edx 65 + movzwq efi32_boot_cs(%rip), %rax 66 + pushq %rax 62 67 leaq efi_enter32(%rip), %rax 63 68 pushq %rax 64 69 lretq ··· 78 73 movl %ebx, %es 79 74 pop %rbx 80 75 movl %ebx, %ds 76 + /* Clear out 32-bit selector from FS and GS */ 77 + xorl %ebx, %ebx 78 + movl %ebx, %fs 79 + movl %ebx, %gs 81 80 82 81 /* 83 82 * Convert 32-bit status code into 64-bit. ··· 101 92 * The stack should represent the 32-bit calling convention. 102 93 */ 103 94 SYM_FUNC_START_LOCAL(efi_enter32) 104 - movl $__KERNEL_DS, %eax 105 - movl %eax, %ds 106 - movl %eax, %es 107 - movl %eax, %ss 95 + /* Load firmware selector into data and stack segment registers */ 96 + movl %edx, %ds 97 + movl %edx, %es 98 + movl %edx, %fs 99 + movl %edx, %gs 100 + movl %edx, %ss 108 101 109 102 /* Reload pgtables */ 110 103 movl %cr3, %eax ··· 167 156 .word 0 168 157 .quad 0 169 158 SYM_DATA_END(efi32_boot_gdt) 159 + 160 + SYM_DATA_START(efi32_boot_cs) 161 + .word 0 162 + SYM_DATA_END(efi32_boot_cs) 163 + 164 + SYM_DATA_START(efi32_boot_ds) 165 + .word 0 166 + SYM_DATA_END(efi32_boot_ds) 170 167 171 168 SYM_DATA_START(efi_gdt64) 172 169 .word efi_gdt64_end - efi_gdt64
+34 -14
arch/x86/boot/compressed/head_32.S
··· 63 63 __HEAD 64 64 SYM_FUNC_START(startup_32) 65 65 cld 66 - /* 67 - * Test KEEP_SEGMENTS flag to see if the bootloader is asking 68 - * us to not reload segments 69 - */ 70 - testb $KEEP_SEGMENTS, BP_loadflags(%esi) 71 - jnz 1f 72 - 73 66 cli 74 - movl $__BOOT_DS, %eax 75 - movl %eax, %ds 76 - movl %eax, %es 77 - movl %eax, %fs 78 - movl %eax, %gs 79 - movl %eax, %ss 80 - 1: 81 67 82 68 /* 83 69 * Calculate the delta between where we were compiled to run ··· 77 91 call 1f 78 92 1: popl %ebp 79 93 subl $1b, %ebp 94 + 95 + /* Load new GDT */ 96 + leal gdt(%ebp), %eax 97 + movl %eax, 2(%eax) 98 + lgdt (%eax) 99 + 100 + /* Load segment registers with our descriptors */ 101 + movl $__BOOT_DS, %eax 102 + movl %eax, %ds 103 + movl %eax, %es 104 + movl %eax, %fs 105 + movl %eax, %gs 106 + movl %eax, %ss 80 107 81 108 /* 82 109 * %ebp contains the address we are loaded at by the boot loader and %ebx ··· 135 136 rep movsl 136 137 cld 137 138 popl %esi 139 + 140 + /* 141 + * The GDT may get overwritten either during the copy we just did or 142 + * during extract_kernel below. To avoid any issues, repoint the GDTR 143 + * to the new copy of the GDT. EAX still contains the previously 144 + * calculated relocation offset of init_size - _end. 145 + */ 146 + leal gdt(%ebx), %edx 147 + addl %eax, 2(%edx) 148 + lgdt (%edx) 138 149 139 150 /* 140 151 * Jump to the relocated address. ··· 217 208 xorl %ebx, %ebx 218 209 jmp *%eax 219 210 SYM_FUNC_END(.Lrelocated) 211 + 212 + .data 213 + .balign 8 214 + SYM_DATA_START_LOCAL(gdt) 215 + .word gdt_end - gdt - 1 216 + .long 0 217 + .word 0 218 + .quad 0x0000000000000000 /* Reserved */ 219 + .quad 0x00cf9a000000ffff /* __KERNEL_CS */ 220 + .quad 0x00cf92000000ffff /* __KERNEL_DS */ 221 + SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) 220 222 221 223 /* 222 224 * Stack and heap for uncompression
+96 -29
arch/x86/boot/compressed/head_64.S
··· 53 53 * all need to be under the 4G limit. 54 54 */ 55 55 cld 56 - /* 57 - * Test KEEP_SEGMENTS flag to see if the bootloader is asking 58 - * us to not reload segments 59 - */ 60 - testb $KEEP_SEGMENTS, BP_loadflags(%esi) 61 - jnz 1f 62 - 63 56 cli 64 - movl $(__BOOT_DS), %eax 65 - movl %eax, %ds 66 - movl %eax, %es 67 - movl %eax, %ss 68 - 1: 69 57 70 58 /* 71 59 * Calculate the delta between where we were compiled to run ··· 68 80 1: popl %ebp 69 81 subl $1b, %ebp 70 82 83 + /* Load new GDT with the 64bit segments using 32bit descriptor */ 84 + leal gdt(%ebp), %eax 85 + movl %eax, 2(%eax) 86 + lgdt (%eax) 87 + 88 + /* Load segment registers with our descriptors */ 89 + movl $__BOOT_DS, %eax 90 + movl %eax, %ds 91 + movl %eax, %es 92 + movl %eax, %fs 93 + movl %eax, %gs 94 + movl %eax, %ss 95 + 71 96 /* setup a stack and make sure cpu supports long mode. */ 72 - movl $boot_stack_end, %eax 73 - addl %ebp, %eax 74 - movl %eax, %esp 97 + leal boot_stack_end(%ebp), %esp 75 98 76 99 call verify_cpu 77 100 testl %eax, %eax ··· 118 119 /* 119 120 * Prepare for entering 64 bit mode 120 121 */ 121 - 122 - /* Load new GDT with the 64bit segments using 32bit descriptor */ 123 - addl %ebp, gdt+2(%ebp) 124 - lgdt gdt(%ebp) 125 122 126 123 /* Enable PAE mode */ 127 124 movl %cr4, %eax ··· 207 212 cmp $0, %edi 208 213 jz 1f 209 214 leal efi64_stub_entry(%ebp), %eax 210 - movl %esi, %edx 211 215 movl efi32_boot_args+4(%ebp), %esi 216 + movl efi32_boot_args+8(%ebp), %edx // saved bootparams pointer 217 + cmpl $0, %edx 218 + jnz 1f 219 + leal efi_pe_entry(%ebp), %eax 220 + movl %edi, %ecx // MS calling convention 221 + movl %esi, %edx 212 222 1: 213 223 #endif 214 224 pushl %eax ··· 238 238 1: pop %ebp 239 239 subl $1b, %ebp 240 240 241 + movl %esi, efi32_boot_args+8(%ebp) 242 + SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL) 241 243 movl %ecx, efi32_boot_args(%ebp) 242 244 movl %edx, efi32_boot_args+4(%ebp) 243 - sgdtl efi32_boot_gdt(%ebp) 244 245 movb $0, efi_is64(%ebp) 246 + 247 + /* Save firmware GDTR and code/data selectors */ 248 + sgdtl efi32_boot_gdt(%ebp) 249 + movw %cs, efi32_boot_cs(%ebp) 250 + movw %ds, efi32_boot_ds(%ebp) 245 251 246 252 /* Disable paging */ 247 253 movl %cr0, %eax ··· 271 265 * that maps our entire kernel(text+data+bss+brk), zero page 272 266 * and command line. 273 267 */ 268 + 269 + cld 270 + cli 274 271 275 272 /* Setup data segments. */ 276 273 xorl %eax, %eax ··· 363 354 */ 364 355 365 356 /* Make sure we have GDT with 32-bit code segment */ 366 - leaq gdt(%rip), %rax 367 - movq %rax, gdt64+2(%rip) 368 - lgdt gdt64(%rip) 357 + leaq gdt64(%rip), %rax 358 + addq %rax, 2(%rax) 359 + lgdt (%rax) 369 360 370 361 /* 371 362 * paging_prepare() sets up the trampoline and checks if we need to ··· 449 440 rep movsq 450 441 cld 451 442 popq %rsi 443 + 444 + /* 445 + * The GDT may get overwritten either during the copy we just did or 446 + * during extract_kernel below. To avoid any issues, repoint the GDTR 447 + * to the new copy of the GDT. 448 + */ 449 + leaq gdt64(%rbx), %rax 450 + subq %rbp, 2(%rax) 451 + addq %rbx, 2(%rax) 452 + lgdt (%rax) 452 453 453 454 /* 454 455 * Jump to the relocated address. ··· 632 613 633 614 .data 634 615 SYM_DATA_START_LOCAL(gdt64) 635 - .word gdt_end - gdt 636 - .quad 0 616 + .word gdt_end - gdt - 1 617 + .quad gdt - gdt64 637 618 SYM_DATA_END(gdt64) 638 619 .balign 8 639 620 SYM_DATA_START_LOCAL(gdt) 640 - .word gdt_end - gdt 641 - .long gdt 621 + .word gdt_end - gdt - 1 622 + .long 0 642 623 .word 0 643 624 .quad 0x00cf9a000000ffff /* __KERNEL32_CS */ 644 625 .quad 0x00af9a000000ffff /* __KERNEL_CS */ ··· 648 629 SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) 649 630 650 631 #ifdef CONFIG_EFI_MIXED 651 - SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0) 632 + SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) 652 633 SYM_DATA(efi_is64, .byte 1) 634 + 635 + #define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) 636 + #define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) 637 + #define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) 638 + 639 + .text 640 + .code32 641 + SYM_FUNC_START(efi32_pe_entry) 642 + pushl %ebp 643 + 644 + call verify_cpu // check for long mode support 645 + testl %eax, %eax 646 + movl $0x80000003, %eax // EFI_UNSUPPORTED 647 + jnz 3f 648 + 649 + call 1f 650 + 1: pop %ebp 651 + subl $1b, %ebp 652 + 653 + /* Get the loaded image protocol pointer from the image handle */ 654 + subl $12, %esp // space for the loaded image pointer 655 + pushl %esp // pass its address 656 + leal 4f(%ebp), %eax 657 + pushl %eax // pass the GUID address 658 + pushl 28(%esp) // pass the image handle 659 + 660 + movl 36(%esp), %eax // sys_table 661 + movl ST32_boottime(%eax), %eax // sys_table->boottime 662 + call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol 663 + cmp $0, %eax 664 + jnz 2f 665 + 666 + movl 32(%esp), %ecx // image_handle 667 + movl 36(%esp), %edx // sys_table 668 + movl 12(%esp), %esi // loaded_image 669 + movl LI32_image_base(%esi), %esi // loaded_image->image_base 670 + jmp efi32_pe_stub_entry 671 + 672 + 2: addl $24, %esp 673 + 3: popl %ebp 674 + ret 675 + SYM_FUNC_END(efi32_pe_entry) 676 + 677 + .section ".rodata" 678 + /* EFI loaded image protocol GUID */ 679 + 4: .long 0x5B1B31A1 680 + .word 0x9562, 0x11d2 681 + .byte 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B 653 682 #endif 654 683 655 684 /*
+52 -51
arch/x86/boot/header.S
··· 15 15 * hex while segment addresses are written as segment:offset. 16 16 * 17 17 */ 18 - 18 + #include <linux/pe.h> 19 19 #include <asm/segment.h> 20 20 #include <asm/boot.h> 21 21 #include <asm/page_types.h> ··· 43 43 bootsect_start: 44 44 #ifdef CONFIG_EFI_STUB 45 45 # "MZ", MS-DOS header 46 - .byte 0x4d 47 - .byte 0x5a 46 + .word MZ_MAGIC 48 47 #endif 49 48 50 49 # Normalize the start address ··· 96 97 97 98 #ifdef CONFIG_EFI_STUB 98 99 pe_header: 99 - .ascii "PE" 100 - .word 0 100 + .long PE_MAGIC 101 101 102 102 coff_header: 103 103 #ifdef CONFIG_X86_32 104 - .word 0x14c # i386 104 + .set image_file_add_flags, IMAGE_FILE_32BIT_MACHINE 105 + .set pe_opt_magic, PE_OPT_MAGIC_PE32 106 + .word IMAGE_FILE_MACHINE_I386 105 107 #else 106 - .word 0x8664 # x86-64 108 + .set image_file_add_flags, 0 109 + .set pe_opt_magic, PE_OPT_MAGIC_PE32PLUS 110 + .word IMAGE_FILE_MACHINE_AMD64 107 111 #endif 108 - .word 4 # nr_sections 112 + .word section_count # nr_sections 109 113 .long 0 # TimeDateStamp 110 114 .long 0 # PointerToSymbolTable 111 115 .long 1 # NumberOfSymbols 112 116 .word section_table - optional_header # SizeOfOptionalHeader 113 - #ifdef CONFIG_X86_32 114 - .word 0x306 # Characteristics. 115 - # IMAGE_FILE_32BIT_MACHINE | 116 - # IMAGE_FILE_DEBUG_STRIPPED | 117 - # IMAGE_FILE_EXECUTABLE_IMAGE | 118 - # IMAGE_FILE_LINE_NUMS_STRIPPED 119 - #else 120 - .word 0x206 # Characteristics 121 - # IMAGE_FILE_DEBUG_STRIPPED | 122 - # IMAGE_FILE_EXECUTABLE_IMAGE | 123 - # IMAGE_FILE_LINE_NUMS_STRIPPED 124 - #endif 117 + .word IMAGE_FILE_EXECUTABLE_IMAGE | \ 118 + image_file_add_flags | \ 119 + IMAGE_FILE_DEBUG_STRIPPED | \ 120 + IMAGE_FILE_LINE_NUMS_STRIPPED # Characteristics 125 121 126 122 optional_header: 127 - #ifdef CONFIG_X86_32 128 - .word 0x10b # PE32 format 129 - #else 130 - .word 0x20b # PE32+ format 131 - #endif 123 + .word pe_opt_magic 132 124 .byte 0x02 # MajorLinkerVersion 133 125 .byte 0x14 # MinorLinkerVersion 134 126 ··· 147 157 .long 0x20 # FileAlignment 148 158 .word 0 # MajorOperatingSystemVersion 149 159 .word 0 # MinorOperatingSystemVersion 150 - .word 0 # MajorImageVersion 151 - .word 0 # MinorImageVersion 160 + .word LINUX_EFISTUB_MAJOR_VERSION # MajorImageVersion 161 + .word LINUX_EFISTUB_MINOR_VERSION # MinorImageVersion 152 162 .word 0 # MajorSubsystemVersion 153 163 .word 0 # MinorSubsystemVersion 154 164 .long 0 # Win32VersionValue ··· 160 170 161 171 .long 0x200 # SizeOfHeaders 162 172 .long 0 # CheckSum 163 - .word 0xa # Subsystem (EFI application) 173 + .word IMAGE_SUBSYSTEM_EFI_APPLICATION # Subsystem (EFI application) 164 174 .word 0 # DllCharacteristics 165 175 #ifdef CONFIG_X86_32 166 176 .long 0 # SizeOfStackReserve ··· 174 184 .quad 0 # SizeOfHeapCommit 175 185 #endif 176 186 .long 0 # LoaderFlags 177 - .long 0x6 # NumberOfRvaAndSizes 187 + .long (section_table - .) / 8 # NumberOfRvaAndSizes 178 188 179 189 .quad 0 # ExportTable 180 190 .quad 0 # ImportTable ··· 200 210 .long 0 # PointerToLineNumbers 201 211 .word 0 # NumberOfRelocations 202 212 .word 0 # NumberOfLineNumbers 203 - .long 0x60500020 # Characteristics (section flags) 213 + .long IMAGE_SCN_CNT_CODE | \ 214 + IMAGE_SCN_MEM_READ | \ 215 + IMAGE_SCN_MEM_EXECUTE | \ 216 + IMAGE_SCN_ALIGN_16BYTES # Characteristics 204 217 205 218 # 206 219 # The EFI application loader requires a relocation section ··· 221 228 .long 0 # PointerToLineNumbers 222 229 .word 0 # NumberOfRelocations 223 230 .word 0 # NumberOfLineNumbers 224 - .long 0x42100040 # Characteristics (section flags) 231 + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 232 + IMAGE_SCN_MEM_READ | \ 233 + IMAGE_SCN_MEM_DISCARDABLE | \ 234 + IMAGE_SCN_ALIGN_1BYTES # Characteristics 235 + 236 + #ifdef CONFIG_EFI_MIXED 237 + # 238 + # The offset & size fields are filled in by build.c. 239 + # 240 + .asciz ".compat" 241 + .long 0 242 + .long 0x0 243 + .long 0 # Size of initialized data 244 + # on disk 245 + .long 0x0 246 + .long 0 # PointerToRelocations 247 + .long 0 # PointerToLineNumbers 248 + .word 0 # NumberOfRelocations 249 + .word 0 # NumberOfLineNumbers 250 + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 251 + IMAGE_SCN_MEM_READ | \ 252 + IMAGE_SCN_MEM_DISCARDABLE | \ 253 + IMAGE_SCN_ALIGN_1BYTES # Characteristics 254 + #endif 225 255 226 256 # 227 257 # The offset & size fields are filled in by build.c. ··· 262 246 .long 0 # PointerToLineNumbers 263 247 .word 0 # NumberOfRelocations 264 248 .word 0 # NumberOfLineNumbers 265 - .long 0x60500020 # Characteristics (section flags) 249 + .long IMAGE_SCN_CNT_CODE | \ 250 + IMAGE_SCN_MEM_READ | \ 251 + IMAGE_SCN_MEM_EXECUTE | \ 252 + IMAGE_SCN_ALIGN_16BYTES # Characteristics 266 253 267 - # 268 - # The offset & size fields are filled in by build.c. 269 - # 270 - .ascii ".bss" 271 - .byte 0 272 - .byte 0 273 - .byte 0 274 - .byte 0 275 - .long 0 276 - .long 0x0 277 - .long 0 # Size of initialized data 278 - # on disk 279 - .long 0x0 280 - .long 0 # PointerToRelocations 281 - .long 0 # PointerToLineNumbers 282 - .word 0 # NumberOfRelocations 283 - .word 0 # NumberOfLineNumbers 284 - .long 0xc8000080 # Characteristics (section flags) 285 - 254 + .set section_count, (. - section_table) / 40 286 255 #endif /* CONFIG_EFI_STUB */ 287 256 288 257 # Kernel attributes; used by setup. This is part 1 of the
+61 -25
arch/x86/boot/tools/build.c
··· 53 53 54 54 #define PECOFF_RELOC_RESERVE 0x20 55 55 56 + #ifdef CONFIG_EFI_MIXED 57 + #define PECOFF_COMPAT_RESERVE 0x20 58 + #else 59 + #define PECOFF_COMPAT_RESERVE 0x0 60 + #endif 61 + 56 62 unsigned long efi32_stub_entry; 57 63 unsigned long efi64_stub_entry; 58 64 unsigned long efi_pe_entry; 65 + unsigned long efi32_pe_entry; 59 66 unsigned long kernel_info; 60 67 unsigned long startup_64; 61 68 ··· 196 189 static void update_pecoff_setup_and_reloc(unsigned int size) 197 190 { 198 191 u32 setup_offset = 0x200; 199 - u32 reloc_offset = size - PECOFF_RELOC_RESERVE; 192 + u32 reloc_offset = size - PECOFF_RELOC_RESERVE - PECOFF_COMPAT_RESERVE; 193 + #ifdef CONFIG_EFI_MIXED 194 + u32 compat_offset = reloc_offset + PECOFF_RELOC_RESERVE; 195 + #endif 200 196 u32 setup_size = reloc_offset - setup_offset; 201 197 202 198 update_pecoff_section_header(".setup", setup_offset, setup_size); ··· 211 201 */ 212 202 put_unaligned_le32(reloc_offset + 10, &buf[reloc_offset]); 213 203 put_unaligned_le32(10, &buf[reloc_offset + 4]); 204 + 205 + #ifdef CONFIG_EFI_MIXED 206 + update_pecoff_section_header(".compat", compat_offset, PECOFF_COMPAT_RESERVE); 207 + 208 + /* 209 + * Put the IA-32 machine type (0x14c) and the associated entry point 210 + * address in the .compat section, so loaders can figure out which other 211 + * execution modes this image supports. 212 + */ 213 + buf[compat_offset] = 0x1; 214 + buf[compat_offset + 1] = 0x8; 215 + put_unaligned_le16(0x14c, &buf[compat_offset + 2]); 216 + put_unaligned_le32(efi32_pe_entry + size, &buf[compat_offset + 4]); 217 + #endif 214 218 } 215 219 216 - static void update_pecoff_text(unsigned int text_start, unsigned int file_sz) 220 + static void update_pecoff_text(unsigned int text_start, unsigned int file_sz, 221 + unsigned int init_sz) 217 222 { 218 223 unsigned int pe_header; 219 224 unsigned int text_sz = file_sz - text_start; 225 + unsigned int bss_sz = init_sz + text_start - file_sz; 220 226 221 227 pe_header = get_unaligned_le32(&buf[0x3c]); 228 + 229 + #ifdef CONFIG_EFI_MIXED 230 + /* 231 + * In mixed mode, we will execute startup_32() at whichever offset in 232 + * memory it happened to land when the PE/COFF loader loaded the image, 233 + * which may be misaligned with respect to the kernel_alignment field 234 + * in the setup header. 235 + * 236 + * In order for startup_32 to safely execute in place at this offset, 237 + * we need to ensure that the CONFIG_PHYSICAL_ALIGN aligned allocation 238 + * it creates for the page tables does not extend beyond the declared 239 + * size of the image in the PE/COFF header. So add the required slack. 240 + */ 241 + bss_sz += CONFIG_PHYSICAL_ALIGN; 242 + init_sz += CONFIG_PHYSICAL_ALIGN; 243 + #endif 222 244 223 245 /* 224 246 * Size of code: Subtract the size of the first sector (512 bytes) 225 247 * which includes the header. 226 248 */ 227 - put_unaligned_le32(file_sz - 512, &buf[pe_header + 0x1c]); 249 + put_unaligned_le32(file_sz - 512 + bss_sz, &buf[pe_header + 0x1c]); 250 + 251 + /* Size of image */ 252 + put_unaligned_le32(init_sz + text_start, &buf[pe_header + 0x50]); 228 253 229 254 /* 230 255 * Address of entry point for PE/COFF executable 231 256 */ 232 257 put_unaligned_le32(text_start + efi_pe_entry, &buf[pe_header + 0x28]); 233 258 234 - update_pecoff_section_header(".text", text_start, text_sz); 235 - } 236 - 237 - static void update_pecoff_bss(unsigned int file_sz, unsigned int init_sz) 238 - { 239 - unsigned int pe_header; 240 - unsigned int bss_sz = init_sz - file_sz; 241 - 242 - pe_header = get_unaligned_le32(&buf[0x3c]); 243 - 244 - /* Size of uninitialized data */ 245 - put_unaligned_le32(bss_sz, &buf[pe_header + 0x24]); 246 - 247 - /* Size of image */ 248 - put_unaligned_le32(init_sz, &buf[pe_header + 0x50]); 249 - 250 - update_pecoff_section_header_fields(".bss", file_sz, bss_sz, 0, 0); 259 + update_pecoff_section_header_fields(".text", text_start, text_sz + bss_sz, 260 + text_sz, text_start); 251 261 } 252 262 253 263 static int reserve_pecoff_reloc_section(int c) ··· 308 278 309 279 static inline void update_pecoff_setup_and_reloc(unsigned int size) {} 310 280 static inline void update_pecoff_text(unsigned int text_start, 311 - unsigned int file_sz) {} 312 - static inline void update_pecoff_bss(unsigned int file_sz, 313 - unsigned int init_sz) {} 281 + unsigned int file_sz, 282 + unsigned int init_sz) {} 314 283 static inline void efi_stub_defaults(void) {} 315 284 static inline void efi_stub_entry_update(void) {} 316 285 ··· 319 290 } 320 291 #endif /* CONFIG_EFI_STUB */ 321 292 293 + static int reserve_pecoff_compat_section(int c) 294 + { 295 + /* Reserve 0x20 bytes for .compat section */ 296 + memset(buf+c, 0, PECOFF_COMPAT_RESERVE); 297 + return PECOFF_COMPAT_RESERVE; 298 + } 322 299 323 300 /* 324 301 * Parse zoffset.h and find the entry points. We could just #include zoffset.h ··· 357 322 PARSE_ZOFS(p, efi32_stub_entry); 358 323 PARSE_ZOFS(p, efi64_stub_entry); 359 324 PARSE_ZOFS(p, efi_pe_entry); 325 + PARSE_ZOFS(p, efi32_pe_entry); 360 326 PARSE_ZOFS(p, kernel_info); 361 327 PARSE_ZOFS(p, startup_64); 362 328 ··· 401 365 die("Boot block hasn't got boot flag (0xAA55)"); 402 366 fclose(file); 403 367 368 + c += reserve_pecoff_compat_section(c); 404 369 c += reserve_pecoff_reloc_section(c); 405 370 406 371 /* Pad unused space with zeros */ ··· 443 406 buf[0x1f1] = setup_sectors-1; 444 407 put_unaligned_le32(sys_size, &buf[0x1f4]); 445 408 446 - update_pecoff_text(setup_sectors * 512, i + (sys_size * 16)); 447 409 init_sz = get_unaligned_le32(&buf[0x260]); 448 - update_pecoff_bss(i + (sys_size * 16), init_sz); 410 + update_pecoff_text(setup_sectors * 512, i + (sys_size * 16), init_sz); 449 411 450 412 efi_stub_entry_update(); 451 413
+19 -4
arch/x86/include/asm/efi.h
··· 10 10 #include <asm/mmu_context.h> 11 11 #include <linux/build_bug.h> 12 12 13 + extern unsigned long efi_fw_vendor, efi_config_table; 14 + 13 15 /* 14 16 * We map the EFI regions needed for runtime services non-contiguously, 15 17 * with preserved alignment on virtual addresses starting from -4G down ··· 35 33 36 34 #define EFI32_LOADER_SIGNATURE "EL32" 37 35 #define EFI64_LOADER_SIGNATURE "EL64" 38 - 39 - #define MAX_CMDLINE_ADDRESS UINT_MAX 40 36 41 37 #define ARCH_EFI_IRQ_FLAGS_MASK X86_EFLAGS_IF 42 38 ··· 180 180 181 181 struct efi_setup_data { 182 182 u64 fw_vendor; 183 - u64 runtime; 184 183 u64 tables; 185 184 u64 smbios; 186 185 u64 reserved[8]; ··· 218 219 efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size, 219 220 unsigned long descriptor_size, 220 221 u32 descriptor_version, 221 - efi_memory_desc_t *virtual_map); 222 + efi_memory_desc_t *virtual_map, 223 + unsigned long systab_phys); 222 224 223 225 /* arch specific definitions used by the stub code */ 224 226 ··· 270 270 return p; 271 271 } 272 272 273 + static inline u32 efi64_convert_status(efi_status_t status) 274 + { 275 + return (u32)(status | (u64)status >> 32); 276 + } 277 + 273 278 #define __efi64_argmap_free_pages(addr, size) \ 274 279 ((addr), 0, (size)) 275 280 ··· 290 285 #define __efi64_argmap_locate_protocol(protocol, reg, interface) \ 291 286 ((protocol), (reg), efi64_zero_upper(interface)) 292 287 288 + #define __efi64_argmap_locate_device_path(protocol, path, handle) \ 289 + ((protocol), (path), efi64_zero_upper(handle)) 290 + 291 + #define __efi64_argmap_exit(handle, status, size, data) \ 292 + ((handle), efi64_convert_status(status), (size), (data)) 293 + 293 294 /* PCI I/O */ 294 295 #define __efi64_argmap_get_location(protocol, seg, bus, dev, func) \ 295 296 ((protocol), efi64_zero_upper(seg), efi64_zero_upper(bus), \ 296 297 efi64_zero_upper(dev), efi64_zero_upper(func)) 298 + 299 + /* LoadFile */ 300 + #define __efi64_argmap_load_file(protocol, path, policy, bufsize, buf) \ 301 + ((protocol), (path), (policy), efi64_zero_upper(bufsize), (buf)) 297 302 298 303 /* 299 304 * The macros below handle the plumbing for the argument mapping. To add a
+5
arch/x86/kernel/asm-offsets_32.c
··· 3 3 # error "Please do not build this file directly, build asm-offsets.c instead" 4 4 #endif 5 5 6 + #include <linux/efi.h> 7 + 6 8 #include <asm/ucontext.h> 7 9 8 10 #define __SYSCALL_I386(nr, sym, qual) [nr] = 1, ··· 66 64 BLANK(); 67 65 DEFINE(__NR_syscall_max, sizeof(syscalls) - 1); 68 66 DEFINE(NR_syscalls, sizeof(syscalls)); 67 + 68 + BLANK(); 69 + DEFINE(EFI_svam, offsetof(efi_runtime_services_t, set_virtual_address_map)); 69 70 }
-6
arch/x86/kernel/head_32.S
··· 67 67 SYM_CODE_START(startup_32) 68 68 movl pa(initial_stack),%ecx 69 69 70 - /* test KEEP_SEGMENTS flag to see if the bootloader is asking 71 - us to not reload segments */ 72 - testb $KEEP_SEGMENTS, BP_loadflags(%esi) 73 - jnz 2f 74 - 75 70 /* 76 71 * Set segments to known values. 77 72 */ ··· 77 82 movl %eax,%fs 78 83 movl %eax,%gs 79 84 movl %eax,%ss 80 - 2: 81 85 leal -__PAGE_OFFSET(%ecx),%esp 82 86 83 87 /*
+1 -1
arch/x86/kernel/ima_arch.c
··· 17 17 18 18 size = sizeof(secboot); 19 19 20 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) { 20 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) { 21 21 pr_info("ima: secureboot mode unknown, no efi\n"); 22 22 return efi_secureboot_mode_unknown; 23 23 }
+2 -3
arch/x86/kernel/kexec-bzimage64.c
··· 141 141 struct setup_data *sd = (void *)params + efi_setup_data_offset; 142 142 struct efi_setup_data *esd = (void *)sd + sizeof(struct setup_data); 143 143 144 - esd->fw_vendor = efi.fw_vendor; 145 - esd->runtime = efi.runtime; 146 - esd->tables = efi.config_table; 144 + esd->fw_vendor = efi_fw_vendor; 145 + esd->tables = efi_config_table; 147 146 esd->smbios = efi.smbios; 148 147 149 148 sd->type = SETUP_EFI;
+136 -147
arch/x86/platform/efi/efi.c
··· 54 54 #include <asm/x86_init.h> 55 55 #include <asm/uv/uv.h> 56 56 57 - static efi_system_table_t efi_systab __initdata; 58 - static u64 efi_systab_phys __initdata; 57 + static unsigned long efi_systab_phys __initdata; 58 + static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR; 59 + static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR; 60 + static unsigned long efi_runtime, efi_nr_tables; 59 61 60 - static efi_config_table_type_t arch_tables[] __initdata = { 62 + unsigned long efi_fw_vendor, efi_config_table; 63 + 64 + static const efi_config_table_type_t arch_tables[] __initconst = { 65 + {EFI_PROPERTIES_TABLE_GUID, "PROP", &prop_phys}, 66 + {UGA_IO_PROTOCOL_GUID, "UGA", &uga_phys}, 61 67 #ifdef CONFIG_X86_UV 62 68 {UV_SYSTEM_TABLE_GUID, "UVsystab", &uv_systab_phys}, 63 69 #endif ··· 71 65 }; 72 66 73 67 static const unsigned long * const efi_tables[] = { 74 - &efi.mps, 75 68 &efi.acpi, 76 69 &efi.acpi20, 77 70 &efi.smbios, 78 71 &efi.smbios3, 79 - &efi.boot_info, 80 - &efi.hcdp, 81 - &efi.uga, 72 + &uga_phys, 82 73 #ifdef CONFIG_X86_UV 83 74 &uv_systab_phys, 84 75 #endif 85 - &efi.fw_vendor, 86 - &efi.runtime, 87 - &efi.config_table, 76 + &efi_fw_vendor, 77 + &efi_runtime, 78 + &efi_config_table, 88 79 &efi.esrt, 89 - &efi.properties_table, 90 - &efi.mem_attr_table, 80 + &prop_phys, 81 + &efi_mem_attr_table, 91 82 #ifdef CONFIG_EFI_RCI2_TABLE 92 83 &rci2_table_phys, 93 84 #endif ··· 217 214 if (efi_enabled(EFI_PARAVIRT)) 218 215 return 0; 219 216 220 - #ifdef CONFIG_X86_32 221 - /* Can't handle data above 4GB at this time */ 222 - if (e->efi_memmap_hi) { 217 + /* Can't handle firmware tables above 4GB on i386 */ 218 + if (IS_ENABLED(CONFIG_X86_32) && e->efi_memmap_hi > 0) { 223 219 pr_err("Memory map is above 4GB, disabling EFI.\n"); 224 220 return -EINVAL; 225 221 } 226 - pmap = e->efi_memmap; 227 - #else 228 - pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); 229 - #endif 222 + pmap = (phys_addr_t)(e->efi_memmap | ((u64)e->efi_memmap_hi << 32)); 223 + 230 224 data.phys_map = pmap; 231 225 data.size = e->efi_memmap_size; 232 226 data.desc_size = e->efi_memdesc_size; ··· 305 305 306 306 if (n_removal > 0) { 307 307 struct efi_memory_map_data data = { 308 - .phys_map = efi.memmap.phys_map, 309 - .desc_version = efi.memmap.desc_version, 310 - .desc_size = efi.memmap.desc_size, 311 - .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), 312 - .flags = 0, 308 + .phys_map = efi.memmap.phys_map, 309 + .desc_version = efi.memmap.desc_version, 310 + .desc_size = efi.memmap.desc_size, 311 + .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), 312 + .flags = 0, 313 313 }; 314 314 315 315 pr_warn("Removing %d invalid memory map entries.\n", n_removal); ··· 333 333 } 334 334 } 335 335 336 - static int __init efi_systab_init(u64 phys) 336 + static int __init efi_systab_init(unsigned long phys) 337 337 { 338 338 int size = efi_enabled(EFI_64BIT) ? sizeof(efi_system_table_64_t) 339 339 : sizeof(efi_system_table_32_t); 340 + const efi_table_hdr_t *hdr; 340 341 bool over4g = false; 341 342 void *p; 343 + int ret; 342 344 343 - p = early_memremap_ro(phys, size); 345 + hdr = p = early_memremap_ro(phys, size); 344 346 if (p == NULL) { 345 347 pr_err("Couldn't map the system table!\n"); 346 348 return -ENOMEM; 347 349 } 348 350 351 + ret = efi_systab_check_header(hdr, 1); 352 + if (ret) { 353 + early_memunmap(p, size); 354 + return ret; 355 + } 356 + 349 357 if (efi_enabled(EFI_64BIT)) { 350 358 const efi_system_table_64_t *systab64 = p; 351 359 352 - efi_systab.hdr = systab64->hdr; 353 - efi_systab.fw_vendor = systab64->fw_vendor; 354 - efi_systab.fw_revision = systab64->fw_revision; 355 - efi_systab.con_in_handle = systab64->con_in_handle; 356 - efi_systab.con_in = systab64->con_in; 357 - efi_systab.con_out_handle = systab64->con_out_handle; 358 - efi_systab.con_out = (void *)(unsigned long)systab64->con_out; 359 - efi_systab.stderr_handle = systab64->stderr_handle; 360 - efi_systab.stderr = systab64->stderr; 361 - efi_systab.runtime = (void *)(unsigned long)systab64->runtime; 362 - efi_systab.boottime = (void *)(unsigned long)systab64->boottime; 363 - efi_systab.nr_tables = systab64->nr_tables; 364 - efi_systab.tables = systab64->tables; 365 - 366 - over4g = systab64->con_in_handle > U32_MAX || 367 - systab64->con_in > U32_MAX || 368 - systab64->con_out_handle > U32_MAX || 369 - systab64->con_out > U32_MAX || 370 - systab64->stderr_handle > U32_MAX || 371 - systab64->stderr > U32_MAX || 372 - systab64->boottime > U32_MAX; 360 + efi_runtime = systab64->runtime; 361 + over4g = systab64->runtime > U32_MAX; 373 362 374 363 if (efi_setup) { 375 364 struct efi_setup_data *data; ··· 369 380 return -ENOMEM; 370 381 } 371 382 372 - efi_systab.fw_vendor = (unsigned long)data->fw_vendor; 373 - efi_systab.runtime = (void *)(unsigned long)data->runtime; 374 - efi_systab.tables = (unsigned long)data->tables; 383 + efi_fw_vendor = (unsigned long)data->fw_vendor; 384 + efi_config_table = (unsigned long)data->tables; 375 385 376 386 over4g |= data->fw_vendor > U32_MAX || 377 - data->runtime > U32_MAX || 378 387 data->tables > U32_MAX; 379 388 380 389 early_memunmap(data, sizeof(*data)); 381 390 } else { 391 + efi_fw_vendor = systab64->fw_vendor; 392 + efi_config_table = systab64->tables; 393 + 382 394 over4g |= systab64->fw_vendor > U32_MAX || 383 - systab64->runtime > U32_MAX || 384 395 systab64->tables > U32_MAX; 385 396 } 397 + efi_nr_tables = systab64->nr_tables; 386 398 } else { 387 399 const efi_system_table_32_t *systab32 = p; 388 400 389 - efi_systab.hdr = systab32->hdr; 390 - efi_systab.fw_vendor = systab32->fw_vendor; 391 - efi_systab.fw_revision = systab32->fw_revision; 392 - efi_systab.con_in_handle = systab32->con_in_handle; 393 - efi_systab.con_in = systab32->con_in; 394 - efi_systab.con_out_handle = systab32->con_out_handle; 395 - efi_systab.con_out = (void *)(unsigned long)systab32->con_out; 396 - efi_systab.stderr_handle = systab32->stderr_handle; 397 - efi_systab.stderr = systab32->stderr; 398 - efi_systab.runtime = (void *)(unsigned long)systab32->runtime; 399 - efi_systab.boottime = (void *)(unsigned long)systab32->boottime; 400 - efi_systab.nr_tables = systab32->nr_tables; 401 - efi_systab.tables = systab32->tables; 401 + efi_fw_vendor = systab32->fw_vendor; 402 + efi_runtime = systab32->runtime; 403 + efi_config_table = systab32->tables; 404 + efi_nr_tables = systab32->nr_tables; 402 405 } 403 406 407 + efi.runtime_version = hdr->revision; 408 + 409 + efi_systab_report_header(hdr, efi_fw_vendor); 404 410 early_memunmap(p, size); 405 411 406 412 if (IS_ENABLED(CONFIG_X86_32) && over4g) { ··· 403 419 return -EINVAL; 404 420 } 405 421 406 - efi.systab = &efi_systab; 422 + return 0; 423 + } 424 + 425 + static int __init efi_config_init(const efi_config_table_type_t *arch_tables) 426 + { 427 + void *config_tables; 428 + int sz, ret; 429 + 430 + if (efi_nr_tables == 0) 431 + return 0; 432 + 433 + if (efi_enabled(EFI_64BIT)) 434 + sz = sizeof(efi_config_table_64_t); 435 + else 436 + sz = sizeof(efi_config_table_32_t); 407 437 408 438 /* 409 - * Verify the EFI Table 439 + * Let's see what config tables the firmware passed to us. 410 440 */ 411 - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 412 - pr_err("System table signature incorrect!\n"); 413 - return -EINVAL; 441 + config_tables = early_memremap(efi_config_table, efi_nr_tables * sz); 442 + if (config_tables == NULL) { 443 + pr_err("Could not map Configuration table!\n"); 444 + return -ENOMEM; 414 445 } 415 - if ((efi.systab->hdr.revision >> 16) == 0) 416 - pr_err("Warning: System table version %d.%02d, expected 1.00 or greater!\n", 417 - efi.systab->hdr.revision >> 16, 418 - efi.systab->hdr.revision & 0xffff); 419 446 420 - return 0; 447 + ret = efi_config_parse_tables(config_tables, efi_nr_tables, 448 + arch_tables); 449 + 450 + early_memunmap(config_tables, efi_nr_tables * sz); 451 + return ret; 421 452 } 422 453 423 454 void __init efi_init(void) 424 455 { 425 - efi_char16_t *c16; 426 - char vendor[100] = "unknown"; 427 - int i = 0; 428 - 429 456 if (IS_ENABLED(CONFIG_X86_32) && 430 457 (boot_params.efi_info.efi_systab_hi || 431 458 boot_params.efi_info.efi_memmap_hi)) { ··· 450 455 if (efi_systab_init(efi_systab_phys)) 451 456 return; 452 457 453 - efi.config_table = (unsigned long)efi.systab->tables; 454 - efi.fw_vendor = (unsigned long)efi.systab->fw_vendor; 455 - efi.runtime = (unsigned long)efi.systab->runtime; 456 - 457 - /* 458 - * Show what we know for posterity 459 - */ 460 - c16 = early_memremap_ro(efi.systab->fw_vendor, 461 - sizeof(vendor) * sizeof(efi_char16_t)); 462 - if (c16) { 463 - for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i) 464 - vendor[i] = c16[i]; 465 - vendor[i] = '\0'; 466 - early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); 467 - } else { 468 - pr_err("Could not map the firmware vendor!\n"); 469 - } 470 - 471 - pr_info("EFI v%u.%.02u by %s\n", 472 - efi.systab->hdr.revision >> 16, 473 - efi.systab->hdr.revision & 0xffff, vendor); 474 - 475 - if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables)) 458 + if (efi_reuse_config(efi_config_table, efi_nr_tables)) 476 459 return; 477 460 478 461 if (efi_config_init(arch_tables)) ··· 467 494 if (!efi_runtime_supported() || efi_runtime_disabled()) { 468 495 efi_memmap_unmap(); 469 496 return; 497 + } 498 + 499 + /* Parse the EFI Properties table if it exists */ 500 + if (prop_phys != EFI_INVALID_TABLE_ADDR) { 501 + efi_properties_table_t *tbl; 502 + 503 + tbl = early_memremap_ro(prop_phys, sizeof(*tbl)); 504 + if (tbl == NULL) { 505 + pr_err("Could not map Properties table!\n"); 506 + } else { 507 + if (tbl->memory_protection_attribute & 508 + EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) 509 + set_bit(EFI_NX_PE_DATA, &efi.flags); 510 + 511 + early_memunmap(tbl, sizeof(*tbl)); 512 + } 470 513 } 471 514 472 515 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); ··· 588 599 continue; 589 600 } 590 601 prev_md = md; 591 - } 592 - } 593 - 594 - static void __init get_systab_virt_addr(efi_memory_desc_t *md) 595 - { 596 - unsigned long size; 597 - u64 end, systab; 598 - 599 - size = md->num_pages << EFI_PAGE_SHIFT; 600 - end = md->phys_addr + size; 601 - systab = efi_systab_phys; 602 - if (md->phys_addr <= systab && systab < end) { 603 - systab += md->virt_addr - md->phys_addr; 604 - efi.systab = (efi_system_table_t *)(unsigned long)systab; 605 602 } 606 603 } 607 604 ··· 746 771 continue; 747 772 748 773 efi_map_region(md); 749 - get_systab_virt_addr(md); 750 774 751 775 if (left < desc_size) { 752 776 new_memmap = realloc_pages(new_memmap, *pg_shift); ··· 771 797 efi_memory_desc_t *md; 772 798 unsigned int num_pages; 773 799 774 - efi.systab = NULL; 775 - 776 800 /* 777 801 * We don't do virtual mode, since we don't do runtime services, on 778 802 * non-native EFI. With the UV1 memmap, we don't do runtime services in ··· 793 821 * Map efi regions which were passed via setup_data. The virt_addr is a 794 822 * fixed addr which was used in first kernel of a kexec boot. 795 823 */ 796 - for_each_efi_memory_desc(md) { 824 + for_each_efi_memory_desc(md) 797 825 efi_map_region_fixed(md); /* FIXME: add error handling */ 798 - get_systab_virt_addr(md); 799 - } 800 826 801 827 /* 802 828 * Unregister the early EFI memmap from efi_init() and install ··· 809 839 return; 810 840 } 811 841 812 - BUG_ON(!efi.systab); 813 - 814 842 num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE); 815 843 num_pages >>= PAGE_SHIFT; 816 844 ··· 818 850 } 819 851 820 852 efi_sync_low_kernel_mappings(); 821 - 822 - /* 823 - * Now that EFI is in virtual mode, update the function 824 - * pointers in the runtime service table to the new virtual addresses. 825 - * 826 - * Call EFI services through wrapper functions. 827 - */ 828 - efi.runtime_version = efi_systab.hdr.revision; 829 - 830 853 efi_native_runtime_setup(); 831 854 #endif 832 855 } ··· 851 892 efi_status_t status; 852 893 unsigned long pa; 853 894 854 - efi.systab = NULL; 855 - 856 895 if (efi_alloc_page_tables()) { 857 896 pr_err("Failed to allocate EFI page tables\n"); 858 897 goto err; ··· 882 925 efi_print_memmap(); 883 926 } 884 927 885 - if (WARN_ON(!efi.systab)) 886 - goto err; 887 - 888 928 if (efi_setup_page_tables(pa, 1 << pg_shift)) 889 929 goto err; 890 930 ··· 890 936 status = efi_set_virtual_address_map(efi.memmap.desc_size * count, 891 937 efi.memmap.desc_size, 892 938 efi.memmap.desc_version, 893 - (efi_memory_desc_t *)pa); 939 + (efi_memory_desc_t *)pa, 940 + efi_systab_phys); 894 941 if (status != EFI_SUCCESS) { 895 942 pr_err("Unable to switch EFI into virtual mode (status=%lx)!\n", 896 943 status); ··· 899 944 } 900 945 901 946 efi_free_boot_services(); 902 - 903 - /* 904 - * Now that EFI is in virtual mode, update the function 905 - * pointers in the runtime service table to the new virtual addresses. 906 - * 907 - * Call EFI services through wrapper functions. 908 - */ 909 - efi.runtime_version = efi_systab.hdr.revision; 910 947 911 948 if (!efi_is_mixed()) 912 949 efi_native_runtime_setup(); ··· 925 978 if (efi_enabled(EFI_PARAVIRT)) 926 979 return; 927 980 981 + efi.runtime = (efi_runtime_services_t *)efi_runtime; 982 + 928 983 if (efi_setup) 929 984 kexec_enter_virtual_mode(); 930 985 else ··· 947 998 return true; 948 999 949 1000 return false; 1001 + } 1002 + 1003 + char *efi_systab_show_arch(char *str) 1004 + { 1005 + if (uga_phys != EFI_INVALID_TABLE_ADDR) 1006 + str += sprintf(str, "UGA=0x%lx\n", uga_phys); 1007 + return str; 1008 + } 1009 + 1010 + #define EFI_FIELD(var) efi_ ## var 1011 + 1012 + #define EFI_ATTR_SHOW(name) \ 1013 + static ssize_t name##_show(struct kobject *kobj, \ 1014 + struct kobj_attribute *attr, char *buf) \ 1015 + { \ 1016 + return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 1017 + } 1018 + 1019 + EFI_ATTR_SHOW(fw_vendor); 1020 + EFI_ATTR_SHOW(runtime); 1021 + EFI_ATTR_SHOW(config_table); 1022 + 1023 + struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 1024 + struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 1025 + struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 1026 + 1027 + umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 1028 + { 1029 + if (attr == &efi_attr_fw_vendor.attr) { 1030 + if (efi_enabled(EFI_PARAVIRT) || 1031 + efi_fw_vendor == EFI_INVALID_TABLE_ADDR) 1032 + return 0; 1033 + } else if (attr == &efi_attr_runtime.attr) { 1034 + if (efi_runtime == EFI_INVALID_TABLE_ADDR) 1035 + return 0; 1036 + } else if (attr == &efi_attr_config_table.attr) { 1037 + if (efi_config_table == EFI_INVALID_TABLE_ADDR) 1038 + return 0; 1039 + } 1040 + return attr->mode; 950 1041 }
+8 -5
arch/x86/platform/efi/efi_32.c
··· 66 66 void __init efi_map_region_fixed(efi_memory_desc_t *md) {} 67 67 void __init parse_efi_setup(u64 phys_addr, u32 data_len) {} 68 68 69 - efi_status_t efi_call_svam(efi_set_virtual_address_map_t *__efiapi *, 70 - u32, u32, u32, void *); 69 + efi_status_t efi_call_svam(efi_runtime_services_t * const *, 70 + u32, u32, u32, void *, u32); 71 71 72 72 efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size, 73 73 unsigned long descriptor_size, 74 74 u32 descriptor_version, 75 - efi_memory_desc_t *virtual_map) 75 + efi_memory_desc_t *virtual_map, 76 + unsigned long systab_phys) 76 77 { 78 + const efi_system_table_t *systab = (efi_system_table_t *)systab_phys; 77 79 struct desc_ptr gdt_descr; 78 80 efi_status_t status; 79 81 unsigned long flags; ··· 92 90 93 91 /* Disable interrupts around EFI calls: */ 94 92 local_irq_save(flags); 95 - status = efi_call_svam(&efi.systab->runtime->set_virtual_address_map, 93 + status = efi_call_svam(&systab->runtime, 96 94 memory_map_size, descriptor_size, 97 - descriptor_version, virtual_map); 95 + descriptor_version, virtual_map, 96 + __pa(&efi.runtime)); 98 97 local_irq_restore(flags); 99 98 100 99 load_fixmap_gdt(0);
+8 -6
arch/x86/platform/efi/efi_64.c
··· 500 500 */ 501 501 #define __efi_thunk(func, ...) \ 502 502 ({ \ 503 - efi_runtime_services_32_t *__rt; \ 504 503 unsigned short __ds, __es; \ 505 504 efi_status_t ____s; \ 506 - \ 507 - __rt = (void *)(unsigned long)efi.systab->mixed_mode.runtime; \ 508 505 \ 509 506 savesegment(ds, __ds); \ 510 507 savesegment(es, __es); \ ··· 510 513 loadsegment(ds, __KERNEL_DS); \ 511 514 loadsegment(es, __KERNEL_DS); \ 512 515 \ 513 - ____s = efi64_thunk(__rt->func, __VA_ARGS__); \ 516 + ____s = efi64_thunk(efi.runtime->mixed_mode.func, __VA_ARGS__); \ 514 517 \ 515 518 loadsegment(ds, __ds); \ 516 519 loadsegment(es, __es); \ ··· 883 886 efi_set_virtual_address_map(unsigned long memory_map_size, 884 887 unsigned long descriptor_size, 885 888 u32 descriptor_version, 886 - efi_memory_desc_t *virtual_map) 889 + efi_memory_desc_t *virtual_map, 890 + unsigned long systab_phys) 887 891 { 892 + const efi_system_table_t *systab = (efi_system_table_t *)systab_phys; 888 893 efi_status_t status; 889 894 unsigned long flags; 890 895 pgd_t *save_pgd = NULL; ··· 909 910 910 911 /* Disable interrupts around EFI calls: */ 911 912 local_irq_save(flags); 912 - status = efi_call(efi.systab->runtime->set_virtual_address_map, 913 + status = efi_call(efi.runtime->set_virtual_address_map, 913 914 memory_map_size, descriptor_size, 914 915 descriptor_version, virtual_map); 915 916 local_irq_restore(flags); 916 917 917 918 kernel_fpu_end(); 919 + 920 + /* grab the virtually remapped EFI runtime services table pointer */ 921 + efi.runtime = READ_ONCE(systab->runtime); 918 922 919 923 if (save_pgd) 920 924 efi_uv1_memmap_phys_epilog(save_pgd);
+16 -5
arch/x86/platform/efi/efi_stub_32.S
··· 8 8 9 9 #include <linux/linkage.h> 10 10 #include <linux/init.h> 11 + #include <asm/asm-offsets.h> 11 12 #include <asm/page_types.h> 12 13 13 14 __INIT 14 15 SYM_FUNC_START(efi_call_svam) 15 - push 8(%esp) 16 - push 8(%esp) 16 + push %ebp 17 + movl %esp, %ebp 18 + push %ebx 19 + 20 + push 16(%esp) 21 + push 16(%esp) 17 22 push %ecx 18 23 push %edx 24 + movl %eax, %ebx // &systab_phys->runtime 19 25 20 26 /* 21 27 * Switch to the flat mapped alias of this routine, by jumping to the ··· 41 35 subl $__PAGE_OFFSET, %esp 42 36 43 37 /* call the EFI routine */ 44 - call *(%eax) 38 + movl (%eax), %eax 39 + call *EFI_svam(%eax) 45 40 46 - /* convert ESP back to a kernel VA, and pop the outgoing args */ 47 - addl $__PAGE_OFFSET + 16, %esp 41 + /* grab the virtually remapped EFI runtime services table pointer */ 42 + movl (%ebx), %ecx 43 + movl 36(%esp), %edx // &efi.runtime 44 + movl %ecx, (%edx) 48 45 49 46 /* re-enable paging */ 50 47 movl %cr0, %edx 51 48 orl $0x80000000, %edx 52 49 movl %edx, %cr0 53 50 51 + pop %ebx 52 + leave 54 53 ret 55 54 SYM_FUNC_END(efi_call_svam)
+1 -1
arch/x86/platform/efi/quirks.c
··· 537 537 goto out_memremap; 538 538 } 539 539 540 - for (i = 0; i < efi.systab->nr_tables; i++) { 540 + for (i = 0; i < nr_tables; i++) { 541 541 efi_guid_t guid; 542 542 543 543 guid = ((efi_config_table_64_t *)p)->guid;
+1
drivers/firmware/efi/Makefile
··· 13 13 obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o 14 14 obj-$(CONFIG_EFI) += efi.o vars.o reboot.o memattr.o tpm.o 15 15 obj-$(CONFIG_EFI) += capsule.o memmap.o 16 + obj-$(CONFIG_EFI_PARAMS_FROM_FDT) += fdtparams.o 16 17 obj-$(CONFIG_EFI_VARS) += efivars.o 17 18 obj-$(CONFIG_EFI_ESRT) += esrt.o 18 19 obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o
+6 -6
drivers/firmware/efi/apple-properties.c
··· 31 31 struct dev_header { 32 32 u32 len; 33 33 u32 prop_count; 34 - struct efi_dev_path path[0]; 34 + struct efi_dev_path path[]; 35 35 /* 36 36 * followed by key/value pairs, each key and value preceded by u32 len, 37 37 * len includes itself, value may be empty (in which case its len is 4) ··· 42 42 u32 len; 43 43 u32 version; 44 44 u32 dev_count; 45 - struct dev_header dev_header[0]; 45 + struct dev_header dev_header[]; 46 46 }; 47 47 48 48 static void __init unmarshal_key_value_pairs(struct dev_header *dev_header, 49 - struct device *dev, void *ptr, 49 + struct device *dev, const void *ptr, 50 50 struct property_entry entry[]) 51 51 { 52 52 int i; ··· 117 117 while (offset + sizeof(struct dev_header) < properties->len) { 118 118 struct dev_header *dev_header = (void *)properties + offset; 119 119 struct property_entry *entry = NULL; 120 + const struct efi_dev_path *ptr; 120 121 struct device *dev; 121 122 size_t len; 122 123 int ret, i; 123 - void *ptr; 124 124 125 125 if (offset + dev_header->len > properties->len || 126 126 dev_header->len <= sizeof(*dev_header)) { ··· 131 131 ptr = dev_header->path; 132 132 len = dev_header->len - sizeof(*dev_header); 133 133 134 - dev = efi_get_device_by_path((struct efi_dev_path **)&ptr, &len); 134 + dev = efi_get_device_by_path(&ptr, &len); 135 135 if (IS_ERR(dev)) { 136 136 pr_err("device path parse error %ld at %#zx:\n", 137 - PTR_ERR(dev), ptr - (void *)dev_header); 137 + PTR_ERR(dev), (void *)ptr - (void *)dev_header); 138 138 print_hex_dump(KERN_ERR, pr_fmt(), DUMP_PREFIX_OFFSET, 139 139 16, 1, dev_header, dev_header->len, true); 140 140 dev = NULL;
+23 -58
drivers/firmware/efi/arm-init.c
··· 22 22 23 23 #include <asm/efi.h> 24 24 25 - u64 efi_system_table; 26 - 27 25 static int __init is_memory(efi_memory_desc_t *md) 28 26 { 29 27 if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC)) ··· 34 36 * as some data members of the EFI system table are virtually remapped after 35 37 * SetVirtualAddressMap() has been called. 36 38 */ 37 - static phys_addr_t efi_to_phys(unsigned long addr) 39 + static phys_addr_t __init efi_to_phys(unsigned long addr) 38 40 { 39 41 efi_memory_desc_t *md; 40 42 ··· 53 55 54 56 static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR; 55 57 56 - static __initdata efi_config_table_type_t arch_tables[] = { 58 + static const efi_config_table_type_t arch_tables[] __initconst = { 57 59 {LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, NULL, &screen_info_table}, 58 60 {NULL_GUID, NULL, NULL} 59 61 }; ··· 81 83 memblock_mark_nomap(screen_info.lfb_base, screen_info.lfb_size); 82 84 } 83 85 84 - static int __init uefi_init(void) 86 + static int __init uefi_init(u64 efi_system_table) 85 87 { 86 - efi_char16_t *c16; 87 - void *config_tables; 88 + efi_config_table_t *config_tables; 89 + efi_system_table_t *systab; 88 90 size_t table_size; 89 - char vendor[100] = "unknown"; 90 - int i, retval; 91 + int retval; 91 92 92 - efi.systab = early_memremap_ro(efi_system_table, 93 - sizeof(efi_system_table_t)); 94 - if (efi.systab == NULL) { 93 + systab = early_memremap_ro(efi_system_table, sizeof(efi_system_table_t)); 94 + if (systab == NULL) { 95 95 pr_warn("Unable to map EFI system table.\n"); 96 96 return -ENOMEM; 97 97 } ··· 98 102 if (IS_ENABLED(CONFIG_64BIT)) 99 103 set_bit(EFI_64BIT, &efi.flags); 100 104 101 - /* 102 - * Verify the EFI Table 103 - */ 104 - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 105 - pr_err("System table signature incorrect\n"); 106 - retval = -EINVAL; 105 + retval = efi_systab_check_header(&systab->hdr, 2); 106 + if (retval) 107 107 goto out; 108 - } 109 - if ((efi.systab->hdr.revision >> 16) < 2) 110 - pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n", 111 - efi.systab->hdr.revision >> 16, 112 - efi.systab->hdr.revision & 0xffff); 113 108 114 - efi.runtime_version = efi.systab->hdr.revision; 109 + efi.runtime = systab->runtime; 110 + efi.runtime_version = systab->hdr.revision; 115 111 116 - /* Show what we know for posterity */ 117 - c16 = early_memremap_ro(efi_to_phys(efi.systab->fw_vendor), 118 - sizeof(vendor) * sizeof(efi_char16_t)); 119 - if (c16) { 120 - for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i) 121 - vendor[i] = c16[i]; 122 - vendor[i] = '\0'; 123 - early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); 124 - } 112 + efi_systab_report_header(&systab->hdr, efi_to_phys(systab->fw_vendor)); 125 113 126 - pr_info("EFI v%u.%.02u by %s\n", 127 - efi.systab->hdr.revision >> 16, 128 - efi.systab->hdr.revision & 0xffff, vendor); 129 - 130 - table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables; 131 - config_tables = early_memremap_ro(efi_to_phys(efi.systab->tables), 114 + table_size = sizeof(efi_config_table_t) * systab->nr_tables; 115 + config_tables = early_memremap_ro(efi_to_phys(systab->tables), 132 116 table_size); 133 117 if (config_tables == NULL) { 134 118 pr_warn("Unable to map EFI config table array.\n"); 135 119 retval = -ENOMEM; 136 120 goto out; 137 121 } 138 - retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables, 139 - sizeof(efi_config_table_t), 122 + retval = efi_config_parse_tables(config_tables, systab->nr_tables, 140 123 arch_tables); 141 - 142 - if (!retval) 143 - efi.config_table = (unsigned long)efi.systab->tables; 144 124 145 125 early_memunmap(config_tables, table_size); 146 126 out: 147 - early_memunmap(efi.systab, sizeof(efi_system_table_t)); 127 + early_memunmap(systab, sizeof(efi_system_table_t)); 148 128 return retval; 149 129 } 150 130 ··· 205 233 void __init efi_init(void) 206 234 { 207 235 struct efi_memory_map_data data; 208 - struct efi_fdt_params params; 236 + u64 efi_system_table; 209 237 210 238 /* Grab UEFI information placed in FDT by stub */ 211 - if (!efi_get_fdt_params(&params)) 239 + efi_system_table = efi_get_fdt_params(&data); 240 + if (!efi_system_table) 212 241 return; 213 - 214 - efi_system_table = params.system_table; 215 - 216 - data.desc_version = params.desc_ver; 217 - data.desc_size = params.desc_size; 218 - data.size = params.mmap_size; 219 - data.phys_map = params.mmap; 220 242 221 243 if (efi_memmap_init_early(&data) < 0) { 222 244 /* ··· 225 259 "Unexpected EFI_MEMORY_DESCRIPTOR version %ld", 226 260 efi.memmap.desc_version); 227 261 228 - if (uefi_init() < 0) { 262 + if (uefi_init(efi_system_table) < 0) { 229 263 efi_memmap_unmap(); 230 264 return; 231 265 } ··· 233 267 reserve_regions(); 234 268 efi_esrt_init(); 235 269 236 - memblock_reserve(params.mmap & PAGE_MASK, 237 - PAGE_ALIGN(params.mmap_size + 238 - (params.mmap & ~PAGE_MASK))); 270 + memblock_reserve(data.phys_map & PAGE_MASK, 271 + PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK))); 239 272 240 273 init_screen_info(); 241 274
-18
drivers/firmware/efi/arm-runtime.c
··· 25 25 #include <asm/pgalloc.h> 26 26 #include <asm/pgtable.h> 27 27 28 - extern u64 efi_system_table; 29 - 30 28 #if defined(CONFIG_PTDUMP_DEBUGFS) && defined(CONFIG_ARM64) 31 29 #include <asm/ptdump.h> 32 30 ··· 52 54 static bool __init efi_virtmap_init(void) 53 55 { 54 56 efi_memory_desc_t *md; 55 - bool systab_found; 56 57 57 58 efi_mm.pgd = pgd_alloc(&efi_mm); 58 59 mm_init_cpumask(&efi_mm); 59 60 init_new_context(NULL, &efi_mm); 60 61 61 - systab_found = false; 62 62 for_each_efi_memory_desc(md) { 63 63 phys_addr_t phys = md->phys_addr; 64 64 int ret; ··· 72 76 &phys, ret); 73 77 return false; 74 78 } 75 - /* 76 - * If this entry covers the address of the UEFI system table, 77 - * calculate and record its virtual address. 78 - */ 79 - if (efi_system_table >= phys && 80 - efi_system_table < phys + (md->num_pages * EFI_PAGE_SIZE)) { 81 - efi.systab = (void *)(unsigned long)(efi_system_table - 82 - phys + md->virt_addr); 83 - systab_found = true; 84 - } 85 - } 86 - if (!systab_found) { 87 - pr_err("No virtual mapping found for the UEFI System Table\n"); 88 - return false; 89 79 } 90 80 91 81 if (efi_memattr_apply_permissions(&efi_mm, efi_set_mapping_permissions))
+1 -1
drivers/firmware/efi/capsule-loader.c
··· 168 168 static ssize_t efi_capsule_write(struct file *file, const char __user *buff, 169 169 size_t count, loff_t *offp) 170 170 { 171 - int ret = 0; 171 + int ret; 172 172 struct capsule_info *cap_info = file->private_data; 173 173 struct page *page; 174 174 void *kbuff = NULL;
+19 -19
drivers/firmware/efi/dev-path-parser.c
··· 31 31 return !strcmp("0", hid_uid.uid); 32 32 } 33 33 34 - static long __init parse_acpi_path(struct efi_dev_path *node, 34 + static long __init parse_acpi_path(const struct efi_dev_path *node, 35 35 struct device *parent, struct device **child) 36 36 { 37 37 struct acpi_hid_uid hid_uid = {}; 38 38 struct device *phys_dev; 39 39 40 - if (node->length != 12) 40 + if (node->header.length != 12) 41 41 return -EINVAL; 42 42 43 43 sprintf(hid_uid.hid[0].id, "%c%c%c%04X", ··· 69 69 return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; 70 70 } 71 71 72 - static long __init parse_pci_path(struct efi_dev_path *node, 72 + static long __init parse_pci_path(const struct efi_dev_path *node, 73 73 struct device *parent, struct device **child) 74 74 { 75 75 unsigned int devfn; 76 76 77 - if (node->length != 6) 77 + if (node->header.length != 6) 78 78 return -EINVAL; 79 79 if (!parent) 80 80 return -EINVAL; ··· 105 105 * search for a device. 106 106 */ 107 107 108 - static long __init parse_end_path(struct efi_dev_path *node, 108 + static long __init parse_end_path(const struct efi_dev_path *node, 109 109 struct device *parent, struct device **child) 110 110 { 111 - if (node->length != 4) 111 + if (node->header.length != 4) 112 112 return -EINVAL; 113 - if (node->sub_type != EFI_DEV_END_INSTANCE && 114 - node->sub_type != EFI_DEV_END_ENTIRE) 113 + if (node->header.sub_type != EFI_DEV_END_INSTANCE && 114 + node->header.sub_type != EFI_DEV_END_ENTIRE) 115 115 return -EINVAL; 116 116 if (!parent) 117 117 return -ENODEV; 118 118 119 119 *child = get_device(parent); 120 - return node->sub_type; 120 + return node->header.sub_type; 121 121 } 122 122 123 123 /** ··· 156 156 * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len, 157 157 * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented. 158 158 */ 159 - struct device * __init efi_get_device_by_path(struct efi_dev_path **node, 159 + struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, 160 160 size_t *len) 161 161 { 162 162 struct device *parent = NULL, *child; ··· 166 166 return NULL; 167 167 168 168 while (!ret) { 169 - if (*len < 4 || *len < (*node)->length) 169 + if (*len < 4 || *len < (*node)->header.length) 170 170 ret = -EINVAL; 171 - else if ((*node)->type == EFI_DEV_ACPI && 172 - (*node)->sub_type == EFI_DEV_BASIC_ACPI) 171 + else if ((*node)->header.type == EFI_DEV_ACPI && 172 + (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) 173 173 ret = parse_acpi_path(*node, parent, &child); 174 - else if ((*node)->type == EFI_DEV_HW && 175 - (*node)->sub_type == EFI_DEV_PCI) 174 + else if ((*node)->header.type == EFI_DEV_HW && 175 + (*node)->header.sub_type == EFI_DEV_PCI) 176 176 ret = parse_pci_path(*node, parent, &child); 177 - else if (((*node)->type == EFI_DEV_END_PATH || 178 - (*node)->type == EFI_DEV_END_PATH2)) 177 + else if (((*node)->header.type == EFI_DEV_END_PATH || 178 + (*node)->header.type == EFI_DEV_END_PATH2)) 179 179 ret = parse_end_path(*node, parent, &child); 180 180 else 181 181 ret = -ENOTSUPP; ··· 185 185 return ERR_PTR(ret); 186 186 187 187 parent = child; 188 - *node = (void *)*node + (*node)->length; 189 - *len -= (*node)->length; 188 + *node = (void *)*node + (*node)->header.length; 189 + *len -= (*node)->header.length; 190 190 } 191 191 192 192 if (ret == EFI_DEV_END_ENTIRE)
+6 -1
drivers/firmware/efi/efi-bgrt.c
··· 42 42 return; 43 43 } 44 44 *bgrt = *(struct acpi_table_bgrt *)table; 45 - if (bgrt->version != 1) { 45 + /* 46 + * Only version 1 is defined but some older laptops (seen on Lenovo 47 + * Ivy Bridge models) have a correct version 1 BGRT table with the 48 + * version set to 0, so we accept version 0 and 1. 49 + */ 50 + if (bgrt->version > 1) { 46 51 pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n", 47 52 bgrt->version); 48 53 goto out;
+1 -1
drivers/firmware/efi/efi-pstore.c
··· 356 356 357 357 static __init int efivars_pstore_init(void) 358 358 { 359 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 359 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 360 360 return 0; 361 361 362 362 if (!efivars_kobject())
+135 -289
drivers/firmware/efi/efi.c
··· 20 20 #include <linux/device.h> 21 21 #include <linux/efi.h> 22 22 #include <linux/of.h> 23 - #include <linux/of_fdt.h> 24 23 #include <linux/io.h> 25 24 #include <linux/kexec.h> 26 25 #include <linux/platform_device.h> ··· 34 35 #include <asm/early_ioremap.h> 35 36 36 37 struct efi __read_mostly efi = { 37 - .mps = EFI_INVALID_TABLE_ADDR, 38 + .runtime_supported_mask = EFI_RT_SUPPORTED_ALL, 38 39 .acpi = EFI_INVALID_TABLE_ADDR, 39 40 .acpi20 = EFI_INVALID_TABLE_ADDR, 40 41 .smbios = EFI_INVALID_TABLE_ADDR, 41 42 .smbios3 = EFI_INVALID_TABLE_ADDR, 42 - .boot_info = EFI_INVALID_TABLE_ADDR, 43 - .hcdp = EFI_INVALID_TABLE_ADDR, 44 - .uga = EFI_INVALID_TABLE_ADDR, 45 - .fw_vendor = EFI_INVALID_TABLE_ADDR, 46 - .runtime = EFI_INVALID_TABLE_ADDR, 47 - .config_table = EFI_INVALID_TABLE_ADDR, 48 43 .esrt = EFI_INVALID_TABLE_ADDR, 49 - .properties_table = EFI_INVALID_TABLE_ADDR, 50 - .mem_attr_table = EFI_INVALID_TABLE_ADDR, 51 - .rng_seed = EFI_INVALID_TABLE_ADDR, 52 44 .tpm_log = EFI_INVALID_TABLE_ADDR, 53 45 .tpm_final_log = EFI_INVALID_TABLE_ADDR, 54 - .mem_reserve = EFI_INVALID_TABLE_ADDR, 55 46 }; 56 47 EXPORT_SYMBOL(efi); 48 + 49 + static unsigned long __ro_after_init rng_seed = EFI_INVALID_TABLE_ADDR; 50 + static unsigned long __initdata mem_reserve = EFI_INVALID_TABLE_ADDR; 51 + static unsigned long __initdata rt_prop = EFI_INVALID_TABLE_ADDR; 57 52 58 53 struct mm_struct efi_mm = { 59 54 .mm_rb = RB_ROOT, ··· 115 122 if (!kobj || !buf) 116 123 return -EINVAL; 117 124 118 - if (efi.mps != EFI_INVALID_TABLE_ADDR) 119 - str += sprintf(str, "MPS=0x%lx\n", efi.mps); 120 125 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) 121 126 str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20); 122 127 if (efi.acpi != EFI_INVALID_TABLE_ADDR) ··· 128 137 str += sprintf(str, "SMBIOS3=0x%lx\n", efi.smbios3); 129 138 if (efi.smbios != EFI_INVALID_TABLE_ADDR) 130 139 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios); 131 - if (efi.hcdp != EFI_INVALID_TABLE_ADDR) 132 - str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp); 133 - if (efi.boot_info != EFI_INVALID_TABLE_ADDR) 134 - str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info); 135 - if (efi.uga != EFI_INVALID_TABLE_ADDR) 136 - str += sprintf(str, "UGA=0x%lx\n", efi.uga); 140 + 141 + if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86)) { 142 + extern char *efi_systab_show_arch(char *str); 143 + 144 + str = efi_systab_show_arch(str); 145 + } 137 146 138 147 return str - buf; 139 148 } 140 149 141 150 static struct kobj_attribute efi_attr_systab = __ATTR_RO_MODE(systab, 0400); 142 - 143 - #define EFI_FIELD(var) efi.var 144 - 145 - #define EFI_ATTR_SHOW(name) \ 146 - static ssize_t name##_show(struct kobject *kobj, \ 147 - struct kobj_attribute *attr, char *buf) \ 148 - { \ 149 - return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 150 - } 151 - 152 - EFI_ATTR_SHOW(fw_vendor); 153 - EFI_ATTR_SHOW(runtime); 154 - EFI_ATTR_SHOW(config_table); 155 151 156 152 static ssize_t fw_platform_size_show(struct kobject *kobj, 157 153 struct kobj_attribute *attr, char *buf) ··· 146 168 return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32); 147 169 } 148 170 149 - static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 150 - static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 151 - static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 171 + extern __weak struct kobj_attribute efi_attr_fw_vendor; 172 + extern __weak struct kobj_attribute efi_attr_runtime; 173 + extern __weak struct kobj_attribute efi_attr_config_table; 152 174 static struct kobj_attribute efi_attr_fw_platform_size = 153 175 __ATTR_RO(fw_platform_size); 154 176 155 177 static struct attribute *efi_subsys_attrs[] = { 156 178 &efi_attr_systab.attr, 179 + &efi_attr_fw_platform_size.attr, 157 180 &efi_attr_fw_vendor.attr, 158 181 &efi_attr_runtime.attr, 159 182 &efi_attr_config_table.attr, 160 - &efi_attr_fw_platform_size.attr, 161 183 NULL, 162 184 }; 163 185 164 - static umode_t efi_attr_is_visible(struct kobject *kobj, 165 - struct attribute *attr, int n) 186 + umode_t __weak efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, 187 + int n) 166 188 { 167 - if (attr == &efi_attr_fw_vendor.attr) { 168 - if (efi_enabled(EFI_PARAVIRT) || 169 - efi.fw_vendor == EFI_INVALID_TABLE_ADDR) 170 - return 0; 171 - } else if (attr == &efi_attr_runtime.attr) { 172 - if (efi.runtime == EFI_INVALID_TABLE_ADDR) 173 - return 0; 174 - } else if (attr == &efi_attr_config_table.attr) { 175 - if (efi.config_table == EFI_INVALID_TABLE_ADDR) 176 - return 0; 177 - } 178 - 179 189 return attr->mode; 180 190 } 181 191 ··· 303 337 if (!efi_enabled(EFI_BOOT)) 304 338 return 0; 305 339 306 - /* 307 - * Since we process only one efi_runtime_service() at a time, an 308 - * ordered workqueue (which creates only one execution context) 309 - * should suffice all our needs. 310 - */ 311 - efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0); 312 - if (!efi_rts_wq) { 313 - pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n"); 314 - clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); 315 - return 0; 340 + if (!efi_enabled(EFI_RUNTIME_SERVICES)) 341 + efi.runtime_supported_mask = 0; 342 + 343 + if (efi.runtime_supported_mask) { 344 + /* 345 + * Since we process only one efi_runtime_service() at a time, an 346 + * ordered workqueue (which creates only one execution context) 347 + * should suffice for all our needs. 348 + */ 349 + efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0); 350 + if (!efi_rts_wq) { 351 + pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n"); 352 + clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); 353 + efi.runtime_supported_mask = 0; 354 + return 0; 355 + } 316 356 } 357 + 358 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_TIME_SERVICES)) 359 + platform_device_register_simple("rtc-efi", 0, NULL, 0); 317 360 318 361 /* We register the efi directory at /sys/firmware/efi */ 319 362 efi_kobj = kobject_create_and_add("efi", firmware_kobj); ··· 331 356 return -ENOMEM; 332 357 } 333 358 334 - error = generic_ops_register(); 335 - if (error) 336 - goto err_put; 337 - 338 - if (efi_enabled(EFI_RUNTIME_SERVICES)) 359 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) { 339 360 efivar_ssdt_load(); 361 + error = generic_ops_register(); 362 + if (error) 363 + goto err_put; 364 + platform_device_register_simple("efivars", 0, NULL, 0); 365 + } 340 366 341 367 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); 342 368 if (error) { ··· 362 386 err_remove_group: 363 387 sysfs_remove_group(efi_kobj, &efi_subsys_attr_group); 364 388 err_unregister: 365 - generic_ops_unregister(); 389 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 390 + generic_ops_unregister(); 366 391 err_put: 367 392 kobject_put(efi_kobj); 368 393 return error; ··· 444 467 efi_arch_mem_reserve(addr, size); 445 468 } 446 469 447 - static __initdata efi_config_table_type_t common_tables[] = { 470 + static const efi_config_table_type_t common_tables[] __initconst = { 448 471 {ACPI_20_TABLE_GUID, "ACPI 2.0", &efi.acpi20}, 449 472 {ACPI_TABLE_GUID, "ACPI", &efi.acpi}, 450 - {HCDP_TABLE_GUID, "HCDP", &efi.hcdp}, 451 - {MPS_TABLE_GUID, "MPS", &efi.mps}, 452 473 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 453 474 {SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3}, 454 - {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 455 475 {EFI_SYSTEM_RESOURCE_TABLE_GUID, "ESRT", &efi.esrt}, 456 - {EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table}, 457 - {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table}, 458 - {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed}, 476 + {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi_mem_attr_table}, 477 + {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &rng_seed}, 459 478 {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log}, 460 479 {LINUX_EFI_TPM_FINAL_LOG_GUID, "TPMFinalLog", &efi.tpm_final_log}, 461 - {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve}, 480 + {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &mem_reserve}, 481 + {EFI_RT_PROPERTIES_TABLE_GUID, "RTPROP", &rt_prop}, 462 482 #ifdef CONFIG_EFI_RCI2_TABLE 463 483 {DELLEMC_EFI_RCI2_TABLE_GUID, NULL, &rci2_table_phys}, 464 484 #endif 465 485 {NULL_GUID, NULL, NULL}, 466 486 }; 467 487 468 - static __init int match_config_table(efi_guid_t *guid, 488 + static __init int match_config_table(const efi_guid_t *guid, 469 489 unsigned long table, 470 - efi_config_table_type_t *table_types) 490 + const efi_config_table_type_t *table_types) 471 491 { 472 492 int i; 473 493 ··· 483 509 return 0; 484 510 } 485 511 486 - int __init efi_config_parse_tables(void *config_tables, int count, int sz, 487 - efi_config_table_type_t *arch_tables) 512 + int __init efi_config_parse_tables(const efi_config_table_t *config_tables, 513 + int count, 514 + const efi_config_table_type_t *arch_tables) 488 515 { 489 - void *tablep; 516 + const efi_config_table_64_t *tbl64 = (void *)config_tables; 517 + const efi_config_table_32_t *tbl32 = (void *)config_tables; 518 + const efi_guid_t *guid; 519 + unsigned long table; 490 520 int i; 491 521 492 - tablep = config_tables; 493 522 pr_info(""); 494 523 for (i = 0; i < count; i++) { 495 - efi_guid_t guid; 496 - unsigned long table; 524 + if (!IS_ENABLED(CONFIG_X86)) { 525 + guid = &config_tables[i].guid; 526 + table = (unsigned long)config_tables[i].table; 527 + } else if (efi_enabled(EFI_64BIT)) { 528 + guid = &tbl64[i].guid; 529 + table = tbl64[i].table; 497 530 498 - if (efi_enabled(EFI_64BIT)) { 499 - u64 table64; 500 - guid = ((efi_config_table_64_t *)tablep)->guid; 501 - table64 = ((efi_config_table_64_t *)tablep)->table; 502 - table = table64; 503 - #ifndef CONFIG_64BIT 504 - if (table64 >> 32) { 531 + if (IS_ENABLED(CONFIG_X86_32) && 532 + tbl64[i].table > U32_MAX) { 505 533 pr_cont("\n"); 506 534 pr_err("Table located above 4GB, disabling EFI.\n"); 507 535 return -EINVAL; 508 536 } 509 - #endif 510 537 } else { 511 - guid = ((efi_config_table_32_t *)tablep)->guid; 512 - table = ((efi_config_table_32_t *)tablep)->table; 538 + guid = &tbl32[i].guid; 539 + table = tbl32[i].table; 513 540 } 514 541 515 - if (!match_config_table(&guid, table, common_tables)) 516 - match_config_table(&guid, table, arch_tables); 517 - 518 - tablep += sz; 542 + if (!match_config_table(guid, table, common_tables)) 543 + match_config_table(guid, table, arch_tables); 519 544 } 520 545 pr_cont("\n"); 521 546 set_bit(EFI_CONFIG_TABLES, &efi.flags); 522 547 523 - if (efi.rng_seed != EFI_INVALID_TABLE_ADDR) { 548 + if (rng_seed != EFI_INVALID_TABLE_ADDR) { 524 549 struct linux_efi_random_seed *seed; 525 550 u32 size = 0; 526 551 527 - seed = early_memremap(efi.rng_seed, sizeof(*seed)); 552 + seed = early_memremap(rng_seed, sizeof(*seed)); 528 553 if (seed != NULL) { 529 554 size = seed->size; 530 555 early_memunmap(seed, sizeof(*seed)); ··· 531 558 pr_err("Could not map UEFI random seed!\n"); 532 559 } 533 560 if (size > 0) { 534 - seed = early_memremap(efi.rng_seed, 535 - sizeof(*seed) + size); 561 + seed = early_memremap(rng_seed, sizeof(*seed) + size); 536 562 if (seed != NULL) { 537 563 pr_notice("seeding entropy pool\n"); 538 564 add_bootloader_randomness(seed->bits, seed->size); ··· 547 575 548 576 efi_tpm_eventlog_init(); 549 577 550 - /* Parse the EFI Properties table if it exists */ 551 - if (efi.properties_table != EFI_INVALID_TABLE_ADDR) { 552 - efi_properties_table_t *tbl; 553 - 554 - tbl = early_memremap(efi.properties_table, sizeof(*tbl)); 555 - if (tbl == NULL) { 556 - pr_err("Could not map Properties table!\n"); 557 - return -ENOMEM; 558 - } 559 - 560 - if (tbl->memory_protection_attribute & 561 - EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) 562 - set_bit(EFI_NX_PE_DATA, &efi.flags); 563 - 564 - early_memunmap(tbl, sizeof(*tbl)); 565 - } 566 - 567 - if (efi.mem_reserve != EFI_INVALID_TABLE_ADDR) { 568 - unsigned long prsv = efi.mem_reserve; 578 + if (mem_reserve != EFI_INVALID_TABLE_ADDR) { 579 + unsigned long prsv = mem_reserve; 569 580 570 581 while (prsv) { 571 582 struct linux_efi_memreserve *rsv; ··· 582 627 } 583 628 } 584 629 630 + if (rt_prop != EFI_INVALID_TABLE_ADDR) { 631 + efi_rt_properties_table_t *tbl; 632 + 633 + tbl = early_memremap(rt_prop, sizeof(*tbl)); 634 + if (tbl) { 635 + efi.runtime_supported_mask &= tbl->runtime_services_supported; 636 + early_memunmap(tbl, sizeof(*tbl)); 637 + } 638 + } 639 + 585 640 return 0; 586 641 } 587 642 588 - int __init efi_config_init(efi_config_table_type_t *arch_tables) 643 + int __init efi_systab_check_header(const efi_table_hdr_t *systab_hdr, 644 + int min_major_version) 589 645 { 590 - void *config_tables; 591 - int sz, ret; 592 - 593 - if (efi.systab->nr_tables == 0) 594 - return 0; 595 - 596 - if (efi_enabled(EFI_64BIT)) 597 - sz = sizeof(efi_config_table_64_t); 598 - else 599 - sz = sizeof(efi_config_table_32_t); 600 - 601 - /* 602 - * Let's see what config tables the firmware passed to us. 603 - */ 604 - config_tables = early_memremap(efi.systab->tables, 605 - efi.systab->nr_tables * sz); 606 - if (config_tables == NULL) { 607 - pr_err("Could not map Configuration table!\n"); 608 - return -ENOMEM; 646 + if (systab_hdr->signature != EFI_SYSTEM_TABLE_SIGNATURE) { 647 + pr_err("System table signature incorrect!\n"); 648 + return -EINVAL; 609 649 } 610 650 611 - ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables, sz, 612 - arch_tables); 651 + if ((systab_hdr->revision >> 16) < min_major_version) 652 + pr_err("Warning: System table version %d.%02d, expected %d.00 or greater!\n", 653 + systab_hdr->revision >> 16, 654 + systab_hdr->revision & 0xffff, 655 + min_major_version); 613 656 614 - early_memunmap(config_tables, efi.systab->nr_tables * sz); 657 + return 0; 658 + } 659 + 660 + #ifndef CONFIG_IA64 661 + static const efi_char16_t *__init map_fw_vendor(unsigned long fw_vendor, 662 + size_t size) 663 + { 664 + const efi_char16_t *ret; 665 + 666 + ret = early_memremap_ro(fw_vendor, size); 667 + if (!ret) 668 + pr_err("Could not map the firmware vendor!\n"); 615 669 return ret; 616 670 } 617 671 618 - #ifdef CONFIG_EFI_VARS_MODULE 619 - static int __init efi_load_efivars(void) 672 + static void __init unmap_fw_vendor(const void *fw_vendor, size_t size) 620 673 { 621 - struct platform_device *pdev; 622 - 623 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 624 - return 0; 625 - 626 - pdev = platform_device_register_simple("efivars", 0, NULL, 0); 627 - return PTR_ERR_OR_ZERO(pdev); 674 + early_memunmap((void *)fw_vendor, size); 628 675 } 629 - device_initcall(efi_load_efivars); 676 + #else 677 + #define map_fw_vendor(p, s) __va(p) 678 + #define unmap_fw_vendor(v, s) 630 679 #endif 631 680 632 - #ifdef CONFIG_EFI_PARAMS_FROM_FDT 681 + void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr, 682 + unsigned long fw_vendor) 683 + { 684 + char vendor[100] = "unknown"; 685 + const efi_char16_t *c16; 686 + size_t i; 633 687 634 - #define UEFI_PARAM(name, prop, field) \ 635 - { \ 636 - { name }, \ 637 - { prop }, \ 638 - offsetof(struct efi_fdt_params, field), \ 639 - sizeof_field(struct efi_fdt_params, field) \ 688 + c16 = map_fw_vendor(fw_vendor, sizeof(vendor) * sizeof(efi_char16_t)); 689 + if (c16) { 690 + for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i) 691 + vendor[i] = c16[i]; 692 + vendor[i] = '\0'; 693 + 694 + unmap_fw_vendor(c16, sizeof(vendor) * sizeof(efi_char16_t)); 640 695 } 641 696 642 - struct params { 643 - const char name[32]; 644 - const char propname[32]; 645 - int offset; 646 - int size; 647 - }; 648 - 649 - static __initdata struct params fdt_params[] = { 650 - UEFI_PARAM("System Table", "linux,uefi-system-table", system_table), 651 - UEFI_PARAM("MemMap Address", "linux,uefi-mmap-start", mmap), 652 - UEFI_PARAM("MemMap Size", "linux,uefi-mmap-size", mmap_size), 653 - UEFI_PARAM("MemMap Desc. Size", "linux,uefi-mmap-desc-size", desc_size), 654 - UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver) 655 - }; 656 - 657 - static __initdata struct params xen_fdt_params[] = { 658 - UEFI_PARAM("System Table", "xen,uefi-system-table", system_table), 659 - UEFI_PARAM("MemMap Address", "xen,uefi-mmap-start", mmap), 660 - UEFI_PARAM("MemMap Size", "xen,uefi-mmap-size", mmap_size), 661 - UEFI_PARAM("MemMap Desc. Size", "xen,uefi-mmap-desc-size", desc_size), 662 - UEFI_PARAM("MemMap Desc. Version", "xen,uefi-mmap-desc-ver", desc_ver) 663 - }; 664 - 665 - #define EFI_FDT_PARAMS_SIZE ARRAY_SIZE(fdt_params) 666 - 667 - static __initdata struct { 668 - const char *uname; 669 - const char *subnode; 670 - struct params *params; 671 - } dt_params[] = { 672 - { "hypervisor", "uefi", xen_fdt_params }, 673 - { "chosen", NULL, fdt_params }, 674 - }; 675 - 676 - struct param_info { 677 - int found; 678 - void *params; 679 - const char *missing; 680 - }; 681 - 682 - static int __init __find_uefi_params(unsigned long node, 683 - struct param_info *info, 684 - struct params *params) 685 - { 686 - const void *prop; 687 - void *dest; 688 - u64 val; 689 - int i, len; 690 - 691 - for (i = 0; i < EFI_FDT_PARAMS_SIZE; i++) { 692 - prop = of_get_flat_dt_prop(node, params[i].propname, &len); 693 - if (!prop) { 694 - info->missing = params[i].name; 695 - return 0; 696 - } 697 - 698 - dest = info->params + params[i].offset; 699 - info->found++; 700 - 701 - val = of_read_number(prop, len / sizeof(u32)); 702 - 703 - if (params[i].size == sizeof(u32)) 704 - *(u32 *)dest = val; 705 - else 706 - *(u64 *)dest = val; 707 - 708 - if (efi_enabled(EFI_DBG)) 709 - pr_info(" %s: 0x%0*llx\n", params[i].name, 710 - params[i].size * 2, val); 711 - } 712 - 713 - return 1; 697 + pr_info("EFI v%u.%.02u by %s\n", 698 + systab_hdr->revision >> 16, 699 + systab_hdr->revision & 0xffff, 700 + vendor); 714 701 } 715 - 716 - static int __init fdt_find_uefi_params(unsigned long node, const char *uname, 717 - int depth, void *data) 718 - { 719 - struct param_info *info = data; 720 - int i; 721 - 722 - for (i = 0; i < ARRAY_SIZE(dt_params); i++) { 723 - const char *subnode = dt_params[i].subnode; 724 - 725 - if (depth != 1 || strcmp(uname, dt_params[i].uname) != 0) { 726 - info->missing = dt_params[i].params[0].name; 727 - continue; 728 - } 729 - 730 - if (subnode) { 731 - int err = of_get_flat_dt_subnode_by_name(node, subnode); 732 - 733 - if (err < 0) 734 - return 0; 735 - 736 - node = err; 737 - } 738 - 739 - return __find_uefi_params(node, info, dt_params[i].params); 740 - } 741 - 742 - return 0; 743 - } 744 - 745 - int __init efi_get_fdt_params(struct efi_fdt_params *params) 746 - { 747 - struct param_info info; 748 - int ret; 749 - 750 - pr_info("Getting EFI parameters from FDT:\n"); 751 - 752 - info.found = 0; 753 - info.params = params; 754 - 755 - ret = of_scan_flat_dt(fdt_find_uefi_params, &info); 756 - if (!info.found) 757 - pr_info("UEFI not found.\n"); 758 - else if (!ret) 759 - pr_err("Can't find '%s' in device tree!\n", 760 - info.missing); 761 - 762 - return ret; 763 - } 764 - #endif /* CONFIG_EFI_PARAMS_FROM_FDT */ 765 702 766 703 static __initdata char memory_type_name[][20] = { 767 704 "Reserved", ··· 815 968 816 969 static int __init efi_memreserve_map_root(void) 817 970 { 818 - if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) 971 + if (mem_reserve == EFI_INVALID_TABLE_ADDR) 819 972 return -ENODEV; 820 973 821 - efi_memreserve_root = memremap(efi.mem_reserve, 974 + efi_memreserve_root = memremap(mem_reserve, 822 975 sizeof(*efi_memreserve_root), 823 976 MEMREMAP_WB); 824 977 if (WARN_ON_ONCE(!efi_memreserve_root)) ··· 923 1076 if (!kexec_in_progress) 924 1077 return NOTIFY_DONE; 925 1078 926 - seed = memremap(efi.rng_seed, sizeof(*seed), MEMREMAP_WB); 1079 + seed = memremap(rng_seed, sizeof(*seed), MEMREMAP_WB); 927 1080 if (seed != NULL) { 928 1081 size = min(seed->size, EFI_RANDOM_SEED_SIZE); 929 1082 memunmap(seed); ··· 931 1084 pr_err("Could not map UEFI random seed!\n"); 932 1085 } 933 1086 if (size > 0) { 934 - seed = memremap(efi.rng_seed, sizeof(*seed) + size, 935 - MEMREMAP_WB); 1087 + seed = memremap(rng_seed, sizeof(*seed) + size, MEMREMAP_WB); 936 1088 if (seed != NULL) { 937 1089 seed->size = size; 938 1090 get_random_bytes(seed->bits, seed->size); ··· 947 1101 .notifier_call = update_efi_random_seed, 948 1102 }; 949 1103 950 - static int register_update_efi_random_seed(void) 1104 + static int __init register_update_efi_random_seed(void) 951 1105 { 952 - if (efi.rng_seed == EFI_INVALID_TABLE_ADDR) 1106 + if (rng_seed == EFI_INVALID_TABLE_ADDR) 953 1107 return 0; 954 1108 return register_reboot_notifier(&efi_random_seed_nb); 955 1109 }
+1 -1
drivers/firmware/efi/efivars.c
··· 664 664 struct kobject *parent_kobj = efivars_kobject(); 665 665 int error = 0; 666 666 667 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 667 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 668 668 return -ENODEV; 669 669 670 670 /* No efivars has been registered yet */
+2 -4
drivers/firmware/efi/esrt.c
··· 240 240 { 241 241 void *va; 242 242 struct efi_system_resource_table tmpesrt; 243 - struct efi_system_resource_entry_v1 *v1_entries; 244 243 size_t size, max, entry_size, entries_size; 245 244 efi_memory_desc_t md; 246 245 int rc; ··· 287 288 memcpy(&tmpesrt, va, sizeof(tmpesrt)); 288 289 early_memunmap(va, size); 289 290 290 - if (tmpesrt.fw_resource_version == 1) { 291 - entry_size = sizeof (*v1_entries); 292 - } else { 291 + if (tmpesrt.fw_resource_version != 1) { 293 292 pr_err("Unsupported ESRT version %lld.\n", 294 293 tmpesrt.fw_resource_version); 295 294 return; 296 295 } 297 296 297 + entry_size = sizeof(struct efi_system_resource_entry_v1); 298 298 if (tmpesrt.fw_resource_count > 0 && max - size < entry_size) { 299 299 pr_err("ESRT memory map entry can only hold the header. (max: %zu size: %zu)\n", 300 300 max - size, entry_size);
+126
drivers/firmware/efi/fdtparams.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #define pr_fmt(fmt) "efi: " fmt 4 + 5 + #include <linux/module.h> 6 + #include <linux/init.h> 7 + #include <linux/efi.h> 8 + #include <linux/libfdt.h> 9 + #include <linux/of_fdt.h> 10 + 11 + #include <asm/unaligned.h> 12 + 13 + enum { 14 + SYSTAB, 15 + MMBASE, 16 + MMSIZE, 17 + DCSIZE, 18 + DCVERS, 19 + 20 + PARAMCOUNT 21 + }; 22 + 23 + static __initconst const char name[][22] = { 24 + [SYSTAB] = "System Table ", 25 + [MMBASE] = "MemMap Address ", 26 + [MMSIZE] = "MemMap Size ", 27 + [DCSIZE] = "MemMap Desc. Size ", 28 + [DCVERS] = "MemMap Desc. Version ", 29 + }; 30 + 31 + static __initconst const struct { 32 + const char path[17]; 33 + const char params[PARAMCOUNT][26]; 34 + } dt_params[] = { 35 + { 36 + #ifdef CONFIG_XEN // <-------17------> 37 + .path = "/hypervisor/uefi", 38 + .params = { 39 + [SYSTAB] = "xen,uefi-system-table", 40 + [MMBASE] = "xen,uefi-mmap-start", 41 + [MMSIZE] = "xen,uefi-mmap-size", 42 + [DCSIZE] = "xen,uefi-mmap-desc-size", 43 + [DCVERS] = "xen,uefi-mmap-desc-ver", 44 + } 45 + }, { 46 + #endif 47 + .path = "/chosen", 48 + .params = { // <-----------26-----------> 49 + [SYSTAB] = "linux,uefi-system-table", 50 + [MMBASE] = "linux,uefi-mmap-start", 51 + [MMSIZE] = "linux,uefi-mmap-size", 52 + [DCSIZE] = "linux,uefi-mmap-desc-size", 53 + [DCVERS] = "linux,uefi-mmap-desc-ver", 54 + } 55 + } 56 + }; 57 + 58 + static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname, 59 + const char *rname, void *var, int size) 60 + { 61 + const void *prop; 62 + int len; 63 + u64 val; 64 + 65 + prop = fdt_getprop(fdt, node, pname, &len); 66 + if (!prop) 67 + return 1; 68 + 69 + val = (len == 4) ? (u64)be32_to_cpup(prop) : get_unaligned_be64(prop); 70 + 71 + if (size == 8) 72 + *(u64 *)var = val; 73 + else 74 + *(u32 *)var = (val < U32_MAX) ? val : U32_MAX; // saturate 75 + 76 + if (efi_enabled(EFI_DBG)) 77 + pr_info(" %s: 0x%0*llx\n", rname, size * 2, val); 78 + 79 + return 0; 80 + } 81 + 82 + u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm) 83 + { 84 + const void *fdt = initial_boot_params; 85 + unsigned long systab; 86 + int i, j, node; 87 + struct { 88 + void *var; 89 + int size; 90 + } target[] = { 91 + [SYSTAB] = { &systab, sizeof(systab) }, 92 + [MMBASE] = { &mm->phys_map, sizeof(mm->phys_map) }, 93 + [MMSIZE] = { &mm->size, sizeof(mm->size) }, 94 + [DCSIZE] = { &mm->desc_size, sizeof(mm->desc_size) }, 95 + [DCVERS] = { &mm->desc_version, sizeof(mm->desc_version) }, 96 + }; 97 + 98 + BUILD_BUG_ON(ARRAY_SIZE(target) != ARRAY_SIZE(name)); 99 + BUILD_BUG_ON(ARRAY_SIZE(target) != ARRAY_SIZE(dt_params[0].params)); 100 + 101 + for (i = 0; i < ARRAY_SIZE(dt_params); i++) { 102 + node = fdt_path_offset(fdt, dt_params[i].path); 103 + if (node < 0) 104 + continue; 105 + 106 + if (efi_enabled(EFI_DBG)) 107 + pr_info("Getting UEFI parameters from %s in DT:\n", 108 + dt_params[i].path); 109 + 110 + for (j = 0; j < ARRAY_SIZE(target); j++) { 111 + const char *pname = dt_params[i].params[j]; 112 + 113 + if (!efi_get_fdt_prop(fdt, node, pname, name[j], 114 + target[j].var, target[j].size)) 115 + continue; 116 + if (!j) 117 + goto notfound; 118 + pr_err("Can't find property '%s' in DT!\n", pname); 119 + return 0; 120 + } 121 + return systab; 122 + } 123 + notfound: 124 + pr_info("UEFI not found.\n"); 125 + return 0; 126 + }
+4 -2
drivers/firmware/efi/libstub/Makefile
··· 25 25 cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt 26 26 27 27 KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ 28 + -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ 28 29 -D__NO_FORTIFY \ 29 30 $(call cc-option,-ffreestanding) \ 30 31 $(call cc-option,-fno-stack-protector) \ ··· 40 39 KCOV_INSTRUMENT := n 41 40 42 41 lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \ 43 - random.o pci.o 42 + file.o mem.o random.o randomalloc.o pci.o \ 43 + skip_spaces.o lib-cmdline.o lib-ctype.o 44 44 45 45 # include the stub's generic dependencies from lib/ when building for ARM/arm64 46 46 arm-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c 47 - arm-deps-$(CONFIG_ARM64) += sort.c 48 47 49 48 $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE 50 49 $(call if_changed_rule,cc_o_c) ··· 54 53 55 54 lib-$(CONFIG_ARM) += arm32-stub.o 56 55 lib-$(CONFIG_ARM64) += arm64-stub.o 56 + lib-$(CONFIG_X86) += x86-stub.o 57 57 CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 58 58 CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 59 59
+100 -93
drivers/firmware/efi/libstub/arm-stub.c
··· 10 10 */ 11 11 12 12 #include <linux/efi.h> 13 - #include <linux/sort.h> 13 + #include <linux/libfdt.h> 14 14 #include <asm/efi.h> 15 15 16 16 #include "efistub.h" ··· 36 36 #endif 37 37 38 38 static u64 virtmap_base = EFI_RT_VIRTUAL_BASE; 39 + static bool __efistub_global flat_va_mapping; 39 40 40 41 static efi_system_table_t *__efistub_global sys_table; 41 42 ··· 88 87 pr_efi_err("Failed to install memreserve config table!\n"); 89 88 } 90 89 90 + static unsigned long get_dram_base(void) 91 + { 92 + efi_status_t status; 93 + unsigned long map_size, buff_size; 94 + unsigned long membase = EFI_ERROR; 95 + struct efi_memory_map map; 96 + efi_memory_desc_t *md; 97 + struct efi_boot_memmap boot_map; 98 + 99 + boot_map.map = (efi_memory_desc_t **)&map.map; 100 + boot_map.map_size = &map_size; 101 + boot_map.desc_size = &map.desc_size; 102 + boot_map.desc_ver = NULL; 103 + boot_map.key_ptr = NULL; 104 + boot_map.buff_size = &buff_size; 105 + 106 + status = efi_get_memory_map(&boot_map); 107 + if (status != EFI_SUCCESS) 108 + return membase; 109 + 110 + map.map_end = map.map + map_size; 111 + 112 + for_each_efi_memory_desc_in_map(&map, md) { 113 + if (md->attribute & EFI_MEMORY_WB) { 114 + if (membase > md->phys_addr) 115 + membase = md->phys_addr; 116 + } 117 + } 118 + 119 + efi_bs_call(free_pool, map.map); 120 + 121 + return membase; 122 + } 91 123 92 124 /* 93 125 * This function handles the architcture specific differences between arm and ··· 134 100 unsigned long *reserve_size, 135 101 unsigned long dram_base, 136 102 efi_loaded_image_t *image); 103 + 104 + asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint, 105 + unsigned long fdt_addr, 106 + unsigned long fdt_size); 107 + 137 108 /* 138 109 * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint 139 110 * that is described in the PE/COFF header. Most of the code is the same 140 111 * for both archictectures, with the arch-specific code provided in the 141 112 * handle_kernel_image() function. 142 113 */ 143 - unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg, 144 - unsigned long *image_addr) 114 + efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg) 145 115 { 146 116 efi_loaded_image_t *image; 147 117 efi_status_t status; 118 + unsigned long image_addr; 148 119 unsigned long image_size = 0; 149 120 unsigned long dram_base; 150 121 /* addr/point and size pairs for memory management*/ 151 - unsigned long initrd_addr; 152 - u64 initrd_size = 0; 122 + unsigned long initrd_addr = 0; 123 + unsigned long initrd_size = 0; 153 124 unsigned long fdt_addr = 0; /* Original DTB */ 154 125 unsigned long fdt_size = 0; 155 126 char *cmdline_ptr = NULL; 156 127 int cmdline_size = 0; 157 - unsigned long new_fdt_addr; 158 128 efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID; 159 129 unsigned long reserve_addr = 0; 160 130 unsigned long reserve_size = 0; 161 131 enum efi_secureboot_mode secure_boot; 162 132 struct screen_info *si; 133 + efi_properties_table_t *prop_tbl; 134 + unsigned long max_addr; 163 135 164 136 sys_table = sys_table_arg; 165 137 166 138 /* Check if we were booted by the EFI firmware */ 167 - if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 139 + if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 140 + status = EFI_INVALID_PARAMETER; 168 141 goto fail; 142 + } 169 143 170 144 status = check_platform_features(); 171 145 if (status != EFI_SUCCESS) ··· 194 152 dram_base = get_dram_base(); 195 153 if (dram_base == EFI_ERROR) { 196 154 pr_efi_err("Failed to find DRAM base\n"); 155 + status = EFI_LOAD_ERROR; 197 156 goto fail; 198 157 } 199 158 ··· 203 160 * protocol. We are going to copy the command line into the 204 161 * device tree, so this can be allocated anywhere. 205 162 */ 206 - cmdline_ptr = efi_convert_cmdline(image, &cmdline_size); 163 + cmdline_ptr = efi_convert_cmdline(image, &cmdline_size, ULONG_MAX); 207 164 if (!cmdline_ptr) { 208 165 pr_efi_err("getting command line via LOADED_IMAGE_PROTOCOL\n"); 166 + status = EFI_OUT_OF_RESOURCES; 209 167 goto fail; 210 168 } 211 169 ··· 222 178 223 179 si = setup_graphics(); 224 180 225 - status = handle_kernel_image(image_addr, &image_size, 181 + status = handle_kernel_image(&image_addr, &image_size, 226 182 &reserve_addr, 227 183 &reserve_size, 228 184 dram_base, image); ··· 248 204 if (strstr(cmdline_ptr, "dtb=")) 249 205 pr_efi("Ignoring DTB from command line.\n"); 250 206 } else { 251 - status = handle_cmdline_files(image, cmdline_ptr, "dtb=", 252 - ~0UL, &fdt_addr, &fdt_size); 207 + status = efi_load_dtb(image, &fdt_addr, &fdt_size); 253 208 254 209 if (status != EFI_SUCCESS) { 255 210 pr_efi_err("Failed to load device tree!\n"); ··· 268 225 if (!fdt_addr) 269 226 pr_efi("Generating empty DTB\n"); 270 227 271 - status = handle_cmdline_files(image, cmdline_ptr, "initrd=", 272 - efi_get_max_initrd_addr(dram_base, 273 - *image_addr), 274 - (unsigned long *)&initrd_addr, 275 - (unsigned long *)&initrd_size); 276 - if (status != EFI_SUCCESS) 277 - pr_efi_err("Failed initrd from command line!\n"); 228 + if (!noinitrd()) { 229 + max_addr = efi_get_max_initrd_addr(dram_base, image_addr); 230 + status = efi_load_initrd_dev_path(&initrd_addr, &initrd_size, 231 + max_addr); 232 + if (status == EFI_SUCCESS) { 233 + pr_efi("Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path\n"); 234 + } else if (status == EFI_NOT_FOUND) { 235 + status = efi_load_initrd(image, &initrd_addr, &initrd_size, 236 + ULONG_MAX, max_addr); 237 + if (status == EFI_SUCCESS) 238 + pr_efi("Loaded initrd from command line option\n"); 239 + } 240 + if (status != EFI_SUCCESS) 241 + pr_efi_err("Failed to load initrd!\n"); 242 + } 278 243 279 244 efi_random_get_seed(); 280 245 246 + /* 247 + * If the NX PE data feature is enabled in the properties table, we 248 + * should take care not to create a virtual mapping that changes the 249 + * relative placement of runtime services code and data regions, as 250 + * they may belong to the same PE/COFF executable image in memory. 251 + * The easiest way to achieve that is to simply use a 1:1 mapping. 252 + */ 253 + prop_tbl = get_efi_config_table(EFI_PROPERTIES_TABLE_GUID); 254 + flat_va_mapping = prop_tbl && 255 + (prop_tbl->memory_protection_attribute & 256 + EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA); 257 + 281 258 /* hibernation expects the runtime regions to stay in the same place */ 282 - if (!IS_ENABLED(CONFIG_HIBERNATION) && !nokaslr()) { 259 + if (!IS_ENABLED(CONFIG_HIBERNATION) && !nokaslr() && !flat_va_mapping) { 283 260 /* 284 261 * Randomize the base of the UEFI runtime services region. 285 262 * Preserve the 2 MB alignment of the region by taking a ··· 320 257 321 258 install_memreserve_table(); 322 259 323 - new_fdt_addr = fdt_addr; 324 - status = allocate_new_fdt_and_exit_boot(handle, 325 - &new_fdt_addr, efi_get_max_fdt_addr(dram_base), 326 - initrd_addr, initrd_size, cmdline_ptr, 327 - fdt_addr, fdt_size); 260 + status = allocate_new_fdt_and_exit_boot(handle, &fdt_addr, 261 + efi_get_max_fdt_addr(dram_base), 262 + initrd_addr, initrd_size, 263 + cmdline_ptr, fdt_addr, fdt_size); 264 + if (status != EFI_SUCCESS) 265 + goto fail_free_initrd; 328 266 329 - /* 330 - * If all went well, we need to return the FDT address to the 331 - * calling function so it can be passed to kernel as part of 332 - * the kernel boot protocol. 333 - */ 334 - if (status == EFI_SUCCESS) 335 - return new_fdt_addr; 267 + efi_enter_kernel(image_addr, fdt_addr, fdt_totalsize((void *)fdt_addr)); 268 + /* not reached */ 336 269 270 + fail_free_initrd: 337 271 pr_efi_err("Failed to update FDT and exit boot services\n"); 338 272 339 273 efi_free(initrd_size, initrd_addr); 340 274 efi_free(fdt_size, fdt_addr); 341 275 342 276 fail_free_image: 343 - efi_free(image_size, *image_addr); 277 + efi_free(image_size, image_addr); 344 278 efi_free(reserve_size, reserve_addr); 345 279 fail_free_cmdline: 346 280 free_screen_info(si); 347 281 efi_free(cmdline_size, (unsigned long)cmdline_ptr); 348 282 fail: 349 - return EFI_ERROR; 350 - } 351 - 352 - static int cmp_mem_desc(const void *l, const void *r) 353 - { 354 - const efi_memory_desc_t *left = l, *right = r; 355 - 356 - return (left->phys_addr > right->phys_addr) ? 1 : -1; 357 - } 358 - 359 - /* 360 - * Returns whether region @left ends exactly where region @right starts, 361 - * or false if either argument is NULL. 362 - */ 363 - static bool regions_are_adjacent(efi_memory_desc_t *left, 364 - efi_memory_desc_t *right) 365 - { 366 - u64 left_end; 367 - 368 - if (left == NULL || right == NULL) 369 - return false; 370 - 371 - left_end = left->phys_addr + left->num_pages * EFI_PAGE_SIZE; 372 - 373 - return left_end == right->phys_addr; 374 - } 375 - 376 - /* 377 - * Returns whether region @left and region @right have compatible memory type 378 - * mapping attributes, and are both EFI_MEMORY_RUNTIME regions. 379 - */ 380 - static bool regions_have_compatible_memory_type_attrs(efi_memory_desc_t *left, 381 - efi_memory_desc_t *right) 382 - { 383 - static const u64 mem_type_mask = EFI_MEMORY_WB | EFI_MEMORY_WT | 384 - EFI_MEMORY_WC | EFI_MEMORY_UC | 385 - EFI_MEMORY_RUNTIME; 386 - 387 - return ((left->attribute ^ right->attribute) & mem_type_mask) == 0; 283 + return status; 388 284 } 389 285 390 286 /* ··· 358 336 int *count) 359 337 { 360 338 u64 efi_virt_base = virtmap_base; 361 - efi_memory_desc_t *in, *prev = NULL, *out = runtime_map; 339 + efi_memory_desc_t *in, *out = runtime_map; 362 340 int l; 363 341 364 - /* 365 - * To work around potential issues with the Properties Table feature 366 - * introduced in UEFI 2.5, which may split PE/COFF executable images 367 - * in memory into several RuntimeServicesCode and RuntimeServicesData 368 - * regions, we need to preserve the relative offsets between adjacent 369 - * EFI_MEMORY_RUNTIME regions with the same memory type attributes. 370 - * The easiest way to find adjacent regions is to sort the memory map 371 - * before traversing it. 372 - */ 373 - if (IS_ENABLED(CONFIG_ARM64)) 374 - sort(memory_map, map_size / desc_size, desc_size, cmp_mem_desc, 375 - NULL); 376 - 377 - for (l = 0; l < map_size; l += desc_size, prev = in) { 342 + for (l = 0; l < map_size; l += desc_size) { 378 343 u64 paddr, size; 379 344 380 345 in = (void *)memory_map + l; ··· 371 362 paddr = in->phys_addr; 372 363 size = in->num_pages * EFI_PAGE_SIZE; 373 364 365 + in->virt_addr = in->phys_addr; 374 366 if (novamap()) { 375 - in->virt_addr = in->phys_addr; 376 367 continue; 377 368 } 378 369 ··· 381 372 * a 4k page size kernel to kexec a 64k page size kernel and 382 373 * vice versa. 383 374 */ 384 - if ((IS_ENABLED(CONFIG_ARM64) && 385 - !regions_are_adjacent(prev, in)) || 386 - !regions_have_compatible_memory_type_attrs(prev, in)) { 375 + if (!flat_va_mapping) { 387 376 388 377 paddr = round_down(in->phys_addr, SZ_64K); 389 378 size += in->phys_addr - paddr; ··· 396 389 efi_virt_base = round_up(efi_virt_base, SZ_2M); 397 390 else 398 391 efi_virt_base = round_up(efi_virt_base, SZ_64K); 399 - } 400 392 401 - in->virt_addr = efi_virt_base + in->phys_addr - paddr; 402 - efi_virt_base += size; 393 + in->virt_addr += efi_virt_base - paddr; 394 + efi_virt_base += size; 395 + } 403 396 404 397 memcpy(out, in, desc_size); 405 398 out = (void *)out + desc_size;
+1
drivers/firmware/efi/libstub/arm32-stub.c
··· 227 227 * Relocate the zImage, so that it appears in the lowest 128 MB 228 228 * memory window. 229 229 */ 230 + *image_addr = (unsigned long)image->image_base; 230 231 *image_size = image->image_size; 231 232 status = efi_relocate_kernel(image_addr, *image_size, *image_size, 232 233 kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0, 0);
+2 -9
drivers/firmware/efi/libstub/arm64-stub.c
··· 6 6 * Adapted from ARM version by Mark Salter <msalter@redhat.com> 7 7 */ 8 8 9 - /* 10 - * To prevent the compiler from emitting GOT-indirected (and thus absolute) 11 - * references to the section markers, override their visibility as 'hidden' 12 - */ 13 - #pragma GCC visibility push(hidden) 14 - #include <asm/sections.h> 15 - #pragma GCC visibility pop 16 9 17 10 #include <linux/efi.h> 18 11 #include <asm/efi.h> 19 12 #include <asm/memory.h> 13 + #include <asm/sections.h> 20 14 #include <asm/sysreg.h> 21 15 22 16 #include "efistub.h" ··· 43 49 { 44 50 efi_status_t status; 45 51 unsigned long kernel_size, kernel_memsize = 0; 46 - void *old_image_addr = (void *)*image_addr; 47 52 unsigned long preferred_offset; 48 53 u64 phys_seed = 0; 49 54 ··· 140 147 } 141 148 *image_addr = *reserve_addr + TEXT_OFFSET; 142 149 } 143 - memcpy((void *)*image_addr, old_image_addr, kernel_size); 150 + memcpy((void *)*image_addr, image->image_base, kernel_size); 144 151 145 152 return EFI_SUCCESS; 146 153 }
+132 -702
drivers/firmware/efi/libstub/efi-stub-helper.c
··· 12 12 13 13 #include "efistub.h" 14 14 15 - /* 16 - * Some firmware implementations have problems reading files in one go. 17 - * A read chunk size of 1MB seems to work for most platforms. 18 - * 19 - * Unfortunately, reading files in chunks triggers *other* bugs on some 20 - * platforms, so we provide a way to disable this workaround, which can 21 - * be done by passing "efi=nochunk" on the EFI boot stub command line. 22 - * 23 - * If you experience issues with initrd images being corrupt it's worth 24 - * trying efi=nochunk, but chunking is enabled by default because there 25 - * are far more machines that require the workaround than those that 26 - * break with it enabled. 27 - */ 28 - #define EFI_READ_CHUNK_SIZE (1024 * 1024) 29 - 30 - static unsigned long efi_chunk_size = EFI_READ_CHUNK_SIZE; 31 - 15 + static bool __efistub_global efi_nochunk; 32 16 static bool __efistub_global efi_nokaslr; 17 + static bool __efistub_global efi_noinitrd; 33 18 static bool __efistub_global efi_quiet; 34 19 static bool __efistub_global efi_novamap; 35 20 static bool __efistub_global efi_nosoftreserve; 36 21 static bool __efistub_global efi_disable_pci_dma = 37 22 IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA); 38 23 24 + bool __pure nochunk(void) 25 + { 26 + return efi_nochunk; 27 + } 39 28 bool __pure nokaslr(void) 40 29 { 41 30 return efi_nokaslr; 31 + } 32 + bool __pure noinitrd(void) 33 + { 34 + return efi_noinitrd; 42 35 } 43 36 bool __pure is_quiet(void) 44 37 { ··· 45 52 { 46 53 return !efi_nosoftreserve; 47 54 } 48 - 49 - #define EFI_MMAP_NR_SLACK_SLOTS 8 50 - 51 - struct file_info { 52 - efi_file_handle_t *handle; 53 - u64 size; 54 - }; 55 55 56 56 void efi_printk(char *str) 57 57 { ··· 63 77 } 64 78 } 65 79 66 - static inline bool mmap_has_headroom(unsigned long buff_size, 67 - unsigned long map_size, 68 - unsigned long desc_size) 69 - { 70 - unsigned long slack = buff_size - map_size; 71 - 72 - return slack / desc_size >= EFI_MMAP_NR_SLACK_SLOTS; 73 - } 74 - 75 - efi_status_t efi_get_memory_map(struct efi_boot_memmap *map) 76 - { 77 - efi_memory_desc_t *m = NULL; 78 - efi_status_t status; 79 - unsigned long key; 80 - u32 desc_version; 81 - 82 - *map->desc_size = sizeof(*m); 83 - *map->map_size = *map->desc_size * 32; 84 - *map->buff_size = *map->map_size; 85 - again: 86 - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, 87 - *map->map_size, (void **)&m); 88 - if (status != EFI_SUCCESS) 89 - goto fail; 90 - 91 - *map->desc_size = 0; 92 - key = 0; 93 - status = efi_bs_call(get_memory_map, map->map_size, m, 94 - &key, map->desc_size, &desc_version); 95 - if (status == EFI_BUFFER_TOO_SMALL || 96 - !mmap_has_headroom(*map->buff_size, *map->map_size, 97 - *map->desc_size)) { 98 - efi_bs_call(free_pool, m); 99 - /* 100 - * Make sure there is some entries of headroom so that the 101 - * buffer can be reused for a new map after allocations are 102 - * no longer permitted. Its unlikely that the map will grow to 103 - * exceed this headroom once we are ready to trigger 104 - * ExitBootServices() 105 - */ 106 - *map->map_size += *map->desc_size * EFI_MMAP_NR_SLACK_SLOTS; 107 - *map->buff_size = *map->map_size; 108 - goto again; 109 - } 110 - 111 - if (status != EFI_SUCCESS) 112 - efi_bs_call(free_pool, m); 113 - 114 - if (map->key_ptr && status == EFI_SUCCESS) 115 - *map->key_ptr = key; 116 - if (map->desc_ver && status == EFI_SUCCESS) 117 - *map->desc_ver = desc_version; 118 - 119 - fail: 120 - *map->map = m; 121 - return status; 122 - } 123 - 124 - 125 - unsigned long get_dram_base(void) 126 - { 127 - efi_status_t status; 128 - unsigned long map_size, buff_size; 129 - unsigned long membase = EFI_ERROR; 130 - struct efi_memory_map map; 131 - efi_memory_desc_t *md; 132 - struct efi_boot_memmap boot_map; 133 - 134 - boot_map.map = (efi_memory_desc_t **)&map.map; 135 - boot_map.map_size = &map_size; 136 - boot_map.desc_size = &map.desc_size; 137 - boot_map.desc_ver = NULL; 138 - boot_map.key_ptr = NULL; 139 - boot_map.buff_size = &buff_size; 140 - 141 - status = efi_get_memory_map(&boot_map); 142 - if (status != EFI_SUCCESS) 143 - return membase; 144 - 145 - map.map_end = map.map + map_size; 146 - 147 - for_each_efi_memory_desc_in_map(&map, md) { 148 - if (md->attribute & EFI_MEMORY_WB) { 149 - if (membase > md->phys_addr) 150 - membase = md->phys_addr; 151 - } 152 - } 153 - 154 - efi_bs_call(free_pool, map.map); 155 - 156 - return membase; 157 - } 158 - 159 - /* 160 - * Allocate at the highest possible address that is not above 'max'. 161 - */ 162 - efi_status_t efi_high_alloc(unsigned long size, unsigned long align, 163 - unsigned long *addr, unsigned long max) 164 - { 165 - unsigned long map_size, desc_size, buff_size; 166 - efi_memory_desc_t *map; 167 - efi_status_t status; 168 - unsigned long nr_pages; 169 - u64 max_addr = 0; 170 - int i; 171 - struct efi_boot_memmap boot_map; 172 - 173 - boot_map.map = &map; 174 - boot_map.map_size = &map_size; 175 - boot_map.desc_size = &desc_size; 176 - boot_map.desc_ver = NULL; 177 - boot_map.key_ptr = NULL; 178 - boot_map.buff_size = &buff_size; 179 - 180 - status = efi_get_memory_map(&boot_map); 181 - if (status != EFI_SUCCESS) 182 - goto fail; 183 - 184 - /* 185 - * Enforce minimum alignment that EFI or Linux requires when 186 - * requesting a specific address. We are doing page-based (or 187 - * larger) allocations, and both the address and size must meet 188 - * alignment constraints. 189 - */ 190 - if (align < EFI_ALLOC_ALIGN) 191 - align = EFI_ALLOC_ALIGN; 192 - 193 - size = round_up(size, EFI_ALLOC_ALIGN); 194 - nr_pages = size / EFI_PAGE_SIZE; 195 - again: 196 - for (i = 0; i < map_size / desc_size; i++) { 197 - efi_memory_desc_t *desc; 198 - unsigned long m = (unsigned long)map; 199 - u64 start, end; 200 - 201 - desc = efi_early_memdesc_ptr(m, desc_size, i); 202 - if (desc->type != EFI_CONVENTIONAL_MEMORY) 203 - continue; 204 - 205 - if (efi_soft_reserve_enabled() && 206 - (desc->attribute & EFI_MEMORY_SP)) 207 - continue; 208 - 209 - if (desc->num_pages < nr_pages) 210 - continue; 211 - 212 - start = desc->phys_addr; 213 - end = start + desc->num_pages * EFI_PAGE_SIZE; 214 - 215 - if (end > max) 216 - end = max; 217 - 218 - if ((start + size) > end) 219 - continue; 220 - 221 - if (round_down(end - size, align) < start) 222 - continue; 223 - 224 - start = round_down(end - size, align); 225 - 226 - /* 227 - * Don't allocate at 0x0. It will confuse code that 228 - * checks pointers against NULL. 229 - */ 230 - if (start == 0x0) 231 - continue; 232 - 233 - if (start > max_addr) 234 - max_addr = start; 235 - } 236 - 237 - if (!max_addr) 238 - status = EFI_NOT_FOUND; 239 - else { 240 - status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 241 - EFI_LOADER_DATA, nr_pages, &max_addr); 242 - if (status != EFI_SUCCESS) { 243 - max = max_addr; 244 - max_addr = 0; 245 - goto again; 246 - } 247 - 248 - *addr = max_addr; 249 - } 250 - 251 - efi_bs_call(free_pool, map); 252 - fail: 253 - return status; 254 - } 255 - 256 - /* 257 - * Allocate at the lowest possible address that is not below 'min'. 258 - */ 259 - efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, 260 - unsigned long *addr, unsigned long min) 261 - { 262 - unsigned long map_size, desc_size, buff_size; 263 - efi_memory_desc_t *map; 264 - efi_status_t status; 265 - unsigned long nr_pages; 266 - int i; 267 - struct efi_boot_memmap boot_map; 268 - 269 - boot_map.map = &map; 270 - boot_map.map_size = &map_size; 271 - boot_map.desc_size = &desc_size; 272 - boot_map.desc_ver = NULL; 273 - boot_map.key_ptr = NULL; 274 - boot_map.buff_size = &buff_size; 275 - 276 - status = efi_get_memory_map(&boot_map); 277 - if (status != EFI_SUCCESS) 278 - goto fail; 279 - 280 - /* 281 - * Enforce minimum alignment that EFI or Linux requires when 282 - * requesting a specific address. We are doing page-based (or 283 - * larger) allocations, and both the address and size must meet 284 - * alignment constraints. 285 - */ 286 - if (align < EFI_ALLOC_ALIGN) 287 - align = EFI_ALLOC_ALIGN; 288 - 289 - size = round_up(size, EFI_ALLOC_ALIGN); 290 - nr_pages = size / EFI_PAGE_SIZE; 291 - for (i = 0; i < map_size / desc_size; i++) { 292 - efi_memory_desc_t *desc; 293 - unsigned long m = (unsigned long)map; 294 - u64 start, end; 295 - 296 - desc = efi_early_memdesc_ptr(m, desc_size, i); 297 - 298 - if (desc->type != EFI_CONVENTIONAL_MEMORY) 299 - continue; 300 - 301 - if (efi_soft_reserve_enabled() && 302 - (desc->attribute & EFI_MEMORY_SP)) 303 - continue; 304 - 305 - if (desc->num_pages < nr_pages) 306 - continue; 307 - 308 - start = desc->phys_addr; 309 - end = start + desc->num_pages * EFI_PAGE_SIZE; 310 - 311 - if (start < min) 312 - start = min; 313 - 314 - start = round_up(start, align); 315 - if ((start + size) > end) 316 - continue; 317 - 318 - status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 319 - EFI_LOADER_DATA, nr_pages, &start); 320 - if (status == EFI_SUCCESS) { 321 - *addr = start; 322 - break; 323 - } 324 - } 325 - 326 - if (i == map_size / desc_size) 327 - status = EFI_NOT_FOUND; 328 - 329 - efi_bs_call(free_pool, map); 330 - fail: 331 - return status; 332 - } 333 - 334 - void efi_free(unsigned long size, unsigned long addr) 335 - { 336 - unsigned long nr_pages; 337 - 338 - if (!size) 339 - return; 340 - 341 - nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; 342 - efi_bs_call(free_pages, addr, nr_pages); 343 - } 344 - 345 - static efi_status_t efi_file_size(void *__fh, efi_char16_t *filename_16, 346 - void **handle, u64 *file_sz) 347 - { 348 - efi_file_handle_t *h, *fh = __fh; 349 - efi_file_info_t *info; 350 - efi_status_t status; 351 - efi_guid_t info_guid = EFI_FILE_INFO_ID; 352 - unsigned long info_sz; 353 - 354 - status = fh->open(fh, &h, filename_16, EFI_FILE_MODE_READ, 0); 355 - if (status != EFI_SUCCESS) { 356 - efi_printk("Failed to open file: "); 357 - efi_char16_printk(filename_16); 358 - efi_printk("\n"); 359 - return status; 360 - } 361 - 362 - *handle = h; 363 - 364 - info_sz = 0; 365 - status = h->get_info(h, &info_guid, &info_sz, NULL); 366 - if (status != EFI_BUFFER_TOO_SMALL) { 367 - efi_printk("Failed to get file info size\n"); 368 - return status; 369 - } 370 - 371 - grow: 372 - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, info_sz, 373 - (void **)&info); 374 - if (status != EFI_SUCCESS) { 375 - efi_printk("Failed to alloc mem for file info\n"); 376 - return status; 377 - } 378 - 379 - status = h->get_info(h, &info_guid, &info_sz, info); 380 - if (status == EFI_BUFFER_TOO_SMALL) { 381 - efi_bs_call(free_pool, info); 382 - goto grow; 383 - } 384 - 385 - *file_sz = info->file_size; 386 - efi_bs_call(free_pool, info); 387 - 388 - if (status != EFI_SUCCESS) 389 - efi_printk("Failed to get initrd info\n"); 390 - 391 - return status; 392 - } 393 - 394 - static efi_status_t efi_file_read(efi_file_handle_t *handle, 395 - unsigned long *size, void *addr) 396 - { 397 - return handle->read(handle, size, addr); 398 - } 399 - 400 - static efi_status_t efi_file_close(efi_file_handle_t *handle) 401 - { 402 - return handle->close(handle); 403 - } 404 - 405 - static efi_status_t efi_open_volume(efi_loaded_image_t *image, 406 - efi_file_handle_t **__fh) 407 - { 408 - efi_file_io_interface_t *io; 409 - efi_file_handle_t *fh; 410 - efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; 411 - efi_status_t status; 412 - efi_handle_t handle = image->device_handle; 413 - 414 - status = efi_bs_call(handle_protocol, handle, &fs_proto, (void **)&io); 415 - if (status != EFI_SUCCESS) { 416 - efi_printk("Failed to handle fs_proto\n"); 417 - return status; 418 - } 419 - 420 - status = io->open_volume(io, &fh); 421 - if (status != EFI_SUCCESS) 422 - efi_printk("Failed to open volume\n"); 423 - else 424 - *__fh = fh; 425 - 426 - return status; 427 - } 428 - 429 80 /* 430 81 * Parse the ASCII string 'cmdline' for EFI options, denoted by the efi= 431 82 * option, e.g. efi=nochunk. ··· 73 450 */ 74 451 efi_status_t efi_parse_options(char const *cmdline) 75 452 { 76 - char *str; 77 - 78 - str = strstr(cmdline, "nokaslr"); 79 - if (str == cmdline || (str && str > cmdline && *(str - 1) == ' ')) 80 - efi_nokaslr = true; 81 - 82 - str = strstr(cmdline, "quiet"); 83 - if (str == cmdline || (str && str > cmdline && *(str - 1) == ' ')) 84 - efi_quiet = true; 85 - 86 - /* 87 - * If no EFI parameters were specified on the cmdline we've got 88 - * nothing to do. 89 - */ 90 - str = strstr(cmdline, "efi="); 91 - if (!str) 92 - return EFI_SUCCESS; 93 - 94 - /* Skip ahead to first argument */ 95 - str += strlen("efi="); 96 - 97 - /* 98 - * Remember, because efi= is also used by the kernel we need to 99 - * skip over arguments we don't understand. 100 - */ 101 - while (*str && *str != ' ') { 102 - if (!strncmp(str, "nochunk", 7)) { 103 - str += strlen("nochunk"); 104 - efi_chunk_size = -1UL; 105 - } 106 - 107 - if (!strncmp(str, "novamap", 7)) { 108 - str += strlen("novamap"); 109 - efi_novamap = true; 110 - } 111 - 112 - if (IS_ENABLED(CONFIG_EFI_SOFT_RESERVE) && 113 - !strncmp(str, "nosoftreserve", 7)) { 114 - str += strlen("nosoftreserve"); 115 - efi_nosoftreserve = true; 116 - } 117 - 118 - if (!strncmp(str, "disable_early_pci_dma", 21)) { 119 - str += strlen("disable_early_pci_dma"); 120 - efi_disable_pci_dma = true; 121 - } 122 - 123 - if (!strncmp(str, "no_disable_early_pci_dma", 24)) { 124 - str += strlen("no_disable_early_pci_dma"); 125 - efi_disable_pci_dma = false; 126 - } 127 - 128 - /* Group words together, delimited by "," */ 129 - while (*str && *str != ' ' && *str != ',') 130 - str++; 131 - 132 - if (*str == ',') 133 - str++; 134 - } 135 - 136 - return EFI_SUCCESS; 137 - } 138 - 139 - /* 140 - * Check the cmdline for a LILO-style file= arguments. 141 - * 142 - * We only support loading a file from the same filesystem as 143 - * the kernel image. 144 - */ 145 - efi_status_t handle_cmdline_files(efi_loaded_image_t *image, 146 - char *cmd_line, char *option_string, 147 - unsigned long max_addr, 148 - unsigned long *load_addr, 149 - unsigned long *load_size) 150 - { 151 - struct file_info *files; 152 - unsigned long file_addr; 153 - u64 file_size_total; 154 - efi_file_handle_t *fh = NULL; 453 + size_t len = strlen(cmdline) + 1; 155 454 efi_status_t status; 156 - int nr_files; 157 - char *str; 158 - int i, j, k; 455 + char *str, *buf; 159 456 160 - file_addr = 0; 161 - file_size_total = 0; 162 - 163 - str = cmd_line; 164 - 165 - j = 0; /* See close_handles */ 166 - 167 - if (!load_addr || !load_size) 168 - return EFI_INVALID_PARAMETER; 169 - 170 - *load_addr = 0; 171 - *load_size = 0; 172 - 173 - if (!str || !*str) 174 - return EFI_SUCCESS; 175 - 176 - for (nr_files = 0; *str; nr_files++) { 177 - str = strstr(str, option_string); 178 - if (!str) 179 - break; 180 - 181 - str += strlen(option_string); 182 - 183 - /* Skip any leading slashes */ 184 - while (*str == '/' || *str == '\\') 185 - str++; 186 - 187 - while (*str && *str != ' ' && *str != '\n') 188 - str++; 189 - } 190 - 191 - if (!nr_files) 192 - return EFI_SUCCESS; 193 - 194 - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, 195 - nr_files * sizeof(*files), (void **)&files); 196 - if (status != EFI_SUCCESS) { 197 - pr_efi_err("Failed to alloc mem for file handle list\n"); 198 - goto fail; 199 - } 200 - 201 - str = cmd_line; 202 - for (i = 0; i < nr_files; i++) { 203 - struct file_info *file; 204 - efi_char16_t filename_16[256]; 205 - efi_char16_t *p; 206 - 207 - str = strstr(str, option_string); 208 - if (!str) 209 - break; 210 - 211 - str += strlen(option_string); 212 - 213 - file = &files[i]; 214 - p = filename_16; 215 - 216 - /* Skip any leading slashes */ 217 - while (*str == '/' || *str == '\\') 218 - str++; 219 - 220 - while (*str && *str != ' ' && *str != '\n') { 221 - if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16)) 222 - break; 223 - 224 - if (*str == '/') { 225 - *p++ = '\\'; 226 - str++; 227 - } else { 228 - *p++ = *str++; 229 - } 230 - } 231 - 232 - *p = '\0'; 233 - 234 - /* Only open the volume once. */ 235 - if (!i) { 236 - status = efi_open_volume(image, &fh); 237 - if (status != EFI_SUCCESS) 238 - goto free_files; 239 - } 240 - 241 - status = efi_file_size(fh, filename_16, (void **)&file->handle, 242 - &file->size); 243 - if (status != EFI_SUCCESS) 244 - goto close_handles; 245 - 246 - file_size_total += file->size; 247 - } 248 - 249 - if (file_size_total) { 250 - unsigned long addr; 251 - 252 - /* 253 - * Multiple files need to be at consecutive addresses in memory, 254 - * so allocate enough memory for all the files. This is used 255 - * for loading multiple files. 256 - */ 257 - status = efi_high_alloc(file_size_total, 0x1000, &file_addr, 258 - max_addr); 259 - if (status != EFI_SUCCESS) { 260 - pr_efi_err("Failed to alloc highmem for files\n"); 261 - goto close_handles; 262 - } 263 - 264 - /* We've run out of free low memory. */ 265 - if (file_addr > max_addr) { 266 - pr_efi_err("We've run out of free low memory\n"); 267 - status = EFI_INVALID_PARAMETER; 268 - goto free_file_total; 269 - } 270 - 271 - addr = file_addr; 272 - for (j = 0; j < nr_files; j++) { 273 - unsigned long size; 274 - 275 - size = files[j].size; 276 - while (size) { 277 - unsigned long chunksize; 278 - 279 - if (IS_ENABLED(CONFIG_X86) && size > efi_chunk_size) 280 - chunksize = efi_chunk_size; 281 - else 282 - chunksize = size; 283 - 284 - status = efi_file_read(files[j].handle, 285 - &chunksize, 286 - (void *)addr); 287 - if (status != EFI_SUCCESS) { 288 - pr_efi_err("Failed to read file\n"); 289 - goto free_file_total; 290 - } 291 - addr += chunksize; 292 - size -= chunksize; 293 - } 294 - 295 - efi_file_close(files[j].handle); 296 - } 297 - 298 - } 299 - 300 - efi_bs_call(free_pool, files); 301 - 302 - *load_addr = file_addr; 303 - *load_size = file_size_total; 304 - 305 - return status; 306 - 307 - free_file_total: 308 - efi_free(file_size_total, file_addr); 309 - 310 - close_handles: 311 - for (k = j; k < i; k++) 312 - efi_file_close(files[k].handle); 313 - free_files: 314 - efi_bs_call(free_pool, files); 315 - fail: 316 - *load_addr = 0; 317 - *load_size = 0; 318 - 319 - return status; 320 - } 321 - /* 322 - * Relocate a kernel image, either compressed or uncompressed. 323 - * In the ARM64 case, all kernel images are currently 324 - * uncompressed, and as such when we relocate it we need to 325 - * allocate additional space for the BSS segment. Any low 326 - * memory that this function should avoid needs to be 327 - * unavailable in the EFI memory map, as if the preferred 328 - * address is not available the lowest available address will 329 - * be used. 330 - */ 331 - efi_status_t efi_relocate_kernel(unsigned long *image_addr, 332 - unsigned long image_size, 333 - unsigned long alloc_size, 334 - unsigned long preferred_addr, 335 - unsigned long alignment, 336 - unsigned long min_addr) 337 - { 338 - unsigned long cur_image_addr; 339 - unsigned long new_addr = 0; 340 - efi_status_t status; 341 - unsigned long nr_pages; 342 - efi_physical_addr_t efi_addr = preferred_addr; 343 - 344 - if (!image_addr || !image_size || !alloc_size) 345 - return EFI_INVALID_PARAMETER; 346 - if (alloc_size < image_size) 347 - return EFI_INVALID_PARAMETER; 348 - 349 - cur_image_addr = *image_addr; 350 - 351 - /* 352 - * The EFI firmware loader could have placed the kernel image 353 - * anywhere in memory, but the kernel has restrictions on the 354 - * max physical address it can run at. Some architectures 355 - * also have a prefered address, so first try to relocate 356 - * to the preferred address. If that fails, allocate as low 357 - * as possible while respecting the required alignment. 358 - */ 359 - nr_pages = round_up(alloc_size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; 360 - status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 361 - EFI_LOADER_DATA, nr_pages, &efi_addr); 362 - new_addr = efi_addr; 363 - /* 364 - * If preferred address allocation failed allocate as low as 365 - * possible. 366 - */ 367 - if (status != EFI_SUCCESS) { 368 - status = efi_low_alloc_above(alloc_size, alignment, &new_addr, 369 - min_addr); 370 - } 371 - if (status != EFI_SUCCESS) { 372 - pr_efi_err("Failed to allocate usable memory for kernel.\n"); 457 + status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, len, (void **)&buf); 458 + if (status != EFI_SUCCESS) 373 459 return status; 460 + 461 + str = skip_spaces(memcpy(buf, cmdline, len)); 462 + 463 + while (*str) { 464 + char *param, *val; 465 + 466 + str = next_arg(str, &param, &val); 467 + 468 + if (!strcmp(param, "nokaslr")) { 469 + efi_nokaslr = true; 470 + } else if (!strcmp(param, "quiet")) { 471 + efi_quiet = true; 472 + } else if (!strcmp(param, "noinitrd")) { 473 + efi_noinitrd = true; 474 + } else if (!strcmp(param, "efi") && val) { 475 + efi_nochunk = parse_option_str(val, "nochunk"); 476 + efi_novamap = parse_option_str(val, "novamap"); 477 + 478 + efi_nosoftreserve = IS_ENABLED(CONFIG_EFI_SOFT_RESERVE) && 479 + parse_option_str(val, "nosoftreserve"); 480 + 481 + if (parse_option_str(val, "disable_early_pci_dma")) 482 + efi_disable_pci_dma = true; 483 + if (parse_option_str(val, "no_disable_early_pci_dma")) 484 + efi_disable_pci_dma = false; 485 + } 374 486 } 375 - 376 - /* 377 - * We know source/dest won't overlap since both memory ranges 378 - * have been allocated by UEFI, so we can safely use memcpy. 379 - */ 380 - memcpy((void *)new_addr, (void *)cur_image_addr, image_size); 381 - 382 - /* Return the new address of the relocated image. */ 383 - *image_addr = new_addr; 384 - 385 - return status; 487 + efi_bs_call(free_pool, buf); 488 + return EFI_SUCCESS; 386 489 } 387 490 388 491 /* ··· 160 811 return dst; 161 812 } 162 813 163 - #ifndef MAX_CMDLINE_ADDRESS 164 - #define MAX_CMDLINE_ADDRESS ULONG_MAX 165 - #endif 166 - 167 814 /* 168 815 * Convert the unicode UEFI command line to ASCII to pass to kernel. 169 816 * Size of memory allocated return in *cmd_line_len. 170 817 * Returns NULL on error. 171 818 */ 172 819 char *efi_convert_cmdline(efi_loaded_image_t *image, 173 - int *cmd_line_len) 820 + int *cmd_line_len, unsigned long max_addr) 174 821 { 175 822 const u16 *s2; 176 823 u8 *s1 = NULL; 177 824 unsigned long cmdline_addr = 0; 178 - int load_options_chars = image->load_options_size / 2; /* UTF-16 */ 179 - const u16 *options = image->load_options; 825 + int load_options_chars = efi_table_attr(image, load_options_size) / 2; 826 + const u16 *options = efi_table_attr(image, load_options); 180 827 int options_bytes = 0; /* UTF-8 bytes */ 181 828 int options_chars = 0; /* UTF-16 chars */ 182 829 efi_status_t status; ··· 194 849 195 850 options_bytes++; /* NUL termination */ 196 851 197 - status = efi_high_alloc(options_bytes, 0, &cmdline_addr, 198 - MAX_CMDLINE_ADDRESS); 852 + status = efi_allocate_pages(options_bytes, &cmdline_addr, max_addr); 199 853 if (status != EFI_SUCCESS) 200 854 return NULL; 201 855 ··· 305 961 { 306 962 efi_call_proto(efi_table_attr(efi_system_table(), con_out), 307 963 output_string, str); 964 + } 965 + 966 + /* 967 + * The LINUX_EFI_INITRD_MEDIA_GUID vendor media device path below provides a way 968 + * for the firmware or bootloader to expose the initrd data directly to the stub 969 + * via the trivial LoadFile2 protocol, which is defined in the UEFI spec, and is 970 + * very easy to implement. It is a simple Linux initrd specific conduit between 971 + * kernel and firmware, allowing us to put the EFI stub (being part of the 972 + * kernel) in charge of where and when to load the initrd, while leaving it up 973 + * to the firmware to decide whether it needs to expose its filesystem hierarchy 974 + * via EFI protocols. 975 + */ 976 + static const struct { 977 + struct efi_vendor_dev_path vendor; 978 + struct efi_generic_dev_path end; 979 + } __packed initrd_dev_path = { 980 + { 981 + { 982 + EFI_DEV_MEDIA, 983 + EFI_DEV_MEDIA_VENDOR, 984 + sizeof(struct efi_vendor_dev_path), 985 + }, 986 + LINUX_EFI_INITRD_MEDIA_GUID 987 + }, { 988 + EFI_DEV_END_PATH, 989 + EFI_DEV_END_ENTIRE, 990 + sizeof(struct efi_generic_dev_path) 991 + } 992 + }; 993 + 994 + /** 995 + * efi_load_initrd_dev_path - load the initrd from the Linux initrd device path 996 + * @load_addr: pointer to store the address where the initrd was loaded 997 + * @load_size: pointer to store the size of the loaded initrd 998 + * @max: upper limit for the initrd memory allocation 999 + * @return: %EFI_SUCCESS if the initrd was loaded successfully, in which 1000 + * case @load_addr and @load_size are assigned accordingly 1001 + * %EFI_NOT_FOUND if no LoadFile2 protocol exists on the initrd 1002 + * device path 1003 + * %EFI_INVALID_PARAMETER if load_addr == NULL or load_size == NULL 1004 + * %EFI_OUT_OF_RESOURCES if memory allocation failed 1005 + * %EFI_LOAD_ERROR in all other cases 1006 + */ 1007 + efi_status_t efi_load_initrd_dev_path(unsigned long *load_addr, 1008 + unsigned long *load_size, 1009 + unsigned long max) 1010 + { 1011 + efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; 1012 + efi_device_path_protocol_t *dp; 1013 + efi_load_file2_protocol_t *lf2; 1014 + unsigned long initrd_addr; 1015 + unsigned long initrd_size; 1016 + efi_handle_t handle; 1017 + efi_status_t status; 1018 + 1019 + if (!load_addr || !load_size) 1020 + return EFI_INVALID_PARAMETER; 1021 + 1022 + dp = (efi_device_path_protocol_t *)&initrd_dev_path; 1023 + status = efi_bs_call(locate_device_path, &lf2_proto_guid, &dp, &handle); 1024 + if (status != EFI_SUCCESS) 1025 + return status; 1026 + 1027 + status = efi_bs_call(handle_protocol, handle, &lf2_proto_guid, 1028 + (void **)&lf2); 1029 + if (status != EFI_SUCCESS) 1030 + return status; 1031 + 1032 + status = efi_call_proto(lf2, load_file, dp, false, &initrd_size, NULL); 1033 + if (status != EFI_BUFFER_TOO_SMALL) 1034 + return EFI_LOAD_ERROR; 1035 + 1036 + status = efi_allocate_pages(initrd_size, &initrd_addr, max); 1037 + if (status != EFI_SUCCESS) 1038 + return status; 1039 + 1040 + status = efi_call_proto(lf2, load_file, dp, false, &initrd_size, 1041 + (void *)initrd_addr); 1042 + if (status != EFI_SUCCESS) { 1043 + efi_free(initrd_size, initrd_addr); 1044 + return EFI_LOAD_ERROR; 1045 + } 1046 + 1047 + *load_addr = initrd_addr; 1048 + *load_size = initrd_size; 1049 + return EFI_SUCCESS; 308 1050 }
+593 -18
drivers/firmware/efi/libstub/efistub.h
··· 31 31 #define __efistub_global 32 32 #endif 33 33 34 + extern bool __pure nochunk(void); 34 35 extern bool __pure nokaslr(void); 36 + extern bool __pure noinitrd(void); 35 37 extern bool __pure is_quiet(void); 36 38 extern bool __pure novamap(void); 37 39 ··· 45 43 46 44 #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg) 47 45 48 - void efi_char16_printk(efi_char16_t *); 49 - void efi_char16_printk(efi_char16_t *); 46 + /* Helper macros for the usual case of using simple C variables: */ 47 + #ifndef fdt_setprop_inplace_var 48 + #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \ 49 + fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var)) 50 + #endif 50 51 51 - unsigned long get_dram_base(void); 52 + #ifndef fdt_setprop_var 53 + #define fdt_setprop_var(fdt, node_offset, name, var) \ 54 + fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var)) 55 + #endif 56 + 57 + #define get_efi_var(name, vendor, ...) \ 58 + efi_rt_call(get_variable, (efi_char16_t *)(name), \ 59 + (efi_guid_t *)(vendor), __VA_ARGS__) 60 + 61 + #define set_efi_var(name, vendor, ...) \ 62 + efi_rt_call(set_variable, (efi_char16_t *)(name), \ 63 + (efi_guid_t *)(vendor), __VA_ARGS__) 64 + 65 + #define efi_get_handle_at(array, idx) \ 66 + (efi_is_native() ? (array)[idx] \ 67 + : (efi_handle_t)(unsigned long)((u32 *)(array))[idx]) 68 + 69 + #define efi_get_handle_num(size) \ 70 + ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32))) 71 + 72 + #define for_each_efi_handle(handle, array, size, i) \ 73 + for (i = 0; \ 74 + i < efi_get_handle_num(size) && \ 75 + ((handle = efi_get_handle_at((array), i)) || true); \ 76 + i++) 77 + 78 + /* 79 + * Allocation types for calls to boottime->allocate_pages. 80 + */ 81 + #define EFI_ALLOCATE_ANY_PAGES 0 82 + #define EFI_ALLOCATE_MAX_ADDRESS 1 83 + #define EFI_ALLOCATE_ADDRESS 2 84 + #define EFI_MAX_ALLOCATE_TYPE 3 85 + 86 + /* 87 + * The type of search to perform when calling boottime->locate_handle 88 + */ 89 + #define EFI_LOCATE_ALL_HANDLES 0 90 + #define EFI_LOCATE_BY_REGISTER_NOTIFY 1 91 + #define EFI_LOCATE_BY_PROTOCOL 2 92 + 93 + struct efi_boot_memmap { 94 + efi_memory_desc_t **map; 95 + unsigned long *map_size; 96 + unsigned long *desc_size; 97 + u32 *desc_ver; 98 + unsigned long *key_ptr; 99 + unsigned long *buff_size; 100 + }; 101 + 102 + typedef struct efi_generic_dev_path efi_device_path_protocol_t; 103 + 104 + /* 105 + * EFI Boot Services table 106 + */ 107 + union efi_boot_services { 108 + struct { 109 + efi_table_hdr_t hdr; 110 + void *raise_tpl; 111 + void *restore_tpl; 112 + efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long, 113 + efi_physical_addr_t *); 114 + efi_status_t (__efiapi *free_pages)(efi_physical_addr_t, 115 + unsigned long); 116 + efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *, 117 + unsigned long *, 118 + unsigned long *, u32 *); 119 + efi_status_t (__efiapi *allocate_pool)(int, unsigned long, 120 + void **); 121 + efi_status_t (__efiapi *free_pool)(void *); 122 + void *create_event; 123 + void *set_timer; 124 + void *wait_for_event; 125 + void *signal_event; 126 + void *close_event; 127 + void *check_event; 128 + void *install_protocol_interface; 129 + void *reinstall_protocol_interface; 130 + void *uninstall_protocol_interface; 131 + efi_status_t (__efiapi *handle_protocol)(efi_handle_t, 132 + efi_guid_t *, void **); 133 + void *__reserved; 134 + void *register_protocol_notify; 135 + efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *, 136 + void *, unsigned long *, 137 + efi_handle_t *); 138 + efi_status_t (__efiapi *locate_device_path)(efi_guid_t *, 139 + efi_device_path_protocol_t **, 140 + efi_handle_t *); 141 + efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *, 142 + void *); 143 + void *load_image; 144 + void *start_image; 145 + efi_status_t __noreturn (__efiapi *exit)(efi_handle_t, 146 + efi_status_t, 147 + unsigned long, 148 + efi_char16_t *); 149 + void *unload_image; 150 + efi_status_t (__efiapi *exit_boot_services)(efi_handle_t, 151 + unsigned long); 152 + void *get_next_monotonic_count; 153 + void *stall; 154 + void *set_watchdog_timer; 155 + void *connect_controller; 156 + efi_status_t (__efiapi *disconnect_controller)(efi_handle_t, 157 + efi_handle_t, 158 + efi_handle_t); 159 + void *open_protocol; 160 + void *close_protocol; 161 + void *open_protocol_information; 162 + void *protocols_per_handle; 163 + void *locate_handle_buffer; 164 + efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, 165 + void **); 166 + void *install_multiple_protocol_interfaces; 167 + void *uninstall_multiple_protocol_interfaces; 168 + void *calculate_crc32; 169 + void *copy_mem; 170 + void *set_mem; 171 + void *create_event_ex; 172 + }; 173 + struct { 174 + efi_table_hdr_t hdr; 175 + u32 raise_tpl; 176 + u32 restore_tpl; 177 + u32 allocate_pages; 178 + u32 free_pages; 179 + u32 get_memory_map; 180 + u32 allocate_pool; 181 + u32 free_pool; 182 + u32 create_event; 183 + u32 set_timer; 184 + u32 wait_for_event; 185 + u32 signal_event; 186 + u32 close_event; 187 + u32 check_event; 188 + u32 install_protocol_interface; 189 + u32 reinstall_protocol_interface; 190 + u32 uninstall_protocol_interface; 191 + u32 handle_protocol; 192 + u32 __reserved; 193 + u32 register_protocol_notify; 194 + u32 locate_handle; 195 + u32 locate_device_path; 196 + u32 install_configuration_table; 197 + u32 load_image; 198 + u32 start_image; 199 + u32 exit; 200 + u32 unload_image; 201 + u32 exit_boot_services; 202 + u32 get_next_monotonic_count; 203 + u32 stall; 204 + u32 set_watchdog_timer; 205 + u32 connect_controller; 206 + u32 disconnect_controller; 207 + u32 open_protocol; 208 + u32 close_protocol; 209 + u32 open_protocol_information; 210 + u32 protocols_per_handle; 211 + u32 locate_handle_buffer; 212 + u32 locate_protocol; 213 + u32 install_multiple_protocol_interfaces; 214 + u32 uninstall_multiple_protocol_interfaces; 215 + u32 calculate_crc32; 216 + u32 copy_mem; 217 + u32 set_mem; 218 + u32 create_event_ex; 219 + } mixed_mode; 220 + }; 221 + 222 + typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t; 223 + 224 + union efi_uga_draw_protocol { 225 + struct { 226 + efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *, 227 + u32*, u32*, u32*, u32*); 228 + void *set_mode; 229 + void *blt; 230 + }; 231 + struct { 232 + u32 get_mode; 233 + u32 set_mode; 234 + u32 blt; 235 + } mixed_mode; 236 + }; 237 + 238 + union efi_simple_text_output_protocol { 239 + struct { 240 + void *reset; 241 + efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *, 242 + efi_char16_t *); 243 + void *test_string; 244 + }; 245 + struct { 246 + u32 reset; 247 + u32 output_string; 248 + u32 test_string; 249 + } mixed_mode; 250 + }; 251 + 252 + #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 253 + #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 254 + #define PIXEL_BIT_MASK 2 255 + #define PIXEL_BLT_ONLY 3 256 + #define PIXEL_FORMAT_MAX 4 257 + 258 + typedef struct { 259 + u32 red_mask; 260 + u32 green_mask; 261 + u32 blue_mask; 262 + u32 reserved_mask; 263 + } efi_pixel_bitmask_t; 264 + 265 + typedef struct { 266 + u32 version; 267 + u32 horizontal_resolution; 268 + u32 vertical_resolution; 269 + int pixel_format; 270 + efi_pixel_bitmask_t pixel_information; 271 + u32 pixels_per_scan_line; 272 + } efi_graphics_output_mode_info_t; 273 + 274 + typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t; 275 + 276 + union efi_graphics_output_protocol_mode { 277 + struct { 278 + u32 max_mode; 279 + u32 mode; 280 + efi_graphics_output_mode_info_t *info; 281 + unsigned long size_of_info; 282 + efi_physical_addr_t frame_buffer_base; 283 + unsigned long frame_buffer_size; 284 + }; 285 + struct { 286 + u32 max_mode; 287 + u32 mode; 288 + u32 info; 289 + u32 size_of_info; 290 + u64 frame_buffer_base; 291 + u32 frame_buffer_size; 292 + } mixed_mode; 293 + }; 294 + 295 + typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t; 296 + 297 + union efi_graphics_output_protocol { 298 + struct { 299 + void *query_mode; 300 + void *set_mode; 301 + void *blt; 302 + efi_graphics_output_protocol_mode_t *mode; 303 + }; 304 + struct { 305 + u32 query_mode; 306 + u32 set_mode; 307 + u32 blt; 308 + u32 mode; 309 + } mixed_mode; 310 + }; 311 + 312 + typedef union { 313 + struct { 314 + u32 revision; 315 + efi_handle_t parent_handle; 316 + efi_system_table_t *system_table; 317 + efi_handle_t device_handle; 318 + void *file_path; 319 + void *reserved; 320 + u32 load_options_size; 321 + void *load_options; 322 + void *image_base; 323 + __aligned_u64 image_size; 324 + unsigned int image_code_type; 325 + unsigned int image_data_type; 326 + efi_status_t (__efiapi *unload)(efi_handle_t image_handle); 327 + }; 328 + struct { 329 + u32 revision; 330 + u32 parent_handle; 331 + u32 system_table; 332 + u32 device_handle; 333 + u32 file_path; 334 + u32 reserved; 335 + u32 load_options_size; 336 + u32 load_options; 337 + u32 image_base; 338 + __aligned_u64 image_size; 339 + u32 image_code_type; 340 + u32 image_data_type; 341 + u32 unload; 342 + } mixed_mode; 343 + } efi_loaded_image_t; 344 + 345 + typedef struct { 346 + u64 size; 347 + u64 file_size; 348 + u64 phys_size; 349 + efi_time_t create_time; 350 + efi_time_t last_access_time; 351 + efi_time_t modification_time; 352 + __aligned_u64 attribute; 353 + efi_char16_t filename[]; 354 + } efi_file_info_t; 355 + 356 + typedef struct efi_file_protocol efi_file_protocol_t; 357 + 358 + struct efi_file_protocol { 359 + u64 revision; 360 + efi_status_t (__efiapi *open) (efi_file_protocol_t *, 361 + efi_file_protocol_t **, 362 + efi_char16_t *, u64, u64); 363 + efi_status_t (__efiapi *close) (efi_file_protocol_t *); 364 + efi_status_t (__efiapi *delete) (efi_file_protocol_t *); 365 + efi_status_t (__efiapi *read) (efi_file_protocol_t *, 366 + unsigned long *, void *); 367 + efi_status_t (__efiapi *write) (efi_file_protocol_t *, 368 + unsigned long, void *); 369 + efi_status_t (__efiapi *get_position)(efi_file_protocol_t *, u64 *); 370 + efi_status_t (__efiapi *set_position)(efi_file_protocol_t *, u64); 371 + efi_status_t (__efiapi *get_info) (efi_file_protocol_t *, 372 + efi_guid_t *, unsigned long *, 373 + void *); 374 + efi_status_t (__efiapi *set_info) (efi_file_protocol_t *, 375 + efi_guid_t *, unsigned long, 376 + void *); 377 + efi_status_t (__efiapi *flush) (efi_file_protocol_t *); 378 + }; 379 + 380 + typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t; 381 + 382 + struct efi_simple_file_system_protocol { 383 + u64 revision; 384 + int (__efiapi *open_volume)(efi_simple_file_system_protocol_t *, 385 + efi_file_protocol_t **); 386 + }; 387 + 388 + #define EFI_FILE_MODE_READ 0x0000000000000001 389 + #define EFI_FILE_MODE_WRITE 0x0000000000000002 390 + #define EFI_FILE_MODE_CREATE 0x8000000000000000 391 + 392 + typedef enum { 393 + EfiPciIoWidthUint8, 394 + EfiPciIoWidthUint16, 395 + EfiPciIoWidthUint32, 396 + EfiPciIoWidthUint64, 397 + EfiPciIoWidthFifoUint8, 398 + EfiPciIoWidthFifoUint16, 399 + EfiPciIoWidthFifoUint32, 400 + EfiPciIoWidthFifoUint64, 401 + EfiPciIoWidthFillUint8, 402 + EfiPciIoWidthFillUint16, 403 + EfiPciIoWidthFillUint32, 404 + EfiPciIoWidthFillUint64, 405 + EfiPciIoWidthMaximum 406 + } EFI_PCI_IO_PROTOCOL_WIDTH; 407 + 408 + typedef enum { 409 + EfiPciIoAttributeOperationGet, 410 + EfiPciIoAttributeOperationSet, 411 + EfiPciIoAttributeOperationEnable, 412 + EfiPciIoAttributeOperationDisable, 413 + EfiPciIoAttributeOperationSupported, 414 + EfiPciIoAttributeOperationMaximum 415 + } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION; 416 + 417 + typedef struct { 418 + u32 read; 419 + u32 write; 420 + } efi_pci_io_protocol_access_32_t; 421 + 422 + typedef union efi_pci_io_protocol efi_pci_io_protocol_t; 423 + 424 + typedef 425 + efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *, 426 + EFI_PCI_IO_PROTOCOL_WIDTH, 427 + u32 offset, 428 + unsigned long count, 429 + void *buffer); 430 + 431 + typedef struct { 432 + void *read; 433 + void *write; 434 + } efi_pci_io_protocol_access_t; 435 + 436 + typedef struct { 437 + efi_pci_io_protocol_cfg_t read; 438 + efi_pci_io_protocol_cfg_t write; 439 + } efi_pci_io_protocol_config_access_t; 440 + 441 + union efi_pci_io_protocol { 442 + struct { 443 + void *poll_mem; 444 + void *poll_io; 445 + efi_pci_io_protocol_access_t mem; 446 + efi_pci_io_protocol_access_t io; 447 + efi_pci_io_protocol_config_access_t pci; 448 + void *copy_mem; 449 + void *map; 450 + void *unmap; 451 + void *allocate_buffer; 452 + void *free_buffer; 453 + void *flush; 454 + efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *, 455 + unsigned long *segment_nr, 456 + unsigned long *bus_nr, 457 + unsigned long *device_nr, 458 + unsigned long *func_nr); 459 + void *attributes; 460 + void *get_bar_attributes; 461 + void *set_bar_attributes; 462 + uint64_t romsize; 463 + void *romimage; 464 + }; 465 + struct { 466 + u32 poll_mem; 467 + u32 poll_io; 468 + efi_pci_io_protocol_access_32_t mem; 469 + efi_pci_io_protocol_access_32_t io; 470 + efi_pci_io_protocol_access_32_t pci; 471 + u32 copy_mem; 472 + u32 map; 473 + u32 unmap; 474 + u32 allocate_buffer; 475 + u32 free_buffer; 476 + u32 flush; 477 + u32 get_location; 478 + u32 attributes; 479 + u32 get_bar_attributes; 480 + u32 set_bar_attributes; 481 + u64 romsize; 482 + u32 romimage; 483 + } mixed_mode; 484 + }; 485 + 486 + #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001 487 + #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002 488 + #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004 489 + #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008 490 + #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010 491 + #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020 492 + #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040 493 + #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080 494 + #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100 495 + #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200 496 + #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400 497 + #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800 498 + #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000 499 + #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000 500 + #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000 501 + #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000 502 + #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000 503 + #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000 504 + #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000 505 + 506 + struct efi_dev_path; 507 + 508 + typedef union apple_properties_protocol apple_properties_protocol_t; 509 + 510 + union apple_properties_protocol { 511 + struct { 512 + unsigned long version; 513 + efi_status_t (__efiapi *get)(apple_properties_protocol_t *, 514 + struct efi_dev_path *, 515 + efi_char16_t *, void *, u32 *); 516 + efi_status_t (__efiapi *set)(apple_properties_protocol_t *, 517 + struct efi_dev_path *, 518 + efi_char16_t *, void *, u32); 519 + efi_status_t (__efiapi *del)(apple_properties_protocol_t *, 520 + struct efi_dev_path *, 521 + efi_char16_t *); 522 + efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *, 523 + void *buffer, u32 *); 524 + }; 525 + struct { 526 + u32 version; 527 + u32 get; 528 + u32 set; 529 + u32 del; 530 + u32 get_all; 531 + } mixed_mode; 532 + }; 533 + 534 + typedef u32 efi_tcg2_event_log_format; 535 + 536 + typedef union efi_tcg2_protocol efi_tcg2_protocol_t; 537 + 538 + union efi_tcg2_protocol { 539 + struct { 540 + void *get_capability; 541 + efi_status_t (__efiapi *get_event_log)(efi_handle_t, 542 + efi_tcg2_event_log_format, 543 + efi_physical_addr_t *, 544 + efi_physical_addr_t *, 545 + efi_bool_t *); 546 + void *hash_log_extend_event; 547 + void *submit_command; 548 + void *get_active_pcr_banks; 549 + void *set_active_pcr_banks; 550 + void *get_result_of_set_active_pcr_banks; 551 + }; 552 + struct { 553 + u32 get_capability; 554 + u32 get_event_log; 555 + u32 hash_log_extend_event; 556 + u32 submit_command; 557 + u32 get_active_pcr_banks; 558 + u32 set_active_pcr_banks; 559 + u32 get_result_of_set_active_pcr_banks; 560 + } mixed_mode; 561 + }; 562 + 563 + typedef union efi_load_file_protocol efi_load_file_protocol_t; 564 + typedef union efi_load_file_protocol efi_load_file2_protocol_t; 565 + 566 + union efi_load_file_protocol { 567 + struct { 568 + efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *, 569 + efi_device_path_protocol_t *, 570 + bool, unsigned long *, void *); 571 + }; 572 + struct { 573 + u32 load_file; 574 + } mixed_mode; 575 + }; 576 + 577 + void efi_pci_disable_bridge_busmaster(void); 578 + 579 + typedef efi_status_t (*efi_exit_boot_map_processing)( 580 + struct efi_boot_memmap *map, 581 + void *priv); 582 + 583 + efi_status_t efi_exit_boot_services(void *handle, 584 + struct efi_boot_memmap *map, 585 + void *priv, 586 + efi_exit_boot_map_processing priv_func); 587 + 588 + void efi_char16_printk(efi_char16_t *); 52 589 53 590 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, 54 591 unsigned long *new_fdt_addr, ··· 612 71 613 72 void *get_efi_config_table(efi_guid_t guid); 614 73 615 - /* Helper macros for the usual case of using simple C variables: */ 616 - #ifndef fdt_setprop_inplace_var 617 - #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \ 618 - fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var)) 619 - #endif 74 + void efi_printk(char *str); 620 75 621 - #ifndef fdt_setprop_var 622 - #define fdt_setprop_var(fdt, node_offset, name, var) \ 623 - fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var)) 624 - #endif 76 + void efi_free(unsigned long size, unsigned long addr); 625 77 626 - #define get_efi_var(name, vendor, ...) \ 627 - efi_rt_call(get_variable, (efi_char16_t *)(name), \ 628 - (efi_guid_t *)(vendor), __VA_ARGS__) 78 + char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len, 79 + unsigned long max_addr); 629 80 630 - #define set_efi_var(name, vendor, ...) \ 631 - efi_rt_call(set_variable, (efi_char16_t *)(name), \ 632 - (efi_guid_t *)(vendor), __VA_ARGS__) 81 + efi_status_t efi_get_memory_map(struct efi_boot_memmap *map); 82 + 83 + efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, 84 + unsigned long *addr, unsigned long min); 85 + 86 + static inline 87 + efi_status_t efi_low_alloc(unsigned long size, unsigned long align, 88 + unsigned long *addr) 89 + { 90 + /* 91 + * Don't allocate at 0x0. It will confuse code that 92 + * checks pointers against NULL. Skip the first 8 93 + * bytes so we start at a nice even number. 94 + */ 95 + return efi_low_alloc_above(size, align, addr, 0x8); 96 + } 97 + 98 + efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr, 99 + unsigned long max); 100 + 101 + efi_status_t efi_relocate_kernel(unsigned long *image_addr, 102 + unsigned long image_size, 103 + unsigned long alloc_size, 104 + unsigned long preferred_addr, 105 + unsigned long alignment, 106 + unsigned long min_addr); 107 + 108 + efi_status_t efi_parse_options(char const *cmdline); 109 + 110 + efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, 111 + unsigned long size); 112 + 113 + efi_status_t efi_load_dtb(efi_loaded_image_t *image, 114 + unsigned long *load_addr, 115 + unsigned long *load_size); 116 + 117 + efi_status_t efi_load_initrd(efi_loaded_image_t *image, 118 + unsigned long *load_addr, 119 + unsigned long *load_size, 120 + unsigned long soft_limit, 121 + unsigned long hard_limit); 122 + 123 + efi_status_t efi_load_initrd_dev_path(unsigned long *load_addr, 124 + unsigned long *load_size, 125 + unsigned long max); 633 126 634 127 #endif
+1 -6
drivers/firmware/efi/libstub/fdt.c
··· 199 199 return EFI_SUCCESS; 200 200 } 201 201 202 - #ifndef EFI_FDT_ALIGN 203 - # define EFI_FDT_ALIGN EFI_PAGE_SIZE 204 - #endif 205 - 206 202 struct exit_boot_struct { 207 203 efi_memory_desc_t *runtime_map; 208 204 int *runtime_entry_count; ··· 277 281 pr_efi("Exiting boot services and installing virtual address map...\n"); 278 282 279 283 map.map = &memory_map; 280 - status = efi_high_alloc(MAX_FDT_SIZE, EFI_FDT_ALIGN, 281 - new_fdt_addr, max_addr); 284 + status = efi_allocate_pages(MAX_FDT_SIZE, new_fdt_addr, max_addr); 282 285 if (status != EFI_SUCCESS) { 283 286 pr_efi_err("Unable to allocate memory for new device tree.\n"); 284 287 goto fail;
+258
drivers/firmware/efi/libstub/file.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Helper functions used by the EFI stub on multiple 4 + * architectures. This should be #included by the EFI stub 5 + * implementation files. 6 + * 7 + * Copyright 2011 Intel Corporation; author Matt Fleming 8 + */ 9 + 10 + #include <linux/efi.h> 11 + #include <asm/efi.h> 12 + 13 + #include "efistub.h" 14 + 15 + #define MAX_FILENAME_SIZE 256 16 + 17 + /* 18 + * Some firmware implementations have problems reading files in one go. 19 + * A read chunk size of 1MB seems to work for most platforms. 20 + * 21 + * Unfortunately, reading files in chunks triggers *other* bugs on some 22 + * platforms, so we provide a way to disable this workaround, which can 23 + * be done by passing "efi=nochunk" on the EFI boot stub command line. 24 + * 25 + * If you experience issues with initrd images being corrupt it's worth 26 + * trying efi=nochunk, but chunking is enabled by default on x86 because 27 + * there are far more machines that require the workaround than those that 28 + * break with it enabled. 29 + */ 30 + #define EFI_READ_CHUNK_SIZE SZ_1M 31 + 32 + static efi_status_t efi_open_file(efi_file_protocol_t *volume, 33 + efi_char16_t *filename_16, 34 + efi_file_protocol_t **handle, 35 + unsigned long *file_size) 36 + { 37 + struct { 38 + efi_file_info_t info; 39 + efi_char16_t filename[MAX_FILENAME_SIZE]; 40 + } finfo; 41 + efi_guid_t info_guid = EFI_FILE_INFO_ID; 42 + efi_file_protocol_t *fh; 43 + unsigned long info_sz; 44 + efi_status_t status; 45 + 46 + status = volume->open(volume, &fh, filename_16, EFI_FILE_MODE_READ, 0); 47 + if (status != EFI_SUCCESS) { 48 + pr_efi_err("Failed to open file: "); 49 + efi_char16_printk(filename_16); 50 + efi_printk("\n"); 51 + return status; 52 + } 53 + 54 + info_sz = sizeof(finfo); 55 + status = fh->get_info(fh, &info_guid, &info_sz, &finfo); 56 + if (status != EFI_SUCCESS) { 57 + pr_efi_err("Failed to get file info\n"); 58 + fh->close(fh); 59 + return status; 60 + } 61 + 62 + *handle = fh; 63 + *file_size = finfo.info.file_size; 64 + return EFI_SUCCESS; 65 + } 66 + 67 + static efi_status_t efi_open_volume(efi_loaded_image_t *image, 68 + efi_file_protocol_t **fh) 69 + { 70 + efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; 71 + efi_simple_file_system_protocol_t *io; 72 + efi_status_t status; 73 + 74 + status = efi_bs_call(handle_protocol, image->device_handle, &fs_proto, 75 + (void **)&io); 76 + if (status != EFI_SUCCESS) { 77 + pr_efi_err("Failed to handle fs_proto\n"); 78 + return status; 79 + } 80 + 81 + status = io->open_volume(io, fh); 82 + if (status != EFI_SUCCESS) 83 + pr_efi_err("Failed to open volume\n"); 84 + 85 + return status; 86 + } 87 + 88 + static int find_file_option(const efi_char16_t *cmdline, int cmdline_len, 89 + const efi_char16_t *prefix, int prefix_size, 90 + efi_char16_t *result, int result_len) 91 + { 92 + int prefix_len = prefix_size / 2; 93 + bool found = false; 94 + int i; 95 + 96 + for (i = prefix_len; i < cmdline_len; i++) { 97 + if (!memcmp(&cmdline[i - prefix_len], prefix, prefix_size)) { 98 + found = true; 99 + break; 100 + } 101 + } 102 + 103 + if (!found) 104 + return 0; 105 + 106 + while (--result_len > 0 && i < cmdline_len) { 107 + if (cmdline[i] == L'\0' || 108 + cmdline[i] == L'\n' || 109 + cmdline[i] == L' ') 110 + break; 111 + *result++ = cmdline[i++]; 112 + } 113 + *result = L'\0'; 114 + return i; 115 + } 116 + 117 + /* 118 + * Check the cmdline for a LILO-style file= arguments. 119 + * 120 + * We only support loading a file from the same filesystem as 121 + * the kernel image. 122 + */ 123 + static efi_status_t handle_cmdline_files(efi_loaded_image_t *image, 124 + const efi_char16_t *optstr, 125 + int optstr_size, 126 + unsigned long soft_limit, 127 + unsigned long hard_limit, 128 + unsigned long *load_addr, 129 + unsigned long *load_size) 130 + { 131 + const efi_char16_t *cmdline = image->load_options; 132 + int cmdline_len = image->load_options_size / 2; 133 + unsigned long efi_chunk_size = ULONG_MAX; 134 + efi_file_protocol_t *volume = NULL; 135 + efi_file_protocol_t *file; 136 + unsigned long alloc_addr; 137 + unsigned long alloc_size; 138 + efi_status_t status; 139 + int offset; 140 + 141 + if (!load_addr || !load_size) 142 + return EFI_INVALID_PARAMETER; 143 + 144 + if (IS_ENABLED(CONFIG_X86) && !nochunk()) 145 + efi_chunk_size = EFI_READ_CHUNK_SIZE; 146 + 147 + alloc_addr = alloc_size = 0; 148 + do { 149 + efi_char16_t filename[MAX_FILENAME_SIZE]; 150 + unsigned long size; 151 + void *addr; 152 + 153 + offset = find_file_option(cmdline, cmdline_len, 154 + optstr, optstr_size, 155 + filename, ARRAY_SIZE(filename)); 156 + 157 + if (!offset) 158 + break; 159 + 160 + cmdline += offset; 161 + cmdline_len -= offset; 162 + 163 + if (!volume) { 164 + status = efi_open_volume(image, &volume); 165 + if (status != EFI_SUCCESS) 166 + return status; 167 + } 168 + 169 + status = efi_open_file(volume, filename, &file, &size); 170 + if (status != EFI_SUCCESS) 171 + goto err_close_volume; 172 + 173 + /* 174 + * Check whether the existing allocation can contain the next 175 + * file. This condition will also trigger naturally during the 176 + * first (and typically only) iteration of the loop, given that 177 + * alloc_size == 0 in that case. 178 + */ 179 + if (round_up(alloc_size + size, EFI_ALLOC_ALIGN) > 180 + round_up(alloc_size, EFI_ALLOC_ALIGN)) { 181 + unsigned long old_addr = alloc_addr; 182 + 183 + status = EFI_OUT_OF_RESOURCES; 184 + if (soft_limit < hard_limit) 185 + status = efi_allocate_pages(alloc_size + size, 186 + &alloc_addr, 187 + soft_limit); 188 + if (status == EFI_OUT_OF_RESOURCES) 189 + status = efi_allocate_pages(alloc_size + size, 190 + &alloc_addr, 191 + hard_limit); 192 + if (status != EFI_SUCCESS) { 193 + pr_efi_err("Failed to allocate memory for files\n"); 194 + goto err_close_file; 195 + } 196 + 197 + if (old_addr != 0) { 198 + /* 199 + * This is not the first time we've gone 200 + * around this loop, and so we are loading 201 + * multiple files that need to be concatenated 202 + * and returned in a single buffer. 203 + */ 204 + memcpy((void *)alloc_addr, (void *)old_addr, alloc_size); 205 + efi_free(alloc_size, old_addr); 206 + } 207 + } 208 + 209 + addr = (void *)alloc_addr + alloc_size; 210 + alloc_size += size; 211 + 212 + while (size) { 213 + unsigned long chunksize = min(size, efi_chunk_size); 214 + 215 + status = file->read(file, &chunksize, addr); 216 + if (status != EFI_SUCCESS) { 217 + pr_efi_err("Failed to read file\n"); 218 + goto err_close_file; 219 + } 220 + addr += chunksize; 221 + size -= chunksize; 222 + } 223 + file->close(file); 224 + } while (offset > 0); 225 + 226 + *load_addr = alloc_addr; 227 + *load_size = alloc_size; 228 + 229 + if (volume) 230 + volume->close(volume); 231 + return EFI_SUCCESS; 232 + 233 + err_close_file: 234 + file->close(file); 235 + 236 + err_close_volume: 237 + volume->close(volume); 238 + efi_free(alloc_size, alloc_addr); 239 + return status; 240 + } 241 + 242 + efi_status_t efi_load_dtb(efi_loaded_image_t *image, 243 + unsigned long *load_addr, 244 + unsigned long *load_size) 245 + { 246 + return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2, 247 + ULONG_MAX, ULONG_MAX, load_addr, load_size); 248 + } 249 + 250 + efi_status_t efi_load_initrd(efi_loaded_image_t *image, 251 + unsigned long *load_addr, 252 + unsigned long *load_size, 253 + unsigned long soft_limit, 254 + unsigned long hard_limit) 255 + { 256 + return handle_cmdline_files(image, L"initrd=", sizeof(L"initrd=") - 2, 257 + soft_limit, hard_limit, load_addr, load_size); 258 + }
+6
drivers/firmware/efi/libstub/hidden.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * To prevent the compiler from emitting GOT-indirected (and thus absolute) 4 + * references to any global symbols, override their visibility as 'hidden' 5 + */ 6 + #pragma GCC visibility push(hidden)
+309
drivers/firmware/efi/libstub/mem.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/efi.h> 4 + #include <asm/efi.h> 5 + 6 + #include "efistub.h" 7 + 8 + #define EFI_MMAP_NR_SLACK_SLOTS 8 9 + 10 + static inline bool mmap_has_headroom(unsigned long buff_size, 11 + unsigned long map_size, 12 + unsigned long desc_size) 13 + { 14 + unsigned long slack = buff_size - map_size; 15 + 16 + return slack / desc_size >= EFI_MMAP_NR_SLACK_SLOTS; 17 + } 18 + 19 + /** 20 + * efi_get_memory_map() - get memory map 21 + * @map: on return pointer to memory map 22 + * 23 + * Retrieve the UEFI memory map. The allocated memory leaves room for 24 + * up to EFI_MMAP_NR_SLACK_SLOTS additional memory map entries. 25 + * 26 + * Return: status code 27 + */ 28 + efi_status_t efi_get_memory_map(struct efi_boot_memmap *map) 29 + { 30 + efi_memory_desc_t *m = NULL; 31 + efi_status_t status; 32 + unsigned long key; 33 + u32 desc_version; 34 + 35 + *map->desc_size = sizeof(*m); 36 + *map->map_size = *map->desc_size * 32; 37 + *map->buff_size = *map->map_size; 38 + again: 39 + status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, 40 + *map->map_size, (void **)&m); 41 + if (status != EFI_SUCCESS) 42 + goto fail; 43 + 44 + *map->desc_size = 0; 45 + key = 0; 46 + status = efi_bs_call(get_memory_map, map->map_size, m, 47 + &key, map->desc_size, &desc_version); 48 + if (status == EFI_BUFFER_TOO_SMALL || 49 + !mmap_has_headroom(*map->buff_size, *map->map_size, 50 + *map->desc_size)) { 51 + efi_bs_call(free_pool, m); 52 + /* 53 + * Make sure there is some entries of headroom so that the 54 + * buffer can be reused for a new map after allocations are 55 + * no longer permitted. Its unlikely that the map will grow to 56 + * exceed this headroom once we are ready to trigger 57 + * ExitBootServices() 58 + */ 59 + *map->map_size += *map->desc_size * EFI_MMAP_NR_SLACK_SLOTS; 60 + *map->buff_size = *map->map_size; 61 + goto again; 62 + } 63 + 64 + if (status == EFI_SUCCESS) { 65 + if (map->key_ptr) 66 + *map->key_ptr = key; 67 + if (map->desc_ver) 68 + *map->desc_ver = desc_version; 69 + } else { 70 + efi_bs_call(free_pool, m); 71 + } 72 + 73 + fail: 74 + *map->map = m; 75 + return status; 76 + } 77 + 78 + /** 79 + * efi_allocate_pages() - Allocate memory pages 80 + * @size: minimum number of bytes to allocate 81 + * @addr: On return the address of the first allocated page. The first 82 + * allocated page has alignment EFI_ALLOC_ALIGN which is an 83 + * architecture dependent multiple of the page size. 84 + * @max: the address that the last allocated memory page shall not 85 + * exceed 86 + * 87 + * Allocate pages as EFI_LOADER_DATA. The allocated pages are aligned according 88 + * to EFI_ALLOC_ALIGN. The last allocated page will not exceed the address 89 + * given by @max. 90 + * 91 + * Return: status code 92 + */ 93 + efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr, 94 + unsigned long max) 95 + { 96 + efi_physical_addr_t alloc_addr = ALIGN_DOWN(max + 1, EFI_ALLOC_ALIGN) - 1; 97 + int slack = EFI_ALLOC_ALIGN / EFI_PAGE_SIZE - 1; 98 + efi_status_t status; 99 + 100 + size = round_up(size, EFI_ALLOC_ALIGN); 101 + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_MAX_ADDRESS, 102 + EFI_LOADER_DATA, size / EFI_PAGE_SIZE + slack, 103 + &alloc_addr); 104 + if (status != EFI_SUCCESS) 105 + return status; 106 + 107 + *addr = ALIGN((unsigned long)alloc_addr, EFI_ALLOC_ALIGN); 108 + 109 + if (slack > 0) { 110 + int l = (alloc_addr % EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; 111 + 112 + if (l) { 113 + efi_bs_call(free_pages, alloc_addr, slack - l + 1); 114 + slack = l - 1; 115 + } 116 + if (slack) 117 + efi_bs_call(free_pages, *addr + size, slack); 118 + } 119 + return EFI_SUCCESS; 120 + } 121 + /** 122 + * efi_low_alloc_above() - allocate pages at or above given address 123 + * @size: size of the memory area to allocate 124 + * @align: minimum alignment of the allocated memory area. It should 125 + * a power of two. 126 + * @addr: on exit the address of the allocated memory 127 + * @min: minimum address to used for the memory allocation 128 + * 129 + * Allocate at the lowest possible address that is not below @min as 130 + * EFI_LOADER_DATA. The allocated pages are aligned according to @align but at 131 + * least EFI_ALLOC_ALIGN. The first allocated page will not below the address 132 + * given by @min. 133 + * 134 + * Return: status code 135 + */ 136 + efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, 137 + unsigned long *addr, unsigned long min) 138 + { 139 + unsigned long map_size, desc_size, buff_size; 140 + efi_memory_desc_t *map; 141 + efi_status_t status; 142 + unsigned long nr_pages; 143 + int i; 144 + struct efi_boot_memmap boot_map; 145 + 146 + boot_map.map = &map; 147 + boot_map.map_size = &map_size; 148 + boot_map.desc_size = &desc_size; 149 + boot_map.desc_ver = NULL; 150 + boot_map.key_ptr = NULL; 151 + boot_map.buff_size = &buff_size; 152 + 153 + status = efi_get_memory_map(&boot_map); 154 + if (status != EFI_SUCCESS) 155 + goto fail; 156 + 157 + /* 158 + * Enforce minimum alignment that EFI or Linux requires when 159 + * requesting a specific address. We are doing page-based (or 160 + * larger) allocations, and both the address and size must meet 161 + * alignment constraints. 162 + */ 163 + if (align < EFI_ALLOC_ALIGN) 164 + align = EFI_ALLOC_ALIGN; 165 + 166 + size = round_up(size, EFI_ALLOC_ALIGN); 167 + nr_pages = size / EFI_PAGE_SIZE; 168 + for (i = 0; i < map_size / desc_size; i++) { 169 + efi_memory_desc_t *desc; 170 + unsigned long m = (unsigned long)map; 171 + u64 start, end; 172 + 173 + desc = efi_early_memdesc_ptr(m, desc_size, i); 174 + 175 + if (desc->type != EFI_CONVENTIONAL_MEMORY) 176 + continue; 177 + 178 + if (efi_soft_reserve_enabled() && 179 + (desc->attribute & EFI_MEMORY_SP)) 180 + continue; 181 + 182 + if (desc->num_pages < nr_pages) 183 + continue; 184 + 185 + start = desc->phys_addr; 186 + end = start + desc->num_pages * EFI_PAGE_SIZE; 187 + 188 + if (start < min) 189 + start = min; 190 + 191 + start = round_up(start, align); 192 + if ((start + size) > end) 193 + continue; 194 + 195 + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 196 + EFI_LOADER_DATA, nr_pages, &start); 197 + if (status == EFI_SUCCESS) { 198 + *addr = start; 199 + break; 200 + } 201 + } 202 + 203 + if (i == map_size / desc_size) 204 + status = EFI_NOT_FOUND; 205 + 206 + efi_bs_call(free_pool, map); 207 + fail: 208 + return status; 209 + } 210 + 211 + /** 212 + * efi_free() - free memory pages 213 + * @size: size of the memory area to free in bytes 214 + * @addr: start of the memory area to free (must be EFI_PAGE_SIZE 215 + * aligned) 216 + * 217 + * @size is rounded up to a multiple of EFI_ALLOC_ALIGN which is an 218 + * architecture specific multiple of EFI_PAGE_SIZE. So this function should 219 + * only be used to return pages allocated with efi_allocate_pages() or 220 + * efi_low_alloc_above(). 221 + */ 222 + void efi_free(unsigned long size, unsigned long addr) 223 + { 224 + unsigned long nr_pages; 225 + 226 + if (!size) 227 + return; 228 + 229 + nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; 230 + efi_bs_call(free_pages, addr, nr_pages); 231 + } 232 + 233 + /** 234 + * efi_relocate_kernel() - copy memory area 235 + * @image_addr: pointer to address of memory area to copy 236 + * @image_size: size of memory area to copy 237 + * @alloc_size: minimum size of memory to allocate, must be greater or 238 + * equal to image_size 239 + * @preferred_addr: preferred target address 240 + * @alignment: minimum alignment of the allocated memory area. It 241 + * should be a power of two. 242 + * @min_addr: minimum target address 243 + * 244 + * Copy a memory area to a newly allocated memory area aligned according 245 + * to @alignment but at least EFI_ALLOC_ALIGN. If the preferred address 246 + * is not available, the allocated address will not be below @min_addr. 247 + * On exit, @image_addr is updated to the target copy address that was used. 248 + * 249 + * This function is used to copy the Linux kernel verbatim. It does not apply 250 + * any relocation changes. 251 + * 252 + * Return: status code 253 + */ 254 + efi_status_t efi_relocate_kernel(unsigned long *image_addr, 255 + unsigned long image_size, 256 + unsigned long alloc_size, 257 + unsigned long preferred_addr, 258 + unsigned long alignment, 259 + unsigned long min_addr) 260 + { 261 + unsigned long cur_image_addr; 262 + unsigned long new_addr = 0; 263 + efi_status_t status; 264 + unsigned long nr_pages; 265 + efi_physical_addr_t efi_addr = preferred_addr; 266 + 267 + if (!image_addr || !image_size || !alloc_size) 268 + return EFI_INVALID_PARAMETER; 269 + if (alloc_size < image_size) 270 + return EFI_INVALID_PARAMETER; 271 + 272 + cur_image_addr = *image_addr; 273 + 274 + /* 275 + * The EFI firmware loader could have placed the kernel image 276 + * anywhere in memory, but the kernel has restrictions on the 277 + * max physical address it can run at. Some architectures 278 + * also have a prefered address, so first try to relocate 279 + * to the preferred address. If that fails, allocate as low 280 + * as possible while respecting the required alignment. 281 + */ 282 + nr_pages = round_up(alloc_size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; 283 + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 284 + EFI_LOADER_DATA, nr_pages, &efi_addr); 285 + new_addr = efi_addr; 286 + /* 287 + * If preferred address allocation failed allocate as low as 288 + * possible. 289 + */ 290 + if (status != EFI_SUCCESS) { 291 + status = efi_low_alloc_above(alloc_size, alignment, &new_addr, 292 + min_addr); 293 + } 294 + if (status != EFI_SUCCESS) { 295 + pr_efi_err("Failed to allocate usable memory for kernel.\n"); 296 + return status; 297 + } 298 + 299 + /* 300 + * We know source/dest won't overlap since both memory ranges 301 + * have been allocated by UEFI, so we can safely use memcpy. 302 + */ 303 + memcpy((void *)new_addr, (void *)cur_image_addr, image_size); 304 + 305 + /* Return the new address of the relocated image. */ 306 + *image_addr = new_addr; 307 + 308 + return status; 309 + }
+23 -113
drivers/firmware/efi/libstub/random.c
··· 4 4 */ 5 5 6 6 #include <linux/efi.h> 7 - #include <linux/log2.h> 8 7 #include <asm/efi.h> 9 8 10 9 #include "efistub.h" ··· 25 26 } mixed_mode; 26 27 }; 27 28 29 + /** 30 + * efi_get_random_bytes() - fill a buffer with random bytes 31 + * @size: size of the buffer 32 + * @out: caller allocated buffer to receive the random bytes 33 + * 34 + * The call will fail if either the firmware does not implement the 35 + * EFI_RNG_PROTOCOL or there are not enough random bytes available to fill 36 + * the buffer. 37 + * 38 + * Return: status code 39 + */ 28 40 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out) 29 41 { 30 42 efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID; ··· 49 39 return efi_call_proto(rng, get_rng, NULL, size, out); 50 40 } 51 41 52 - /* 53 - * Return the number of slots covered by this entry, i.e., the number of 54 - * addresses it covers that are suitably aligned and supply enough room 55 - * for the allocation. 42 + /** 43 + * efi_random_get_seed() - provide random seed as configuration table 44 + * 45 + * The EFI_RNG_PROTOCOL is used to read random bytes. These random bytes are 46 + * saved as a configuration table which can be used as entropy by the kernel 47 + * for the initialization of its pseudo random number generator. 48 + * 49 + * If the EFI_RNG_PROTOCOL is not available or there are not enough random bytes 50 + * available, the configuration table will not be installed and an error code 51 + * will be returned. 52 + * 53 + * Return: status code 56 54 */ 57 - static unsigned long get_entry_num_slots(efi_memory_desc_t *md, 58 - unsigned long size, 59 - unsigned long align_shift) 60 - { 61 - unsigned long align = 1UL << align_shift; 62 - u64 first_slot, last_slot, region_end; 63 - 64 - if (md->type != EFI_CONVENTIONAL_MEMORY) 65 - return 0; 66 - 67 - if (efi_soft_reserve_enabled() && 68 - (md->attribute & EFI_MEMORY_SP)) 69 - return 0; 70 - 71 - region_end = min((u64)ULONG_MAX, md->phys_addr + md->num_pages*EFI_PAGE_SIZE - 1); 72 - 73 - first_slot = round_up(md->phys_addr, align); 74 - last_slot = round_down(region_end - size + 1, align); 75 - 76 - if (first_slot > last_slot) 77 - return 0; 78 - 79 - return ((unsigned long)(last_slot - first_slot) >> align_shift) + 1; 80 - } 81 - 82 - /* 83 - * The UEFI memory descriptors have a virtual address field that is only used 84 - * when installing the virtual mapping using SetVirtualAddressMap(). Since it 85 - * is unused here, we can reuse it to keep track of each descriptor's slot 86 - * count. 87 - */ 88 - #define MD_NUM_SLOTS(md) ((md)->virt_addr) 89 - 90 - efi_status_t efi_random_alloc(unsigned long size, 91 - unsigned long align, 92 - unsigned long *addr, 93 - unsigned long random_seed) 94 - { 95 - unsigned long map_size, desc_size, total_slots = 0, target_slot; 96 - unsigned long buff_size; 97 - efi_status_t status; 98 - efi_memory_desc_t *memory_map; 99 - int map_offset; 100 - struct efi_boot_memmap map; 101 - 102 - map.map = &memory_map; 103 - map.map_size = &map_size; 104 - map.desc_size = &desc_size; 105 - map.desc_ver = NULL; 106 - map.key_ptr = NULL; 107 - map.buff_size = &buff_size; 108 - 109 - status = efi_get_memory_map(&map); 110 - if (status != EFI_SUCCESS) 111 - return status; 112 - 113 - if (align < EFI_ALLOC_ALIGN) 114 - align = EFI_ALLOC_ALIGN; 115 - 116 - /* count the suitable slots in each memory map entry */ 117 - for (map_offset = 0; map_offset < map_size; map_offset += desc_size) { 118 - efi_memory_desc_t *md = (void *)memory_map + map_offset; 119 - unsigned long slots; 120 - 121 - slots = get_entry_num_slots(md, size, ilog2(align)); 122 - MD_NUM_SLOTS(md) = slots; 123 - total_slots += slots; 124 - } 125 - 126 - /* find a random number between 0 and total_slots */ 127 - target_slot = (total_slots * (u16)random_seed) >> 16; 128 - 129 - /* 130 - * target_slot is now a value in the range [0, total_slots), and so 131 - * it corresponds with exactly one of the suitable slots we recorded 132 - * when iterating over the memory map the first time around. 133 - * 134 - * So iterate over the memory map again, subtracting the number of 135 - * slots of each entry at each iteration, until we have found the entry 136 - * that covers our chosen slot. Use the residual value of target_slot 137 - * to calculate the randomly chosen address, and allocate it directly 138 - * using EFI_ALLOCATE_ADDRESS. 139 - */ 140 - for (map_offset = 0; map_offset < map_size; map_offset += desc_size) { 141 - efi_memory_desc_t *md = (void *)memory_map + map_offset; 142 - efi_physical_addr_t target; 143 - unsigned long pages; 144 - 145 - if (target_slot >= MD_NUM_SLOTS(md)) { 146 - target_slot -= MD_NUM_SLOTS(md); 147 - continue; 148 - } 149 - 150 - target = round_up(md->phys_addr, align) + target_slot * align; 151 - pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 152 - 153 - status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 154 - EFI_LOADER_DATA, pages, &target); 155 - if (status == EFI_SUCCESS) 156 - *addr = target; 157 - break; 158 - } 159 - 160 - efi_bs_call(free_pool, memory_map); 161 - 162 - return status; 163 - } 164 - 165 55 efi_status_t efi_random_get_seed(void) 166 56 { 167 57 efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID;
+124
drivers/firmware/efi/libstub/randomalloc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2016 Linaro Ltd; <ard.biesheuvel@linaro.org> 4 + */ 5 + 6 + #include <linux/efi.h> 7 + #include <linux/log2.h> 8 + #include <asm/efi.h> 9 + 10 + #include "efistub.h" 11 + 12 + /* 13 + * Return the number of slots covered by this entry, i.e., the number of 14 + * addresses it covers that are suitably aligned and supply enough room 15 + * for the allocation. 16 + */ 17 + static unsigned long get_entry_num_slots(efi_memory_desc_t *md, 18 + unsigned long size, 19 + unsigned long align_shift) 20 + { 21 + unsigned long align = 1UL << align_shift; 22 + u64 first_slot, last_slot, region_end; 23 + 24 + if (md->type != EFI_CONVENTIONAL_MEMORY) 25 + return 0; 26 + 27 + if (efi_soft_reserve_enabled() && 28 + (md->attribute & EFI_MEMORY_SP)) 29 + return 0; 30 + 31 + region_end = min(md->phys_addr + md->num_pages * EFI_PAGE_SIZE - 1, 32 + (u64)ULONG_MAX); 33 + 34 + first_slot = round_up(md->phys_addr, align); 35 + last_slot = round_down(region_end - size + 1, align); 36 + 37 + if (first_slot > last_slot) 38 + return 0; 39 + 40 + return ((unsigned long)(last_slot - first_slot) >> align_shift) + 1; 41 + } 42 + 43 + /* 44 + * The UEFI memory descriptors have a virtual address field that is only used 45 + * when installing the virtual mapping using SetVirtualAddressMap(). Since it 46 + * is unused here, we can reuse it to keep track of each descriptor's slot 47 + * count. 48 + */ 49 + #define MD_NUM_SLOTS(md) ((md)->virt_addr) 50 + 51 + efi_status_t efi_random_alloc(unsigned long size, 52 + unsigned long align, 53 + unsigned long *addr, 54 + unsigned long random_seed) 55 + { 56 + unsigned long map_size, desc_size, total_slots = 0, target_slot; 57 + unsigned long buff_size; 58 + efi_status_t status; 59 + efi_memory_desc_t *memory_map; 60 + int map_offset; 61 + struct efi_boot_memmap map; 62 + 63 + map.map = &memory_map; 64 + map.map_size = &map_size; 65 + map.desc_size = &desc_size; 66 + map.desc_ver = NULL; 67 + map.key_ptr = NULL; 68 + map.buff_size = &buff_size; 69 + 70 + status = efi_get_memory_map(&map); 71 + if (status != EFI_SUCCESS) 72 + return status; 73 + 74 + if (align < EFI_ALLOC_ALIGN) 75 + align = EFI_ALLOC_ALIGN; 76 + 77 + /* count the suitable slots in each memory map entry */ 78 + for (map_offset = 0; map_offset < map_size; map_offset += desc_size) { 79 + efi_memory_desc_t *md = (void *)memory_map + map_offset; 80 + unsigned long slots; 81 + 82 + slots = get_entry_num_slots(md, size, ilog2(align)); 83 + MD_NUM_SLOTS(md) = slots; 84 + total_slots += slots; 85 + } 86 + 87 + /* find a random number between 0 and total_slots */ 88 + target_slot = (total_slots * (u16)random_seed) >> 16; 89 + 90 + /* 91 + * target_slot is now a value in the range [0, total_slots), and so 92 + * it corresponds with exactly one of the suitable slots we recorded 93 + * when iterating over the memory map the first time around. 94 + * 95 + * So iterate over the memory map again, subtracting the number of 96 + * slots of each entry at each iteration, until we have found the entry 97 + * that covers our chosen slot. Use the residual value of target_slot 98 + * to calculate the randomly chosen address, and allocate it directly 99 + * using EFI_ALLOCATE_ADDRESS. 100 + */ 101 + for (map_offset = 0; map_offset < map_size; map_offset += desc_size) { 102 + efi_memory_desc_t *md = (void *)memory_map + map_offset; 103 + efi_physical_addr_t target; 104 + unsigned long pages; 105 + 106 + if (target_slot >= MD_NUM_SLOTS(md)) { 107 + target_slot -= MD_NUM_SLOTS(md); 108 + continue; 109 + } 110 + 111 + target = round_up(md->phys_addr, align) + target_slot * align; 112 + pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 113 + 114 + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, 115 + EFI_LOADER_DATA, pages, &target); 116 + if (status == EFI_SUCCESS) 117 + *addr = target; 118 + break; 119 + } 120 + 121 + efi_bs_call(free_pool, memory_map); 122 + 123 + return status; 124 + }
+11
drivers/firmware/efi/libstub/skip_spaces.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/ctype.h> 4 + #include <linux/types.h> 5 + 6 + char *skip_spaces(const char *str) 7 + { 8 + while (isspace(*str)) 9 + ++str; 10 + return (char *)str; 11 + }
+56
drivers/firmware/efi/libstub/string.c
··· 6 6 * Copyright (C) 1991, 1992 Linus Torvalds 7 7 */ 8 8 9 + #include <linux/ctype.h> 9 10 #include <linux/types.h> 10 11 #include <linux/string.h> 11 12 ··· 57 56 return 0; 58 57 } 59 58 #endif 59 + 60 + /* Works only for digits and letters, but small and fast */ 61 + #define TOLOWER(x) ((x) | 0x20) 62 + 63 + static unsigned int simple_guess_base(const char *cp) 64 + { 65 + if (cp[0] == '0') { 66 + if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2])) 67 + return 16; 68 + else 69 + return 8; 70 + } else { 71 + return 10; 72 + } 73 + } 74 + 75 + /** 76 + * simple_strtoull - convert a string to an unsigned long long 77 + * @cp: The start of the string 78 + * @endp: A pointer to the end of the parsed string will be placed here 79 + * @base: The number base to use 80 + */ 81 + 82 + unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) 83 + { 84 + unsigned long long result = 0; 85 + 86 + if (!base) 87 + base = simple_guess_base(cp); 88 + 89 + if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') 90 + cp += 2; 91 + 92 + while (isxdigit(*cp)) { 93 + unsigned int value; 94 + 95 + value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; 96 + if (value >= base) 97 + break; 98 + result = result * base + value; 99 + cp++; 100 + } 101 + if (endp) 102 + *endp = (char *)cp; 103 + 104 + return result; 105 + } 106 + 107 + long simple_strtol(const char *cp, char **endp, unsigned int base) 108 + { 109 + if (*cp == '-') 110 + return -simple_strtoull(cp + 1, endp, base); 111 + 112 + return simple_strtoull(cp, endp, base); 113 + }
+7 -6
drivers/firmware/efi/memattr.c
··· 13 13 #include <asm/early_ioremap.h> 14 14 15 15 static int __initdata tbl_size; 16 + unsigned long __ro_after_init efi_mem_attr_table = EFI_INVALID_TABLE_ADDR; 16 17 17 18 /* 18 19 * Reserve the memory associated with the Memory Attributes configuration ··· 23 22 { 24 23 efi_memory_attributes_table_t *tbl; 25 24 26 - if (efi.mem_attr_table == EFI_INVALID_TABLE_ADDR) 25 + if (efi_mem_attr_table == EFI_INVALID_TABLE_ADDR) 27 26 return 0; 28 27 29 - tbl = early_memremap(efi.mem_attr_table, sizeof(*tbl)); 28 + tbl = early_memremap(efi_mem_attr_table, sizeof(*tbl)); 30 29 if (!tbl) { 31 30 pr_err("Failed to map EFI Memory Attributes table @ 0x%lx\n", 32 - efi.mem_attr_table); 31 + efi_mem_attr_table); 33 32 return -ENOMEM; 34 33 } 35 34 ··· 40 39 } 41 40 42 41 tbl_size = sizeof(*tbl) + tbl->num_entries * tbl->desc_size; 43 - memblock_reserve(efi.mem_attr_table, tbl_size); 42 + memblock_reserve(efi_mem_attr_table, tbl_size); 44 43 set_bit(EFI_MEM_ATTR, &efi.flags); 45 44 46 45 unmap: ··· 148 147 if (WARN_ON(!efi_enabled(EFI_MEMMAP))) 149 148 return 0; 150 149 151 - tbl = memremap(efi.mem_attr_table, tbl_size, MEMREMAP_WB); 150 + tbl = memremap(efi_mem_attr_table, tbl_size, MEMREMAP_WB); 152 151 if (!tbl) { 153 152 pr_err("Failed to map EFI Memory Attributes table @ 0x%lx\n", 154 - efi.mem_attr_table); 153 + efi_mem_attr_table); 155 154 return -ENOMEM; 156 155 } 157 156
+2 -2
drivers/firmware/efi/reboot.c
··· 15 15 const char *str[] = { "cold", "warm", "shutdown", "platform" }; 16 16 int efi_mode, cap_reset_mode; 17 17 18 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 18 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM)) 19 19 return; 20 20 21 21 switch (reboot_mode) { ··· 64 64 65 65 static int __init efi_shutdown_init(void) 66 66 { 67 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 67 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM)) 68 68 return -ENODEV; 69 69 70 70 if (efi_poweroff_required()) {
+2 -2
drivers/firmware/efi/runtime-wrappers.c
··· 40 40 * code doesn't get too cluttered: 41 41 */ 42 42 #define efi_call_virt(f, args...) \ 43 - efi_call_virt_pointer(efi.systab->runtime, f, args) 43 + efi_call_virt_pointer(efi.runtime, f, args) 44 44 #define __efi_call_virt(f, args...) \ 45 - __efi_call_virt_pointer(efi.systab->runtime, f, args) 45 + __efi_call_virt_pointer(efi.runtime, f, args) 46 46 47 47 struct efi_runtime_work efi_rts_work; 48 48
+5 -3
drivers/firmware/pcdp.c
··· 80 80 #endif 81 81 } 82 82 83 + extern unsigned long hcdp_phys; 84 + 83 85 int __init 84 86 efi_setup_pcdp_console(char *cmdline) 85 87 { ··· 91 89 int i, serial = 0; 92 90 int rc = -ENODEV; 93 91 94 - if (efi.hcdp == EFI_INVALID_TABLE_ADDR) 92 + if (hcdp_phys == EFI_INVALID_TABLE_ADDR) 95 93 return -ENODEV; 96 94 97 - pcdp = early_memremap(efi.hcdp, 4096); 98 - printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp); 95 + pcdp = early_memremap(hcdp_phys, 4096); 96 + printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, hcdp_phys); 99 97 100 98 if (strstr(cmdline, "console=hcdp")) { 101 99 if (pcdp->rev < 3)
+1 -1
drivers/infiniband/hw/hfi1/efivar.c
··· 78 78 *size = 0; 79 79 *return_data = NULL; 80 80 81 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 81 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) 82 82 return -EOPNOTSUPP; 83 83 84 84 uni_name = kcalloc(strlen(name) + 1, sizeof(efi_char16_t), GFP_KERNEL);
-4
drivers/rtc/Makefile
··· 12 12 obj-$(CONFIG_RTC_MC146818_LIB) += rtc-mc146818-lib.o 13 13 rtc-core-y := class.o interface.o 14 14 15 - ifdef CONFIG_RTC_DRV_EFI 16 - rtc-core-y += rtc-efi-platform.o 17 - endif 18 - 19 15 rtc-core-$(CONFIG_RTC_NVMEM) += nvmem.o 20 16 rtc-core-$(CONFIG_RTC_INTF_DEV) += dev.o 21 17 rtc-core-$(CONFIG_RTC_INTF_PROC) += proc.o
-35
drivers/rtc/rtc-efi-platform.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Moved from arch/ia64/kernel/time.c 4 - * 5 - * Copyright (C) 1998-2003 Hewlett-Packard Co 6 - * Stephane Eranian <eranian@hpl.hp.com> 7 - * David Mosberger <davidm@hpl.hp.com> 8 - * Copyright (C) 1999 Don Dugger <don.dugger@intel.com> 9 - * Copyright (C) 1999-2000 VA Linux Systems 10 - * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> 11 - */ 12 - 13 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14 - 15 - #include <linux/init.h> 16 - #include <linux/kernel.h> 17 - #include <linux/module.h> 18 - #include <linux/efi.h> 19 - #include <linux/platform_device.h> 20 - 21 - static struct platform_device rtc_efi_dev = { 22 - .name = "rtc-efi", 23 - .id = -1, 24 - }; 25 - 26 - static int __init rtc_init(void) 27 - { 28 - if (efi_enabled(EFI_RUNTIME_SERVICES)) 29 - if (platform_device_register(&rtc_efi_dev) < 0) 30 - pr_err("unable to register rtc device...\n"); 31 - 32 - /* not necessarily an error */ 33 - return 0; 34 - } 35 - module_init(rtc_init);
+1 -1
drivers/scsi/isci/init.c
··· 621 621 return -ENOMEM; 622 622 pci_set_drvdata(pdev, pci_info); 623 623 624 - if (efi_enabled(EFI_RUNTIME_SERVICES)) 624 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) 625 625 orom = isci_get_efi_var(pdev); 626 626 627 627 if (!orom)
+1 -1
fs/efivarfs/super.c
··· 252 252 253 253 static __init int efivarfs_init(void) 254 254 { 255 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 255 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 256 256 return -ENODEV; 257 257 258 258 if (!efivars_kobject())
+111 -580
include/linux/efi.h
··· 56 56 #define __efiapi 57 57 #endif 58 58 59 - #define efi_get_handle_at(array, idx) \ 60 - (efi_is_native() ? (array)[idx] \ 61 - : (efi_handle_t)(unsigned long)((u32 *)(array))[idx]) 62 - 63 - #define efi_get_handle_num(size) \ 64 - ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32))) 65 - 66 - #define for_each_efi_handle(handle, array, size, i) \ 67 - for (i = 0; \ 68 - i < efi_get_handle_num(size) && \ 69 - ((handle = efi_get_handle_at((array), i)) || true); \ 70 - i++) 71 - 72 59 /* 73 60 * The UEFI spec and EDK2 reference implementation both define EFI_GUID as 74 61 * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment ··· 144 157 u32 imagesize; 145 158 } efi_capsule_header_t; 146 159 147 - struct efi_boot_memmap { 148 - efi_memory_desc_t **map; 149 - unsigned long *map_size; 150 - unsigned long *desc_size; 151 - u32 *desc_ver; 152 - unsigned long *key_ptr; 153 - unsigned long *buff_size; 154 - }; 155 - 156 160 /* 157 161 * EFI capsule flags 158 162 */ ··· 164 186 }; 165 187 166 188 int __efi_capsule_setup_info(struct capsule_info *cap_info); 167 - 168 - /* 169 - * Allocation types for calls to boottime->allocate_pages. 170 - */ 171 - #define EFI_ALLOCATE_ANY_PAGES 0 172 - #define EFI_ALLOCATE_MAX_ADDRESS 1 173 - #define EFI_ALLOCATE_ADDRESS 2 174 - #define EFI_MAX_ALLOCATE_TYPE 3 175 189 176 190 typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg); 177 191 ··· 194 224 u8 sets_to_zero; 195 225 } efi_time_cap_t; 196 226 197 - typedef struct { 198 - efi_table_hdr_t hdr; 199 - u32 raise_tpl; 200 - u32 restore_tpl; 201 - u32 allocate_pages; 202 - u32 free_pages; 203 - u32 get_memory_map; 204 - u32 allocate_pool; 205 - u32 free_pool; 206 - u32 create_event; 207 - u32 set_timer; 208 - u32 wait_for_event; 209 - u32 signal_event; 210 - u32 close_event; 211 - u32 check_event; 212 - u32 install_protocol_interface; 213 - u32 reinstall_protocol_interface; 214 - u32 uninstall_protocol_interface; 215 - u32 handle_protocol; 216 - u32 __reserved; 217 - u32 register_protocol_notify; 218 - u32 locate_handle; 219 - u32 locate_device_path; 220 - u32 install_configuration_table; 221 - u32 load_image; 222 - u32 start_image; 223 - u32 exit; 224 - u32 unload_image; 225 - u32 exit_boot_services; 226 - u32 get_next_monotonic_count; 227 - u32 stall; 228 - u32 set_watchdog_timer; 229 - u32 connect_controller; 230 - u32 disconnect_controller; 231 - u32 open_protocol; 232 - u32 close_protocol; 233 - u32 open_protocol_information; 234 - u32 protocols_per_handle; 235 - u32 locate_handle_buffer; 236 - u32 locate_protocol; 237 - u32 install_multiple_protocol_interfaces; 238 - u32 uninstall_multiple_protocol_interfaces; 239 - u32 calculate_crc32; 240 - u32 copy_mem; 241 - u32 set_mem; 242 - u32 create_event_ex; 243 - } __packed efi_boot_services_32_t; 244 - 245 - /* 246 - * EFI Boot Services table 247 - */ 248 - typedef union { 249 - struct { 250 - efi_table_hdr_t hdr; 251 - void *raise_tpl; 252 - void *restore_tpl; 253 - efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long, 254 - efi_physical_addr_t *); 255 - efi_status_t (__efiapi *free_pages)(efi_physical_addr_t, 256 - unsigned long); 257 - efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *, 258 - unsigned long *, 259 - unsigned long *, u32 *); 260 - efi_status_t (__efiapi *allocate_pool)(int, unsigned long, 261 - void **); 262 - efi_status_t (__efiapi *free_pool)(void *); 263 - void *create_event; 264 - void *set_timer; 265 - void *wait_for_event; 266 - void *signal_event; 267 - void *close_event; 268 - void *check_event; 269 - void *install_protocol_interface; 270 - void *reinstall_protocol_interface; 271 - void *uninstall_protocol_interface; 272 - efi_status_t (__efiapi *handle_protocol)(efi_handle_t, 273 - efi_guid_t *, void **); 274 - void *__reserved; 275 - void *register_protocol_notify; 276 - efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *, 277 - void *, unsigned long *, 278 - efi_handle_t *); 279 - void *locate_device_path; 280 - efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *, 281 - void *); 282 - void *load_image; 283 - void *start_image; 284 - void *exit; 285 - void *unload_image; 286 - efi_status_t (__efiapi *exit_boot_services)(efi_handle_t, 287 - unsigned long); 288 - void *get_next_monotonic_count; 289 - void *stall; 290 - void *set_watchdog_timer; 291 - void *connect_controller; 292 - efi_status_t (__efiapi *disconnect_controller)(efi_handle_t, 293 - efi_handle_t, 294 - efi_handle_t); 295 - void *open_protocol; 296 - void *close_protocol; 297 - void *open_protocol_information; 298 - void *protocols_per_handle; 299 - void *locate_handle_buffer; 300 - efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, 301 - void **); 302 - void *install_multiple_protocol_interfaces; 303 - void *uninstall_multiple_protocol_interfaces; 304 - void *calculate_crc32; 305 - void *copy_mem; 306 - void *set_mem; 307 - void *create_event_ex; 308 - }; 309 - efi_boot_services_32_t mixed_mode; 310 - } efi_boot_services_t; 311 - 312 - typedef enum { 313 - EfiPciIoWidthUint8, 314 - EfiPciIoWidthUint16, 315 - EfiPciIoWidthUint32, 316 - EfiPciIoWidthUint64, 317 - EfiPciIoWidthFifoUint8, 318 - EfiPciIoWidthFifoUint16, 319 - EfiPciIoWidthFifoUint32, 320 - EfiPciIoWidthFifoUint64, 321 - EfiPciIoWidthFillUint8, 322 - EfiPciIoWidthFillUint16, 323 - EfiPciIoWidthFillUint32, 324 - EfiPciIoWidthFillUint64, 325 - EfiPciIoWidthMaximum 326 - } EFI_PCI_IO_PROTOCOL_WIDTH; 327 - 328 - typedef enum { 329 - EfiPciIoAttributeOperationGet, 330 - EfiPciIoAttributeOperationSet, 331 - EfiPciIoAttributeOperationEnable, 332 - EfiPciIoAttributeOperationDisable, 333 - EfiPciIoAttributeOperationSupported, 334 - EfiPciIoAttributeOperationMaximum 335 - } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION; 336 - 337 - typedef struct { 338 - u32 read; 339 - u32 write; 340 - } efi_pci_io_protocol_access_32_t; 341 - 342 - typedef union efi_pci_io_protocol efi_pci_io_protocol_t; 343 - 344 - typedef 345 - efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *, 346 - EFI_PCI_IO_PROTOCOL_WIDTH, 347 - u32 offset, 348 - unsigned long count, 349 - void *buffer); 350 - 351 - typedef struct { 352 - void *read; 353 - void *write; 354 - } efi_pci_io_protocol_access_t; 355 - 356 - typedef struct { 357 - efi_pci_io_protocol_cfg_t read; 358 - efi_pci_io_protocol_cfg_t write; 359 - } efi_pci_io_protocol_config_access_t; 360 - 361 - union efi_pci_io_protocol { 362 - struct { 363 - void *poll_mem; 364 - void *poll_io; 365 - efi_pci_io_protocol_access_t mem; 366 - efi_pci_io_protocol_access_t io; 367 - efi_pci_io_protocol_config_access_t pci; 368 - void *copy_mem; 369 - void *map; 370 - void *unmap; 371 - void *allocate_buffer; 372 - void *free_buffer; 373 - void *flush; 374 - efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *, 375 - unsigned long *segment_nr, 376 - unsigned long *bus_nr, 377 - unsigned long *device_nr, 378 - unsigned long *func_nr); 379 - void *attributes; 380 - void *get_bar_attributes; 381 - void *set_bar_attributes; 382 - uint64_t romsize; 383 - void *romimage; 384 - }; 385 - struct { 386 - u32 poll_mem; 387 - u32 poll_io; 388 - efi_pci_io_protocol_access_32_t mem; 389 - efi_pci_io_protocol_access_32_t io; 390 - efi_pci_io_protocol_access_32_t pci; 391 - u32 copy_mem; 392 - u32 map; 393 - u32 unmap; 394 - u32 allocate_buffer; 395 - u32 free_buffer; 396 - u32 flush; 397 - u32 get_location; 398 - u32 attributes; 399 - u32 get_bar_attributes; 400 - u32 set_bar_attributes; 401 - u64 romsize; 402 - u32 romimage; 403 - } mixed_mode; 404 - }; 405 - 406 - #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001 407 - #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002 408 - #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004 409 - #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008 410 - #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010 411 - #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020 412 - #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040 413 - #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080 414 - #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100 415 - #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200 416 - #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400 417 - #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800 418 - #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000 419 - #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000 420 - #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000 421 - #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000 422 - #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000 423 - #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000 424 - #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000 425 - 426 - struct efi_dev_path; 427 - 428 - typedef union apple_properties_protocol apple_properties_protocol_t; 429 - 430 - union apple_properties_protocol { 431 - struct { 432 - unsigned long version; 433 - efi_status_t (__efiapi *get)(apple_properties_protocol_t *, 434 - struct efi_dev_path *, 435 - efi_char16_t *, void *, u32 *); 436 - efi_status_t (__efiapi *set)(apple_properties_protocol_t *, 437 - struct efi_dev_path *, 438 - efi_char16_t *, void *, u32); 439 - efi_status_t (__efiapi *del)(apple_properties_protocol_t *, 440 - struct efi_dev_path *, 441 - efi_char16_t *); 442 - efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *, 443 - void *buffer, u32 *); 444 - }; 445 - struct { 446 - u32 version; 447 - u32 get; 448 - u32 set; 449 - u32 del; 450 - u32 get_all; 451 - } mixed_mode; 452 - }; 453 - 454 - typedef u32 efi_tcg2_event_log_format; 455 - 456 - typedef union efi_tcg2_protocol efi_tcg2_protocol_t; 457 - 458 - union efi_tcg2_protocol { 459 - struct { 460 - void *get_capability; 461 - efi_status_t (__efiapi *get_event_log)(efi_handle_t, 462 - efi_tcg2_event_log_format, 463 - efi_physical_addr_t *, 464 - efi_physical_addr_t *, 465 - efi_bool_t *); 466 - void *hash_log_extend_event; 467 - void *submit_command; 468 - void *get_active_pcr_banks; 469 - void *set_active_pcr_banks; 470 - void *get_result_of_set_active_pcr_banks; 471 - }; 472 - struct { 473 - u32 get_capability; 474 - u32 get_event_log; 475 - u32 hash_log_extend_event; 476 - u32 submit_command; 477 - u32 get_active_pcr_banks; 478 - u32 set_active_pcr_banks; 479 - u32 get_result_of_set_active_pcr_banks; 480 - } mixed_mode; 481 - }; 227 + typedef union efi_boot_services efi_boot_services_t; 482 228 483 229 /* 484 230 * Types and defines for EFI ResetSystem ··· 332 646 #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) 333 647 #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0) 334 648 #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) 649 + #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) 650 + #define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d) 651 + #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9) 335 652 336 653 #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f) 337 654 #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23) ··· 354 665 #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa) 355 666 #define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25) 356 667 #define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2) 668 + #define LINUX_EFI_INITRD_MEDIA_GUID EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) 357 669 358 670 /* OEM GUIDs */ 359 671 #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) ··· 478 788 u64 attribute; 479 789 }; 480 790 481 - struct efi_fdt_params { 482 - u64 system_table; 483 - u64 mmap; 484 - u32 mmap_size; 485 - u32 desc_size; 486 - u32 desc_ver; 487 - }; 488 - 489 - typedef struct { 490 - u32 revision; 491 - efi_handle_t parent_handle; 492 - efi_system_table_t *system_table; 493 - efi_handle_t device_handle; 494 - void *file_path; 495 - void *reserved; 496 - u32 load_options_size; 497 - void *load_options; 498 - void *image_base; 499 - __aligned_u64 image_size; 500 - unsigned int image_code_type; 501 - unsigned int image_data_type; 502 - efi_status_t ( __efiapi *unload)(efi_handle_t image_handle); 503 - } efi_loaded_image_t; 504 - 505 - typedef struct { 506 - u64 size; 507 - u64 file_size; 508 - u64 phys_size; 509 - efi_time_t create_time; 510 - efi_time_t last_access_time; 511 - efi_time_t modification_time; 512 - __aligned_u64 attribute; 513 - efi_char16_t filename[1]; 514 - } efi_file_info_t; 515 - 516 - typedef struct efi_file_handle efi_file_handle_t; 517 - 518 - struct efi_file_handle { 519 - u64 revision; 520 - efi_status_t (__efiapi *open)(efi_file_handle_t *, 521 - efi_file_handle_t **, 522 - efi_char16_t *, u64, u64); 523 - efi_status_t (__efiapi *close)(efi_file_handle_t *); 524 - void *delete; 525 - efi_status_t (__efiapi *read)(efi_file_handle_t *, 526 - unsigned long *, void *); 527 - void *write; 528 - void *get_position; 529 - void *set_position; 530 - efi_status_t (__efiapi *get_info)(efi_file_handle_t *, 531 - efi_guid_t *, unsigned long *, 532 - void *); 533 - void *set_info; 534 - void *flush; 535 - }; 536 - 537 - typedef struct efi_file_io_interface efi_file_io_interface_t; 538 - 539 - struct efi_file_io_interface { 540 - u64 revision; 541 - int (__efiapi *open_volume)(efi_file_io_interface_t *, 542 - efi_file_handle_t **); 543 - }; 544 - 545 - #define EFI_FILE_MODE_READ 0x0000000000000001 546 - #define EFI_FILE_MODE_WRITE 0x0000000000000002 547 - #define EFI_FILE_MODE_CREATE 0x8000000000000000 548 - 549 791 typedef struct { 550 792 u32 version; 551 793 u32 length; ··· 486 864 487 865 #define EFI_PROPERTIES_TABLE_VERSION 0x00010000 488 866 #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1 867 + 868 + typedef struct { 869 + u16 version; 870 + u16 length; 871 + u32 runtime_services_supported; 872 + } efi_rt_properties_table_t; 873 + 874 + #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1 489 875 490 876 #define EFI_INVALID_TABLE_ADDR (~0UL) 491 877 ··· 530 900 * All runtime access to EFI goes through this structure: 531 901 */ 532 902 extern struct efi { 533 - efi_system_table_t *systab; /* EFI system table */ 534 - unsigned int runtime_version; /* Runtime services version */ 535 - unsigned long mps; /* MPS table */ 536 - unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ 537 - unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 538 - unsigned long smbios; /* SMBIOS table (32 bit entry point) */ 539 - unsigned long smbios3; /* SMBIOS table (64 bit entry point) */ 540 - unsigned long boot_info; /* boot info table */ 541 - unsigned long hcdp; /* HCDP table */ 542 - unsigned long uga; /* UGA table */ 543 - unsigned long fw_vendor; /* fw_vendor */ 544 - unsigned long runtime; /* runtime table */ 545 - unsigned long config_table; /* config tables */ 546 - unsigned long esrt; /* ESRT table */ 547 - unsigned long properties_table; /* properties table */ 548 - unsigned long mem_attr_table; /* memory attributes table */ 549 - unsigned long rng_seed; /* UEFI firmware random seed */ 550 - unsigned long tpm_log; /* TPM2 Event Log table */ 551 - unsigned long tpm_final_log; /* TPM2 Final Events Log table */ 552 - unsigned long mem_reserve; /* Linux EFI memreserve table */ 553 - efi_get_time_t *get_time; 554 - efi_set_time_t *set_time; 555 - efi_get_wakeup_time_t *get_wakeup_time; 556 - efi_set_wakeup_time_t *set_wakeup_time; 557 - efi_get_variable_t *get_variable; 558 - efi_get_next_variable_t *get_next_variable; 559 - efi_set_variable_t *set_variable; 560 - efi_set_variable_t *set_variable_nonblocking; 561 - efi_query_variable_info_t *query_variable_info; 562 - efi_query_variable_info_t *query_variable_info_nonblocking; 563 - efi_update_capsule_t *update_capsule; 564 - efi_query_capsule_caps_t *query_capsule_caps; 565 - efi_get_next_high_mono_count_t *get_next_high_mono_count; 566 - efi_reset_system_t *reset_system; 567 - struct efi_memory_map memmap; 568 - unsigned long flags; 903 + const efi_runtime_services_t *runtime; /* EFI runtime services table */ 904 + unsigned int runtime_version; /* Runtime services version */ 905 + unsigned int runtime_supported_mask; 906 + 907 + unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ 908 + unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 909 + unsigned long smbios; /* SMBIOS table (32 bit entry point) */ 910 + unsigned long smbios3; /* SMBIOS table (64 bit entry point) */ 911 + unsigned long esrt; /* ESRT table */ 912 + unsigned long tpm_log; /* TPM2 Event Log table */ 913 + unsigned long tpm_final_log; /* TPM2 Final Events Log table */ 914 + 915 + efi_get_time_t *get_time; 916 + efi_set_time_t *set_time; 917 + efi_get_wakeup_time_t *get_wakeup_time; 918 + efi_set_wakeup_time_t *set_wakeup_time; 919 + efi_get_variable_t *get_variable; 920 + efi_get_next_variable_t *get_next_variable; 921 + efi_set_variable_t *set_variable; 922 + efi_set_variable_t *set_variable_nonblocking; 923 + efi_query_variable_info_t *query_variable_info; 924 + efi_query_variable_info_t *query_variable_info_nonblocking; 925 + efi_update_capsule_t *update_capsule; 926 + efi_query_capsule_caps_t *query_capsule_caps; 927 + efi_get_next_high_mono_count_t *get_next_high_mono_count; 928 + efi_reset_system_t *reset_system; 929 + 930 + struct efi_memory_map memmap; 931 + unsigned long flags; 569 932 } efi; 933 + 934 + #define EFI_RT_SUPPORTED_GET_TIME 0x0001 935 + #define EFI_RT_SUPPORTED_SET_TIME 0x0002 936 + #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 937 + #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008 938 + #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010 939 + #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020 940 + #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040 941 + #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080 942 + #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100 943 + #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200 944 + #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400 945 + #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800 946 + #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000 947 + #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000 948 + 949 + #define EFI_RT_SUPPORTED_ALL 0x3fff 950 + 951 + #define EFI_RT_SUPPORTED_TIME_SERVICES 0x000f 952 + #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070 570 953 571 954 extern struct mm_struct efi_mm; 572 955 ··· 630 987 extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap, 631 988 void *buf, struct efi_mem_range *mem); 632 989 633 - extern int efi_config_init(efi_config_table_type_t *arch_tables); 634 990 #ifdef CONFIG_EFI_ESRT 635 991 extern void __init efi_esrt_init(void); 636 992 #else 637 993 static inline void efi_esrt_init(void) { } 638 994 #endif 639 - extern int efi_config_parse_tables(void *config_tables, int count, int sz, 640 - efi_config_table_type_t *arch_tables); 995 + extern int efi_config_parse_tables(const efi_config_table_t *config_tables, 996 + int count, 997 + const efi_config_table_type_t *arch_tables); 998 + extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr, 999 + int min_major_version); 1000 + extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr, 1001 + unsigned long fw_vendor); 641 1002 extern u64 efi_get_iobase (void); 642 1003 extern int efi_mem_type(unsigned long phys_addr); 643 1004 extern u64 efi_mem_attributes (unsigned long phys_addr); ··· 653 1006 extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size); 654 1007 extern void efi_initialize_iomem_resources(struct resource *code_resource, 655 1008 struct resource *data_resource, struct resource *bss_resource); 656 - extern int efi_get_fdt_params(struct efi_fdt_params *params); 1009 + extern u64 efi_get_fdt_params(struct efi_memory_map_data *data); 657 1010 extern struct kobject *efi_kobj; 658 1011 659 1012 extern int efi_reboot_quirk_mode; ··· 664 1017 #else 665 1018 static inline void efi_fake_memmap(void) { } 666 1019 #endif 1020 + 1021 + extern unsigned long efi_mem_attr_table; 667 1022 668 1023 /* 669 1024 * efi_memattr_perm_setter - arch specific callback function passed into ··· 791 1142 return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE) 792 1143 && __efi_soft_reserve_enabled(); 793 1144 } 1145 + 1146 + static inline bool efi_rt_services_supported(unsigned int mask) 1147 + { 1148 + return (efi.runtime_supported_mask & mask) == mask; 1149 + } 794 1150 #else 795 1151 static inline bool efi_enabled(int feature) 796 1152 { ··· 811 1157 } 812 1158 813 1159 static inline bool efi_soft_reserve_enabled(void) 1160 + { 1161 + return false; 1162 + } 1163 + 1164 + static inline bool efi_rt_services_supported(unsigned int mask) 814 1165 { 815 1166 return false; 816 1167 } ··· 846 1187 * not including trailing NUL 847 1188 */ 848 1189 #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN 849 - 850 - /* 851 - * The type of search to perform when calling boottime->locate_handle 852 - */ 853 - #define EFI_LOCATE_ALL_HANDLES 0 854 - #define EFI_LOCATE_BY_REGISTER_NOTIFY 1 855 - #define EFI_LOCATE_BY_PROTOCOL 2 856 1190 857 1191 /* 858 1192 * EFI Device Path information ··· 886 1234 #define EFI_DEV_END_ENTIRE 0xFF 887 1235 888 1236 struct efi_generic_dev_path { 889 - u8 type; 890 - u8 sub_type; 891 - u16 length; 892 - } __attribute ((packed)); 1237 + u8 type; 1238 + u8 sub_type; 1239 + u16 length; 1240 + } __packed; 1241 + 1242 + struct efi_acpi_dev_path { 1243 + struct efi_generic_dev_path header; 1244 + u32 hid; 1245 + u32 uid; 1246 + } __packed; 1247 + 1248 + struct efi_pci_dev_path { 1249 + struct efi_generic_dev_path header; 1250 + u8 fn; 1251 + u8 dev; 1252 + } __packed; 1253 + 1254 + struct efi_vendor_dev_path { 1255 + struct efi_generic_dev_path header; 1256 + efi_guid_t vendorguid; 1257 + u8 vendordata[]; 1258 + } __packed; 893 1259 894 1260 struct efi_dev_path { 895 - u8 type; /* can be replaced with unnamed */ 896 - u8 sub_type; /* struct efi_generic_dev_path; */ 897 - u16 length; /* once we've moved to -std=c11 */ 898 1261 union { 899 - struct { 900 - u32 hid; 901 - u32 uid; 902 - } acpi; 903 - struct { 904 - u8 fn; 905 - u8 dev; 906 - } pci; 1262 + struct efi_generic_dev_path header; 1263 + struct efi_acpi_dev_path acpi; 1264 + struct efi_pci_dev_path pci; 1265 + struct efi_vendor_dev_path vendor; 907 1266 }; 908 - } __attribute ((packed)); 1267 + } __packed; 909 1268 910 - #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER) 911 - struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len); 912 - #endif 1269 + struct device *efi_get_device_by_path(const struct efi_dev_path **node, 1270 + size_t *len); 913 1271 914 1272 static inline void memrange_efi_to_native(u64 *addr, u64 *npages) 915 1273 { ··· 972 1310 struct kobject kobj; 973 1311 bool scanning; 974 1312 bool deleting; 975 - }; 976 - 977 - union efi_simple_text_output_protocol { 978 - struct { 979 - void *reset; 980 - efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *, 981 - efi_char16_t *); 982 - void *test_string; 983 - }; 984 - struct { 985 - u32 reset; 986 - u32 output_string; 987 - u32 test_string; 988 - } mixed_mode; 989 - }; 990 - 991 - #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 992 - #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 993 - #define PIXEL_BIT_MASK 2 994 - #define PIXEL_BLT_ONLY 3 995 - #define PIXEL_FORMAT_MAX 4 996 - 997 - typedef struct { 998 - u32 red_mask; 999 - u32 green_mask; 1000 - u32 blue_mask; 1001 - u32 reserved_mask; 1002 - } efi_pixel_bitmask_t; 1003 - 1004 - typedef struct { 1005 - u32 version; 1006 - u32 horizontal_resolution; 1007 - u32 vertical_resolution; 1008 - int pixel_format; 1009 - efi_pixel_bitmask_t pixel_information; 1010 - u32 pixels_per_scan_line; 1011 - } efi_graphics_output_mode_info_t; 1012 - 1013 - typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t; 1014 - 1015 - union efi_graphics_output_protocol_mode { 1016 - struct { 1017 - u32 max_mode; 1018 - u32 mode; 1019 - efi_graphics_output_mode_info_t *info; 1020 - unsigned long size_of_info; 1021 - efi_physical_addr_t frame_buffer_base; 1022 - unsigned long frame_buffer_size; 1023 - }; 1024 - struct { 1025 - u32 max_mode; 1026 - u32 mode; 1027 - u32 info; 1028 - u32 size_of_info; 1029 - u64 frame_buffer_base; 1030 - u32 frame_buffer_size; 1031 - } mixed_mode; 1032 - }; 1033 - 1034 - typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t; 1035 - 1036 - union efi_graphics_output_protocol { 1037 - struct { 1038 - void *query_mode; 1039 - void *set_mode; 1040 - void *blt; 1041 - efi_graphics_output_protocol_mode_t *mode; 1042 - }; 1043 - struct { 1044 - u32 query_mode; 1045 - u32 set_mode; 1046 - u32 blt; 1047 - u32 mode; 1048 - } mixed_mode; 1049 1313 }; 1050 1314 1051 1315 extern struct list_head efivar_sysfs_list; ··· 1071 1483 1072 1484 #endif 1073 1485 1074 - /* prototypes shared between arch specific and generic stub code */ 1075 - 1076 - void efi_printk(char *str); 1077 - 1078 - void efi_free(unsigned long size, unsigned long addr); 1079 - 1080 - char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len); 1081 - 1082 - efi_status_t efi_get_memory_map(struct efi_boot_memmap *map); 1083 - 1084 - efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, 1085 - unsigned long *addr, unsigned long min); 1086 - 1087 - static inline 1088 - efi_status_t efi_low_alloc(unsigned long size, unsigned long align, 1089 - unsigned long *addr) 1090 - { 1091 - /* 1092 - * Don't allocate at 0x0. It will confuse code that 1093 - * checks pointers against NULL. Skip the first 8 1094 - * bytes so we start at a nice even number. 1095 - */ 1096 - return efi_low_alloc_above(size, align, addr, 0x8); 1097 - } 1098 - 1099 - efi_status_t efi_high_alloc(unsigned long size, unsigned long align, 1100 - unsigned long *addr, unsigned long max); 1101 - 1102 - efi_status_t efi_relocate_kernel(unsigned long *image_addr, 1103 - unsigned long image_size, 1104 - unsigned long alloc_size, 1105 - unsigned long preferred_addr, 1106 - unsigned long alignment, 1107 - unsigned long min_addr); 1108 - 1109 - efi_status_t handle_cmdline_files(efi_loaded_image_t *image, 1110 - char *cmd_line, char *option_string, 1111 - unsigned long max_addr, 1112 - unsigned long *load_addr, 1113 - unsigned long *load_size); 1114 - 1115 - efi_status_t efi_parse_options(char const *cmdline); 1116 - 1117 - efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, 1118 - unsigned long size); 1119 - 1120 1486 #ifdef CONFIG_EFI 1121 1487 extern bool efi_runtime_disabled(void); 1122 1488 #else ··· 1147 1605 \ 1148 1606 arch_efi_call_virt_teardown(); \ 1149 1607 }) 1150 - 1151 - typedef efi_status_t (*efi_exit_boot_map_processing)( 1152 - struct efi_boot_memmap *map, 1153 - void *priv); 1154 - 1155 - efi_status_t efi_exit_boot_services(void *handle, 1156 - struct efi_boot_memmap *map, 1157 - void *priv, 1158 - efi_exit_boot_map_processing priv_func); 1159 1608 1160 1609 #define EFI_RANDOM_SEED_SIZE 64U 1161 1610 ··· 1233 1700 1234 1701 #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \ 1235 1702 / sizeof(((struct linux_efi_memreserve *)0)->entry[0])) 1236 - 1237 - void efi_pci_disable_bridge_busmaster(void); 1238 1703 1239 1704 #endif /* _LINUX_EFI_H */
+21
include/linux/pe.h
··· 10 10 11 11 #include <linux/types.h> 12 12 13 + /* 14 + * Linux EFI stub v1.0 adds the following functionality: 15 + * - Loading initrd from the LINUX_EFI_INITRD_MEDIA_GUID device path, 16 + * - Loading/starting the kernel from firmware that targets a different 17 + * machine type, via the entrypoint exposed in the .compat PE/COFF section. 18 + * 19 + * The recommended way of loading and starting v1.0 or later kernels is to use 20 + * the LoadImage() and StartImage() EFI boot services, and expose the initrd 21 + * via the LINUX_EFI_INITRD_MEDIA_GUID device path. 22 + * 23 + * Versions older than v1.0 support initrd loading via the image load options 24 + * (using initrd=, limited to the volume from which the kernel itself was 25 + * loaded), or via arch specific means (bootparams, DT, etc). 26 + * 27 + * On x86, LoadImage() and StartImage() can be omitted if the EFI handover 28 + * protocol is implemented, which can be inferred from the version, 29 + * handover_offset and xloadflags fields in the bootparams structure. 30 + */ 31 + #define LINUX_EFISTUB_MAJOR_VERSION 0x1 32 + #define LINUX_EFISTUB_MINOR_VERSION 0x0 33 + 13 34 #define MZ_MAGIC 0x5a4d /* "MZ" */ 14 35 15 36 #define PE_MAGIC 0x00004550 /* "PE\0\0" */
+1 -1
security/integrity/platform_certs/load_uefi.c
··· 79 79 efi_status_t status; 80 80 int rc = 0; 81 81 82 - if (!efi.get_variable) 82 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) 83 83 return false; 84 84 85 85 /* Get db, MokListRT, and dbx. They might not exist, so it isn't