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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull EFI updates from Ingo Molnar:
"The EFI changes in this cycle are much larger than usual, for two
(positive) reasons:

- The GRUB project is showing signs of life again, resulting in the
introduction of the generic Linux/UEFI boot protocol, instead of
x86 specific hacks which are increasingly difficult to maintain.
There's hope that all future extensions will now go through that
boot protocol.

- Preparatory work for RISC-V EFI support.

The main changes are:

- Boot time GDT handling changes

- 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.

- Partial fix for the lack of by-VA cache maintenance in the
decompressor on 32-bit ARM.

- Changes to load device firmware from EFI boot service memory
regions

- Various documentation updates and minor code cleanups and fixes"

* 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (114 commits)
efi/libstub/arm: Fix spurious message that an initrd was loaded
efi/libstub/arm64: Avoid image_base value from efi_loaded_image
partitions/efi: Fix partition name parsing in GUID partition entry
efi/x86: Fix cast of image argument
efi/libstub/x86: Use ULONG_MAX as upper bound for all allocations
efi: Fix a mistype in comments mentioning efivar_entry_iter_begin()
efi/libstub: Avoid linking libstub/lib-ksyms.o into vmlinux
efi/x86: Preserve %ebx correctly in efi_set_virtual_address_map()
efi/x86: Ignore the memory attributes table on i386
efi/x86: Don't relocate the kernel unless necessary
efi/x86: Remove extra headroom for setup block
efi/x86: Add kernel preferred address to PE header
efi/x86: Decompress at start of PE image load address
x86/boot/compressed/32: Save the output address instead of recalculating it
efi/libstub/x86: Deal with exit() boot service returning
x86/boot: Use unsigned comparison for addresses
efi/x86: Avoid using code32_start
efi/x86: Make efi32_pe_entry() more readable
efi/x86: Respect 32-bit ABI in efi32_pe_entry()
efi/x86: Annotate the LOADED_IMAGE_PROTOCOL_GUID with SYM_DATA
...

+2945 -2697
+11
Documentation/driver-api/firmware/efi/index.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ============ 4 + UEFI Support 5 + ============ 6 + 7 + UEFI stub library functions 8 + =========================== 9 + 10 + .. kernel-doc:: drivers/firmware/efi/libstub/mem.c 11 + :internal:
+1
Documentation/driver-api/firmware/index.rst
··· 6 6 7 7 introduction 8 8 core 9 + efi/index 9 10 request_firmware 10 11 other_interfaces 11 12
+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
-1
MAINTAINERS
··· 6363 6363 S: Maintained 6364 6364 F: Documentation/admin-guide/efi-stub.rst 6365 6365 F: arch/*/kernel/efi.c 6366 - F: arch/x86/boot/compressed/eboot.[ch] 6367 6366 F: arch/*/include/asm/efi.h 6368 6367 F: arch/x86/platform/efi/ 6369 6368 F: drivers/firmware/efi/
+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
+20 -32
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 1444 + mov r0, r4 @ DT start 1445 + add r1, r4, r2 @ DT end 1446 + bl cache_clean_flush 1455 1447 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 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 1460 1452 1461 - @ Preserve return value of efi_entry() in r4 1462 - mov r4, r0 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 unless 1456 + @ we explicitly clean it to the PoC. 1457 + adr r0, call_cache_fn @ region of code we will 1458 + adr r1, 0f @ run with MMU off 1463 1459 bl cache_clean_flush 1464 1460 bl cache_off 1465 1461 ··· 1465 1469 mov r0, #0 1466 1470 mov r1, #0xFFFFFFFF 1467 1471 mov r2, r4 1468 - 1469 - @ Branch to (possibly) relocated zImage that is in [sp] 1470 - ldr lr, [sp] 1471 - ldr ip, =start_offset 1472 - add lr, lr, ip 1473 - mov pc, lr @ no mode switch 1474 - 1475 - efi_load_fail: 1476 - @ Return EFI_LOAD_ERROR to EFI firmware on error. 1477 - ldr r0, =0x80000001 1478 - ldmfd sp!, {ip, pc} 1479 - ENDPROC(efi_stub_entry) 1472 + add r7, r7, #(__efi_start - start) 1473 + mov pc, r7 @ no mode switch 1474 + ENDPROC(efi_enter_kernel) 1475 + 0: 1480 1476 #endif 1481 1477 1482 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 {
+19 -71
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 + SYM_CODE_START(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 22 + ldr w2, =stext_offset 23 + add x19, x0, x2 // relocated Image entrypoint 24 + mov x20, x1 // DTB address 62 25 63 26 /* 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 69 - 70 - /* 71 - * Flush the copied Image to the PoC, and ensure it is not shadowed by 27 + * Clean the copied Image to the PoC, and ensure it is not shadowed by 72 28 * stale icache entries from before relocation. 73 29 */ 74 - bl __flush_dcache_area 30 + ldr w1, =kernel_size 31 + bl __clean_dcache_area_poc 75 32 ic ialluis 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 + * Clean the remainder of this routine to the PoC 36 + * 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 + adr x0, 0f 39 + ldr w1, 3f 40 + bl __clean_dcache_area_poc 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 + br x19 113 + SYM_CODE_END(efi_enter_kernel) 114 + 3: .long . - 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
+5 -2
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 + __efistub_stext_offset = stext - _text; 17 + 16 18 17 19 /* 18 20 * The EFI stub has its own symbol namespace prefixed by __efistub_, to ··· 35 33 __efistub_strcmp = __pi_strcmp; 36 34 __efistub_strncmp = __pi_strncmp; 37 35 __efistub_strrchr = __pi_strrchr; 38 - __efistub___flush_dcache_area = __pi___flush_dcache_area; 36 + __efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc; 39 37 40 38 #ifdef CONFIG_KASAN 41 39 __efistub___memcpy = __pi_memcpy; ··· 47 45 __efistub__end = _end; 48 46 __efistub__edata = _edata; 49 47 __efistub_screen_info = screen_info; 48 + __efistub__ctype = _ctype; 50 49 51 50 #endif 52 51
+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
+122 -174
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" 21 + 22 + /* Maximum physical address for 64-bit kernel with 4-level paging */ 23 + #define MAXMEM_X86_64_4LEVEL (1ull << 46) 20 24 21 25 static efi_system_table_t *sys_table; 22 26 extern const bool efi_is64; 27 + extern u32 image_offset; 23 28 24 29 __pure efi_system_table_t *efi_system_table(void) 25 30 { ··· 316 315 return status; 317 316 } 318 317 319 - void setup_graphics(struct boot_params *boot_params) 318 + static void setup_graphics(struct boot_params *boot_params) 320 319 { 321 320 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; 322 321 struct screen_info *si; ··· 344 343 } 345 344 } 346 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 + for(;;) 351 + asm("hlt"); 352 + } 353 + 347 354 void startup_32(struct boot_params *boot_params); 348 355 349 356 void __noreturn efi_stub_entry(efi_handle_t handle, ··· 367 358 efi_system_table_t *sys_table_arg) 368 359 { 369 360 struct boot_params *boot_params; 370 - struct apm_bios_info *bi; 371 361 struct setup_header *hdr; 372 362 efi_loaded_image_t *image; 363 + void *image_base; 373 364 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; 374 365 int options_size = 0; 375 366 efi_status_t status; ··· 381 372 382 373 /* Check if we were booted by the EFI firmware */ 383 374 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 384 - return EFI_INVALID_PARAMETER; 375 + efi_exit(handle, EFI_INVALID_PARAMETER); 385 376 386 - status = efi_bs_call(handle_protocol, handle, &proto, (void *)&image); 377 + status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image); 387 378 if (status != EFI_SUCCESS) { 388 379 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); 389 - return status; 380 + efi_exit(handle, status); 390 381 } 391 382 392 - status = efi_low_alloc(0x4000, 1, (unsigned long *)&boot_params); 383 + image_base = efi_table_attr(image, image_base); 384 + image_offset = (void *)startup_32 - image_base; 385 + 386 + hdr = &((struct boot_params *)image_base)->hdr; 387 + 388 + status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params, ULONG_MAX); 393 389 if (status != EFI_SUCCESS) { 394 390 efi_printk("Failed to allocate lowmem for boot params\n"); 395 - return status; 391 + efi_exit(handle, status); 396 392 } 397 393 398 394 memset(boot_params, 0x0, 0x4000); 399 395 400 396 hdr = &boot_params->hdr; 401 - bi = &boot_params->apm_bios_info; 402 397 403 398 /* Copy the second sector to boot_params */ 404 - memcpy(&hdr->jump, image->image_base + 512, 512); 399 + memcpy(&hdr->jump, image_base + 512, 512); 405 400 406 401 /* 407 402 * Fill out some of the header fields ourselves because the ··· 418 405 hdr->type_of_loader = 0x21; 419 406 420 407 /* Convert unicode cmdline to ascii */ 421 - cmdline_ptr = efi_convert_cmdline(image, &options_size); 408 + cmdline_ptr = efi_convert_cmdline(image, &options_size, ULONG_MAX); 422 409 if (!cmdline_ptr) 423 410 goto fail; 424 411 ··· 429 416 hdr->ramdisk_image = 0; 430 417 hdr->ramdisk_size = 0; 431 418 432 - /* Clear APM BIOS info */ 433 - 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; 434 423 435 - status = efi_parse_options(cmdline_ptr); 436 - if (status != EFI_SUCCESS) 437 - goto fail2; 438 - 439 - status = handle_cmdline_files(image, 440 - (char *)(unsigned long)hdr->cmd_line_ptr, 441 - "initrd=", hdr->initrd_addr_max, 442 - &ramdisk_addr, &ramdisk_size); 443 - 444 - if (status != EFI_SUCCESS && 445 - hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) { 446 - efi_printk("Trying to load files to higher address\n"); 447 - status = handle_cmdline_files(image, 448 - (char *)(unsigned long)hdr->cmd_line_ptr, 449 - "initrd=", -1UL, 450 - &ramdisk_addr, &ramdisk_size); 424 + if (!noinitrd()) { 425 + status = efi_load_initrd(image, &ramdisk_addr, 426 + &ramdisk_size, 427 + hdr->initrd_addr_max, 428 + ULONG_MAX); 429 + if (status != EFI_SUCCESS) 430 + goto fail2; 431 + hdr->ramdisk_image = ramdisk_addr & 0xffffffff; 432 + hdr->ramdisk_size = ramdisk_size & 0xffffffff; 433 + boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; 434 + boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; 435 + } 451 436 } 452 - 453 - if (status != EFI_SUCCESS) 454 - goto fail2; 455 - hdr->ramdisk_image = ramdisk_addr & 0xffffffff; 456 - hdr->ramdisk_size = ramdisk_size & 0xffffffff; 457 - boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; 458 - boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; 459 - 460 - hdr->code32_start = (u32)(unsigned long)startup_32; 461 437 462 438 efi_stub_entry(handle, sys_table, boot_params); 463 439 /* not reached */ 464 440 465 441 fail2: 466 - efi_free(options_size, hdr->cmd_line_ptr); 442 + efi_free(options_size, (unsigned long)cmdline_ptr); 467 443 fail: 468 444 efi_free(0x4000, (unsigned long)boot_params); 469 445 470 - return status; 446 + efi_exit(handle, status); 471 447 } 472 448 473 449 static void add_e820ext(struct boot_params *params, ··· 707 705 } 708 706 709 707 /* 710 - * On success we return a pointer to a boot_params structure, and NULL 711 - * on failure. 708 + * On success, we return the address of startup_32, which has potentially been 709 + * relocated by efi_relocate_kernel. 710 + * On failure, we exit to the firmware via efi_exit instead of returning. 712 711 */ 713 - struct boot_params *efi_main(efi_handle_t handle, 712 + unsigned long efi_main(efi_handle_t handle, 714 713 efi_system_table_t *sys_table_arg, 715 714 struct boot_params *boot_params) 716 715 { 717 - struct desc_ptr *gdt = NULL; 716 + unsigned long bzimage_addr = (unsigned long)startup_32; 717 + unsigned long buffer_start, buffer_end; 718 718 struct setup_header *hdr = &boot_params->hdr; 719 719 efi_status_t status; 720 - struct desc_struct *desc; 721 720 unsigned long cmdline_paddr; 722 721 723 722 sys_table = sys_table_arg; 724 723 725 724 /* Check if we were booted by the EFI firmware */ 726 725 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 727 - goto fail; 726 + efi_exit(handle, EFI_INVALID_PARAMETER); 728 727 729 728 /* 730 - * make_boot_params() may have been called before efi_main(), in which 729 + * If the kernel isn't already loaded at a suitable address, 730 + * relocate it. 731 + * 732 + * It must be loaded above LOAD_PHYSICAL_ADDR. 733 + * 734 + * The maximum address for 64-bit is 1 << 46 for 4-level paging. This 735 + * is defined as the macro MAXMEM, but unfortunately that is not a 736 + * compile-time constant if 5-level paging is configured, so we instead 737 + * define our own macro for use here. 738 + * 739 + * For 32-bit, the maximum address is complicated to figure out, for 740 + * now use KERNEL_IMAGE_SIZE, which will be 512MiB, the same as what 741 + * KASLR uses. 742 + * 743 + * Also relocate it if image_offset is zero, i.e. we weren't loaded by 744 + * LoadImage, but we are not aligned correctly. 745 + */ 746 + 747 + buffer_start = ALIGN(bzimage_addr - image_offset, 748 + hdr->kernel_alignment); 749 + buffer_end = buffer_start + hdr->init_size; 750 + 751 + if ((buffer_start < LOAD_PHYSICAL_ADDR) || 752 + (IS_ENABLED(CONFIG_X86_32) && buffer_end > KERNEL_IMAGE_SIZE) || 753 + (IS_ENABLED(CONFIG_X86_64) && buffer_end > MAXMEM_X86_64_4LEVEL) || 754 + (image_offset == 0 && !IS_ALIGNED(bzimage_addr, 755 + hdr->kernel_alignment))) { 756 + status = efi_relocate_kernel(&bzimage_addr, 757 + hdr->init_size, hdr->init_size, 758 + hdr->pref_address, 759 + hdr->kernel_alignment, 760 + LOAD_PHYSICAL_ADDR); 761 + if (status != EFI_SUCCESS) { 762 + efi_printk("efi_relocate_kernel() failed!\n"); 763 + goto fail; 764 + } 765 + /* 766 + * Now that we've copied the kernel elsewhere, we no longer 767 + * have a set up block before startup_32(), so reset image_offset 768 + * to zero in case it was set earlier. 769 + */ 770 + image_offset = 0; 771 + } 772 + 773 + /* 774 + * efi_pe_entry() may have been called before efi_main(), in which 731 775 * case this is the second time we parse the cmdline. This is ok, 732 776 * parsing the cmdline multiple times does not have side-effects. 733 777 */ 734 778 cmdline_paddr = ((u64)hdr->cmd_line_ptr | 735 779 ((u64)boot_params->ext_cmd_line_ptr << 32)); 736 780 efi_parse_options((char *)cmdline_paddr); 781 + 782 + /* 783 + * At this point, an initrd may already have been loaded, either by 784 + * the bootloader and passed via bootparams, or loaded from a initrd= 785 + * command line option by efi_pe_entry() above. In either case, we 786 + * permit an initrd loaded from the LINUX_EFI_INITRD_MEDIA_GUID device 787 + * path to supersede it. 788 + */ 789 + if (!noinitrd()) { 790 + unsigned long addr, size; 791 + 792 + status = efi_load_initrd_dev_path(&addr, &size, ULONG_MAX); 793 + if (status == EFI_SUCCESS) { 794 + hdr->ramdisk_image = (u32)addr; 795 + hdr->ramdisk_size = (u32)size; 796 + boot_params->ext_ramdisk_image = (u64)addr >> 32; 797 + boot_params->ext_ramdisk_size = (u64)size >> 32; 798 + } else if (status != EFI_NOT_FOUND) { 799 + efi_printk("efi_load_initrd_dev_path() failed!\n"); 800 + goto fail; 801 + } 802 + } 737 803 738 804 /* 739 805 * If the boot loader gave us a value for secure_boot then we use that, ··· 823 753 824 754 setup_quirks(boot_params); 825 755 826 - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*gdt), 827 - (void **)&gdt); 828 - if (status != EFI_SUCCESS) { 829 - efi_printk("Failed to allocate memory for 'gdt' structure\n"); 830 - goto fail; 831 - } 832 - 833 - gdt->size = 0x800; 834 - status = efi_low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); 835 - if (status != EFI_SUCCESS) { 836 - efi_printk("Failed to allocate memory for 'gdt'\n"); 837 - goto fail; 838 - } 839 - 840 - /* 841 - * If the kernel isn't already loaded at the preferred load 842 - * address, relocate it. 843 - */ 844 - if (hdr->pref_address != hdr->code32_start) { 845 - unsigned long bzimage_addr = hdr->code32_start; 846 - status = efi_relocate_kernel(&bzimage_addr, 847 - hdr->init_size, hdr->init_size, 848 - hdr->pref_address, 849 - hdr->kernel_alignment, 850 - LOAD_PHYSICAL_ADDR); 851 - if (status != EFI_SUCCESS) { 852 - efi_printk("efi_relocate_kernel() failed!\n"); 853 - goto fail; 854 - } 855 - 856 - hdr->pref_address = hdr->code32_start; 857 - hdr->code32_start = bzimage_addr; 858 - } 859 - 860 756 status = exit_boot(boot_params, handle); 861 757 if (status != EFI_SUCCESS) { 862 758 efi_printk("exit_boot() failed!\n"); 863 759 goto fail; 864 760 } 865 761 866 - memset((char *)gdt->address, 0x0, gdt->size); 867 - desc = (struct desc_struct *)gdt->address; 868 - 869 - /* The first GDT is a dummy. */ 870 - desc++; 871 - 872 - if (IS_ENABLED(CONFIG_X86_64)) { 873 - /* __KERNEL32_CS */ 874 - desc->limit0 = 0xffff; 875 - desc->base0 = 0x0000; 876 - desc->base1 = 0x0000; 877 - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; 878 - desc->s = DESC_TYPE_CODE_DATA; 879 - desc->dpl = 0; 880 - desc->p = 1; 881 - desc->limit1 = 0xf; 882 - desc->avl = 0; 883 - desc->l = 0; 884 - desc->d = SEG_OP_SIZE_32BIT; 885 - desc->g = SEG_GRANULARITY_4KB; 886 - desc->base2 = 0x00; 887 - 888 - desc++; 889 - } else { 890 - /* Second entry is unused on 32-bit */ 891 - desc++; 892 - } 893 - 894 - /* __KERNEL_CS */ 895 - desc->limit0 = 0xffff; 896 - desc->base0 = 0x0000; 897 - desc->base1 = 0x0000; 898 - desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; 899 - desc->s = DESC_TYPE_CODE_DATA; 900 - desc->dpl = 0; 901 - desc->p = 1; 902 - desc->limit1 = 0xf; 903 - desc->avl = 0; 904 - 905 - if (IS_ENABLED(CONFIG_X86_64)) { 906 - desc->l = 1; 907 - desc->d = 0; 908 - } else { 909 - desc->l = 0; 910 - desc->d = SEG_OP_SIZE_32BIT; 911 - } 912 - desc->g = SEG_GRANULARITY_4KB; 913 - desc->base2 = 0x00; 914 - desc++; 915 - 916 - /* __KERNEL_DS */ 917 - desc->limit0 = 0xffff; 918 - desc->base0 = 0x0000; 919 - desc->base1 = 0x0000; 920 - desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; 921 - desc->s = DESC_TYPE_CODE_DATA; 922 - desc->dpl = 0; 923 - desc->p = 1; 924 - desc->limit1 = 0xf; 925 - desc->avl = 0; 926 - desc->l = 0; 927 - desc->d = SEG_OP_SIZE_32BIT; 928 - desc->g = SEG_GRANULARITY_4KB; 929 - desc->base2 = 0x00; 930 - desc++; 931 - 932 - if (IS_ENABLED(CONFIG_X86_64)) { 933 - /* Task segment value */ 934 - desc->limit0 = 0x0000; 935 - desc->base0 = 0x0000; 936 - desc->base1 = 0x0000; 937 - desc->type = SEG_TYPE_TSS; 938 - desc->s = 0; 939 - desc->dpl = 0; 940 - desc->p = 1; 941 - desc->limit1 = 0x0; 942 - desc->avl = 0; 943 - desc->l = 0; 944 - desc->d = 0; 945 - desc->g = SEG_GRANULARITY_4KB; 946 - desc->base2 = 0x00; 947 - desc++; 948 - } 949 - 950 - asm volatile("cli"); 951 - asm volatile ("lgdt %0" : : "m" (*gdt)); 952 - 953 - return boot_params; 762 + return bzimage_addr; 954 763 fail: 955 764 efi_printk("efi_main() failed!\n"); 956 765 957 - for (;;) 958 - asm("hlt"); 766 + efi_exit(handle, status); 959 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
+63 -29
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 ··· 75 89 */ 76 90 leal (BP_scratch+4)(%esi), %esp 77 91 call 1f 78 - 1: popl %ebp 79 - subl $1b, %ebp 92 + 1: popl %edx 93 + subl $1b, %edx 94 + 95 + /* Load new GDT */ 96 + leal gdt(%edx), %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 - * %ebp contains the address we are loaded at by the boot loader and %ebx 109 + * %edx contains the address we are loaded at by the boot loader and %ebx 83 110 * contains the address where we should move the kernel image temporarily 84 - * for safe in-place decompression. 111 + * for safe in-place decompression. %ebp contains the address that the kernel 112 + * will be decompressed to. 85 113 */ 86 114 87 115 #ifdef CONFIG_RELOCATABLE 88 - movl %ebp, %ebx 116 + movl %edx, %ebx 117 + 118 + #ifdef CONFIG_EFI_STUB 119 + /* 120 + * If we were loaded via the EFI LoadImage service, startup_32() will be at an 121 + * offset to the start of the space allocated for the image. efi_pe_entry() will 122 + * set up image_offset to tell us where the image actually starts, so that we 123 + * can use the full available buffer. 124 + * image_offset = startup_32 - image_base 125 + * Otherwise image_offset will be zero and has no effect on the calculations. 126 + */ 127 + subl image_offset(%edx), %ebx 128 + #endif 129 + 89 130 movl BP_kernel_alignment(%esi), %eax 90 131 decl %eax 91 132 addl %eax, %ebx 92 133 notl %eax 93 134 andl %eax, %ebx 94 135 cmpl $LOAD_PHYSICAL_ADDR, %ebx 95 - jge 1f 136 + jae 1f 96 137 #endif 97 138 movl $LOAD_PHYSICAL_ADDR, %ebx 98 139 1: 99 140 141 + movl %ebx, %ebp // Save the output address for later 100 142 /* Target address to relocate to for decompression */ 101 - movl BP_init_size(%esi), %eax 102 - subl $_end, %eax 103 - addl %eax, %ebx 143 + addl BP_init_size(%esi), %ebx 144 + subl $_end, %ebx 104 145 105 146 /* Set up the stack */ 106 147 leal boot_stack_end(%ebx), %esp ··· 141 128 * where decompression in place becomes safe. 142 129 */ 143 130 pushl %esi 144 - leal (_bss-4)(%ebp), %esi 131 + leal (_bss-4)(%edx), %esi 145 132 leal (_bss-4)(%ebx), %edi 146 133 movl $(_bss - startup_32), %ecx 147 134 shrl $2, %ecx ··· 149 136 rep movsl 150 137 cld 151 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. 144 + */ 145 + leal gdt(%ebx), %eax 146 + movl %eax, 2(%eax) 147 + lgdt (%eax) 152 148 153 149 /* 154 150 * Jump to the relocated address. ··· 170 148 SYM_FUNC_START(efi32_stub_entry) 171 149 SYM_FUNC_START_ALIAS(efi_stub_entry) 172 150 add $0x4, %esp 151 + movl 8(%esp), %esi /* save boot_params pointer */ 173 152 call efi_main 174 - movl %eax, %esi 175 - movl BP_code32_start(%esi), %eax 176 153 leal startup_32(%eax), %eax 177 154 jmp *%eax 178 155 SYM_FUNC_END(efi32_stub_entry) ··· 210 189 /* push arguments for extract_kernel: */ 211 190 pushl $z_output_len /* decompressed length, end of relocs */ 212 191 213 - leal _end(%ebx), %eax 214 - subl BP_init_size(%esi), %eax 215 - pushl %eax /* output address */ 192 + pushl %ebp /* output address */ 216 193 217 194 pushl $z_input_len /* input_len */ 218 195 leal input_data(%ebx), %eax ··· 227 208 xorl %ebx, %ebx 228 209 jmp *%eax 229 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) 222 + 223 + #ifdef CONFIG_EFI_STUB 224 + SYM_DATA(image_offset, .long 0) 225 + #endif 230 226 231 227 /* 232 228 * Stack and heap for uncompression
+169 -36
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 ··· 99 100 100 101 #ifdef CONFIG_RELOCATABLE 101 102 movl %ebp, %ebx 103 + 104 + #ifdef CONFIG_EFI_STUB 105 + /* 106 + * If we were loaded via the EFI LoadImage service, startup_32 will be at an 107 + * offset to the start of the space allocated for the image. efi_pe_entry will 108 + * set up image_offset to tell us where the image actually starts, so that we 109 + * can use the full available buffer. 110 + * image_offset = startup_32 - image_base 111 + * Otherwise image_offset will be zero and has no effect on the calculations. 112 + */ 113 + subl image_offset(%ebp), %ebx 114 + #endif 115 + 102 116 movl BP_kernel_alignment(%esi), %eax 103 117 decl %eax 104 118 addl %eax, %ebx 105 119 notl %eax 106 120 andl %eax, %ebx 107 121 cmpl $LOAD_PHYSICAL_ADDR, %ebx 108 - jge 1f 122 + jae 1f 109 123 #endif 110 124 movl $LOAD_PHYSICAL_ADDR, %ebx 111 125 1: 112 126 113 127 /* Target address to relocate to for decompression */ 114 - movl BP_init_size(%esi), %eax 115 - subl $_end, %eax 116 - addl %eax, %ebx 128 + addl BP_init_size(%esi), %ebx 129 + subl $_end, %ebx 117 130 118 131 /* 119 132 * Prepare for entering 64 bit mode 120 133 */ 121 - 122 - /* Load new GDT with the 64bit segments using 32bit descriptor */ 123 - addl %ebp, gdt+2(%ebp) 124 - lgdt gdt(%ebp) 125 134 126 135 /* Enable PAE mode */ 127 136 movl %cr4, %eax ··· 219 212 cmp $0, %edi 220 213 jz 1f 221 214 leal efi64_stub_entry(%ebp), %eax 222 - movl %esi, %edx 223 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 224 222 1: 225 223 #endif 226 224 pushl %eax ··· 250 238 1: pop %ebp 251 239 subl $1b, %ebp 252 240 241 + movl %esi, efi32_boot_args+8(%ebp) 242 + SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL) 253 243 movl %ecx, efi32_boot_args(%ebp) 254 244 movl %edx, efi32_boot_args+4(%ebp) 255 - sgdtl efi32_boot_gdt(%ebp) 256 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) 257 251 258 252 /* Disable paging */ 259 253 movl %cr0, %eax ··· 283 265 * that maps our entire kernel(text+data+bss+brk), zero page 284 266 * and command line. 285 267 */ 268 + 269 + cld 270 + cli 286 271 287 272 /* Setup data segments. */ 288 273 xorl %eax, %eax ··· 311 290 /* Start with the delta to where the kernel will run at. */ 312 291 #ifdef CONFIG_RELOCATABLE 313 292 leaq startup_32(%rip) /* - $startup_32 */, %rbp 293 + 294 + #ifdef CONFIG_EFI_STUB 295 + /* 296 + * If we were loaded via the EFI LoadImage service, startup_32 will be at an 297 + * offset to the start of the space allocated for the image. efi_pe_entry will 298 + * set up image_offset to tell us where the image actually starts, so that we 299 + * can use the full available buffer. 300 + * image_offset = startup_32 - image_base 301 + * Otherwise image_offset will be zero and has no effect on the calculations. 302 + */ 303 + movl image_offset(%rip), %eax 304 + subq %rax, %rbp 305 + #endif 306 + 314 307 movl BP_kernel_alignment(%rsi), %eax 315 308 decl %eax 316 309 addq %rax, %rbp 317 310 notq %rax 318 311 andq %rax, %rbp 319 312 cmpq $LOAD_PHYSICAL_ADDR, %rbp 320 - jge 1f 313 + jae 1f 321 314 #endif 322 315 movq $LOAD_PHYSICAL_ADDR, %rbp 323 316 1: ··· 389 354 */ 390 355 391 356 /* Make sure we have GDT with 32-bit code segment */ 392 - leaq gdt(%rip), %rax 393 - movq %rax, gdt64+2(%rip) 394 - lgdt gdt64(%rip) 357 + leaq gdt64(%rip), %rax 358 + addq %rax, 2(%rax) 359 + lgdt (%rax) 395 360 396 361 /* 397 362 * paging_prepare() sets up the trampoline and checks if we need to ··· 476 441 cld 477 442 popq %rsi 478 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 + leaq gdt(%rbx), %rdx 451 + movq %rdx, 2(%rax) 452 + lgdt (%rax) 453 + 479 454 /* 480 455 * Jump to the relocated address. 481 456 */ ··· 498 453 SYM_FUNC_START(efi64_stub_entry) 499 454 SYM_FUNC_START_ALIAS(efi_stub_entry) 500 455 and $~0xf, %rsp /* realign the stack */ 456 + movq %rdx, %rbx /* save boot_params pointer */ 501 457 call efi_main 502 - movq %rax,%rsi 503 - movl BP_code32_start(%esi), %eax 458 + movq %rbx,%rsi 504 459 leaq startup_64(%rax), %rax 505 460 jmp *%rax 506 461 SYM_FUNC_END(efi64_stub_entry) ··· 658 613 659 614 .data 660 615 SYM_DATA_START_LOCAL(gdt64) 661 - .word gdt_end - gdt 662 - .quad 0 616 + .word gdt_end - gdt - 1 617 + .quad gdt - gdt64 663 618 SYM_DATA_END(gdt64) 664 619 .balign 8 665 620 SYM_DATA_START_LOCAL(gdt) 666 - .word gdt_end - gdt 667 - .long gdt 621 + .word gdt_end - gdt - 1 622 + .long 0 668 623 .word 0 669 624 .quad 0x00cf9a000000ffff /* __KERNEL32_CS */ 670 625 .quad 0x00af9a000000ffff /* __KERNEL_CS */ ··· 673 628 .quad 0x0000000000000000 /* TS continued */ 674 629 SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) 675 630 631 + #ifdef CONFIG_EFI_STUB 632 + SYM_DATA(image_offset, .long 0) 633 + #endif 634 + 676 635 #ifdef CONFIG_EFI_MIXED 677 - SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0) 636 + SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) 678 637 SYM_DATA(efi_is64, .byte 1) 638 + 639 + #define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) 640 + #define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) 641 + #define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) 642 + 643 + .text 644 + .code32 645 + SYM_FUNC_START(efi32_pe_entry) 646 + /* 647 + * efi_status_t efi32_pe_entry(efi_handle_t image_handle, 648 + * efi_system_table_32_t *sys_table) 649 + */ 650 + 651 + pushl %ebp 652 + movl %esp, %ebp 653 + pushl %eax // dummy push to allocate loaded_image 654 + 655 + pushl %ebx // save callee-save registers 656 + pushl %edi 657 + 658 + call verify_cpu // check for long mode support 659 + testl %eax, %eax 660 + movl $0x80000003, %eax // EFI_UNSUPPORTED 661 + jnz 2f 662 + 663 + call 1f 664 + 1: pop %ebx 665 + subl $1b, %ebx 666 + 667 + /* Get the loaded image protocol pointer from the image handle */ 668 + leal -4(%ebp), %eax 669 + pushl %eax // &loaded_image 670 + leal loaded_image_proto(%ebx), %eax 671 + pushl %eax // pass the GUID address 672 + pushl 8(%ebp) // pass the image handle 673 + 674 + /* 675 + * Note the alignment of the stack frame. 676 + * sys_table 677 + * handle <-- 16-byte aligned on entry by ABI 678 + * return address 679 + * frame pointer 680 + * loaded_image <-- local variable 681 + * saved %ebx <-- 16-byte aligned here 682 + * saved %edi 683 + * &loaded_image 684 + * &loaded_image_proto 685 + * handle <-- 16-byte aligned for call to handle_protocol 686 + */ 687 + 688 + movl 12(%ebp), %eax // sys_table 689 + movl ST32_boottime(%eax), %eax // sys_table->boottime 690 + call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol 691 + addl $12, %esp // restore argument space 692 + testl %eax, %eax 693 + jnz 2f 694 + 695 + movl 8(%ebp), %ecx // image_handle 696 + movl 12(%ebp), %edx // sys_table 697 + movl -4(%ebp), %esi // loaded_image 698 + movl LI32_image_base(%esi), %esi // loaded_image->image_base 699 + movl %ebx, %ebp // startup_32 for efi32_pe_stub_entry 700 + /* 701 + * We need to set the image_offset variable here since startup_32() will 702 + * use it before we get to the 64-bit efi_pe_entry() in C code. 703 + */ 704 + subl %esi, %ebx 705 + movl %ebx, image_offset(%ebp) // save image_offset 706 + jmp efi32_pe_stub_entry 707 + 708 + 2: popl %edi // restore callee-save registers 709 + popl %ebx 710 + leave 711 + ret 712 + SYM_FUNC_END(efi32_pe_entry) 713 + 714 + .section ".rodata" 715 + /* EFI loaded image protocol GUID */ 716 + .balign 4 717 + SYM_DATA_START_LOCAL(loaded_image_proto) 718 + .long 0x5b1b31a1 719 + .word 0x9562, 0x11d2 720 + .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b 721 + SYM_DATA_END(loaded_image_proto) 679 722 #endif 680 723 681 724 /*
+56 -53
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 ··· 138 148 #endif 139 149 140 150 extra_header_fields: 151 + # PE specification requires ImageBase to be 64k aligned 152 + .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff 141 153 #ifdef CONFIG_X86_32 142 - .long 0 # ImageBase 154 + .long image_base # ImageBase 143 155 #else 144 - .quad 0 # ImageBase 156 + .quad image_base # ImageBase 145 157 #endif 146 158 .long 0x20 # SectionAlignment 147 159 .long 0x20 # FileAlignment 148 160 .word 0 # MajorOperatingSystemVersion 149 161 .word 0 # MinorOperatingSystemVersion 150 - .word 0 # MajorImageVersion 151 - .word 0 # MinorImageVersion 162 + .word LINUX_EFISTUB_MAJOR_VERSION # MajorImageVersion 163 + .word LINUX_EFISTUB_MINOR_VERSION # MinorImageVersion 152 164 .word 0 # MajorSubsystemVersion 153 165 .word 0 # MinorSubsystemVersion 154 166 .long 0 # Win32VersionValue ··· 162 170 163 171 .long 0x200 # SizeOfHeaders 164 172 .long 0 # CheckSum 165 - .word 0xa # Subsystem (EFI application) 173 + .word IMAGE_SUBSYSTEM_EFI_APPLICATION # Subsystem (EFI application) 166 174 .word 0 # DllCharacteristics 167 175 #ifdef CONFIG_X86_32 168 176 .long 0 # SizeOfStackReserve ··· 176 184 .quad 0 # SizeOfHeapCommit 177 185 #endif 178 186 .long 0 # LoaderFlags 179 - .long 0x6 # NumberOfRvaAndSizes 187 + .long (section_table - .) / 8 # NumberOfRvaAndSizes 180 188 181 189 .quad 0 # ExportTable 182 190 .quad 0 # ImportTable ··· 202 210 .long 0 # PointerToLineNumbers 203 211 .word 0 # NumberOfRelocations 204 212 .word 0 # NumberOfLineNumbers 205 - .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 206 217 207 218 # 208 219 # The EFI application loader requires a relocation section ··· 223 228 .long 0 # PointerToLineNumbers 224 229 .word 0 # NumberOfRelocations 225 230 .word 0 # NumberOfLineNumbers 226 - .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 227 255 228 256 # 229 257 # The offset & size fields are filled in by build.c. ··· 264 246 .long 0 # PointerToLineNumbers 265 247 .word 0 # NumberOfRelocations 266 248 .word 0 # NumberOfLineNumbers 267 - .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 268 253 269 - # 270 - # The offset & size fields are filled in by build.c. 271 - # 272 - .ascii ".bss" 273 - .byte 0 274 - .byte 0 275 - .byte 0 276 - .byte 0 277 - .long 0 278 - .long 0x0 279 - .long 0 # Size of initialized data 280 - # on disk 281 - .long 0x0 282 - .long 0 # PointerToRelocations 283 - .long 0 # PointerToLineNumbers 284 - .word 0 # NumberOfRelocations 285 - .word 0 # NumberOfLineNumbers 286 - .long 0xc8000080 # Characteristics (section flags) 287 - 254 + .set section_count, (. - section_table) / 40 288 255 #endif /* CONFIG_EFI_STUB */ 289 256 290 257 # Kernel attributes; used by setup. This is part 1 of the
+81 -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; 68 + unsigned long _ehead; 69 + unsigned long _end; 61 70 62 71 /*----------------------------------------------------------------------*/ 63 72 ··· 198 189 static void update_pecoff_setup_and_reloc(unsigned int size) 199 190 { 200 191 u32 setup_offset = 0x200; 201 - 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 202 196 u32 setup_size = reloc_offset - setup_offset; 203 197 204 198 update_pecoff_section_header(".setup", setup_offset, setup_size); ··· 213 201 */ 214 202 put_unaligned_le32(reloc_offset + 10, &buf[reloc_offset]); 215 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 216 218 } 217 219 218 - 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) 219 222 { 220 223 unsigned int pe_header; 221 224 unsigned int text_sz = file_sz - text_start; 225 + unsigned int bss_sz = init_sz - file_sz; 222 226 223 227 pe_header = get_unaligned_le32(&buf[0x3c]); 228 + 229 + /* 230 + * The PE/COFF loader may load the image at an address which is 231 + * misaligned with respect to the kernel_alignment field in the setup 232 + * header. 233 + * 234 + * In order to avoid relocating the kernel to correct the misalignment, 235 + * add slack to allow the buffer to be aligned within the declared size 236 + * of the image. 237 + */ 238 + bss_sz += CONFIG_PHYSICAL_ALIGN; 239 + init_sz += CONFIG_PHYSICAL_ALIGN; 224 240 225 241 /* 226 242 * Size of code: Subtract the size of the first sector (512 bytes) 227 243 * which includes the header. 228 244 */ 229 - put_unaligned_le32(file_sz - 512, &buf[pe_header + 0x1c]); 245 + put_unaligned_le32(file_sz - 512 + bss_sz, &buf[pe_header + 0x1c]); 246 + 247 + /* Size of image */ 248 + put_unaligned_le32(init_sz, &buf[pe_header + 0x50]); 230 249 231 250 /* 232 251 * Address of entry point for PE/COFF executable 233 252 */ 234 253 put_unaligned_le32(text_start + efi_pe_entry, &buf[pe_header + 0x28]); 235 254 236 - update_pecoff_section_header(".text", text_start, text_sz); 237 - } 238 - 239 - static void update_pecoff_bss(unsigned int file_sz, unsigned int init_sz) 240 - { 241 - unsigned int pe_header; 242 - unsigned int bss_sz = init_sz - file_sz; 243 - 244 - pe_header = get_unaligned_le32(&buf[0x3c]); 245 - 246 - /* Size of uninitialized data */ 247 - put_unaligned_le32(bss_sz, &buf[pe_header + 0x24]); 248 - 249 - /* Size of image */ 250 - put_unaligned_le32(init_sz, &buf[pe_header + 0x50]); 251 - 252 - update_pecoff_section_header_fields(".bss", file_sz, bss_sz, 0, 0); 255 + update_pecoff_section_header_fields(".text", text_start, text_sz + bss_sz, 256 + text_sz, text_start); 253 257 } 254 258 255 259 static int reserve_pecoff_reloc_section(int c) ··· 306 278 307 279 static inline void update_pecoff_setup_and_reloc(unsigned int size) {} 308 280 static inline void update_pecoff_text(unsigned int text_start, 309 - unsigned int file_sz) {} 310 - static inline void update_pecoff_bss(unsigned int file_sz, 311 - unsigned int init_sz) {} 281 + unsigned int file_sz, 282 + unsigned int init_sz) {} 312 283 static inline void efi_stub_defaults(void) {} 313 284 static inline void efi_stub_entry_update(void) {} 314 285 ··· 317 290 } 318 291 #endif /* CONFIG_EFI_STUB */ 319 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 + } 320 299 321 300 /* 322 301 * Parse zoffset.h and find the entry points. We could just #include zoffset.h ··· 355 322 PARSE_ZOFS(p, efi32_stub_entry); 356 323 PARSE_ZOFS(p, efi64_stub_entry); 357 324 PARSE_ZOFS(p, efi_pe_entry); 325 + PARSE_ZOFS(p, efi32_pe_entry); 358 326 PARSE_ZOFS(p, kernel_info); 359 327 PARSE_ZOFS(p, startup_64); 328 + PARSE_ZOFS(p, _ehead); 329 + PARSE_ZOFS(p, _end); 360 330 361 331 p = strchr(p, '\n'); 362 332 while (p && (*p == '\r' || *p == '\n')) ··· 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 + #ifdef CONFIG_EFI_STUB 411 + /* 412 + * The decompression buffer will start at ImageBase. When relocating 413 + * the compressed kernel to its end, we must ensure that the head 414 + * section does not get overwritten. The head section occupies 415 + * [i, i + _ehead), and the destination is [init_sz - _end, init_sz). 416 + * 417 + * At present these should never overlap, because 'i' is at most 32k 418 + * because of SETUP_SECT_MAX, '_ehead' is less than 1k, and the 419 + * calculation of INIT_SIZE in boot/header.S ensures that 420 + * 'init_sz - _end' is at least 64k. 421 + * 422 + * For future-proofing, increase init_sz if necessary. 423 + */ 424 + 425 + if (init_sz - _end < i + _ehead) { 426 + init_sz = (i + _ehead + _end + 4095) & ~4095; 427 + put_unaligned_le32(init_sz, &buf[0x260]); 428 + } 429 + #endif 430 + update_pecoff_text(setup_sectors * 512, i + (sys_size * 16), init_sz); 449 431 450 432 efi_stub_entry_update(); 451 433
+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
-1
arch/x86/kernel/asm-offsets.c
··· 88 88 OFFSET(BP_kernel_alignment, boot_params, hdr.kernel_alignment); 89 89 OFFSET(BP_init_size, boot_params, hdr.init_size); 90 90 OFFSET(BP_pref_address, boot_params, hdr.pref_address); 91 - OFFSET(BP_code32_start, boot_params, hdr.code32_start); 92 91 93 92 BLANK(); 94 93 DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
+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;
+139 -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 85 + &efi.tpm_log, 86 + &efi.tpm_final_log, 87 + &efi_rng_seed, 94 88 }; 95 89 96 90 u64 efi_setup; /* efi setup_data physical address */ ··· 220 214 if (efi_enabled(EFI_PARAVIRT)) 221 215 return 0; 222 216 223 - #ifdef CONFIG_X86_32 224 - /* Can't handle data above 4GB at this time */ 225 - 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) { 226 219 pr_err("Memory map is above 4GB, disabling EFI.\n"); 227 220 return -EINVAL; 228 221 } 229 - pmap = e->efi_memmap; 230 - #else 231 - pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); 232 - #endif 222 + pmap = (phys_addr_t)(e->efi_memmap | ((u64)e->efi_memmap_hi << 32)); 223 + 233 224 data.phys_map = pmap; 234 225 data.size = e->efi_memmap_size; 235 226 data.desc_size = e->efi_memdesc_size; ··· 309 306 310 307 if (n_removal > 0) { 311 308 struct efi_memory_map_data data = { 312 - .phys_map = efi.memmap.phys_map, 313 - .desc_version = efi.memmap.desc_version, 314 - .desc_size = efi.memmap.desc_size, 315 - .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), 316 - .flags = 0, 309 + .phys_map = efi.memmap.phys_map, 310 + .desc_version = efi.memmap.desc_version, 311 + .desc_size = efi.memmap.desc_size, 312 + .size = efi.memmap.desc_size * (efi.memmap.nr_map - n_removal), 313 + .flags = 0, 317 314 }; 318 315 319 316 pr_warn("Removing %d invalid memory map entries.\n", n_removal); ··· 337 334 } 338 335 } 339 336 340 - static int __init efi_systab_init(u64 phys) 337 + static int __init efi_systab_init(unsigned long phys) 341 338 { 342 339 int size = efi_enabled(EFI_64BIT) ? sizeof(efi_system_table_64_t) 343 340 : sizeof(efi_system_table_32_t); 341 + const efi_table_hdr_t *hdr; 344 342 bool over4g = false; 345 343 void *p; 344 + int ret; 346 345 347 - p = early_memremap_ro(phys, size); 346 + hdr = p = early_memremap_ro(phys, size); 348 347 if (p == NULL) { 349 348 pr_err("Couldn't map the system table!\n"); 350 349 return -ENOMEM; 351 350 } 352 351 352 + ret = efi_systab_check_header(hdr, 1); 353 + if (ret) { 354 + early_memunmap(p, size); 355 + return ret; 356 + } 357 + 353 358 if (efi_enabled(EFI_64BIT)) { 354 359 const efi_system_table_64_t *systab64 = p; 355 360 356 - efi_systab.hdr = systab64->hdr; 357 - efi_systab.fw_vendor = systab64->fw_vendor; 358 - efi_systab.fw_revision = systab64->fw_revision; 359 - efi_systab.con_in_handle = systab64->con_in_handle; 360 - efi_systab.con_in = systab64->con_in; 361 - efi_systab.con_out_handle = systab64->con_out_handle; 362 - efi_systab.con_out = (void *)(unsigned long)systab64->con_out; 363 - efi_systab.stderr_handle = systab64->stderr_handle; 364 - efi_systab.stderr = systab64->stderr; 365 - efi_systab.runtime = (void *)(unsigned long)systab64->runtime; 366 - efi_systab.boottime = (void *)(unsigned long)systab64->boottime; 367 - efi_systab.nr_tables = systab64->nr_tables; 368 - efi_systab.tables = systab64->tables; 369 - 370 - over4g = systab64->con_in_handle > U32_MAX || 371 - systab64->con_in > U32_MAX || 372 - systab64->con_out_handle > U32_MAX || 373 - systab64->con_out > U32_MAX || 374 - systab64->stderr_handle > U32_MAX || 375 - systab64->stderr > U32_MAX || 376 - systab64->boottime > U32_MAX; 361 + efi_runtime = systab64->runtime; 362 + over4g = systab64->runtime > U32_MAX; 377 363 378 364 if (efi_setup) { 379 365 struct efi_setup_data *data; ··· 373 381 return -ENOMEM; 374 382 } 375 383 376 - efi_systab.fw_vendor = (unsigned long)data->fw_vendor; 377 - efi_systab.runtime = (void *)(unsigned long)data->runtime; 378 - efi_systab.tables = (unsigned long)data->tables; 384 + efi_fw_vendor = (unsigned long)data->fw_vendor; 385 + efi_config_table = (unsigned long)data->tables; 379 386 380 387 over4g |= data->fw_vendor > U32_MAX || 381 - data->runtime > U32_MAX || 382 388 data->tables > U32_MAX; 383 389 384 390 early_memunmap(data, sizeof(*data)); 385 391 } else { 392 + efi_fw_vendor = systab64->fw_vendor; 393 + efi_config_table = systab64->tables; 394 + 386 395 over4g |= systab64->fw_vendor > U32_MAX || 387 - systab64->runtime > U32_MAX || 388 396 systab64->tables > U32_MAX; 389 397 } 398 + efi_nr_tables = systab64->nr_tables; 390 399 } else { 391 400 const efi_system_table_32_t *systab32 = p; 392 401 393 - efi_systab.hdr = systab32->hdr; 394 - efi_systab.fw_vendor = systab32->fw_vendor; 395 - efi_systab.fw_revision = systab32->fw_revision; 396 - efi_systab.con_in_handle = systab32->con_in_handle; 397 - efi_systab.con_in = systab32->con_in; 398 - efi_systab.con_out_handle = systab32->con_out_handle; 399 - efi_systab.con_out = (void *)(unsigned long)systab32->con_out; 400 - efi_systab.stderr_handle = systab32->stderr_handle; 401 - efi_systab.stderr = systab32->stderr; 402 - efi_systab.runtime = (void *)(unsigned long)systab32->runtime; 403 - efi_systab.boottime = (void *)(unsigned long)systab32->boottime; 404 - efi_systab.nr_tables = systab32->nr_tables; 405 - efi_systab.tables = systab32->tables; 402 + efi_fw_vendor = systab32->fw_vendor; 403 + efi_runtime = systab32->runtime; 404 + efi_config_table = systab32->tables; 405 + efi_nr_tables = systab32->nr_tables; 406 406 } 407 407 408 + efi.runtime_version = hdr->revision; 409 + 410 + efi_systab_report_header(hdr, efi_fw_vendor); 408 411 early_memunmap(p, size); 409 412 410 413 if (IS_ENABLED(CONFIG_X86_32) && over4g) { ··· 407 420 return -EINVAL; 408 421 } 409 422 410 - efi.systab = &efi_systab; 423 + return 0; 424 + } 425 + 426 + static int __init efi_config_init(const efi_config_table_type_t *arch_tables) 427 + { 428 + void *config_tables; 429 + int sz, ret; 430 + 431 + if (efi_nr_tables == 0) 432 + return 0; 433 + 434 + if (efi_enabled(EFI_64BIT)) 435 + sz = sizeof(efi_config_table_64_t); 436 + else 437 + sz = sizeof(efi_config_table_32_t); 411 438 412 439 /* 413 - * Verify the EFI Table 440 + * Let's see what config tables the firmware passed to us. 414 441 */ 415 - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { 416 - pr_err("System table signature incorrect!\n"); 417 - return -EINVAL; 442 + config_tables = early_memremap(efi_config_table, efi_nr_tables * sz); 443 + if (config_tables == NULL) { 444 + pr_err("Could not map Configuration table!\n"); 445 + return -ENOMEM; 418 446 } 419 - if ((efi.systab->hdr.revision >> 16) == 0) 420 - pr_err("Warning: System table version %d.%02d, expected 1.00 or greater!\n", 421 - efi.systab->hdr.revision >> 16, 422 - efi.systab->hdr.revision & 0xffff); 423 447 424 - return 0; 448 + ret = efi_config_parse_tables(config_tables, efi_nr_tables, 449 + arch_tables); 450 + 451 + early_memunmap(config_tables, efi_nr_tables * sz); 452 + return ret; 425 453 } 426 454 427 455 void __init efi_init(void) 428 456 { 429 - efi_char16_t *c16; 430 - char vendor[100] = "unknown"; 431 - int i = 0; 432 - 433 457 if (IS_ENABLED(CONFIG_X86_32) && 434 458 (boot_params.efi_info.efi_systab_hi || 435 459 boot_params.efi_info.efi_memmap_hi)) { ··· 454 456 if (efi_systab_init(efi_systab_phys)) 455 457 return; 456 458 457 - efi.config_table = (unsigned long)efi.systab->tables; 458 - efi.fw_vendor = (unsigned long)efi.systab->fw_vendor; 459 - efi.runtime = (unsigned long)efi.systab->runtime; 460 - 461 - /* 462 - * Show what we know for posterity 463 - */ 464 - c16 = early_memremap_ro(efi.systab->fw_vendor, 465 - sizeof(vendor) * sizeof(efi_char16_t)); 466 - if (c16) { 467 - for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i) 468 - vendor[i] = c16[i]; 469 - vendor[i] = '\0'; 470 - early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); 471 - } else { 472 - pr_err("Could not map the firmware vendor!\n"); 473 - } 474 - 475 - pr_info("EFI v%u.%.02u by %s\n", 476 - efi.systab->hdr.revision >> 16, 477 - efi.systab->hdr.revision & 0xffff, vendor); 478 - 479 - if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables)) 459 + if (efi_reuse_config(efi_config_table, efi_nr_tables)) 480 460 return; 481 461 482 462 if (efi_config_init(arch_tables)) ··· 471 495 if (!efi_runtime_supported() || efi_runtime_disabled()) { 472 496 efi_memmap_unmap(); 473 497 return; 498 + } 499 + 500 + /* Parse the EFI Properties table if it exists */ 501 + if (prop_phys != EFI_INVALID_TABLE_ADDR) { 502 + efi_properties_table_t *tbl; 503 + 504 + tbl = early_memremap_ro(prop_phys, sizeof(*tbl)); 505 + if (tbl == NULL) { 506 + pr_err("Could not map Properties table!\n"); 507 + } else { 508 + if (tbl->memory_protection_attribute & 509 + EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) 510 + set_bit(EFI_NX_PE_DATA, &efi.flags); 511 + 512 + early_memunmap(tbl, sizeof(*tbl)); 513 + } 474 514 } 475 515 476 516 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); ··· 592 600 continue; 593 601 } 594 602 prev_md = md; 595 - } 596 - } 597 - 598 - static void __init get_systab_virt_addr(efi_memory_desc_t *md) 599 - { 600 - unsigned long size; 601 - u64 end, systab; 602 - 603 - size = md->num_pages << EFI_PAGE_SHIFT; 604 - end = md->phys_addr + size; 605 - systab = efi_systab_phys; 606 - if (md->phys_addr <= systab && systab < end) { 607 - systab += md->virt_addr - md->phys_addr; 608 - efi.systab = (efi_system_table_t *)(unsigned long)systab; 609 603 } 610 604 } 611 605 ··· 750 772 continue; 751 773 752 774 efi_map_region(md); 753 - get_systab_virt_addr(md); 754 775 755 776 if (left < desc_size) { 756 777 new_memmap = realloc_pages(new_memmap, *pg_shift); ··· 775 798 efi_memory_desc_t *md; 776 799 unsigned int num_pages; 777 800 778 - efi.systab = NULL; 779 - 780 801 /* 781 802 * We don't do virtual mode, since we don't do runtime services, on 782 803 * non-native EFI. With the UV1 memmap, we don't do runtime services in ··· 797 822 * Map efi regions which were passed via setup_data. The virt_addr is a 798 823 * fixed addr which was used in first kernel of a kexec boot. 799 824 */ 800 - for_each_efi_memory_desc(md) { 825 + for_each_efi_memory_desc(md) 801 826 efi_map_region_fixed(md); /* FIXME: add error handling */ 802 - get_systab_virt_addr(md); 803 - } 804 827 805 828 /* 806 829 * Unregister the early EFI memmap from efi_init() and install ··· 813 840 return; 814 841 } 815 842 816 - BUG_ON(!efi.systab); 817 - 818 843 num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE); 819 844 num_pages >>= PAGE_SHIFT; 820 845 ··· 822 851 } 823 852 824 853 efi_sync_low_kernel_mappings(); 825 - 826 - /* 827 - * Now that EFI is in virtual mode, update the function 828 - * pointers in the runtime service table to the new virtual addresses. 829 - * 830 - * Call EFI services through wrapper functions. 831 - */ 832 - efi.runtime_version = efi_systab.hdr.revision; 833 - 834 854 efi_native_runtime_setup(); 835 855 #endif 836 856 } ··· 855 893 efi_status_t status; 856 894 unsigned long pa; 857 895 858 - efi.systab = NULL; 859 - 860 896 if (efi_alloc_page_tables()) { 861 897 pr_err("Failed to allocate EFI page tables\n"); 862 898 goto err; ··· 886 926 efi_print_memmap(); 887 927 } 888 928 889 - if (WARN_ON(!efi.systab)) 890 - goto err; 891 - 892 929 if (efi_setup_page_tables(pa, 1 << pg_shift)) 893 930 goto err; 894 931 ··· 894 937 status = efi_set_virtual_address_map(efi.memmap.desc_size * count, 895 938 efi.memmap.desc_size, 896 939 efi.memmap.desc_version, 897 - (efi_memory_desc_t *)pa); 940 + (efi_memory_desc_t *)pa, 941 + efi_systab_phys); 898 942 if (status != EFI_SUCCESS) { 899 943 pr_err("Unable to switch EFI into virtual mode (status=%lx)!\n", 900 944 status); ··· 904 946 905 947 efi_check_for_embedded_firmwares(); 906 948 efi_free_boot_services(); 907 - 908 - /* 909 - * Now that EFI is in virtual mode, update the function 910 - * pointers in the runtime service table to the new virtual addresses. 911 - * 912 - * Call EFI services through wrapper functions. 913 - */ 914 - efi.runtime_version = efi_systab.hdr.revision; 915 949 916 950 if (!efi_is_mixed()) 917 951 efi_native_runtime_setup(); ··· 930 980 if (efi_enabled(EFI_PARAVIRT)) 931 981 return; 932 982 983 + efi.runtime = (efi_runtime_services_t *)efi_runtime; 984 + 933 985 if (efi_setup) 934 986 kexec_enter_virtual_mode(); 935 987 else ··· 952 1000 return true; 953 1001 954 1002 return false; 1003 + } 1004 + 1005 + char *efi_systab_show_arch(char *str) 1006 + { 1007 + if (uga_phys != EFI_INVALID_TABLE_ADDR) 1008 + str += sprintf(str, "UGA=0x%lx\n", uga_phys); 1009 + return str; 1010 + } 1011 + 1012 + #define EFI_FIELD(var) efi_ ## var 1013 + 1014 + #define EFI_ATTR_SHOW(name) \ 1015 + static ssize_t name##_show(struct kobject *kobj, \ 1016 + struct kobj_attribute *attr, char *buf) \ 1017 + { \ 1018 + return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 1019 + } 1020 + 1021 + EFI_ATTR_SHOW(fw_vendor); 1022 + EFI_ATTR_SHOW(runtime); 1023 + EFI_ATTR_SHOW(config_table); 1024 + 1025 + struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 1026 + struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 1027 + struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 1028 + 1029 + umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) 1030 + { 1031 + if (attr == &efi_attr_fw_vendor.attr) { 1032 + if (efi_enabled(EFI_PARAVIRT) || 1033 + efi_fw_vendor == EFI_INVALID_TABLE_ADDR) 1034 + return 0; 1035 + } else if (attr == &efi_attr_runtime.attr) { 1036 + if (efi_runtime == EFI_INVALID_TABLE_ADDR) 1037 + return 0; 1038 + } else if (attr == &efi_attr_config_table.attr) { 1039 + if (efi_config_table == EFI_INVALID_TABLE_ADDR) 1040 + return 0; 1041 + } 1042 + return attr->mode; 955 1043 }
+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
··· 497 497 */ 498 498 #define __efi_thunk(func, ...) \ 499 499 ({ \ 500 - efi_runtime_services_32_t *__rt; \ 501 500 unsigned short __ds, __es; \ 502 501 efi_status_t ____s; \ 503 - \ 504 - __rt = (void *)(unsigned long)efi.systab->mixed_mode.runtime; \ 505 502 \ 506 503 savesegment(ds, __ds); \ 507 504 savesegment(es, __es); \ ··· 507 510 loadsegment(ds, __KERNEL_DS); \ 508 511 loadsegment(es, __KERNEL_DS); \ 509 512 \ 510 - ____s = efi64_thunk(__rt->func, __VA_ARGS__); \ 513 + ____s = efi64_thunk(efi.runtime->mixed_mode.func, __VA_ARGS__); \ 511 514 \ 512 515 loadsegment(ds, __ds); \ 513 516 loadsegment(es, __es); \ ··· 836 839 efi_set_virtual_address_map(unsigned long memory_map_size, 837 840 unsigned long descriptor_size, 838 841 u32 descriptor_version, 839 - efi_memory_desc_t *virtual_map) 842 + efi_memory_desc_t *virtual_map, 843 + unsigned long systab_phys) 840 844 { 845 + const efi_system_table_t *systab = (efi_system_table_t *)systab_phys; 841 846 efi_status_t status; 842 847 unsigned long flags; 843 848 pgd_t *save_pgd = NULL; ··· 862 863 863 864 /* Disable interrupts around EFI calls: */ 864 865 local_irq_save(flags); 865 - status = efi_call(efi.systab->runtime->set_virtual_address_map, 866 + status = efi_call(efi.runtime->set_virtual_address_map, 866 867 memory_map_size, descriptor_size, 867 868 descriptor_version, virtual_map); 868 869 local_irq_restore(flags); 869 870 870 871 kernel_fpu_end(); 872 + 873 + /* grab the virtually remapped EFI runtime services table pointer */ 874 + efi.runtime = READ_ONCE(systab->runtime); 871 875 872 876 if (save_pgd) 873 877 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 + movl 16(%esp), %ebx 52 + leave 54 53 ret 55 54 SYM_FUNC_END(efi_call_svam)
+1 -1
arch/x86/platform/efi/quirks.c
··· 541 541 goto out_memremap; 542 542 } 543 543 544 - for (i = 0; i < efi.systab->nr_tables; i++) { 544 + for (i = 0; i < nr_tables; i++) { 545 545 efi_guid_t guid; 546 546 547 547 guid = ((efi_config_table_64_t *)p)->guid;
+26 -9
block/partitions/efi.c
··· 657 657 } 658 658 659 659 /** 660 + * utf16_le_to_7bit(): Naively converts a UTF-16LE string to 7-bit ASCII characters 661 + * @in: input UTF-16LE string 662 + * @size: size of the input string 663 + * @out: output string ptr, should be capable to store @size+1 characters 664 + * 665 + * Description: Converts @size UTF16-LE symbols from @in string to 7-bit 666 + * ASCII characters and stores them to @out. Adds trailing zero to @out array. 667 + */ 668 + static void utf16_le_to_7bit(const __le16 *in, unsigned int size, u8 *out) 669 + { 670 + unsigned int i = 0; 671 + 672 + out[size] = 0; 673 + 674 + while (i < size) { 675 + u8 c = le16_to_cpu(in[i]) & 0xff; 676 + 677 + if (c && !isprint(c)) 678 + c = '!'; 679 + out[i] = c; 680 + i++; 681 + } 682 + } 683 + 684 + /** 660 685 * efi_partition(struct parsed_partitions *state) 661 686 * @state: disk parsed partitions 662 687 * ··· 717 692 718 693 for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { 719 694 struct partition_meta_info *info; 720 - unsigned label_count = 0; 721 695 unsigned label_max; 722 696 u64 start = le64_to_cpu(ptes[i].starting_lba); 723 697 u64 size = le64_to_cpu(ptes[i].ending_lba) - ··· 737 713 /* Naively convert UTF16-LE to 7 bits. */ 738 714 label_max = min(ARRAY_SIZE(info->volname) - 1, 739 715 ARRAY_SIZE(ptes[i].partition_name)); 740 - info->volname[label_max] = 0; 741 - while (label_count < label_max) { 742 - u8 c = ptes[i].partition_name[label_count] & 0xff; 743 - if (c && !isprint(c)) 744 - c = '!'; 745 - info->volname[label_count] = c; 746 - label_count++; 747 - } 716 + utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname); 748 717 state->parts[i + 1].has_info = true; 749 718 } 750 719 kfree(ptes);
+1 -1
block/partitions/efi.h
··· 88 88 __le64 starting_lba; 89 89 __le64 ending_lba; 90 90 gpt_entry_attributes attributes; 91 - efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; 91 + __le16 partition_name[72/sizeof(__le16)]; 92 92 } __packed gpt_entry; 93 93 94 94 typedef struct _gpt_mbr_record {
+2 -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 19 20 obj-$(CONFIG_UEFI_CPER) += cper.o 20 21 obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o 21 22 obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o 22 - obj-$(CONFIG_EFI_STUB) += libstub/ 23 + subdir-$(CONFIG_EFI_STUB) += libstub 23 24 obj-$(CONFIG_EFI_FAKE_MEMMAP) += fake_map.o 24 25 obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o 25 26 obj-$(CONFIG_EFI_TEST) += test/
+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;
+2 -2
drivers/firmware/efi/efi-pstore.c
··· 161 161 * 162 162 * @record: pstore record to pass to callback 163 163 * 164 - * You MUST call efivar_enter_iter_begin() before this function, and 164 + * You MUST call efivar_entry_iter_begin() before this function, and 165 165 * efivar_entry_iter_end() afterwards. 166 166 * 167 167 */ ··· 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())
+136 -289
drivers/firmware/efi/efi.c
··· 21 21 #include <linux/device.h> 22 22 #include <linux/efi.h> 23 23 #include <linux/of.h> 24 - #include <linux/of_fdt.h> 25 24 #include <linux/io.h> 26 25 #include <linux/kexec.h> 27 26 #include <linux/platform_device.h> ··· 35 36 #include <asm/early_ioremap.h> 36 37 37 38 struct efi __read_mostly efi = { 38 - .mps = EFI_INVALID_TABLE_ADDR, 39 + .runtime_supported_mask = EFI_RT_SUPPORTED_ALL, 39 40 .acpi = EFI_INVALID_TABLE_ADDR, 40 41 .acpi20 = EFI_INVALID_TABLE_ADDR, 41 42 .smbios = EFI_INVALID_TABLE_ADDR, 42 43 .smbios3 = EFI_INVALID_TABLE_ADDR, 43 - .boot_info = EFI_INVALID_TABLE_ADDR, 44 - .hcdp = EFI_INVALID_TABLE_ADDR, 45 - .uga = EFI_INVALID_TABLE_ADDR, 46 - .fw_vendor = EFI_INVALID_TABLE_ADDR, 47 - .runtime = EFI_INVALID_TABLE_ADDR, 48 - .config_table = EFI_INVALID_TABLE_ADDR, 49 44 .esrt = EFI_INVALID_TABLE_ADDR, 50 - .properties_table = EFI_INVALID_TABLE_ADDR, 51 - .mem_attr_table = EFI_INVALID_TABLE_ADDR, 52 - .rng_seed = EFI_INVALID_TABLE_ADDR, 53 45 .tpm_log = EFI_INVALID_TABLE_ADDR, 54 46 .tpm_final_log = EFI_INVALID_TABLE_ADDR, 55 - .mem_reserve = EFI_INVALID_TABLE_ADDR, 56 47 }; 57 48 EXPORT_SYMBOL(efi); 49 + 50 + unsigned long __ro_after_init efi_rng_seed = EFI_INVALID_TABLE_ADDR; 51 + static unsigned long __initdata mem_reserve = EFI_INVALID_TABLE_ADDR; 52 + static unsigned long __initdata rt_prop = EFI_INVALID_TABLE_ADDR; 58 53 59 54 struct mm_struct efi_mm = { 60 55 .mm_rb = RB_ROOT, ··· 116 123 if (!kobj || !buf) 117 124 return -EINVAL; 118 125 119 - if (efi.mps != EFI_INVALID_TABLE_ADDR) 120 - str += sprintf(str, "MPS=0x%lx\n", efi.mps); 121 126 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) 122 127 str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20); 123 128 if (efi.acpi != EFI_INVALID_TABLE_ADDR) ··· 129 138 str += sprintf(str, "SMBIOS3=0x%lx\n", efi.smbios3); 130 139 if (efi.smbios != EFI_INVALID_TABLE_ADDR) 131 140 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios); 132 - if (efi.hcdp != EFI_INVALID_TABLE_ADDR) 133 - str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp); 134 - if (efi.boot_info != EFI_INVALID_TABLE_ADDR) 135 - str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info); 136 - if (efi.uga != EFI_INVALID_TABLE_ADDR) 137 - str += sprintf(str, "UGA=0x%lx\n", efi.uga); 141 + 142 + if (IS_ENABLED(CONFIG_IA64) || IS_ENABLED(CONFIG_X86)) { 143 + extern char *efi_systab_show_arch(char *str); 144 + 145 + str = efi_systab_show_arch(str); 146 + } 138 147 139 148 return str - buf; 140 149 } 141 150 142 151 static struct kobj_attribute efi_attr_systab = __ATTR_RO_MODE(systab, 0400); 143 - 144 - #define EFI_FIELD(var) efi.var 145 - 146 - #define EFI_ATTR_SHOW(name) \ 147 - static ssize_t name##_show(struct kobject *kobj, \ 148 - struct kobj_attribute *attr, char *buf) \ 149 - { \ 150 - return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ 151 - } 152 - 153 - EFI_ATTR_SHOW(fw_vendor); 154 - EFI_ATTR_SHOW(runtime); 155 - EFI_ATTR_SHOW(config_table); 156 152 157 153 static ssize_t fw_platform_size_show(struct kobject *kobj, 158 154 struct kobj_attribute *attr, char *buf) ··· 147 169 return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32); 148 170 } 149 171 150 - static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor); 151 - static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime); 152 - static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table); 172 + extern __weak struct kobj_attribute efi_attr_fw_vendor; 173 + extern __weak struct kobj_attribute efi_attr_runtime; 174 + extern __weak struct kobj_attribute efi_attr_config_table; 153 175 static struct kobj_attribute efi_attr_fw_platform_size = 154 176 __ATTR_RO(fw_platform_size); 155 177 156 178 static struct attribute *efi_subsys_attrs[] = { 157 179 &efi_attr_systab.attr, 180 + &efi_attr_fw_platform_size.attr, 158 181 &efi_attr_fw_vendor.attr, 159 182 &efi_attr_runtime.attr, 160 183 &efi_attr_config_table.attr, 161 - &efi_attr_fw_platform_size.attr, 162 184 NULL, 163 185 }; 164 186 165 - static umode_t efi_attr_is_visible(struct kobject *kobj, 166 - struct attribute *attr, int n) 187 + umode_t __weak efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, 188 + int n) 167 189 { 168 - if (attr == &efi_attr_fw_vendor.attr) { 169 - if (efi_enabled(EFI_PARAVIRT) || 170 - efi.fw_vendor == EFI_INVALID_TABLE_ADDR) 171 - return 0; 172 - } else if (attr == &efi_attr_runtime.attr) { 173 - if (efi.runtime == EFI_INVALID_TABLE_ADDR) 174 - return 0; 175 - } else if (attr == &efi_attr_config_table.attr) { 176 - if (efi.config_table == EFI_INVALID_TABLE_ADDR) 177 - return 0; 178 - } 179 - 180 190 return attr->mode; 181 191 } 182 192 ··· 354 388 { 355 389 int error; 356 390 391 + if (!efi_enabled(EFI_RUNTIME_SERVICES)) 392 + efi.runtime_supported_mask = 0; 393 + 357 394 if (!efi_enabled(EFI_BOOT)) 358 395 return 0; 359 396 360 - /* 361 - * Since we process only one efi_runtime_service() at a time, an 362 - * ordered workqueue (which creates only one execution context) 363 - * should suffice all our needs. 364 - */ 365 - efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0); 366 - if (!efi_rts_wq) { 367 - pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n"); 368 - clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); 369 - return 0; 397 + if (efi.runtime_supported_mask) { 398 + /* 399 + * Since we process only one efi_runtime_service() at a time, an 400 + * ordered workqueue (which creates only one execution context) 401 + * should suffice for all our needs. 402 + */ 403 + efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0); 404 + if (!efi_rts_wq) { 405 + pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n"); 406 + clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); 407 + efi.runtime_supported_mask = 0; 408 + return 0; 409 + } 370 410 } 411 + 412 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_TIME_SERVICES)) 413 + platform_device_register_simple("rtc-efi", 0, NULL, 0); 371 414 372 415 /* We register the efi directory at /sys/firmware/efi */ 373 416 efi_kobj = kobject_create_and_add("efi", firmware_kobj); ··· 385 410 return -ENOMEM; 386 411 } 387 412 388 - error = generic_ops_register(); 389 - if (error) 390 - goto err_put; 391 - 392 - if (efi_enabled(EFI_RUNTIME_SERVICES)) 413 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) { 393 414 efivar_ssdt_load(); 415 + error = generic_ops_register(); 416 + if (error) 417 + goto err_put; 418 + platform_device_register_simple("efivars", 0, NULL, 0); 419 + } 394 420 395 421 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); 396 422 if (error) { ··· 419 443 err_remove_group: 420 444 sysfs_remove_group(efi_kobj, &efi_subsys_attr_group); 421 445 err_unregister: 422 - generic_ops_unregister(); 446 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 447 + generic_ops_unregister(); 423 448 err_put: 424 449 kobject_put(efi_kobj); 425 450 return error; ··· 501 524 efi_arch_mem_reserve(addr, size); 502 525 } 503 526 504 - static __initdata efi_config_table_type_t common_tables[] = { 527 + static const efi_config_table_type_t common_tables[] __initconst = { 505 528 {ACPI_20_TABLE_GUID, "ACPI 2.0", &efi.acpi20}, 506 529 {ACPI_TABLE_GUID, "ACPI", &efi.acpi}, 507 - {HCDP_TABLE_GUID, "HCDP", &efi.hcdp}, 508 - {MPS_TABLE_GUID, "MPS", &efi.mps}, 509 530 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 510 531 {SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3}, 511 - {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 512 532 {EFI_SYSTEM_RESOURCE_TABLE_GUID, "ESRT", &efi.esrt}, 513 - {EFI_PROPERTIES_TABLE_GUID, "PROP", &efi.properties_table}, 514 - {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi.mem_attr_table}, 515 - {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi.rng_seed}, 533 + {EFI_MEMORY_ATTRIBUTES_TABLE_GUID, "MEMATTR", &efi_mem_attr_table}, 534 + {LINUX_EFI_RANDOM_SEED_TABLE_GUID, "RNG", &efi_rng_seed}, 516 535 {LINUX_EFI_TPM_EVENT_LOG_GUID, "TPMEventLog", &efi.tpm_log}, 517 536 {LINUX_EFI_TPM_FINAL_LOG_GUID, "TPMFinalLog", &efi.tpm_final_log}, 518 - {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &efi.mem_reserve}, 537 + {LINUX_EFI_MEMRESERVE_TABLE_GUID, "MEMRESERVE", &mem_reserve}, 538 + {EFI_RT_PROPERTIES_TABLE_GUID, "RTPROP", &rt_prop}, 519 539 #ifdef CONFIG_EFI_RCI2_TABLE 520 540 {DELLEMC_EFI_RCI2_TABLE_GUID, NULL, &rci2_table_phys}, 521 541 #endif 522 542 {NULL_GUID, NULL, NULL}, 523 543 }; 524 544 525 - static __init int match_config_table(efi_guid_t *guid, 545 + static __init int match_config_table(const efi_guid_t *guid, 526 546 unsigned long table, 527 - efi_config_table_type_t *table_types) 547 + const efi_config_table_type_t *table_types) 528 548 { 529 549 int i; 530 550 ··· 540 566 return 0; 541 567 } 542 568 543 - int __init efi_config_parse_tables(void *config_tables, int count, int sz, 544 - efi_config_table_type_t *arch_tables) 569 + int __init efi_config_parse_tables(const efi_config_table_t *config_tables, 570 + int count, 571 + const efi_config_table_type_t *arch_tables) 545 572 { 546 - void *tablep; 573 + const efi_config_table_64_t *tbl64 = (void *)config_tables; 574 + const efi_config_table_32_t *tbl32 = (void *)config_tables; 575 + const efi_guid_t *guid; 576 + unsigned long table; 547 577 int i; 548 578 549 - tablep = config_tables; 550 579 pr_info(""); 551 580 for (i = 0; i < count; i++) { 552 - efi_guid_t guid; 553 - unsigned long table; 581 + if (!IS_ENABLED(CONFIG_X86)) { 582 + guid = &config_tables[i].guid; 583 + table = (unsigned long)config_tables[i].table; 584 + } else if (efi_enabled(EFI_64BIT)) { 585 + guid = &tbl64[i].guid; 586 + table = tbl64[i].table; 554 587 555 - if (efi_enabled(EFI_64BIT)) { 556 - u64 table64; 557 - guid = ((efi_config_table_64_t *)tablep)->guid; 558 - table64 = ((efi_config_table_64_t *)tablep)->table; 559 - table = table64; 560 - #ifndef CONFIG_64BIT 561 - if (table64 >> 32) { 588 + if (IS_ENABLED(CONFIG_X86_32) && 589 + tbl64[i].table > U32_MAX) { 562 590 pr_cont("\n"); 563 591 pr_err("Table located above 4GB, disabling EFI.\n"); 564 592 return -EINVAL; 565 593 } 566 - #endif 567 594 } else { 568 - guid = ((efi_config_table_32_t *)tablep)->guid; 569 - table = ((efi_config_table_32_t *)tablep)->table; 595 + guid = &tbl32[i].guid; 596 + table = tbl32[i].table; 570 597 } 571 598 572 - if (!match_config_table(&guid, table, common_tables)) 573 - match_config_table(&guid, table, arch_tables); 574 - 575 - tablep += sz; 599 + if (!match_config_table(guid, table, common_tables)) 600 + match_config_table(guid, table, arch_tables); 576 601 } 577 602 pr_cont("\n"); 578 603 set_bit(EFI_CONFIG_TABLES, &efi.flags); 579 604 580 - if (efi.rng_seed != EFI_INVALID_TABLE_ADDR) { 605 + if (efi_rng_seed != EFI_INVALID_TABLE_ADDR) { 581 606 struct linux_efi_random_seed *seed; 582 607 u32 size = 0; 583 608 584 - seed = early_memremap(efi.rng_seed, sizeof(*seed)); 609 + seed = early_memremap(efi_rng_seed, sizeof(*seed)); 585 610 if (seed != NULL) { 586 611 size = READ_ONCE(seed->size); 587 612 early_memunmap(seed, sizeof(*seed)); ··· 588 615 pr_err("Could not map UEFI random seed!\n"); 589 616 } 590 617 if (size > 0) { 591 - seed = early_memremap(efi.rng_seed, 618 + seed = early_memremap(efi_rng_seed, 592 619 sizeof(*seed) + size); 593 620 if (seed != NULL) { 594 621 pr_notice("seeding entropy pool\n"); ··· 600 627 } 601 628 } 602 629 603 - if (efi_enabled(EFI_MEMMAP)) 630 + if (!IS_ENABLED(CONFIG_X86_32) && efi_enabled(EFI_MEMMAP)) 604 631 efi_memattr_init(); 605 632 606 633 efi_tpm_eventlog_init(); 607 634 608 - /* Parse the EFI Properties table if it exists */ 609 - if (efi.properties_table != EFI_INVALID_TABLE_ADDR) { 610 - efi_properties_table_t *tbl; 611 - 612 - tbl = early_memremap(efi.properties_table, sizeof(*tbl)); 613 - if (tbl == NULL) { 614 - pr_err("Could not map Properties table!\n"); 615 - return -ENOMEM; 616 - } 617 - 618 - if (tbl->memory_protection_attribute & 619 - EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) 620 - set_bit(EFI_NX_PE_DATA, &efi.flags); 621 - 622 - early_memunmap(tbl, sizeof(*tbl)); 623 - } 624 - 625 - if (efi.mem_reserve != EFI_INVALID_TABLE_ADDR) { 626 - unsigned long prsv = efi.mem_reserve; 635 + if (mem_reserve != EFI_INVALID_TABLE_ADDR) { 636 + unsigned long prsv = mem_reserve; 627 637 628 638 while (prsv) { 629 639 struct linux_efi_memreserve *rsv; 630 640 u8 *p; 631 - int i; 632 641 633 642 /* 634 643 * Just map a full page: that is what we will get ··· 639 684 } 640 685 } 641 686 687 + if (rt_prop != EFI_INVALID_TABLE_ADDR) { 688 + efi_rt_properties_table_t *tbl; 689 + 690 + tbl = early_memremap(rt_prop, sizeof(*tbl)); 691 + if (tbl) { 692 + efi.runtime_supported_mask &= tbl->runtime_services_supported; 693 + early_memunmap(tbl, sizeof(*tbl)); 694 + } 695 + } 696 + 642 697 return 0; 643 698 } 644 699 645 - int __init efi_config_init(efi_config_table_type_t *arch_tables) 700 + int __init efi_systab_check_header(const efi_table_hdr_t *systab_hdr, 701 + int min_major_version) 646 702 { 647 - void *config_tables; 648 - int sz, ret; 649 - 650 - if (efi.systab->nr_tables == 0) 651 - return 0; 652 - 653 - if (efi_enabled(EFI_64BIT)) 654 - sz = sizeof(efi_config_table_64_t); 655 - else 656 - sz = sizeof(efi_config_table_32_t); 657 - 658 - /* 659 - * Let's see what config tables the firmware passed to us. 660 - */ 661 - config_tables = early_memremap(efi.systab->tables, 662 - efi.systab->nr_tables * sz); 663 - if (config_tables == NULL) { 664 - pr_err("Could not map Configuration table!\n"); 665 - return -ENOMEM; 703 + if (systab_hdr->signature != EFI_SYSTEM_TABLE_SIGNATURE) { 704 + pr_err("System table signature incorrect!\n"); 705 + return -EINVAL; 666 706 } 667 707 668 - ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables, sz, 669 - arch_tables); 708 + if ((systab_hdr->revision >> 16) < min_major_version) 709 + pr_err("Warning: System table version %d.%02d, expected %d.00 or greater!\n", 710 + systab_hdr->revision >> 16, 711 + systab_hdr->revision & 0xffff, 712 + min_major_version); 670 713 671 - early_memunmap(config_tables, efi.systab->nr_tables * sz); 714 + return 0; 715 + } 716 + 717 + #ifndef CONFIG_IA64 718 + static const efi_char16_t *__init map_fw_vendor(unsigned long fw_vendor, 719 + size_t size) 720 + { 721 + const efi_char16_t *ret; 722 + 723 + ret = early_memremap_ro(fw_vendor, size); 724 + if (!ret) 725 + pr_err("Could not map the firmware vendor!\n"); 672 726 return ret; 673 727 } 674 728 675 - #ifdef CONFIG_EFI_VARS_MODULE 676 - static int __init efi_load_efivars(void) 729 + static void __init unmap_fw_vendor(const void *fw_vendor, size_t size) 677 730 { 678 - struct platform_device *pdev; 679 - 680 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 681 - return 0; 682 - 683 - pdev = platform_device_register_simple("efivars", 0, NULL, 0); 684 - return PTR_ERR_OR_ZERO(pdev); 731 + early_memunmap((void *)fw_vendor, size); 685 732 } 686 - device_initcall(efi_load_efivars); 733 + #else 734 + #define map_fw_vendor(p, s) __va(p) 735 + #define unmap_fw_vendor(v, s) 687 736 #endif 688 737 689 - #ifdef CONFIG_EFI_PARAMS_FROM_FDT 738 + void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr, 739 + unsigned long fw_vendor) 740 + { 741 + char vendor[100] = "unknown"; 742 + const efi_char16_t *c16; 743 + size_t i; 690 744 691 - #define UEFI_PARAM(name, prop, field) \ 692 - { \ 693 - { name }, \ 694 - { prop }, \ 695 - offsetof(struct efi_fdt_params, field), \ 696 - sizeof_field(struct efi_fdt_params, field) \ 745 + c16 = map_fw_vendor(fw_vendor, sizeof(vendor) * sizeof(efi_char16_t)); 746 + if (c16) { 747 + for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i) 748 + vendor[i] = c16[i]; 749 + vendor[i] = '\0'; 750 + 751 + unmap_fw_vendor(c16, sizeof(vendor) * sizeof(efi_char16_t)); 697 752 } 698 753 699 - struct params { 700 - const char name[32]; 701 - const char propname[32]; 702 - int offset; 703 - int size; 704 - }; 705 - 706 - static __initdata struct params fdt_params[] = { 707 - UEFI_PARAM("System Table", "linux,uefi-system-table", system_table), 708 - UEFI_PARAM("MemMap Address", "linux,uefi-mmap-start", mmap), 709 - UEFI_PARAM("MemMap Size", "linux,uefi-mmap-size", mmap_size), 710 - UEFI_PARAM("MemMap Desc. Size", "linux,uefi-mmap-desc-size", desc_size), 711 - UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver) 712 - }; 713 - 714 - static __initdata struct params xen_fdt_params[] = { 715 - UEFI_PARAM("System Table", "xen,uefi-system-table", system_table), 716 - UEFI_PARAM("MemMap Address", "xen,uefi-mmap-start", mmap), 717 - UEFI_PARAM("MemMap Size", "xen,uefi-mmap-size", mmap_size), 718 - UEFI_PARAM("MemMap Desc. Size", "xen,uefi-mmap-desc-size", desc_size), 719 - UEFI_PARAM("MemMap Desc. Version", "xen,uefi-mmap-desc-ver", desc_ver) 720 - }; 721 - 722 - #define EFI_FDT_PARAMS_SIZE ARRAY_SIZE(fdt_params) 723 - 724 - static __initdata struct { 725 - const char *uname; 726 - const char *subnode; 727 - struct params *params; 728 - } dt_params[] = { 729 - { "hypervisor", "uefi", xen_fdt_params }, 730 - { "chosen", NULL, fdt_params }, 731 - }; 732 - 733 - struct param_info { 734 - int found; 735 - void *params; 736 - const char *missing; 737 - }; 738 - 739 - static int __init __find_uefi_params(unsigned long node, 740 - struct param_info *info, 741 - struct params *params) 742 - { 743 - const void *prop; 744 - void *dest; 745 - u64 val; 746 - int i, len; 747 - 748 - for (i = 0; i < EFI_FDT_PARAMS_SIZE; i++) { 749 - prop = of_get_flat_dt_prop(node, params[i].propname, &len); 750 - if (!prop) { 751 - info->missing = params[i].name; 752 - return 0; 753 - } 754 - 755 - dest = info->params + params[i].offset; 756 - info->found++; 757 - 758 - val = of_read_number(prop, len / sizeof(u32)); 759 - 760 - if (params[i].size == sizeof(u32)) 761 - *(u32 *)dest = val; 762 - else 763 - *(u64 *)dest = val; 764 - 765 - if (efi_enabled(EFI_DBG)) 766 - pr_info(" %s: 0x%0*llx\n", params[i].name, 767 - params[i].size * 2, val); 768 - } 769 - 770 - return 1; 754 + pr_info("EFI v%u.%.02u by %s\n", 755 + systab_hdr->revision >> 16, 756 + systab_hdr->revision & 0xffff, 757 + vendor); 771 758 } 772 - 773 - static int __init fdt_find_uefi_params(unsigned long node, const char *uname, 774 - int depth, void *data) 775 - { 776 - struct param_info *info = data; 777 - int i; 778 - 779 - for (i = 0; i < ARRAY_SIZE(dt_params); i++) { 780 - const char *subnode = dt_params[i].subnode; 781 - 782 - if (depth != 1 || strcmp(uname, dt_params[i].uname) != 0) { 783 - info->missing = dt_params[i].params[0].name; 784 - continue; 785 - } 786 - 787 - if (subnode) { 788 - int err = of_get_flat_dt_subnode_by_name(node, subnode); 789 - 790 - if (err < 0) 791 - return 0; 792 - 793 - node = err; 794 - } 795 - 796 - return __find_uefi_params(node, info, dt_params[i].params); 797 - } 798 - 799 - return 0; 800 - } 801 - 802 - int __init efi_get_fdt_params(struct efi_fdt_params *params) 803 - { 804 - struct param_info info; 805 - int ret; 806 - 807 - pr_info("Getting EFI parameters from FDT:\n"); 808 - 809 - info.found = 0; 810 - info.params = params; 811 - 812 - ret = of_scan_flat_dt(fdt_find_uefi_params, &info); 813 - if (!info.found) 814 - pr_info("UEFI not found.\n"); 815 - else if (!ret) 816 - pr_err("Can't find '%s' in device tree!\n", 817 - info.missing); 818 - 819 - return ret; 820 - } 821 - #endif /* CONFIG_EFI_PARAMS_FROM_FDT */ 822 759 823 760 static __initdata char memory_type_name[][20] = { 824 761 "Reserved", ··· 872 1025 873 1026 static int __init efi_memreserve_map_root(void) 874 1027 { 875 - if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) 1028 + if (mem_reserve == EFI_INVALID_TABLE_ADDR) 876 1029 return -ENODEV; 877 1030 878 - efi_memreserve_root = memremap(efi.mem_reserve, 1031 + efi_memreserve_root = memremap(mem_reserve, 879 1032 sizeof(*efi_memreserve_root), 880 1033 MEMREMAP_WB); 881 1034 if (WARN_ON_ONCE(!efi_memreserve_root)) ··· 980 1133 if (!kexec_in_progress) 981 1134 return NOTIFY_DONE; 982 1135 983 - seed = memremap(efi.rng_seed, sizeof(*seed), MEMREMAP_WB); 1136 + seed = memremap(efi_rng_seed, sizeof(*seed), MEMREMAP_WB); 984 1137 if (seed != NULL) { 985 1138 size = min(seed->size, EFI_RANDOM_SEED_SIZE); 986 1139 memunmap(seed); ··· 988 1141 pr_err("Could not map UEFI random seed!\n"); 989 1142 } 990 1143 if (size > 0) { 991 - seed = memremap(efi.rng_seed, sizeof(*seed) + size, 1144 + seed = memremap(efi_rng_seed, sizeof(*seed) + size, 992 1145 MEMREMAP_WB); 993 1146 if (seed != NULL) { 994 1147 seed->size = size; ··· 1005 1158 .notifier_call = update_efi_random_seed, 1006 1159 }; 1007 1160 1008 - static int register_update_efi_random_seed(void) 1161 + static int __init register_update_efi_random_seed(void) 1009 1162 { 1010 - if (efi.rng_seed == EFI_INVALID_TABLE_ADDR) 1163 + if (efi_rng_seed == EFI_INVALID_TABLE_ADDR) 1011 1164 return 0; 1012 1165 return register_reboot_notifier(&efi_random_seed_nb); 1013 1166 }
+1 -1
drivers/firmware/efi/efivars.c
··· 678 678 struct kobject *parent_kobj = efivars_kobject(); 679 679 int error = 0; 680 680 681 - if (!efi_enabled(EFI_RUNTIME_SERVICES)) 681 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_VARIABLE_SERVICES)) 682 682 return -ENODEV; 683 683 684 684 /* 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 && initrd_size > 0) 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);
+7 -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 ··· 116 123 * Mustang), we can still place the kernel at the address 117 124 * 'dram_base + TEXT_OFFSET'. 118 125 */ 126 + *image_addr = (unsigned long)_text; 119 127 if (*image_addr == preferred_offset) 120 128 return EFI_SUCCESS; 121 129 ··· 141 147 } 142 148 *image_addr = *reserve_addr + TEXT_OFFSET; 143 149 } 144 - memcpy((void *)*image_addr, old_image_addr, kernel_size); 150 + 151 + if (image->image_base != _text) 152 + pr_efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n"); 153 + 154 + memcpy((void *)*image_addr, _text, kernel_size); 145 155 146 156 return EFI_SUCCESS; 147 157 }
+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
+1 -1
drivers/firmware/efi/vars.c
··· 1071 1071 * entry on the list. It is safe for @func to remove entries in the 1072 1072 * list via efivar_entry_delete(). 1073 1073 * 1074 - * You MUST call efivar_enter_iter_begin() before this function, and 1074 + * You MUST call efivar_entry_iter_begin() before this function, and 1075 1075 * efivar_entry_iter_end() afterwards. 1076 1076 * 1077 1077 * It is possible to begin iteration from an arbitrary entry within
+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())
+113 -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 ··· 526 896 efi_time_t time_of_revocation; 527 897 } efi_cert_x509_sha256_t; 528 898 899 + extern unsigned long __ro_after_init efi_rng_seed; /* RNG Seed table */ 900 + 529 901 /* 530 902 * All runtime access to EFI goes through this structure: 531 903 */ 532 904 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; 905 + const efi_runtime_services_t *runtime; /* EFI runtime services table */ 906 + unsigned int runtime_version; /* Runtime services version */ 907 + unsigned int runtime_supported_mask; 908 + 909 + unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ 910 + unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 911 + unsigned long smbios; /* SMBIOS table (32 bit entry point) */ 912 + unsigned long smbios3; /* SMBIOS table (64 bit entry point) */ 913 + unsigned long esrt; /* ESRT table */ 914 + unsigned long tpm_log; /* TPM2 Event Log table */ 915 + unsigned long tpm_final_log; /* TPM2 Final Events Log table */ 916 + 917 + efi_get_time_t *get_time; 918 + efi_set_time_t *set_time; 919 + efi_get_wakeup_time_t *get_wakeup_time; 920 + efi_set_wakeup_time_t *set_wakeup_time; 921 + efi_get_variable_t *get_variable; 922 + efi_get_next_variable_t *get_next_variable; 923 + efi_set_variable_t *set_variable; 924 + efi_set_variable_t *set_variable_nonblocking; 925 + efi_query_variable_info_t *query_variable_info; 926 + efi_query_variable_info_t *query_variable_info_nonblocking; 927 + efi_update_capsule_t *update_capsule; 928 + efi_query_capsule_caps_t *query_capsule_caps; 929 + efi_get_next_high_mono_count_t *get_next_high_mono_count; 930 + efi_reset_system_t *reset_system; 931 + 932 + struct efi_memory_map memmap; 933 + unsigned long flags; 569 934 } efi; 935 + 936 + #define EFI_RT_SUPPORTED_GET_TIME 0x0001 937 + #define EFI_RT_SUPPORTED_SET_TIME 0x0002 938 + #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 939 + #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008 940 + #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010 941 + #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020 942 + #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040 943 + #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080 944 + #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100 945 + #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200 946 + #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400 947 + #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800 948 + #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000 949 + #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000 950 + 951 + #define EFI_RT_SUPPORTED_ALL 0x3fff 952 + 953 + #define EFI_RT_SUPPORTED_TIME_SERVICES 0x000f 954 + #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070 570 955 571 956 extern struct mm_struct efi_mm; 572 957 ··· 632 987 extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap, 633 988 void *buf, struct efi_mem_range *mem); 634 989 635 - extern int efi_config_init(efi_config_table_type_t *arch_tables); 636 990 #ifdef CONFIG_EFI_ESRT 637 991 extern void __init efi_esrt_init(void); 638 992 #else 639 993 static inline void efi_esrt_init(void) { } 640 994 #endif 641 - extern int efi_config_parse_tables(void *config_tables, int count, int sz, 642 - 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); 643 1002 extern u64 efi_get_iobase (void); 644 1003 extern int efi_mem_type(unsigned long phys_addr); 645 1004 extern u64 efi_mem_attributes (unsigned long phys_addr); ··· 655 1006 extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size); 656 1007 extern void efi_initialize_iomem_resources(struct resource *code_resource, 657 1008 struct resource *data_resource, struct resource *bss_resource); 658 - extern int efi_get_fdt_params(struct efi_fdt_params *params); 1009 + extern u64 efi_get_fdt_params(struct efi_memory_map_data *data); 659 1010 extern struct kobject *efi_kobj; 660 1011 661 1012 extern int efi_reboot_quirk_mode; ··· 666 1017 #else 667 1018 static inline void efi_fake_memmap(void) { } 668 1019 #endif 1020 + 1021 + extern unsigned long efi_mem_attr_table; 669 1022 670 1023 /* 671 1024 * efi_memattr_perm_setter - arch specific callback function passed into ··· 794 1143 return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE) 795 1144 && __efi_soft_reserve_enabled(); 796 1145 } 1146 + 1147 + static inline bool efi_rt_services_supported(unsigned int mask) 1148 + { 1149 + return (efi.runtime_supported_mask & mask) == mask; 1150 + } 797 1151 #else 798 1152 static inline bool efi_enabled(int feature) 799 1153 { ··· 814 1158 } 815 1159 816 1160 static inline bool efi_soft_reserve_enabled(void) 1161 + { 1162 + return false; 1163 + } 1164 + 1165 + static inline bool efi_rt_services_supported(unsigned int mask) 817 1166 { 818 1167 return false; 819 1168 } ··· 849 1188 * not including trailing NUL 850 1189 */ 851 1190 #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN 852 - 853 - /* 854 - * The type of search to perform when calling boottime->locate_handle 855 - */ 856 - #define EFI_LOCATE_ALL_HANDLES 0 857 - #define EFI_LOCATE_BY_REGISTER_NOTIFY 1 858 - #define EFI_LOCATE_BY_PROTOCOL 2 859 1191 860 1192 /* 861 1193 * EFI Device Path information ··· 889 1235 #define EFI_DEV_END_ENTIRE 0xFF 890 1236 891 1237 struct efi_generic_dev_path { 892 - u8 type; 893 - u8 sub_type; 894 - u16 length; 895 - } __attribute ((packed)); 1238 + u8 type; 1239 + u8 sub_type; 1240 + u16 length; 1241 + } __packed; 1242 + 1243 + struct efi_acpi_dev_path { 1244 + struct efi_generic_dev_path header; 1245 + u32 hid; 1246 + u32 uid; 1247 + } __packed; 1248 + 1249 + struct efi_pci_dev_path { 1250 + struct efi_generic_dev_path header; 1251 + u8 fn; 1252 + u8 dev; 1253 + } __packed; 1254 + 1255 + struct efi_vendor_dev_path { 1256 + struct efi_generic_dev_path header; 1257 + efi_guid_t vendorguid; 1258 + u8 vendordata[]; 1259 + } __packed; 896 1260 897 1261 struct efi_dev_path { 898 - u8 type; /* can be replaced with unnamed */ 899 - u8 sub_type; /* struct efi_generic_dev_path; */ 900 - u16 length; /* once we've moved to -std=c11 */ 901 1262 union { 902 - struct { 903 - u32 hid; 904 - u32 uid; 905 - } acpi; 906 - struct { 907 - u8 fn; 908 - u8 dev; 909 - } pci; 1263 + struct efi_generic_dev_path header; 1264 + struct efi_acpi_dev_path acpi; 1265 + struct efi_pci_dev_path pci; 1266 + struct efi_vendor_dev_path vendor; 910 1267 }; 911 - } __attribute ((packed)); 1268 + } __packed; 912 1269 913 - #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER) 914 - struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len); 915 - #endif 1270 + struct device *efi_get_device_by_path(const struct efi_dev_path **node, 1271 + size_t *len); 916 1272 917 1273 static inline void memrange_efi_to_native(u64 *addr, u64 *npages) 918 1274 { ··· 975 1311 struct kobject kobj; 976 1312 bool scanning; 977 1313 bool deleting; 978 - }; 979 - 980 - union efi_simple_text_output_protocol { 981 - struct { 982 - void *reset; 983 - efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *, 984 - efi_char16_t *); 985 - void *test_string; 986 - }; 987 - struct { 988 - u32 reset; 989 - u32 output_string; 990 - u32 test_string; 991 - } mixed_mode; 992 - }; 993 - 994 - #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 995 - #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 996 - #define PIXEL_BIT_MASK 2 997 - #define PIXEL_BLT_ONLY 3 998 - #define PIXEL_FORMAT_MAX 4 999 - 1000 - typedef struct { 1001 - u32 red_mask; 1002 - u32 green_mask; 1003 - u32 blue_mask; 1004 - u32 reserved_mask; 1005 - } efi_pixel_bitmask_t; 1006 - 1007 - typedef struct { 1008 - u32 version; 1009 - u32 horizontal_resolution; 1010 - u32 vertical_resolution; 1011 - int pixel_format; 1012 - efi_pixel_bitmask_t pixel_information; 1013 - u32 pixels_per_scan_line; 1014 - } efi_graphics_output_mode_info_t; 1015 - 1016 - typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t; 1017 - 1018 - union efi_graphics_output_protocol_mode { 1019 - struct { 1020 - u32 max_mode; 1021 - u32 mode; 1022 - efi_graphics_output_mode_info_t *info; 1023 - unsigned long size_of_info; 1024 - efi_physical_addr_t frame_buffer_base; 1025 - unsigned long frame_buffer_size; 1026 - }; 1027 - struct { 1028 - u32 max_mode; 1029 - u32 mode; 1030 - u32 info; 1031 - u32 size_of_info; 1032 - u64 frame_buffer_base; 1033 - u32 frame_buffer_size; 1034 - } mixed_mode; 1035 - }; 1036 - 1037 - typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t; 1038 - 1039 - union efi_graphics_output_protocol { 1040 - struct { 1041 - void *query_mode; 1042 - void *set_mode; 1043 - void *blt; 1044 - efi_graphics_output_protocol_mode_t *mode; 1045 - }; 1046 - struct { 1047 - u32 query_mode; 1048 - u32 set_mode; 1049 - u32 blt; 1050 - u32 mode; 1051 - } mixed_mode; 1052 1314 }; 1053 1315 1054 1316 extern struct list_head efivar_sysfs_list; ··· 1074 1484 1075 1485 #endif 1076 1486 1077 - /* prototypes shared between arch specific and generic stub code */ 1078 - 1079 - void efi_printk(char *str); 1080 - 1081 - void efi_free(unsigned long size, unsigned long addr); 1082 - 1083 - char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len); 1084 - 1085 - efi_status_t efi_get_memory_map(struct efi_boot_memmap *map); 1086 - 1087 - efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, 1088 - unsigned long *addr, unsigned long min); 1089 - 1090 - static inline 1091 - efi_status_t efi_low_alloc(unsigned long size, unsigned long align, 1092 - unsigned long *addr) 1093 - { 1094 - /* 1095 - * Don't allocate at 0x0. It will confuse code that 1096 - * checks pointers against NULL. Skip the first 8 1097 - * bytes so we start at a nice even number. 1098 - */ 1099 - return efi_low_alloc_above(size, align, addr, 0x8); 1100 - } 1101 - 1102 - efi_status_t efi_high_alloc(unsigned long size, unsigned long align, 1103 - unsigned long *addr, unsigned long max); 1104 - 1105 - efi_status_t efi_relocate_kernel(unsigned long *image_addr, 1106 - unsigned long image_size, 1107 - unsigned long alloc_size, 1108 - unsigned long preferred_addr, 1109 - unsigned long alignment, 1110 - unsigned long min_addr); 1111 - 1112 - efi_status_t handle_cmdline_files(efi_loaded_image_t *image, 1113 - char *cmd_line, char *option_string, 1114 - unsigned long max_addr, 1115 - unsigned long *load_addr, 1116 - unsigned long *load_size); 1117 - 1118 - efi_status_t efi_parse_options(char const *cmdline); 1119 - 1120 - efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, 1121 - unsigned long size); 1122 - 1123 1487 #ifdef CONFIG_EFI 1124 1488 extern bool efi_runtime_disabled(void); 1125 1489 #else ··· 1156 1612 \ 1157 1613 arch_efi_call_virt_teardown(); \ 1158 1614 }) 1159 - 1160 - typedef efi_status_t (*efi_exit_boot_map_processing)( 1161 - struct efi_boot_memmap *map, 1162 - void *priv); 1163 - 1164 - efi_status_t efi_exit_boot_services(void *handle, 1165 - struct efi_boot_memmap *map, 1166 - void *priv, 1167 - efi_exit_boot_map_processing priv_func); 1168 1615 1169 1616 #define EFI_RANDOM_SEED_SIZE 64U 1170 1617 ··· 1242 1707 1243 1708 #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \ 1244 1709 / sizeof(((struct linux_efi_memreserve *)0)->entry[0])) 1245 - 1246 - void efi_pci_disable_bridge_busmaster(void); 1247 1710 1248 1711 #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