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

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

Pull EFI changes from Ingo Molnar:
"Main changes in this cycle are:

- arm64 efi stub fixes, preservation of FP/SIMD registers across
firmware calls, and conversion of the EFI stub code into a static
library - Ard Biesheuvel

- Xen EFI support - Daniel Kiper

- Support for autoloading the efivars driver - Lee, Chun-Yi

- Use the PE/COFF headers in the x86 EFI boot stub to request that
the stub be loaded with CONFIG_PHYSICAL_ALIGN alignment - Michael
Brown

- Consolidate all the x86 EFI quirks into one file - Saurabh Tangri

- Additional error logging in x86 EFI boot stub - Ulf Winkelvos

- Support loading initrd above 4G in EFI boot stub - Yinghai Lu

- EFI reboot patches for ACPI hardware reduced platforms"

* 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (31 commits)
efi/arm64: Handle missing virtual mapping for UEFI System Table
arch/x86/xen: Silence compiler warnings
xen: Silence compiler warnings
x86/efi: Request desired alignment via the PE/COFF headers
x86/efi: Add better error logging to EFI boot stub
efi: Autoload efivars
efi: Update stale locking comment for struct efivars
arch/x86: Remove efi_set_rtc_mmss()
arch/x86: Replace plain strings with constants
xen: Put EFI machinery in place
xen: Define EFI related stuff
arch/x86: Remove redundant set_bit(EFI_MEMMAP) call
arch/x86: Remove redundant set_bit(EFI_SYSTEM_TABLES) call
efi: Introduce EFI_PARAVIRT flag
arch/x86: Do not access EFI memory map if it is not available
efi: Use early_mem*() instead of early_io*()
arch/ia64: Define early_memunmap()
x86/reboot: Add EFI reboot quirk for ACPI Hardware Reduced flag
efi/reboot: Allow powering off machines using EFI
efi/reboot: Add generic wrapper around EfiResetSystem()
...

+1509 -623
+6
arch/arm64/Kconfig
··· 347 347 This is useful if you cannot or don't want to change the 348 348 command-line options your boot loader passes to the kernel. 349 349 350 + config EFI_STUB 351 + bool 352 + 350 353 config EFI 351 354 bool "UEFI runtime support" 352 355 depends on OF && !CPU_BIG_ENDIAN 353 356 select LIBFDT 354 357 select UCS2_STRING 355 358 select EFI_PARAMS_FROM_FDT 359 + select EFI_RUNTIME_WRAPPERS 360 + select EFI_STUB 361 + select EFI_ARMSTUB 356 362 default y 357 363 help 358 364 This option provides support for runtime services provided
+1
arch/arm64/Makefile
··· 52 52 core-$(CONFIG_CRYPTO) += arch/arm64/crypto/ 53 53 libs-y := arch/arm64/lib/ $(libs-y) 54 54 libs-y += $(LIBGCC) 55 + libs-$(CONFIG_EFI_STUB) += drivers/firmware/efi/libstub/ 55 56 56 57 # Default target when executing plain make 57 58 KBUILD_IMAGE := Image.gz
+33
arch/arm64/include/asm/efi.h
··· 2 2 #define _ASM_EFI_H 3 3 4 4 #include <asm/io.h> 5 + #include <asm/neon.h> 5 6 6 7 #ifdef CONFIG_EFI 7 8 extern void efi_init(void); ··· 11 10 #define efi_init() 12 11 #define efi_idmap_init() 13 12 #endif 13 + 14 + #define efi_call_virt(f, ...) \ 15 + ({ \ 16 + efi_##f##_t *__f = efi.systab->runtime->f; \ 17 + efi_status_t __s; \ 18 + \ 19 + kernel_neon_begin(); \ 20 + __s = __f(__VA_ARGS__); \ 21 + kernel_neon_end(); \ 22 + __s; \ 23 + }) 24 + 25 + #define __efi_call_virt(f, ...) \ 26 + ({ \ 27 + efi_##f##_t *__f = efi.systab->runtime->f; \ 28 + \ 29 + kernel_neon_begin(); \ 30 + __f(__VA_ARGS__); \ 31 + kernel_neon_end(); \ 32 + }) 33 + 34 + /* arch specific definitions used by the stub code */ 35 + 36 + /* 37 + * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from 38 + * start of kernel and may not cross a 2MiB boundary. We set alignment to 39 + * 2MiB so we know it won't cross a 2MiB boundary. 40 + */ 41 + #define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ 42 + #define MAX_FDT_OFFSET SZ_512M 43 + 44 + #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) 14 45 15 46 #endif /* _ASM_EFI_H */
+1 -2
arch/arm64/kernel/Makefile
··· 4 4 5 5 CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) 6 6 AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 7 - CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) \ 8 - -I$(src)/../../../scripts/dtc/libfdt 7 + CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 9 8 10 9 CFLAGS_REMOVE_ftrace.o = -pg 11 10 CFLAGS_REMOVE_insn.o = -pg
+9 -39
arch/arm64/kernel/efi-stub.c
··· 10 10 * 11 11 */ 12 12 #include <linux/efi.h> 13 - #include <linux/libfdt.h> 13 + #include <asm/efi.h> 14 14 #include <asm/sections.h> 15 15 16 - /* 17 - * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from 18 - * start of kernel and may not cross a 2MiB boundary. We set alignment to 19 - * 2MiB so we know it won't cross a 2MiB boundary. 20 - */ 21 - #define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ 22 - #define MAX_FDT_OFFSET SZ_512M 23 - 24 - #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) 25 - 26 - static void efi_char16_printk(efi_system_table_t *sys_table_arg, 27 - efi_char16_t *str); 28 - 29 - static efi_status_t efi_open_volume(efi_system_table_t *sys_table, 30 - void *__image, void **__fh); 31 - static efi_status_t efi_file_close(void *handle); 32 - 33 - static efi_status_t 34 - efi_file_read(void *handle, unsigned long *size, void *addr); 35 - 36 - static efi_status_t 37 - efi_file_size(efi_system_table_t *sys_table, void *__fh, 38 - efi_char16_t *filename_16, void **handle, u64 *file_sz); 39 - 40 - /* Include shared EFI stub code */ 41 - #include "../../../drivers/firmware/efi/efi-stub-helper.c" 42 - #include "../../../drivers/firmware/efi/fdt.c" 43 - #include "../../../drivers/firmware/efi/arm-stub.c" 44 - 45 - 46 - static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 47 - unsigned long *image_addr, 48 - unsigned long *image_size, 49 - unsigned long *reserve_addr, 50 - unsigned long *reserve_size, 51 - unsigned long dram_base, 52 - efi_loaded_image_t *image) 16 + efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 17 + unsigned long *image_addr, 18 + unsigned long *image_size, 19 + unsigned long *reserve_addr, 20 + unsigned long *reserve_size, 21 + unsigned long dram_base, 22 + efi_loaded_image_t *image) 53 23 { 54 24 efi_status_t status; 55 25 unsigned long kernel_size, kernel_memsize = 0; ··· 39 69 if (*image_addr != (dram_base + TEXT_OFFSET)) { 40 70 pr_efi_err(sys_table, "Failed to alloc kernel memory\n"); 41 71 efi_free(sys_table, kernel_memsize, *image_addr); 42 - return EFI_ERROR; 72 + return EFI_LOAD_ERROR; 43 73 } 44 74 *image_size = kernel_memsize; 45 75 }
+25 -17
arch/arm64/kernel/efi.c
··· 414 414 for_each_efi_memory_desc(&memmap, md) { 415 415 if (!(md->attribute & EFI_MEMORY_RUNTIME)) 416 416 continue; 417 - if (remap_region(md, &virt_md)) 418 - ++count; 417 + if (!remap_region(md, &virt_md)) 418 + goto err_unmap; 419 + ++count; 419 420 } 420 421 421 422 efi.systab = (__force void *)efi_lookup_mapped_addr(efi_system_table); 422 - if (efi.systab) 423 - set_bit(EFI_SYSTEM_TABLES, &efi.flags); 423 + if (!efi.systab) { 424 + /* 425 + * If we have no virtual mapping for the System Table at this 426 + * point, the memory map doesn't cover the physical offset where 427 + * it resides. This means the System Table will be inaccessible 428 + * to Runtime Services themselves once the virtual mapping is 429 + * installed. 430 + */ 431 + pr_err("Failed to remap EFI System Table -- buggy firmware?\n"); 432 + goto err_unmap; 433 + } 434 + set_bit(EFI_SYSTEM_TABLES, &efi.flags); 424 435 425 436 local_irq_save(flags); 426 437 cpu_switch_mm(idmap_pg_dir, &init_mm); ··· 460 449 461 450 /* Set up runtime services function pointers */ 462 451 runtime = efi.systab->runtime; 463 - efi.get_time = runtime->get_time; 464 - efi.set_time = runtime->set_time; 465 - efi.get_wakeup_time = runtime->get_wakeup_time; 466 - efi.set_wakeup_time = runtime->set_wakeup_time; 467 - efi.get_variable = runtime->get_variable; 468 - efi.get_next_variable = runtime->get_next_variable; 469 - efi.set_variable = runtime->set_variable; 470 - efi.query_variable_info = runtime->query_variable_info; 471 - efi.update_capsule = runtime->update_capsule; 472 - efi.query_capsule_caps = runtime->query_capsule_caps; 473 - efi.get_next_high_mono_count = runtime->get_next_high_mono_count; 474 - efi.reset_system = runtime->reset_system; 475 - 452 + efi_native_runtime_setup(); 476 453 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 477 454 478 455 return 0; 456 + 457 + err_unmap: 458 + /* unmap all mappings that succeeded: there are 'count' of those */ 459 + for (virt_md = virtmap; count--; virt_md += memmap.desc_size) { 460 + md = virt_md; 461 + iounmap((__force void __iomem *)md->virt_addr); 462 + } 463 + kfree(virtmap); 464 + return -1; 479 465 } 480 466 early_initcall(arm64_enter_virtual_mode);
+1
arch/ia64/include/asm/io.h
··· 426 426 extern void __iomem * early_ioremap (unsigned long phys_addr, unsigned long size); 427 427 #define early_memremap(phys_addr, size) early_ioremap(phys_addr, size) 428 428 extern void early_iounmap (volatile void __iomem *addr, unsigned long size); 429 + #define early_memunmap(addr, size) early_iounmap(addr, size) 429 430 static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size) 430 431 { 431 432 return ioremap(phys_addr, size);
+1 -1
arch/ia64/kernel/process.c
··· 662 662 machine_restart (char *restart_cmd) 663 663 { 664 664 (void) notify_die(DIE_MACHINE_RESTART, restart_cmd, NULL, 0, 0, 0); 665 - (*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL); 665 + efi_reboot(REBOOT_WARM, NULL); 666 666 } 667 667 668 668 void
+1
arch/x86/Kconfig
··· 1522 1522 bool "EFI runtime service support" 1523 1523 depends on ACPI 1524 1524 select UCS2_STRING 1525 + select EFI_RUNTIME_WRAPPERS 1525 1526 ---help--- 1526 1527 This enables the kernel to use EFI runtime services that are 1527 1528 available (such as the EFI variable services).
+2 -1
arch/x86/boot/compressed/Makefile
··· 33 33 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone 34 34 35 35 ifeq ($(CONFIG_EFI_STUB), y) 36 - VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o 36 + VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \ 37 + $(objtree)/drivers/firmware/efi/libstub/lib.a 37 38 endif 38 39 39 40 $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
+29 -19
arch/x86/boot/compressed/eboot.c
··· 19 19 20 20 static efi_system_table_t *sys_table; 21 21 22 - static struct efi_config *efi_early; 23 - 24 - #define efi_call_early(f, ...) \ 25 - efi_early->call(efi_early->f, __VA_ARGS__); 22 + struct efi_config *efi_early; 26 23 27 24 #define BOOT_SERVICES(bits) \ 28 25 static void setup_boot_services##bits(struct efi_config *c) \ ··· 45 48 BOOT_SERVICES(32); 46 49 BOOT_SERVICES(64); 47 50 48 - static void efi_printk(efi_system_table_t *, char *); 49 - static void efi_char16_printk(efi_system_table_t *, efi_char16_t *); 51 + void efi_char16_printk(efi_system_table_t *, efi_char16_t *); 50 52 51 53 static efi_status_t 52 54 __file_size32(void *__fh, efi_char16_t *filename_16, ··· 152 156 153 157 return status; 154 158 } 155 - static efi_status_t 159 + efi_status_t 156 160 efi_file_size(efi_system_table_t *sys_table, void *__fh, 157 161 efi_char16_t *filename_16, void **handle, u64 *file_sz) 158 162 { ··· 162 166 return __file_size32(__fh, filename_16, handle, file_sz); 163 167 } 164 168 165 - static inline efi_status_t 169 + efi_status_t 166 170 efi_file_read(void *handle, unsigned long *size, void *addr) 167 171 { 168 172 unsigned long func; ··· 180 184 } 181 185 } 182 186 183 - static inline efi_status_t efi_file_close(void *handle) 187 + efi_status_t efi_file_close(void *handle) 184 188 { 185 189 if (efi_early->is64) { 186 190 efi_file_handle_64_t *fh = handle; ··· 245 249 return status; 246 250 } 247 251 248 - static inline efi_status_t 252 + efi_status_t 249 253 efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) 250 254 { 251 255 if (efi_early->is64) ··· 254 258 return __open_volume32(__image, __fh); 255 259 } 256 260 257 - static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) 261 + void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) 258 262 { 259 263 unsigned long output_string; 260 264 size_t offset; ··· 279 283 efi_early->call(*func, efi_early->text_output, str); 280 284 } 281 285 } 282 - 283 - #include "../../../../drivers/firmware/efi/efi-stub-helper.c" 284 286 285 287 static void find_bits(unsigned long mask, u8 *pos, u8 *size) 286 288 { ··· 1032 1038 int i; 1033 1039 unsigned long ramdisk_addr; 1034 1040 unsigned long ramdisk_size; 1041 + unsigned long initrd_addr_max; 1035 1042 1036 1043 efi_early = c; 1037 1044 sys_table = (efi_system_table_t *)(unsigned long)efi_early->table; ··· 1095 1100 1096 1101 memset(sdt, 0, sizeof(*sdt)); 1097 1102 1103 + if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) 1104 + initrd_addr_max = -1UL; 1105 + else 1106 + initrd_addr_max = hdr->initrd_addr_max; 1107 + 1098 1108 status = handle_cmdline_files(sys_table, image, 1099 1109 (char *)(unsigned long)hdr->cmd_line_ptr, 1100 - "initrd=", hdr->initrd_addr_max, 1110 + "initrd=", initrd_addr_max, 1101 1111 &ramdisk_addr, &ramdisk_size); 1102 1112 if (status != EFI_SUCCESS) 1103 1113 goto fail2; 1104 - hdr->ramdisk_image = ramdisk_addr; 1105 - hdr->ramdisk_size = ramdisk_size; 1114 + hdr->ramdisk_image = ramdisk_addr & 0xffffffff; 1115 + hdr->ramdisk_size = ramdisk_size & 0xffffffff; 1116 + boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; 1117 + boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; 1106 1118 1107 1119 return boot_params; 1108 1120 fail2: ··· 1376 1374 1377 1375 setup_graphics(boot_params); 1378 1376 1379 - setup_efi_pci(boot_params); 1377 + status = setup_efi_pci(boot_params); 1378 + if (status != EFI_SUCCESS) { 1379 + efi_printk(sys_table, "setup_efi_pci() failed!\n"); 1380 + } 1380 1381 1381 1382 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, 1382 1383 sizeof(*gdt), (void **)&gdt); ··· 1406 1401 hdr->init_size, hdr->init_size, 1407 1402 hdr->pref_address, 1408 1403 hdr->kernel_alignment); 1409 - if (status != EFI_SUCCESS) 1404 + if (status != EFI_SUCCESS) { 1405 + efi_printk(sys_table, "efi_relocate_kernel() failed!\n"); 1410 1406 goto fail; 1407 + } 1411 1408 1412 1409 hdr->pref_address = hdr->code32_start; 1413 1410 hdr->code32_start = bzimage_addr; 1414 1411 } 1415 1412 1416 1413 status = exit_boot(boot_params, handle, is64); 1417 - if (status != EFI_SUCCESS) 1414 + if (status != EFI_SUCCESS) { 1415 + efi_printk(sys_table, "exit_boot() failed!\n"); 1418 1416 goto fail; 1417 + } 1419 1418 1420 1419 memset((char *)gdt->address, 0x0, gdt->size); 1421 1420 desc = (struct desc_struct *)gdt->address; ··· 1479 1470 1480 1471 return boot_params; 1481 1472 fail: 1473 + efi_printk(sys_table, "efi_main() failed!\n"); 1482 1474 return NULL; 1483 1475 }
-16
arch/x86/boot/compressed/eboot.h
··· 103 103 void *blt; 104 104 }; 105 105 106 - struct efi_config { 107 - u64 image_handle; 108 - u64 table; 109 - u64 allocate_pool; 110 - u64 allocate_pages; 111 - u64 get_memory_map; 112 - u64 free_pool; 113 - u64 free_pages; 114 - u64 locate_handle; 115 - u64 handle_protocol; 116 - u64 exit_boot_services; 117 - u64 text_output; 118 - efi_status_t (*call)(unsigned long, ...); 119 - bool is64; 120 - } __packed; 121 - 122 106 #endif /* BOOT_COMPRESSED_EBOOT_H */
+1 -1
arch/x86/boot/header.S
··· 154 154 #else 155 155 .quad 0 # ImageBase 156 156 #endif 157 - .long 0x20 # SectionAlignment 157 + .long CONFIG_PHYSICAL_ALIGN # SectionAlignment 158 158 .long 0x20 # FileAlignment 159 159 .word 0 # MajorOperatingSystemVersion 160 160 .word 0 # MinorOperatingSystemVersion
+33
arch/x86/include/asm/efi.h
··· 104 104 extern void __init efi_runtime_mkexec(void); 105 105 extern void __init efi_dump_pagetable(void); 106 106 extern void __init efi_apply_memmap_quirks(void); 107 + extern int __init efi_reuse_config(u64 tables, int nr_tables); 108 + extern void efi_delete_dummy_variable(void); 107 109 108 110 struct efi_setup_data { 109 111 u64 fw_vendor; ··· 158 156 return EFI_SUCCESS; 159 157 } 160 158 #endif /* CONFIG_EFI_MIXED */ 159 + 160 + 161 + /* arch specific definitions used by the stub code */ 162 + 163 + struct efi_config { 164 + u64 image_handle; 165 + u64 table; 166 + u64 allocate_pool; 167 + u64 allocate_pages; 168 + u64 get_memory_map; 169 + u64 free_pool; 170 + u64 free_pages; 171 + u64 locate_handle; 172 + u64 handle_protocol; 173 + u64 exit_boot_services; 174 + u64 text_output; 175 + efi_status_t (*call)(unsigned long, ...); 176 + bool is64; 177 + } __packed; 178 + 179 + extern struct efi_config *efi_early; 180 + 181 + #define efi_call_early(f, ...) \ 182 + efi_early->call(efi_early->f, __VA_ARGS__); 183 + 184 + extern bool efi_reboot_required(void); 185 + 161 186 #else 162 187 /* 163 188 * IF EFI is not configured, have the EFI calls return -ENOSYS. ··· 197 168 #define efi_call5(_f, _a1, _a2, _a3, _a4, _a5) (-ENOSYS) 198 169 #define efi_call6(_f, _a1, _a2, _a3, _a4, _a5, _a6) (-ENOSYS) 199 170 static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {} 171 + static inline bool efi_reboot_required(void) 172 + { 173 + return false; 174 + } 200 175 #endif /* CONFIG_EFI */ 201 176 202 177 #endif /* _ASM_X86_EFI_H */
+17 -7
arch/x86/kernel/reboot.c
··· 28 28 #include <linux/mc146818rtc.h> 29 29 #include <asm/realmode.h> 30 30 #include <asm/x86_init.h> 31 + #include <asm/efi.h> 31 32 32 33 /* 33 34 * Power off function, if any ··· 402 401 403 402 static int __init reboot_init(void) 404 403 { 404 + int rv; 405 + 405 406 /* 406 407 * Only do the DMI check if reboot_type hasn't been overridden 407 408 * on the command line 408 409 */ 409 - if (reboot_default) 410 - dmi_check_system(reboot_dmi_table); 410 + if (!reboot_default) 411 + return 0; 412 + 413 + /* 414 + * The DMI quirks table takes precedence. If no quirks entry 415 + * matches and the ACPI Hardware Reduced bit is set, force EFI 416 + * reboot. 417 + */ 418 + rv = dmi_check_system(reboot_dmi_table); 419 + 420 + if (!rv && efi_reboot_required()) 421 + reboot_type = BOOT_EFI; 422 + 411 423 return 0; 412 424 } 413 425 core_initcall(reboot_init); ··· 542 528 break; 543 529 544 530 case BOOT_EFI: 545 - if (efi_enabled(EFI_RUNTIME_SERVICES)) 546 - efi.reset_system(reboot_mode == REBOOT_WARM ? 547 - EFI_RESET_WARM : 548 - EFI_RESET_COLD, 549 - EFI_SUCCESS, 0, NULL); 531 + efi_reboot(reboot_mode, NULL); 550 532 reboot_type = BOOT_BIOS; 551 533 break; 552 534
+2 -2
arch/x86/kernel/setup.c
··· 924 924 #endif 925 925 #ifdef CONFIG_EFI 926 926 if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 927 - "EL32", 4)) { 927 + EFI32_LOADER_SIGNATURE, 4)) { 928 928 set_bit(EFI_BOOT, &efi.flags); 929 929 } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, 930 - "EL64", 4)) { 930 + EFI64_LOADER_SIGNATURE, 4)) { 931 931 set_bit(EFI_BOOT, &efi.flags); 932 932 set_bit(EFI_64BIT, &efi.flags); 933 933 }
+1 -1
arch/x86/platform/efi/Makefile
··· 1 - obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o 1 + obj-$(CONFIG_EFI) += quirks.o efi.o efi_$(BITS).o efi_stub_$(BITS).o 2 2 obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o 3 3 obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o 4 4 obj-$(CONFIG_EFI_MIXED) += efi_thunk_$(BITS).o
+46 -437
arch/x86/platform/efi/efi.c
··· 56 56 57 57 #define EFI_DEBUG 58 58 59 - #define EFI_MIN_RESERVE 5120 60 - 61 - #define EFI_DUMMY_GUID \ 62 - EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) 63 - 64 - static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; 65 - 66 59 struct efi_memory_map memmap; 67 60 68 61 static struct efi efi_phys __initdata; ··· 88 95 } 89 96 early_param("add_efi_memmap", setup_add_efi_memmap); 90 97 91 - static bool efi_no_storage_paranoia; 92 - 93 - static int __init setup_storage_paranoia(char *arg) 94 - { 95 - efi_no_storage_paranoia = true; 96 - return 0; 97 - } 98 - early_param("efi_no_storage_paranoia", setup_storage_paranoia); 99 - 100 - static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) 101 - { 102 - unsigned long flags; 103 - efi_status_t status; 104 - 105 - spin_lock_irqsave(&rtc_lock, flags); 106 - status = efi_call_virt(get_time, tm, tc); 107 - spin_unlock_irqrestore(&rtc_lock, flags); 108 - return status; 109 - } 110 - 111 - static efi_status_t virt_efi_set_time(efi_time_t *tm) 112 - { 113 - unsigned long flags; 114 - efi_status_t status; 115 - 116 - spin_lock_irqsave(&rtc_lock, flags); 117 - status = efi_call_virt(set_time, tm); 118 - spin_unlock_irqrestore(&rtc_lock, flags); 119 - return status; 120 - } 121 - 122 - static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, 123 - efi_bool_t *pending, 124 - efi_time_t *tm) 125 - { 126 - unsigned long flags; 127 - efi_status_t status; 128 - 129 - spin_lock_irqsave(&rtc_lock, flags); 130 - status = efi_call_virt(get_wakeup_time, enabled, pending, tm); 131 - spin_unlock_irqrestore(&rtc_lock, flags); 132 - return status; 133 - } 134 - 135 - static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) 136 - { 137 - unsigned long flags; 138 - efi_status_t status; 139 - 140 - spin_lock_irqsave(&rtc_lock, flags); 141 - status = efi_call_virt(set_wakeup_time, enabled, tm); 142 - spin_unlock_irqrestore(&rtc_lock, flags); 143 - return status; 144 - } 145 - 146 - static efi_status_t virt_efi_get_variable(efi_char16_t *name, 147 - efi_guid_t *vendor, 148 - u32 *attr, 149 - unsigned long *data_size, 150 - void *data) 151 - { 152 - return efi_call_virt(get_variable, 153 - name, vendor, attr, 154 - data_size, data); 155 - } 156 - 157 - static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, 158 - efi_char16_t *name, 159 - efi_guid_t *vendor) 160 - { 161 - return efi_call_virt(get_next_variable, 162 - name_size, name, vendor); 163 - } 164 - 165 - static efi_status_t virt_efi_set_variable(efi_char16_t *name, 166 - efi_guid_t *vendor, 167 - u32 attr, 168 - unsigned long data_size, 169 - void *data) 170 - { 171 - return efi_call_virt(set_variable, 172 - name, vendor, attr, 173 - data_size, data); 174 - } 175 - 176 - static efi_status_t virt_efi_query_variable_info(u32 attr, 177 - u64 *storage_space, 178 - u64 *remaining_space, 179 - u64 *max_variable_size) 180 - { 181 - if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 182 - return EFI_UNSUPPORTED; 183 - 184 - return efi_call_virt(query_variable_info, attr, storage_space, 185 - remaining_space, max_variable_size); 186 - } 187 - 188 - static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) 189 - { 190 - return efi_call_virt(get_next_high_mono_count, count); 191 - } 192 - 193 - static void virt_efi_reset_system(int reset_type, 194 - efi_status_t status, 195 - unsigned long data_size, 196 - efi_char16_t *data) 197 - { 198 - __efi_call_virt(reset_system, reset_type, status, 199 - data_size, data); 200 - } 201 - 202 - static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, 203 - unsigned long count, 204 - unsigned long sg_list) 205 - { 206 - if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 207 - return EFI_UNSUPPORTED; 208 - 209 - return efi_call_virt(update_capsule, capsules, count, sg_list); 210 - } 211 - 212 - static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, 213 - unsigned long count, 214 - u64 *max_size, 215 - int *reset_type) 216 - { 217 - if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 218 - return EFI_UNSUPPORTED; 219 - 220 - return efi_call_virt(query_capsule_caps, capsules, count, max_size, 221 - reset_type); 222 - } 223 - 224 98 static efi_status_t __init phys_efi_set_virtual_address_map( 225 99 unsigned long memory_map_size, 226 100 unsigned long descriptor_size, ··· 102 242 descriptor_version, virtual_map); 103 243 efi_call_phys_epilog(); 104 244 return status; 105 - } 106 - 107 - int efi_set_rtc_mmss(const struct timespec *now) 108 - { 109 - unsigned long nowtime = now->tv_sec; 110 - efi_status_t status; 111 - efi_time_t eft; 112 - efi_time_cap_t cap; 113 - struct rtc_time tm; 114 - 115 - status = efi.get_time(&eft, &cap); 116 - if (status != EFI_SUCCESS) { 117 - pr_err("Oops: efitime: can't read time!\n"); 118 - return -1; 119 - } 120 - 121 - rtc_time_to_tm(nowtime, &tm); 122 - if (!rtc_valid_tm(&tm)) { 123 - eft.year = tm.tm_year + 1900; 124 - eft.month = tm.tm_mon + 1; 125 - eft.day = tm.tm_mday; 126 - eft.minute = tm.tm_min; 127 - eft.second = tm.tm_sec; 128 - eft.nanosecond = 0; 129 - } else { 130 - pr_err("%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n", 131 - __func__, nowtime); 132 - return -1; 133 - } 134 - 135 - status = efi.set_time(&eft); 136 - if (status != EFI_SUCCESS) { 137 - pr_err("Oops: efitime: can't write time!\n"); 138 - return -1; 139 - } 140 - return 0; 141 245 } 142 246 143 247 void efi_get_time(struct timespec *now) ··· 174 350 struct efi_info *e = &boot_params.efi_info; 175 351 unsigned long pmap; 176 352 353 + if (efi_enabled(EFI_PARAVIRT)) 354 + return 0; 355 + 177 356 #ifdef CONFIG_X86_32 178 357 /* Can't handle data above 4GB at this time */ 179 358 if (e->efi_memmap_hi) { ··· 219 392 #endif /* EFI_DEBUG */ 220 393 } 221 394 222 - void __init efi_reserve_boot_services(void) 223 - { 224 - void *p; 225 - 226 - for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 227 - efi_memory_desc_t *md = p; 228 - u64 start = md->phys_addr; 229 - u64 size = md->num_pages << EFI_PAGE_SHIFT; 230 - 231 - if (md->type != EFI_BOOT_SERVICES_CODE && 232 - md->type != EFI_BOOT_SERVICES_DATA) 233 - continue; 234 - /* Only reserve where possible: 235 - * - Not within any already allocated areas 236 - * - Not over any memory area (really needed, if above?) 237 - * - Not within any part of the kernel 238 - * - Not the bios reserved area 239 - */ 240 - if ((start + size > __pa_symbol(_text) 241 - && start <= __pa_symbol(_end)) || 242 - !e820_all_mapped(start, start+size, E820_RAM) || 243 - memblock_is_region_reserved(start, size)) { 244 - /* Could not reserve, skip it */ 245 - md->num_pages = 0; 246 - memblock_dbg("Could not reserve boot range [0x%010llx-0x%010llx]\n", 247 - start, start+size-1); 248 - } else 249 - memblock_reserve(start, size); 250 - } 251 - } 252 - 253 395 void __init efi_unmap_memmap(void) 254 396 { 255 397 clear_bit(EFI_MEMMAP, &efi.flags); 256 398 if (memmap.map) { 257 - early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size); 399 + early_memunmap(memmap.map, memmap.nr_map * memmap.desc_size); 258 400 memmap.map = NULL; 259 401 } 260 - } 261 - 262 - void __init efi_free_boot_services(void) 263 - { 264 - void *p; 265 - 266 - for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 267 - efi_memory_desc_t *md = p; 268 - unsigned long long start = md->phys_addr; 269 - unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; 270 - 271 - if (md->type != EFI_BOOT_SERVICES_CODE && 272 - md->type != EFI_BOOT_SERVICES_DATA) 273 - continue; 274 - 275 - /* Could not reserve boot area */ 276 - if (!size) 277 - continue; 278 - 279 - free_bootmem_late(start, size); 280 - } 281 - 282 - efi_unmap_memmap(); 283 402 } 284 403 285 404 static int __init efi_systab_init(void *phys) ··· 240 467 if (!data) 241 468 return -ENOMEM; 242 469 } 243 - systab64 = early_ioremap((unsigned long)phys, 470 + systab64 = early_memremap((unsigned long)phys, 244 471 sizeof(*systab64)); 245 472 if (systab64 == NULL) { 246 473 pr_err("Couldn't map the system table!\n"); 247 474 if (data) 248 - early_iounmap(data, sizeof(*data)); 475 + early_memunmap(data, sizeof(*data)); 249 476 return -ENOMEM; 250 477 } 251 478 ··· 277 504 systab64->tables; 278 505 tmp |= data ? data->tables : systab64->tables; 279 506 280 - early_iounmap(systab64, sizeof(*systab64)); 507 + early_memunmap(systab64, sizeof(*systab64)); 281 508 if (data) 282 - early_iounmap(data, sizeof(*data)); 509 + early_memunmap(data, sizeof(*data)); 283 510 #ifdef CONFIG_X86_32 284 511 if (tmp >> 32) { 285 512 pr_err("EFI data located above 4GB, disabling EFI.\n"); ··· 289 516 } else { 290 517 efi_system_table_32_t *systab32; 291 518 292 - systab32 = early_ioremap((unsigned long)phys, 519 + systab32 = early_memremap((unsigned long)phys, 293 520 sizeof(*systab32)); 294 521 if (systab32 == NULL) { 295 522 pr_err("Couldn't map the system table!\n"); ··· 310 537 efi_systab.nr_tables = systab32->nr_tables; 311 538 efi_systab.tables = systab32->tables; 312 539 313 - early_iounmap(systab32, sizeof(*systab32)); 540 + early_memunmap(systab32, sizeof(*systab32)); 314 541 } 315 542 316 543 efi.systab = &efi_systab; ··· 336 563 { 337 564 efi_runtime_services_32_t *runtime; 338 565 339 - runtime = early_ioremap((unsigned long)efi.systab->runtime, 566 + runtime = early_memremap((unsigned long)efi.systab->runtime, 340 567 sizeof(efi_runtime_services_32_t)); 341 568 if (!runtime) { 342 569 pr_err("Could not map the runtime service table!\n"); ··· 351 578 efi_phys.set_virtual_address_map = 352 579 (efi_set_virtual_address_map_t *) 353 580 (unsigned long)runtime->set_virtual_address_map; 354 - early_iounmap(runtime, sizeof(efi_runtime_services_32_t)); 581 + early_memunmap(runtime, sizeof(efi_runtime_services_32_t)); 355 582 356 583 return 0; 357 584 } ··· 360 587 { 361 588 efi_runtime_services_64_t *runtime; 362 589 363 - runtime = early_ioremap((unsigned long)efi.systab->runtime, 590 + runtime = early_memremap((unsigned long)efi.systab->runtime, 364 591 sizeof(efi_runtime_services_64_t)); 365 592 if (!runtime) { 366 593 pr_err("Could not map the runtime service table!\n"); ··· 375 602 efi_phys.set_virtual_address_map = 376 603 (efi_set_virtual_address_map_t *) 377 604 (unsigned long)runtime->set_virtual_address_map; 378 - early_iounmap(runtime, sizeof(efi_runtime_services_64_t)); 605 + early_memunmap(runtime, sizeof(efi_runtime_services_64_t)); 379 606 380 607 return 0; 381 608 } ··· 389 616 * the runtime services table so that we can grab the physical 390 617 * address of several of the EFI runtime functions, needed to 391 618 * set the firmware into virtual mode. 619 + * 620 + * When EFI_PARAVIRT is in force then we could not map runtime 621 + * service memory region because we do not have direct access to it. 622 + * However, runtime services are available through proxy functions 623 + * (e.g. in case of Xen dom0 EFI implementation they call special 624 + * hypercall which executes relevant EFI functions) and that is why 625 + * they are always enabled. 392 626 */ 393 - if (efi_enabled(EFI_64BIT)) 394 - rv = efi_runtime_init64(); 395 - else 396 - rv = efi_runtime_init32(); 397 627 398 - if (rv) 399 - return rv; 628 + if (!efi_enabled(EFI_PARAVIRT)) { 629 + if (efi_enabled(EFI_64BIT)) 630 + rv = efi_runtime_init64(); 631 + else 632 + rv = efi_runtime_init32(); 633 + 634 + if (rv) 635 + return rv; 636 + } 400 637 401 638 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 402 639 ··· 415 632 416 633 static int __init efi_memmap_init(void) 417 634 { 635 + if (efi_enabled(EFI_PARAVIRT)) 636 + return 0; 637 + 418 638 /* Map the EFI memory map */ 419 - memmap.map = early_ioremap((unsigned long)memmap.phys_map, 639 + memmap.map = early_memremap((unsigned long)memmap.phys_map, 420 640 memmap.nr_map * memmap.desc_size); 421 641 if (memmap.map == NULL) { 422 642 pr_err("Could not map the memory map!\n"); ··· 433 647 set_bit(EFI_MEMMAP, &efi.flags); 434 648 435 649 return 0; 436 - } 437 - 438 - /* 439 - * A number of config table entries get remapped to virtual addresses 440 - * after entering EFI virtual mode. However, the kexec kernel requires 441 - * their physical addresses therefore we pass them via setup_data and 442 - * correct those entries to their respective physical addresses here. 443 - * 444 - * Currently only handles smbios which is necessary for some firmware 445 - * implementation. 446 - */ 447 - static int __init efi_reuse_config(u64 tables, int nr_tables) 448 - { 449 - int i, sz, ret = 0; 450 - void *p, *tablep; 451 - struct efi_setup_data *data; 452 - 453 - if (!efi_setup) 454 - return 0; 455 - 456 - if (!efi_enabled(EFI_64BIT)) 457 - return 0; 458 - 459 - data = early_memremap(efi_setup, sizeof(*data)); 460 - if (!data) { 461 - ret = -ENOMEM; 462 - goto out; 463 - } 464 - 465 - if (!data->smbios) 466 - goto out_memremap; 467 - 468 - sz = sizeof(efi_config_table_64_t); 469 - 470 - p = tablep = early_memremap(tables, nr_tables * sz); 471 - if (!p) { 472 - pr_err("Could not map Configuration table!\n"); 473 - ret = -ENOMEM; 474 - goto out_memremap; 475 - } 476 - 477 - for (i = 0; i < efi.systab->nr_tables; i++) { 478 - efi_guid_t guid; 479 - 480 - guid = ((efi_config_table_64_t *)p)->guid; 481 - 482 - if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID)) 483 - ((efi_config_table_64_t *)p)->table = data->smbios; 484 - p += sz; 485 - } 486 - early_iounmap(tablep, nr_tables * sz); 487 - 488 - out_memremap: 489 - early_iounmap(data, sizeof(*data)); 490 - out: 491 - return ret; 492 650 } 493 651 494 652 void __init efi_init(void) ··· 458 728 if (efi_systab_init(efi_phys.systab)) 459 729 return; 460 730 461 - set_bit(EFI_SYSTEM_TABLES, &efi.flags); 462 - 463 731 efi.config_table = (unsigned long)efi.systab->tables; 464 732 efi.fw_vendor = (unsigned long)efi.systab->fw_vendor; 465 733 efi.runtime = (unsigned long)efi.systab->runtime; ··· 465 737 /* 466 738 * Show what we know for posterity 467 739 */ 468 - c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2); 740 + c16 = tmp = early_memremap(efi.systab->fw_vendor, 2); 469 741 if (c16) { 470 742 for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) 471 743 vendor[i] = *c16++; 472 744 vendor[i] = '\0'; 473 745 } else 474 746 pr_err("Could not map the firmware vendor!\n"); 475 - early_iounmap(tmp, 2); 747 + early_memunmap(tmp, 2); 476 748 477 749 pr_info("EFI v%u.%.02u by %s\n", 478 750 efi.systab->hdr.revision >> 16, ··· 497 769 } 498 770 if (efi_memmap_init()) 499 771 return; 500 - 501 - set_bit(EFI_MEMMAP, &efi.flags); 502 772 503 773 print_efi_memmap(); 504 774 } ··· 571 845 if (!va) 572 846 pr_err("ioremap of 0x%llX failed!\n", 573 847 (unsigned long long)md->phys_addr); 574 - } 575 - 576 - static void native_runtime_setup(void) 577 - { 578 - efi.get_time = virt_efi_get_time; 579 - efi.set_time = virt_efi_set_time; 580 - efi.get_wakeup_time = virt_efi_get_wakeup_time; 581 - efi.set_wakeup_time = virt_efi_set_wakeup_time; 582 - efi.get_variable = virt_efi_get_variable; 583 - efi.get_next_variable = virt_efi_get_next_variable; 584 - efi.set_variable = virt_efi_set_variable; 585 - efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; 586 - efi.reset_system = virt_efi_reset_system; 587 - efi.query_variable_info = virt_efi_query_variable_info; 588 - efi.update_capsule = virt_efi_update_capsule; 589 - efi.query_capsule_caps = virt_efi_query_capsule_caps; 590 848 } 591 849 592 850 /* Merge contiguous regions of the same type and attribute */ ··· 759 1049 */ 760 1050 efi.runtime_version = efi_systab.hdr.revision; 761 1051 762 - native_runtime_setup(); 1052 + efi_native_runtime_setup(); 763 1053 764 1054 efi.set_virtual_address_map = NULL; 765 1055 ··· 767 1057 runtime_code_page_mkexec(); 768 1058 769 1059 /* clean DUMMY object */ 770 - efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 771 - EFI_VARIABLE_NON_VOLATILE | 772 - EFI_VARIABLE_BOOTSERVICE_ACCESS | 773 - EFI_VARIABLE_RUNTIME_ACCESS, 774 - 0, NULL); 1060 + efi_delete_dummy_variable(); 775 1061 #endif 776 1062 } 777 1063 ··· 848 1142 efi.runtime_version = efi_systab.hdr.revision; 849 1143 850 1144 if (efi_is_native()) 851 - native_runtime_setup(); 1145 + efi_native_runtime_setup(); 852 1146 else 853 1147 efi_thunk_runtime_setup(); 854 1148 ··· 885 1179 free_pages((unsigned long)new_memmap, pg_shift); 886 1180 887 1181 /* clean DUMMY object */ 888 - efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 889 - EFI_VARIABLE_NON_VOLATILE | 890 - EFI_VARIABLE_BOOTSERVICE_ACCESS | 891 - EFI_VARIABLE_RUNTIME_ACCESS, 892 - 0, NULL); 1182 + efi_delete_dummy_variable(); 893 1183 } 894 1184 895 1185 void __init efi_enter_virtual_mode(void) 896 1186 { 1187 + if (efi_enabled(EFI_PARAVIRT)) 1188 + return; 1189 + 897 1190 if (efi_setup) 898 1191 kexec_enter_virtual_mode(); 899 1192 else ··· 925 1220 efi_memory_desc_t *md; 926 1221 void *p; 927 1222 1223 + if (!efi_enabled(EFI_MEMMAP)) 1224 + return 0; 1225 + 928 1226 for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 929 1227 md = p; 930 1228 if ((md->phys_addr <= phys_addr) && ··· 937 1229 } 938 1230 return 0; 939 1231 } 940 - 941 - /* 942 - * Some firmware implementations refuse to boot if there's insufficient space 943 - * in the variable store. Ensure that we never use more than a safe limit. 944 - * 945 - * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable 946 - * store. 947 - */ 948 - efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) 949 - { 950 - efi_status_t status; 951 - u64 storage_size, remaining_size, max_size; 952 - 953 - if (!(attributes & EFI_VARIABLE_NON_VOLATILE)) 954 - return 0; 955 - 956 - status = efi.query_variable_info(attributes, &storage_size, 957 - &remaining_size, &max_size); 958 - if (status != EFI_SUCCESS) 959 - return status; 960 - 961 - /* 962 - * We account for that by refusing the write if permitting it would 963 - * reduce the available space to under 5KB. This figure was provided by 964 - * Samsung, so should be safe. 965 - */ 966 - if ((remaining_size - size < EFI_MIN_RESERVE) && 967 - !efi_no_storage_paranoia) { 968 - 969 - /* 970 - * Triggering garbage collection may require that the firmware 971 - * generate a real EFI_OUT_OF_RESOURCES error. We can force 972 - * that by attempting to use more space than is available. 973 - */ 974 - unsigned long dummy_size = remaining_size + 1024; 975 - void *dummy = kzalloc(dummy_size, GFP_ATOMIC); 976 - 977 - if (!dummy) 978 - return EFI_OUT_OF_RESOURCES; 979 - 980 - status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 981 - EFI_VARIABLE_NON_VOLATILE | 982 - EFI_VARIABLE_BOOTSERVICE_ACCESS | 983 - EFI_VARIABLE_RUNTIME_ACCESS, 984 - dummy_size, dummy); 985 - 986 - if (status == EFI_SUCCESS) { 987 - /* 988 - * This should have failed, so if it didn't make sure 989 - * that we delete it... 990 - */ 991 - efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 992 - EFI_VARIABLE_NON_VOLATILE | 993 - EFI_VARIABLE_BOOTSERVICE_ACCESS | 994 - EFI_VARIABLE_RUNTIME_ACCESS, 995 - 0, dummy); 996 - } 997 - 998 - kfree(dummy); 999 - 1000 - /* 1001 - * The runtime code may now have triggered a garbage collection 1002 - * run, so check the variable info again 1003 - */ 1004 - status = efi.query_variable_info(attributes, &storage_size, 1005 - &remaining_size, &max_size); 1006 - 1007 - if (status != EFI_SUCCESS) 1008 - return status; 1009 - 1010 - /* 1011 - * There still isn't enough room, so return an error 1012 - */ 1013 - if (remaining_size - size < EFI_MIN_RESERVE) 1014 - return EFI_OUT_OF_RESOURCES; 1015 - } 1016 - 1017 - return EFI_SUCCESS; 1018 - } 1019 - EXPORT_SYMBOL_GPL(efi_query_variable_store); 1020 1232 1021 1233 static int __init parse_efi_cmdline(char *str) 1022 1234 { ··· 949 1321 return 0; 950 1322 } 951 1323 early_param("efi", parse_efi_cmdline); 952 - 953 - void __init efi_apply_memmap_quirks(void) 954 - { 955 - /* 956 - * Once setup is done earlier, unmap the EFI memory map on mismatched 957 - * firmware/kernel architectures since there is no support for runtime 958 - * services. 959 - */ 960 - if (!efi_runtime_supported()) { 961 - pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n"); 962 - efi_unmap_memmap(); 963 - } 964 - 965 - /* 966 - * UV doesn't support the new EFI pagetable mapping yet. 967 - */ 968 - if (is_uv_system()) 969 - set_bit(EFI_OLD_MEMMAP, &efi.flags); 970 - }
+290
arch/x86/platform/efi/quirks.c
··· 1 + #include <linux/init.h> 2 + #include <linux/kernel.h> 3 + #include <linux/string.h> 4 + #include <linux/time.h> 5 + #include <linux/types.h> 6 + #include <linux/efi.h> 7 + #include <linux/slab.h> 8 + #include <linux/memblock.h> 9 + #include <linux/bootmem.h> 10 + #include <linux/acpi.h> 11 + #include <asm/efi.h> 12 + #include <asm/uv/uv.h> 13 + 14 + #define EFI_MIN_RESERVE 5120 15 + 16 + #define EFI_DUMMY_GUID \ 17 + EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) 18 + 19 + static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; 20 + 21 + static bool efi_no_storage_paranoia; 22 + 23 + /* 24 + * Some firmware implementations refuse to boot if there's insufficient 25 + * space in the variable store. The implementation of garbage collection 26 + * in some FW versions causes stale (deleted) variables to take up space 27 + * longer than intended and space is only freed once the store becomes 28 + * almost completely full. 29 + * 30 + * Enabling this option disables the space checks in 31 + * efi_query_variable_store() and forces garbage collection. 32 + * 33 + * Only enable this option if deleting EFI variables does not free up 34 + * space in your variable store, e.g. if despite deleting variables 35 + * you're unable to create new ones. 36 + */ 37 + static int __init setup_storage_paranoia(char *arg) 38 + { 39 + efi_no_storage_paranoia = true; 40 + return 0; 41 + } 42 + early_param("efi_no_storage_paranoia", setup_storage_paranoia); 43 + 44 + /* 45 + * Deleting the dummy variable which kicks off garbage collection 46 + */ 47 + void efi_delete_dummy_variable(void) 48 + { 49 + efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 50 + EFI_VARIABLE_NON_VOLATILE | 51 + EFI_VARIABLE_BOOTSERVICE_ACCESS | 52 + EFI_VARIABLE_RUNTIME_ACCESS, 53 + 0, NULL); 54 + } 55 + 56 + /* 57 + * Some firmware implementations refuse to boot if there's insufficient space 58 + * in the variable store. Ensure that we never use more than a safe limit. 59 + * 60 + * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable 61 + * store. 62 + */ 63 + efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) 64 + { 65 + efi_status_t status; 66 + u64 storage_size, remaining_size, max_size; 67 + 68 + if (!(attributes & EFI_VARIABLE_NON_VOLATILE)) 69 + return 0; 70 + 71 + status = efi.query_variable_info(attributes, &storage_size, 72 + &remaining_size, &max_size); 73 + if (status != EFI_SUCCESS) 74 + return status; 75 + 76 + /* 77 + * We account for that by refusing the write if permitting it would 78 + * reduce the available space to under 5KB. This figure was provided by 79 + * Samsung, so should be safe. 80 + */ 81 + if ((remaining_size - size < EFI_MIN_RESERVE) && 82 + !efi_no_storage_paranoia) { 83 + 84 + /* 85 + * Triggering garbage collection may require that the firmware 86 + * generate a real EFI_OUT_OF_RESOURCES error. We can force 87 + * that by attempting to use more space than is available. 88 + */ 89 + unsigned long dummy_size = remaining_size + 1024; 90 + void *dummy = kzalloc(dummy_size, GFP_ATOMIC); 91 + 92 + if (!dummy) 93 + return EFI_OUT_OF_RESOURCES; 94 + 95 + status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, 96 + EFI_VARIABLE_NON_VOLATILE | 97 + EFI_VARIABLE_BOOTSERVICE_ACCESS | 98 + EFI_VARIABLE_RUNTIME_ACCESS, 99 + dummy_size, dummy); 100 + 101 + if (status == EFI_SUCCESS) { 102 + /* 103 + * This should have failed, so if it didn't make sure 104 + * that we delete it... 105 + */ 106 + efi_delete_dummy_variable(); 107 + } 108 + 109 + kfree(dummy); 110 + 111 + /* 112 + * The runtime code may now have triggered a garbage collection 113 + * run, so check the variable info again 114 + */ 115 + status = efi.query_variable_info(attributes, &storage_size, 116 + &remaining_size, &max_size); 117 + 118 + if (status != EFI_SUCCESS) 119 + return status; 120 + 121 + /* 122 + * There still isn't enough room, so return an error 123 + */ 124 + if (remaining_size - size < EFI_MIN_RESERVE) 125 + return EFI_OUT_OF_RESOURCES; 126 + } 127 + 128 + return EFI_SUCCESS; 129 + } 130 + EXPORT_SYMBOL_GPL(efi_query_variable_store); 131 + 132 + /* 133 + * The UEFI specification makes it clear that the operating system is free to do 134 + * whatever it wants with boot services code after ExitBootServices() has been 135 + * called. Ignoring this recommendation a significant bunch of EFI implementations 136 + * continue calling into boot services code (SetVirtualAddressMap). In order to 137 + * work around such buggy implementations we reserve boot services region during 138 + * EFI init and make sure it stays executable. Then, after SetVirtualAddressMap(), it 139 + * is discarded. 140 + */ 141 + void __init efi_reserve_boot_services(void) 142 + { 143 + void *p; 144 + 145 + for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 146 + efi_memory_desc_t *md = p; 147 + u64 start = md->phys_addr; 148 + u64 size = md->num_pages << EFI_PAGE_SHIFT; 149 + 150 + if (md->type != EFI_BOOT_SERVICES_CODE && 151 + md->type != EFI_BOOT_SERVICES_DATA) 152 + continue; 153 + /* Only reserve where possible: 154 + * - Not within any already allocated areas 155 + * - Not over any memory area (really needed, if above?) 156 + * - Not within any part of the kernel 157 + * - Not the bios reserved area 158 + */ 159 + if ((start + size > __pa_symbol(_text) 160 + && start <= __pa_symbol(_end)) || 161 + !e820_all_mapped(start, start+size, E820_RAM) || 162 + memblock_is_region_reserved(start, size)) { 163 + /* Could not reserve, skip it */ 164 + md->num_pages = 0; 165 + memblock_dbg("Could not reserve boot range [0x%010llx-0x%010llx]\n", 166 + start, start+size-1); 167 + } else 168 + memblock_reserve(start, size); 169 + } 170 + } 171 + 172 + void __init efi_free_boot_services(void) 173 + { 174 + void *p; 175 + 176 + for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { 177 + efi_memory_desc_t *md = p; 178 + unsigned long long start = md->phys_addr; 179 + unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; 180 + 181 + if (md->type != EFI_BOOT_SERVICES_CODE && 182 + md->type != EFI_BOOT_SERVICES_DATA) 183 + continue; 184 + 185 + /* Could not reserve boot area */ 186 + if (!size) 187 + continue; 188 + 189 + free_bootmem_late(start, size); 190 + } 191 + 192 + efi_unmap_memmap(); 193 + } 194 + 195 + /* 196 + * A number of config table entries get remapped to virtual addresses 197 + * after entering EFI virtual mode. However, the kexec kernel requires 198 + * their physical addresses therefore we pass them via setup_data and 199 + * correct those entries to their respective physical addresses here. 200 + * 201 + * Currently only handles smbios which is necessary for some firmware 202 + * implementation. 203 + */ 204 + int __init efi_reuse_config(u64 tables, int nr_tables) 205 + { 206 + int i, sz, ret = 0; 207 + void *p, *tablep; 208 + struct efi_setup_data *data; 209 + 210 + if (!efi_setup) 211 + return 0; 212 + 213 + if (!efi_enabled(EFI_64BIT)) 214 + return 0; 215 + 216 + data = early_memremap(efi_setup, sizeof(*data)); 217 + if (!data) { 218 + ret = -ENOMEM; 219 + goto out; 220 + } 221 + 222 + if (!data->smbios) 223 + goto out_memremap; 224 + 225 + sz = sizeof(efi_config_table_64_t); 226 + 227 + p = tablep = early_memremap(tables, nr_tables * sz); 228 + if (!p) { 229 + pr_err("Could not map Configuration table!\n"); 230 + ret = -ENOMEM; 231 + goto out_memremap; 232 + } 233 + 234 + for (i = 0; i < efi.systab->nr_tables; i++) { 235 + efi_guid_t guid; 236 + 237 + guid = ((efi_config_table_64_t *)p)->guid; 238 + 239 + if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID)) 240 + ((efi_config_table_64_t *)p)->table = data->smbios; 241 + p += sz; 242 + } 243 + early_memunmap(tablep, nr_tables * sz); 244 + 245 + out_memremap: 246 + early_memunmap(data, sizeof(*data)); 247 + out: 248 + return ret; 249 + } 250 + 251 + void __init efi_apply_memmap_quirks(void) 252 + { 253 + /* 254 + * Once setup is done earlier, unmap the EFI memory map on mismatched 255 + * firmware/kernel architectures since there is no support for runtime 256 + * services. 257 + */ 258 + if (!efi_runtime_supported()) { 259 + pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n"); 260 + efi_unmap_memmap(); 261 + } 262 + 263 + /* 264 + * UV doesn't support the new EFI pagetable mapping yet. 265 + */ 266 + if (is_uv_system()) 267 + set_bit(EFI_OLD_MEMMAP, &efi.flags); 268 + } 269 + 270 + /* 271 + * For most modern platforms the preferred method of powering off is via 272 + * ACPI. However, there are some that are known to require the use of 273 + * EFI runtime services and for which ACPI does not work at all. 274 + * 275 + * Using EFI is a last resort, to be used only if no other option 276 + * exists. 277 + */ 278 + bool efi_reboot_required(void) 279 + { 280 + if (!acpi_gbl_reduced_hardware) 281 + return false; 282 + 283 + efi_reboot_quirk_mode = EFI_RESET_WARM; 284 + return true; 285 + } 286 + 287 + bool efi_poweroff_required(void) 288 + { 289 + return !!acpi_gbl_reduced_hardware; 290 + }
+1
arch/x86/xen/Makefile
··· 22 22 obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o 23 23 obj-$(CONFIG_XEN_DOM0) += apic.o vga.o 24 24 obj-$(CONFIG_SWIOTLB_XEN) += pci-swiotlb-xen.o 25 + obj-$(CONFIG_XEN_EFI) += efi.o
+43
arch/x86/xen/efi.c
··· 1 + /* 2 + * Copyright (c) 2014 Oracle Co., Daniel Kiper 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License as published by 6 + * the Free Software Foundation; either version 2 of the License, or 7 + * (at your option) any later version. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License along 15 + * with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include <linux/efi.h> 19 + #include <linux/init.h> 20 + #include <linux/string.h> 21 + 22 + #include <xen/xen-ops.h> 23 + 24 + #include <asm/setup.h> 25 + 26 + void __init xen_efi_init(void) 27 + { 28 + efi_system_table_t *efi_systab_xen; 29 + 30 + efi_systab_xen = xen_efi_probe(); 31 + 32 + if (efi_systab_xen == NULL) 33 + return; 34 + 35 + strncpy((char *)&boot_params.efi_info.efi_loader_signature, "Xen", 36 + sizeof(boot_params.efi_info.efi_loader_signature)); 37 + boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen); 38 + boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32); 39 + 40 + set_bit(EFI_BOOT, &efi.flags); 41 + set_bit(EFI_PARAVIRT, &efi.flags); 42 + set_bit(EFI_64BIT, &efi.flags); 43 + }
+2
arch/x86/xen/enlighten.c
··· 1718 1718 1719 1719 xen_setup_runstate_info(0); 1720 1720 1721 + xen_efi_init(); 1722 + 1721 1723 /* Start the world */ 1722 1724 #ifdef CONFIG_X86_32 1723 1725 i386_start_kernel();
+8
arch/x86/xen/xen-ops.h
··· 105 105 } 106 106 #endif 107 107 108 + #ifdef CONFIG_XEN_EFI 109 + extern void xen_efi_init(void); 110 + #else 111 + static inline void __init xen_efi_init(void) 112 + { 113 + } 114 + #endif 115 + 108 116 /* Declare an asm function, along with symbols needed to make it 109 117 inlineable */ 110 118 #define DECL_ASM(ret, name, ...) \
+6
drivers/firmware/efi/Kconfig
··· 54 54 the EFI runtime support gets system table address, memory 55 55 map address, and other parameters from the device tree. 56 56 57 + config EFI_RUNTIME_WRAPPERS 58 + bool 59 + 60 + config EFI_ARMSTUB 61 + bool 62 + 57 63 endmenu 58 64 59 65 config UEFI_CPER
+3 -1
drivers/firmware/efi/Makefile
··· 1 1 # 2 2 # Makefile for linux kernel 3 3 # 4 - obj-$(CONFIG_EFI) += efi.o vars.o 4 + obj-$(CONFIG_EFI) += efi.o vars.o reboot.o 5 5 obj-$(CONFIG_EFI_VARS) += efivars.o 6 6 obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o 7 7 obj-$(CONFIG_UEFI_CPER) += cper.o 8 8 obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o 9 + obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o 10 + obj-$(CONFIG_EFI_STUB) += libstub/
+19 -13
drivers/firmware/efi/arm-stub.c drivers/firmware/efi/libstub/arm-stub.c
··· 12 12 * 13 13 */ 14 14 15 + #include <linux/efi.h> 16 + #include <asm/efi.h> 17 + 18 + #include "efistub.h" 19 + 15 20 static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) 16 21 { 17 22 static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID; ··· 41 36 } 42 37 } 43 38 44 - static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, 45 - void *__image, void **__fh) 39 + efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, 40 + void *__image, void **__fh) 46 41 { 47 42 efi_file_io_interface_t *io; 48 43 efi_loaded_image_t *image = __image; ··· 65 60 *__fh = fh; 66 61 return status; 67 62 } 68 - static efi_status_t efi_file_close(void *handle) 63 + 64 + efi_status_t efi_file_close(void *handle) 69 65 { 70 66 efi_file_handle_t *fh = handle; 71 67 72 68 return fh->close(handle); 73 69 } 74 70 75 - static efi_status_t 71 + efi_status_t 76 72 efi_file_read(void *handle, unsigned long *size, void *addr) 77 73 { 78 74 efi_file_handle_t *fh = handle; ··· 82 76 } 83 77 84 78 85 - static efi_status_t 79 + efi_status_t 86 80 efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, 87 81 efi_char16_t *filename_16, void **handle, u64 *file_sz) 88 82 { ··· 135 129 136 130 137 131 138 - static void efi_char16_printk(efi_system_table_t *sys_table_arg, 132 + void efi_char16_printk(efi_system_table_t *sys_table_arg, 139 133 efi_char16_t *str) 140 134 { 141 135 struct efi_simple_text_output_protocol *out; ··· 151 145 * must be reserved. On failure it is required to free all 152 146 * all allocations it has made. 153 147 */ 154 - static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 155 - unsigned long *image_addr, 156 - unsigned long *image_size, 157 - unsigned long *reserve_addr, 158 - unsigned long *reserve_size, 159 - unsigned long dram_base, 160 - efi_loaded_image_t *image); 148 + efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 149 + unsigned long *image_addr, 150 + unsigned long *image_size, 151 + unsigned long *reserve_addr, 152 + unsigned long *reserve_size, 153 + unsigned long dram_base, 154 + efi_loaded_image_t *image); 161 155 /* 162 156 * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint 163 157 * that is described in the PE/COFF header. Most of the code is the same
+37 -39
drivers/firmware/efi/efi-stub-helper.c drivers/firmware/efi/libstub/efi-stub-helper.c
··· 9 9 * under the terms of the GNU General Public License version 2. 10 10 * 11 11 */ 12 + 13 + #include <linux/efi.h> 14 + #include <asm/efi.h> 15 + 16 + #include "efistub.h" 17 + 12 18 #define EFI_READ_CHUNK_SIZE (1024 * 1024) 13 - 14 - /* error code which can't be mistaken for valid address */ 15 - #define EFI_ERROR (~0UL) 16 - 17 19 18 20 struct file_info { 19 21 efi_file_handle_t *handle; 20 22 u64 size; 21 23 }; 22 24 23 - static void efi_printk(efi_system_table_t *sys_table_arg, char *str) 25 + void efi_printk(efi_system_table_t *sys_table_arg, char *str) 24 26 { 25 27 char *s8; 26 28 ··· 39 37 } 40 38 } 41 39 42 - #define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg) 43 - #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg) 44 - 45 - 46 - static efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, 47 - efi_memory_desc_t **map, 48 - unsigned long *map_size, 49 - unsigned long *desc_size, 50 - u32 *desc_ver, 51 - unsigned long *key_ptr) 40 + efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, 41 + efi_memory_desc_t **map, 42 + unsigned long *map_size, 43 + unsigned long *desc_size, 44 + u32 *desc_ver, 45 + unsigned long *key_ptr) 52 46 { 53 47 efi_memory_desc_t *m = NULL; 54 48 efi_status_t status; ··· 86 88 } 87 89 88 90 89 - static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) 91 + unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) 90 92 { 91 93 efi_status_t status; 92 94 unsigned long map_size; ··· 114 116 /* 115 117 * Allocate at the highest possible address that is not above 'max'. 116 118 */ 117 - static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, 118 - unsigned long size, unsigned long align, 119 - unsigned long *addr, unsigned long max) 119 + efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, 120 + unsigned long size, unsigned long align, 121 + unsigned long *addr, unsigned long max) 120 122 { 121 123 unsigned long map_size, desc_size; 122 124 efi_memory_desc_t *map; ··· 200 202 /* 201 203 * Allocate at the lowest possible address. 202 204 */ 203 - static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, 204 - unsigned long size, unsigned long align, 205 - unsigned long *addr) 205 + efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, 206 + unsigned long size, unsigned long align, 207 + unsigned long *addr) 206 208 { 207 209 unsigned long map_size, desc_size; 208 210 efi_memory_desc_t *map; ··· 269 271 return status; 270 272 } 271 273 272 - static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, 273 - unsigned long addr) 274 + void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, 275 + unsigned long addr) 274 276 { 275 277 unsigned long nr_pages; 276 278 ··· 288 290 * We only support loading a file from the same filesystem as 289 291 * the kernel image. 290 292 */ 291 - static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, 292 - efi_loaded_image_t *image, 293 - char *cmd_line, char *option_string, 294 - unsigned long max_addr, 295 - unsigned long *load_addr, 296 - unsigned long *load_size) 293 + efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, 294 + efi_loaded_image_t *image, 295 + char *cmd_line, char *option_string, 296 + unsigned long max_addr, 297 + unsigned long *load_addr, 298 + unsigned long *load_size) 297 299 { 298 300 struct file_info *files; 299 301 unsigned long file_addr; ··· 475 477 * address is not available the lowest available address will 476 478 * be used. 477 479 */ 478 - static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, 479 - unsigned long *image_addr, 480 - unsigned long image_size, 481 - unsigned long alloc_size, 482 - unsigned long preferred_addr, 483 - unsigned long alignment) 480 + efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, 481 + unsigned long *image_addr, 482 + unsigned long image_size, 483 + unsigned long alloc_size, 484 + unsigned long preferred_addr, 485 + unsigned long alignment) 484 486 { 485 487 unsigned long cur_image_addr; 486 488 unsigned long new_addr = 0; ··· 587 589 * Size of memory allocated return in *cmd_line_len. 588 590 * Returns NULL on error. 589 591 */ 590 - static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, 591 - efi_loaded_image_t *image, 592 - int *cmd_line_len) 592 + char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, 593 + efi_loaded_image_t *image, 594 + int *cmd_line_len) 593 595 { 594 596 const u16 *s2; 595 597 u8 *s1 = NULL;
+29 -11
drivers/firmware/efi/efi.c
··· 23 23 #include <linux/of.h> 24 24 #include <linux/of_fdt.h> 25 25 #include <linux/io.h> 26 + #include <linux/platform_device.h> 26 27 27 28 struct efi __read_mostly efi = { 28 29 .mps = EFI_INVALID_TABLE_ADDR, ··· 105 104 static umode_t efi_attr_is_visible(struct kobject *kobj, 106 105 struct attribute *attr, int n) 107 106 { 108 - umode_t mode = attr->mode; 107 + if (attr == &efi_attr_fw_vendor.attr) { 108 + if (efi_enabled(EFI_PARAVIRT) || 109 + efi.fw_vendor == EFI_INVALID_TABLE_ADDR) 110 + return 0; 111 + } else if (attr == &efi_attr_runtime.attr) { 112 + if (efi.runtime == EFI_INVALID_TABLE_ADDR) 113 + return 0; 114 + } else if (attr == &efi_attr_config_table.attr) { 115 + if (efi.config_table == EFI_INVALID_TABLE_ADDR) 116 + return 0; 117 + } 109 118 110 - if (attr == &efi_attr_fw_vendor.attr) 111 - return (efi.fw_vendor == EFI_INVALID_TABLE_ADDR) ? 0 : mode; 112 - else if (attr == &efi_attr_runtime.attr) 113 - return (efi.runtime == EFI_INVALID_TABLE_ADDR) ? 0 : mode; 114 - else if (attr == &efi_attr_config_table.attr) 115 - return (efi.config_table == EFI_INVALID_TABLE_ADDR) ? 0 : mode; 116 - 117 - return mode; 119 + return attr->mode; 118 120 } 119 121 120 122 static struct attribute_group efi_subsys_attr_group = { ··· 302 298 if (table64 >> 32) { 303 299 pr_cont("\n"); 304 300 pr_err("Table located above 4GB, disabling EFI.\n"); 305 - early_iounmap(config_tables, 301 + early_memunmap(config_tables, 306 302 efi.systab->nr_tables * sz); 307 303 return -EINVAL; 308 304 } ··· 318 314 tablep += sz; 319 315 } 320 316 pr_cont("\n"); 321 - early_iounmap(config_tables, efi.systab->nr_tables * sz); 317 + early_memunmap(config_tables, efi.systab->nr_tables * sz); 322 318 323 319 set_bit(EFI_CONFIG_TABLES, &efi.flags); 324 320 325 321 return 0; 326 322 } 323 + 324 + #ifdef CONFIG_EFI_VARS_MODULE 325 + static int __init efi_load_efivars(void) 326 + { 327 + struct platform_device *pdev; 328 + 329 + if (!efi_enabled(EFI_RUNTIME_SERVICES)) 330 + return 0; 331 + 332 + pdev = platform_device_register_simple("efivars", 0, NULL, 0); 333 + return IS_ERR(pdev) ? PTR_ERR(pdev) : 0; 334 + } 335 + device_initcall(efi_load_efivars); 336 + #endif 327 337 328 338 #ifdef CONFIG_EFI_PARAMS_FROM_FDT 329 339
+1
drivers/firmware/efi/efivars.c
··· 78 78 MODULE_DESCRIPTION("sysfs interface to EFI Variables"); 79 79 MODULE_LICENSE("GPL"); 80 80 MODULE_VERSION(EFIVARS_VERSION); 81 + MODULE_ALIAS("platform:efivars"); 81 82 82 83 LIST_HEAD(efivar_sysfs_list); 83 84 EXPORT_SYMBOL_GPL(efivar_sysfs_list);
+12 -8
drivers/firmware/efi/fdt.c drivers/firmware/efi/libstub/fdt.c
··· 10 10 * 11 11 */ 12 12 13 - static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, 14 - unsigned long orig_fdt_size, 15 - void *fdt, int new_fdt_size, char *cmdline_ptr, 16 - u64 initrd_addr, u64 initrd_size, 17 - efi_memory_desc_t *memory_map, 18 - unsigned long map_size, unsigned long desc_size, 19 - u32 desc_ver) 13 + #include <linux/efi.h> 14 + #include <linux/libfdt.h> 15 + #include <asm/efi.h> 16 + 17 + efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, 18 + unsigned long orig_fdt_size, 19 + void *fdt, int new_fdt_size, char *cmdline_ptr, 20 + u64 initrd_addr, u64 initrd_size, 21 + efi_memory_desc_t *memory_map, 22 + unsigned long map_size, unsigned long desc_size, 23 + u32 desc_ver) 20 24 { 21 25 int node, prev; 22 26 int status; ··· 259 255 return EFI_LOAD_ERROR; 260 256 } 261 257 262 - static void *get_fdt(efi_system_table_t *sys_table) 258 + void *get_fdt(efi_system_table_t *sys_table) 263 259 { 264 260 efi_guid_t fdt_guid = DEVICE_TREE_GUID; 265 261 efi_config_table_t *tables;
+26
drivers/firmware/efi/libstub/Makefile
··· 1 + # 2 + # The stub may be linked into the kernel proper or into a separate boot binary, 3 + # but in either case, it executes before the kernel does (with MMU disabled) so 4 + # things like ftrace and stack-protector are likely to cause trouble if left 5 + # enabled, even if doing so doesn't break the build. 6 + # 7 + cflags-$(CONFIG_X86_32) := -march=i386 8 + cflags-$(CONFIG_X86_64) := -mcmodel=small 9 + cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \ 10 + -fPIC -fno-strict-aliasing -mno-red-zone \ 11 + -mno-mmx -mno-sse -DDISABLE_BRANCH_PROFILING 12 + 13 + cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) 14 + cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ 15 + -fno-builtin -fpic -mno-single-pic-base 16 + 17 + KBUILD_CFLAGS := $(cflags-y) \ 18 + $(call cc-option,-ffreestanding) \ 19 + $(call cc-option,-fno-stack-protector) 20 + 21 + GCOV_PROFILE := n 22 + 23 + lib-y := efi-stub-helper.o 24 + lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o 25 + 26 + CFLAGS_fdt.o += -I$(srctree)/scripts/dtc/libfdt/
+42
drivers/firmware/efi/libstub/efistub.h
··· 1 + 2 + #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H 3 + #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H 4 + 5 + /* error code which can't be mistaken for valid address */ 6 + #define EFI_ERROR (~0UL) 7 + 8 + void efi_char16_printk(efi_system_table_t *, efi_char16_t *); 9 + 10 + efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, 11 + void **__fh); 12 + 13 + efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, 14 + efi_char16_t *filename_16, void **handle, 15 + u64 *file_sz); 16 + 17 + efi_status_t efi_file_read(void *handle, unsigned long *size, void *addr); 18 + 19 + efi_status_t efi_file_close(void *handle); 20 + 21 + unsigned long get_dram_base(efi_system_table_t *sys_table_arg); 22 + 23 + efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, 24 + unsigned long orig_fdt_size, 25 + void *fdt, int new_fdt_size, char *cmdline_ptr, 26 + u64 initrd_addr, u64 initrd_size, 27 + efi_memory_desc_t *memory_map, 28 + unsigned long map_size, unsigned long desc_size, 29 + u32 desc_ver); 30 + 31 + efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, 32 + void *handle, 33 + unsigned long *new_fdt_addr, 34 + unsigned long max_addr, 35 + u64 initrd_addr, u64 initrd_size, 36 + char *cmdline_ptr, 37 + unsigned long fdt_addr, 38 + unsigned long fdt_size); 39 + 40 + void *get_fdt(efi_system_table_t *sys_table); 41 + 42 + #endif
+56
drivers/firmware/efi/reboot.c
··· 1 + /* 2 + * Copyright (C) 2014 Intel Corporation; author Matt Fleming 3 + * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com> 4 + */ 5 + #include <linux/efi.h> 6 + #include <linux/reboot.h> 7 + 8 + int efi_reboot_quirk_mode = -1; 9 + 10 + void efi_reboot(enum reboot_mode reboot_mode, const char *__unused) 11 + { 12 + int efi_mode; 13 + 14 + if (!efi_enabled(EFI_RUNTIME_SERVICES)) 15 + return; 16 + 17 + switch (reboot_mode) { 18 + case REBOOT_WARM: 19 + case REBOOT_SOFT: 20 + efi_mode = EFI_RESET_WARM; 21 + break; 22 + default: 23 + efi_mode = EFI_RESET_COLD; 24 + break; 25 + } 26 + 27 + /* 28 + * If a quirk forced an EFI reset mode, always use that. 29 + */ 30 + if (efi_reboot_quirk_mode != -1) 31 + efi_mode = efi_reboot_quirk_mode; 32 + 33 + efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL); 34 + } 35 + 36 + bool __weak efi_poweroff_required(void) 37 + { 38 + return false; 39 + } 40 + 41 + static void efi_power_off(void) 42 + { 43 + efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); 44 + } 45 + 46 + static int __init efi_shutdown_init(void) 47 + { 48 + if (!efi_enabled(EFI_RUNTIME_SERVICES)) 49 + return -ENODEV; 50 + 51 + if (efi_poweroff_required()) 52 + pm_power_off = efi_power_off; 53 + 54 + return 0; 55 + } 56 + late_initcall(efi_shutdown_init);
+161
drivers/firmware/efi/runtime-wrappers.c
··· 1 + /* 2 + * runtime-wrappers.c - Runtime Services function call wrappers 3 + * 4 + * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 5 + * 6 + * Split off from arch/x86/platform/efi/efi.c 7 + * 8 + * Copyright (C) 1999 VA Linux Systems 9 + * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> 10 + * Copyright (C) 1999-2002 Hewlett-Packard Co. 11 + * Copyright (C) 2005-2008 Intel Co. 12 + * Copyright (C) 2013 SuSE Labs 13 + * 14 + * This file is released under the GPLv2. 15 + */ 16 + 17 + #include <linux/efi.h> 18 + #include <linux/spinlock.h> /* spinlock_t */ 19 + #include <asm/efi.h> 20 + 21 + /* 22 + * As per commit ef68c8f87ed1 ("x86: Serialize EFI time accesses on rtc_lock"), 23 + * the EFI specification requires that callers of the time related runtime 24 + * functions serialize with other CMOS accesses in the kernel, as the EFI time 25 + * functions may choose to also use the legacy CMOS RTC. 26 + */ 27 + __weak DEFINE_SPINLOCK(rtc_lock); 28 + 29 + static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) 30 + { 31 + unsigned long flags; 32 + efi_status_t status; 33 + 34 + spin_lock_irqsave(&rtc_lock, flags); 35 + status = efi_call_virt(get_time, tm, tc); 36 + spin_unlock_irqrestore(&rtc_lock, flags); 37 + return status; 38 + } 39 + 40 + static efi_status_t virt_efi_set_time(efi_time_t *tm) 41 + { 42 + unsigned long flags; 43 + efi_status_t status; 44 + 45 + spin_lock_irqsave(&rtc_lock, flags); 46 + status = efi_call_virt(set_time, tm); 47 + spin_unlock_irqrestore(&rtc_lock, flags); 48 + return status; 49 + } 50 + 51 + static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, 52 + efi_bool_t *pending, 53 + efi_time_t *tm) 54 + { 55 + unsigned long flags; 56 + efi_status_t status; 57 + 58 + spin_lock_irqsave(&rtc_lock, flags); 59 + status = efi_call_virt(get_wakeup_time, enabled, pending, tm); 60 + spin_unlock_irqrestore(&rtc_lock, flags); 61 + return status; 62 + } 63 + 64 + static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) 65 + { 66 + unsigned long flags; 67 + efi_status_t status; 68 + 69 + spin_lock_irqsave(&rtc_lock, flags); 70 + status = efi_call_virt(set_wakeup_time, enabled, tm); 71 + spin_unlock_irqrestore(&rtc_lock, flags); 72 + return status; 73 + } 74 + 75 + static efi_status_t virt_efi_get_variable(efi_char16_t *name, 76 + efi_guid_t *vendor, 77 + u32 *attr, 78 + unsigned long *data_size, 79 + void *data) 80 + { 81 + return efi_call_virt(get_variable, name, vendor, attr, data_size, data); 82 + } 83 + 84 + static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, 85 + efi_char16_t *name, 86 + efi_guid_t *vendor) 87 + { 88 + return efi_call_virt(get_next_variable, name_size, name, vendor); 89 + } 90 + 91 + static efi_status_t virt_efi_set_variable(efi_char16_t *name, 92 + efi_guid_t *vendor, 93 + u32 attr, 94 + unsigned long data_size, 95 + void *data) 96 + { 97 + return efi_call_virt(set_variable, name, vendor, attr, data_size, data); 98 + } 99 + 100 + static efi_status_t virt_efi_query_variable_info(u32 attr, 101 + u64 *storage_space, 102 + u64 *remaining_space, 103 + u64 *max_variable_size) 104 + { 105 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 106 + return EFI_UNSUPPORTED; 107 + 108 + return efi_call_virt(query_variable_info, attr, storage_space, 109 + remaining_space, max_variable_size); 110 + } 111 + 112 + static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) 113 + { 114 + return efi_call_virt(get_next_high_mono_count, count); 115 + } 116 + 117 + static void virt_efi_reset_system(int reset_type, 118 + efi_status_t status, 119 + unsigned long data_size, 120 + efi_char16_t *data) 121 + { 122 + __efi_call_virt(reset_system, reset_type, status, data_size, data); 123 + } 124 + 125 + static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, 126 + unsigned long count, 127 + unsigned long sg_list) 128 + { 129 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 130 + return EFI_UNSUPPORTED; 131 + 132 + return efi_call_virt(update_capsule, capsules, count, sg_list); 133 + } 134 + 135 + static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, 136 + unsigned long count, 137 + u64 *max_size, 138 + int *reset_type) 139 + { 140 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 141 + return EFI_UNSUPPORTED; 142 + 143 + return efi_call_virt(query_capsule_caps, capsules, count, max_size, 144 + reset_type); 145 + } 146 + 147 + void efi_native_runtime_setup(void) 148 + { 149 + efi.get_time = virt_efi_get_time; 150 + efi.set_time = virt_efi_set_time; 151 + efi.get_wakeup_time = virt_efi_get_wakeup_time; 152 + efi.set_wakeup_time = virt_efi_set_wakeup_time; 153 + efi.get_variable = virt_efi_get_variable; 154 + efi.get_next_variable = virt_efi_get_next_variable; 155 + efi.set_variable = virt_efi_set_variable; 156 + efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; 157 + efi.reset_system = virt_efi_reset_system; 158 + efi.query_variable_info = virt_efi_query_variable_info; 159 + efi.update_capsule = virt_efi_update_capsule; 160 + efi.query_capsule_caps = virt_efi_query_capsule_caps; 161 + }
+4
drivers/xen/Kconfig
··· 240 240 config XEN_HAVE_PVMMU 241 241 bool 242 242 243 + config XEN_EFI 244 + def_bool y 245 + depends on X86_64 && EFI 246 + 243 247 endmenu
+3
drivers/xen/Makefile
··· 9 9 nostackp := $(call cc-option, -fno-stack-protector) 10 10 CFLAGS_features.o := $(nostackp) 11 11 12 + CFLAGS_efi.o += -fshort-wchar 13 + 12 14 dom0-$(CONFIG_PCI) += pci.o 13 15 dom0-$(CONFIG_USB_SUPPORT) += dbgp.o 14 16 dom0-$(CONFIG_ACPI) += acpi.o $(xen-pad-y) ··· 35 33 obj-$(CONFIG_XEN_ACPI_HOTPLUG_MEMORY) += xen-acpi-memhotplug.o 36 34 obj-$(CONFIG_XEN_ACPI_HOTPLUG_CPU) += xen-acpi-cpuhotplug.o 37 35 obj-$(CONFIG_XEN_ACPI_PROCESSOR) += xen-acpi-processor.o 36 + obj-$(CONFIG_XEN_EFI) += efi.o 38 37 xen-evtchn-y := evtchn.o 39 38 xen-gntdev-y := gntdev.o 40 39 xen-gntalloc-y := gntalloc.o
+368
drivers/xen/efi.c
··· 1 + /* 2 + * EFI support for Xen. 3 + * 4 + * Copyright (C) 1999 VA Linux Systems 5 + * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> 6 + * Copyright (C) 1999-2002 Hewlett-Packard Co. 7 + * David Mosberger-Tang <davidm@hpl.hp.com> 8 + * Stephane Eranian <eranian@hpl.hp.com> 9 + * Copyright (C) 2005-2008 Intel Co. 10 + * Fenghua Yu <fenghua.yu@intel.com> 11 + * Bibo Mao <bibo.mao@intel.com> 12 + * Chandramouli Narayanan <mouli@linux.intel.com> 13 + * Huang Ying <ying.huang@intel.com> 14 + * Copyright (C) 2011 Novell Co. 15 + * Jan Beulich <JBeulich@suse.com> 16 + * Copyright (C) 2011-2012 Oracle Co. 17 + * Liang Tang <liang.tang@oracle.com> 18 + * Copyright (c) 2014 Oracle Co., Daniel Kiper 19 + */ 20 + 21 + #include <linux/bug.h> 22 + #include <linux/efi.h> 23 + #include <linux/init.h> 24 + #include <linux/string.h> 25 + 26 + #include <xen/interface/xen.h> 27 + #include <xen/interface/platform.h> 28 + #include <xen/xen.h> 29 + 30 + #include <asm/xen/hypercall.h> 31 + 32 + #define INIT_EFI_OP(name) \ 33 + {.cmd = XENPF_efi_runtime_call, \ 34 + .u.efi_runtime_call.function = XEN_EFI_##name, \ 35 + .u.efi_runtime_call.misc = 0} 36 + 37 + #define efi_data(op) (op.u.efi_runtime_call) 38 + 39 + static efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) 40 + { 41 + struct xen_platform_op op = INIT_EFI_OP(get_time); 42 + 43 + if (HYPERVISOR_dom0_op(&op) < 0) 44 + return EFI_UNSUPPORTED; 45 + 46 + if (tm) { 47 + BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_time.time)); 48 + memcpy(tm, &efi_data(op).u.get_time.time, sizeof(*tm)); 49 + } 50 + 51 + if (tc) { 52 + tc->resolution = efi_data(op).u.get_time.resolution; 53 + tc->accuracy = efi_data(op).u.get_time.accuracy; 54 + tc->sets_to_zero = !!(efi_data(op).misc & 55 + XEN_EFI_GET_TIME_SET_CLEARS_NS); 56 + } 57 + 58 + return efi_data(op).status; 59 + } 60 + 61 + static efi_status_t xen_efi_set_time(efi_time_t *tm) 62 + { 63 + struct xen_platform_op op = INIT_EFI_OP(set_time); 64 + 65 + BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_time)); 66 + memcpy(&efi_data(op).u.set_time, tm, sizeof(*tm)); 67 + 68 + if (HYPERVISOR_dom0_op(&op) < 0) 69 + return EFI_UNSUPPORTED; 70 + 71 + return efi_data(op).status; 72 + } 73 + 74 + static efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, 75 + efi_bool_t *pending, 76 + efi_time_t *tm) 77 + { 78 + struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time); 79 + 80 + if (HYPERVISOR_dom0_op(&op) < 0) 81 + return EFI_UNSUPPORTED; 82 + 83 + if (tm) { 84 + BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_wakeup_time)); 85 + memcpy(tm, &efi_data(op).u.get_wakeup_time, sizeof(*tm)); 86 + } 87 + 88 + if (enabled) 89 + *enabled = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_ENABLED); 90 + 91 + if (pending) 92 + *pending = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_PENDING); 93 + 94 + return efi_data(op).status; 95 + } 96 + 97 + static efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) 98 + { 99 + struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time); 100 + 101 + BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_wakeup_time)); 102 + if (enabled) 103 + efi_data(op).misc = XEN_EFI_SET_WAKEUP_TIME_ENABLE; 104 + if (tm) 105 + memcpy(&efi_data(op).u.set_wakeup_time, tm, sizeof(*tm)); 106 + else 107 + efi_data(op).misc |= XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY; 108 + 109 + if (HYPERVISOR_dom0_op(&op) < 0) 110 + return EFI_UNSUPPORTED; 111 + 112 + return efi_data(op).status; 113 + } 114 + 115 + static efi_status_t xen_efi_get_variable(efi_char16_t *name, 116 + efi_guid_t *vendor, 117 + u32 *attr, 118 + unsigned long *data_size, 119 + void *data) 120 + { 121 + struct xen_platform_op op = INIT_EFI_OP(get_variable); 122 + 123 + set_xen_guest_handle(efi_data(op).u.get_variable.name, name); 124 + BUILD_BUG_ON(sizeof(*vendor) != 125 + sizeof(efi_data(op).u.get_variable.vendor_guid)); 126 + memcpy(&efi_data(op).u.get_variable.vendor_guid, vendor, sizeof(*vendor)); 127 + efi_data(op).u.get_variable.size = *data_size; 128 + set_xen_guest_handle(efi_data(op).u.get_variable.data, data); 129 + 130 + if (HYPERVISOR_dom0_op(&op) < 0) 131 + return EFI_UNSUPPORTED; 132 + 133 + *data_size = efi_data(op).u.get_variable.size; 134 + if (attr) 135 + *attr = efi_data(op).misc; 136 + 137 + return efi_data(op).status; 138 + } 139 + 140 + static efi_status_t xen_efi_get_next_variable(unsigned long *name_size, 141 + efi_char16_t *name, 142 + efi_guid_t *vendor) 143 + { 144 + struct xen_platform_op op = INIT_EFI_OP(get_next_variable_name); 145 + 146 + efi_data(op).u.get_next_variable_name.size = *name_size; 147 + set_xen_guest_handle(efi_data(op).u.get_next_variable_name.name, name); 148 + BUILD_BUG_ON(sizeof(*vendor) != 149 + sizeof(efi_data(op).u.get_next_variable_name.vendor_guid)); 150 + memcpy(&efi_data(op).u.get_next_variable_name.vendor_guid, vendor, 151 + sizeof(*vendor)); 152 + 153 + if (HYPERVISOR_dom0_op(&op) < 0) 154 + return EFI_UNSUPPORTED; 155 + 156 + *name_size = efi_data(op).u.get_next_variable_name.size; 157 + memcpy(vendor, &efi_data(op).u.get_next_variable_name.vendor_guid, 158 + sizeof(*vendor)); 159 + 160 + return efi_data(op).status; 161 + } 162 + 163 + static efi_status_t xen_efi_set_variable(efi_char16_t *name, 164 + efi_guid_t *vendor, 165 + u32 attr, 166 + unsigned long data_size, 167 + void *data) 168 + { 169 + struct xen_platform_op op = INIT_EFI_OP(set_variable); 170 + 171 + set_xen_guest_handle(efi_data(op).u.set_variable.name, name); 172 + efi_data(op).misc = attr; 173 + BUILD_BUG_ON(sizeof(*vendor) != 174 + sizeof(efi_data(op).u.set_variable.vendor_guid)); 175 + memcpy(&efi_data(op).u.set_variable.vendor_guid, vendor, sizeof(*vendor)); 176 + efi_data(op).u.set_variable.size = data_size; 177 + set_xen_guest_handle(efi_data(op).u.set_variable.data, data); 178 + 179 + if (HYPERVISOR_dom0_op(&op) < 0) 180 + return EFI_UNSUPPORTED; 181 + 182 + return efi_data(op).status; 183 + } 184 + 185 + static efi_status_t xen_efi_query_variable_info(u32 attr, 186 + u64 *storage_space, 187 + u64 *remaining_space, 188 + u64 *max_variable_size) 189 + { 190 + struct xen_platform_op op = INIT_EFI_OP(query_variable_info); 191 + 192 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 193 + return EFI_UNSUPPORTED; 194 + 195 + efi_data(op).u.query_variable_info.attr = attr; 196 + 197 + if (HYPERVISOR_dom0_op(&op) < 0) 198 + return EFI_UNSUPPORTED; 199 + 200 + *storage_space = efi_data(op).u.query_variable_info.max_store_size; 201 + *remaining_space = efi_data(op).u.query_variable_info.remain_store_size; 202 + *max_variable_size = efi_data(op).u.query_variable_info.max_size; 203 + 204 + return efi_data(op).status; 205 + } 206 + 207 + static efi_status_t xen_efi_get_next_high_mono_count(u32 *count) 208 + { 209 + struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count); 210 + 211 + if (HYPERVISOR_dom0_op(&op) < 0) 212 + return EFI_UNSUPPORTED; 213 + 214 + *count = efi_data(op).misc; 215 + 216 + return efi_data(op).status; 217 + } 218 + 219 + static efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules, 220 + unsigned long count, 221 + unsigned long sg_list) 222 + { 223 + struct xen_platform_op op = INIT_EFI_OP(update_capsule); 224 + 225 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 226 + return EFI_UNSUPPORTED; 227 + 228 + set_xen_guest_handle(efi_data(op).u.update_capsule.capsule_header_array, 229 + capsules); 230 + efi_data(op).u.update_capsule.capsule_count = count; 231 + efi_data(op).u.update_capsule.sg_list = sg_list; 232 + 233 + if (HYPERVISOR_dom0_op(&op) < 0) 234 + return EFI_UNSUPPORTED; 235 + 236 + return efi_data(op).status; 237 + } 238 + 239 + static efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules, 240 + unsigned long count, 241 + u64 *max_size, 242 + int *reset_type) 243 + { 244 + struct xen_platform_op op = INIT_EFI_OP(query_capsule_capabilities); 245 + 246 + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) 247 + return EFI_UNSUPPORTED; 248 + 249 + set_xen_guest_handle(efi_data(op).u.query_capsule_capabilities.capsule_header_array, 250 + capsules); 251 + efi_data(op).u.query_capsule_capabilities.capsule_count = count; 252 + 253 + if (HYPERVISOR_dom0_op(&op) < 0) 254 + return EFI_UNSUPPORTED; 255 + 256 + *max_size = efi_data(op).u.query_capsule_capabilities.max_capsule_size; 257 + *reset_type = efi_data(op).u.query_capsule_capabilities.reset_type; 258 + 259 + return efi_data(op).status; 260 + } 261 + 262 + static efi_char16_t vendor[100] __initdata; 263 + 264 + static efi_system_table_t efi_systab_xen __initdata = { 265 + .hdr = { 266 + .signature = EFI_SYSTEM_TABLE_SIGNATURE, 267 + .revision = 0, /* Initialized later. */ 268 + .headersize = 0, /* Ignored by Linux Kernel. */ 269 + .crc32 = 0, /* Ignored by Linux Kernel. */ 270 + .reserved = 0 271 + }, 272 + .fw_vendor = EFI_INVALID_TABLE_ADDR, /* Initialized later. */ 273 + .fw_revision = 0, /* Initialized later. */ 274 + .con_in_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 275 + .con_in = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 276 + .con_out_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 277 + .con_out = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 278 + .stderr_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 279 + .stderr = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */ 280 + .runtime = (efi_runtime_services_t *)EFI_INVALID_TABLE_ADDR, 281 + /* Not used under Xen. */ 282 + .boottime = (efi_boot_services_t *)EFI_INVALID_TABLE_ADDR, 283 + /* Not used under Xen. */ 284 + .nr_tables = 0, /* Initialized later. */ 285 + .tables = EFI_INVALID_TABLE_ADDR /* Initialized later. */ 286 + }; 287 + 288 + static const struct efi efi_xen __initconst = { 289 + .systab = NULL, /* Initialized later. */ 290 + .runtime_version = 0, /* Initialized later. */ 291 + .mps = EFI_INVALID_TABLE_ADDR, 292 + .acpi = EFI_INVALID_TABLE_ADDR, 293 + .acpi20 = EFI_INVALID_TABLE_ADDR, 294 + .smbios = EFI_INVALID_TABLE_ADDR, 295 + .sal_systab = EFI_INVALID_TABLE_ADDR, 296 + .boot_info = EFI_INVALID_TABLE_ADDR, 297 + .hcdp = EFI_INVALID_TABLE_ADDR, 298 + .uga = EFI_INVALID_TABLE_ADDR, 299 + .uv_systab = EFI_INVALID_TABLE_ADDR, 300 + .fw_vendor = EFI_INVALID_TABLE_ADDR, 301 + .runtime = EFI_INVALID_TABLE_ADDR, 302 + .config_table = EFI_INVALID_TABLE_ADDR, 303 + .get_time = xen_efi_get_time, 304 + .set_time = xen_efi_set_time, 305 + .get_wakeup_time = xen_efi_get_wakeup_time, 306 + .set_wakeup_time = xen_efi_set_wakeup_time, 307 + .get_variable = xen_efi_get_variable, 308 + .get_next_variable = xen_efi_get_next_variable, 309 + .set_variable = xen_efi_set_variable, 310 + .query_variable_info = xen_efi_query_variable_info, 311 + .update_capsule = xen_efi_update_capsule, 312 + .query_capsule_caps = xen_efi_query_capsule_caps, 313 + .get_next_high_mono_count = xen_efi_get_next_high_mono_count, 314 + .reset_system = NULL, /* Functionality provided by Xen. */ 315 + .set_virtual_address_map = NULL, /* Not used under Xen. */ 316 + .memmap = NULL, /* Not used under Xen. */ 317 + .flags = 0 /* Initialized later. */ 318 + }; 319 + 320 + efi_system_table_t __init *xen_efi_probe(void) 321 + { 322 + struct xen_platform_op op = { 323 + .cmd = XENPF_firmware_info, 324 + .u.firmware_info = { 325 + .type = XEN_FW_EFI_INFO, 326 + .index = XEN_FW_EFI_CONFIG_TABLE 327 + } 328 + }; 329 + union xenpf_efi_info *info = &op.u.firmware_info.u.efi_info; 330 + 331 + if (!xen_initial_domain() || HYPERVISOR_dom0_op(&op) < 0) 332 + return NULL; 333 + 334 + /* Here we know that Xen runs on EFI platform. */ 335 + 336 + efi = efi_xen; 337 + 338 + efi_systab_xen.tables = info->cfg.addr; 339 + efi_systab_xen.nr_tables = info->cfg.nent; 340 + 341 + op.cmd = XENPF_firmware_info; 342 + op.u.firmware_info.type = XEN_FW_EFI_INFO; 343 + op.u.firmware_info.index = XEN_FW_EFI_VENDOR; 344 + info->vendor.bufsz = sizeof(vendor); 345 + set_xen_guest_handle(info->vendor.name, vendor); 346 + 347 + if (HYPERVISOR_dom0_op(&op) == 0) { 348 + efi_systab_xen.fw_vendor = __pa_symbol(vendor); 349 + efi_systab_xen.fw_revision = info->vendor.revision; 350 + } else 351 + efi_systab_xen.fw_vendor = __pa_symbol(L"UNKNOWN"); 352 + 353 + op.cmd = XENPF_firmware_info; 354 + op.u.firmware_info.type = XEN_FW_EFI_INFO; 355 + op.u.firmware_info.index = XEN_FW_EFI_VERSION; 356 + 357 + if (HYPERVISOR_dom0_op(&op) == 0) 358 + efi_systab_xen.hdr.revision = info->version; 359 + 360 + op.cmd = XENPF_firmware_info; 361 + op.u.firmware_info.type = XEN_FW_EFI_INFO; 362 + op.u.firmware_info.index = XEN_FW_EFI_RT_VERSION; 363 + 364 + if (HYPERVISOR_dom0_op(&op) == 0) 365 + efi.runtime_version = info->version; 366 + 367 + return &efi_systab_xen; 368 + }
+55 -8
include/linux/efi.h
··· 20 20 #include <linux/ioport.h> 21 21 #include <linux/pfn.h> 22 22 #include <linux/pstore.h> 23 + #include <linux/reboot.h> 23 24 24 25 #include <asm/page.h> 25 26 ··· 522 521 int *reset_type); 523 522 typedef efi_status_t efi_query_variable_store_t(u32 attributes, unsigned long size); 524 523 524 + void efi_native_runtime_setup(void); 525 + 525 526 /* 526 527 * EFI Configuration Table and GUID definitions 527 528 */ ··· 873 870 extern void efi_initialize_iomem_resources(struct resource *code_resource, 874 871 struct resource *data_resource, struct resource *bss_resource); 875 872 extern void efi_get_time(struct timespec *now); 876 - extern int efi_set_rtc_mmss(const struct timespec *now); 877 873 extern void efi_reserve_boot_services(void); 878 874 extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose); 879 875 extern struct efi_memory_map memmap; 876 + 877 + extern int efi_reboot_quirk_mode; 878 + extern bool efi_poweroff_required(void); 880 879 881 880 /* Iterate through an efi_memory_map */ 882 881 #define for_each_efi_memory_desc(m, md) \ ··· 921 916 #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */ 922 917 #define EFI_MEMMAP 4 /* Can we use EFI memory map? */ 923 918 #define EFI_64BIT 5 /* Is the firmware 64-bit? */ 924 - #define EFI_ARCH_1 6 /* First arch-specific bit */ 919 + #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */ 920 + #define EFI_ARCH_1 7 /* First arch-specific bit */ 925 921 926 922 #ifdef CONFIG_EFI 927 923 /* ··· 932 926 { 933 927 return test_bit(feature, &efi.flags) != 0; 934 928 } 929 + extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused); 935 930 #else 936 931 static inline bool efi_enabled(int feature) 937 932 { 938 933 return false; 939 934 } 935 + static inline void 936 + efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {} 940 937 #endif 941 938 942 939 /* ··· 1040 1031 struct efivars { 1041 1032 /* 1042 1033 * ->lock protects two things: 1043 - * 1) ->list - adds, removals, reads, writes 1044 - * 2) ops.[gs]et_variable() calls. 1045 - * It must not be held when creating sysfs entries or calling kmalloc. 1046 - * ops.get_next_variable() is only called from register_efivars() 1047 - * or efivar_update_sysfs_entries(), 1048 - * which is protected by the BKL, so that path is safe. 1034 + * 1) efivarfs_list and efivars_sysfs_list 1035 + * 2) ->ops calls 1049 1036 */ 1050 1037 spinlock_t lock; 1051 1038 struct kset *kset; ··· 1165 1160 static inline void 1166 1161 efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {} 1167 1162 #endif 1163 + 1164 + /* prototypes shared between arch specific and generic stub code */ 1165 + 1166 + #define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg) 1167 + #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg) 1168 + 1169 + void efi_printk(efi_system_table_t *sys_table_arg, char *str); 1170 + 1171 + void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, 1172 + unsigned long addr); 1173 + 1174 + char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, 1175 + efi_loaded_image_t *image, int *cmd_line_len); 1176 + 1177 + efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, 1178 + efi_memory_desc_t **map, 1179 + unsigned long *map_size, 1180 + unsigned long *desc_size, 1181 + u32 *desc_ver, 1182 + unsigned long *key_ptr); 1183 + 1184 + efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, 1185 + unsigned long size, unsigned long align, 1186 + unsigned long *addr); 1187 + 1188 + efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, 1189 + unsigned long size, unsigned long align, 1190 + unsigned long *addr, unsigned long max); 1191 + 1192 + efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, 1193 + unsigned long *image_addr, 1194 + unsigned long image_size, 1195 + unsigned long alloc_size, 1196 + unsigned long preferred_addr, 1197 + unsigned long alignment); 1198 + 1199 + efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, 1200 + efi_loaded_image_t *image, 1201 + char *cmd_line, char *option_string, 1202 + unsigned long max_addr, 1203 + unsigned long *load_addr, 1204 + unsigned long *load_size); 1168 1205 1169 1206 #endif /* _LINUX_EFI_H */
+123
include/xen/interface/platform.h
··· 108 108 }; 109 109 DEFINE_GUEST_HANDLE_STRUCT(xenpf_platform_quirk_t); 110 110 111 + #define XENPF_efi_runtime_call 49 112 + #define XEN_EFI_get_time 1 113 + #define XEN_EFI_set_time 2 114 + #define XEN_EFI_get_wakeup_time 3 115 + #define XEN_EFI_set_wakeup_time 4 116 + #define XEN_EFI_get_next_high_monotonic_count 5 117 + #define XEN_EFI_get_variable 6 118 + #define XEN_EFI_set_variable 7 119 + #define XEN_EFI_get_next_variable_name 8 120 + #define XEN_EFI_query_variable_info 9 121 + #define XEN_EFI_query_capsule_capabilities 10 122 + #define XEN_EFI_update_capsule 11 123 + 124 + struct xenpf_efi_runtime_call { 125 + uint32_t function; 126 + /* 127 + * This field is generally used for per sub-function flags (defined 128 + * below), except for the XEN_EFI_get_next_high_monotonic_count case, 129 + * where it holds the single returned value. 130 + */ 131 + uint32_t misc; 132 + xen_ulong_t status; 133 + union { 134 + #define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 135 + struct { 136 + struct xenpf_efi_time { 137 + uint16_t year; 138 + uint8_t month; 139 + uint8_t day; 140 + uint8_t hour; 141 + uint8_t min; 142 + uint8_t sec; 143 + uint32_t ns; 144 + int16_t tz; 145 + uint8_t daylight; 146 + } time; 147 + uint32_t resolution; 148 + uint32_t accuracy; 149 + } get_time; 150 + 151 + struct xenpf_efi_time set_time; 152 + 153 + #define XEN_EFI_GET_WAKEUP_TIME_ENABLED 0x00000001 154 + #define XEN_EFI_GET_WAKEUP_TIME_PENDING 0x00000002 155 + struct xenpf_efi_time get_wakeup_time; 156 + 157 + #define XEN_EFI_SET_WAKEUP_TIME_ENABLE 0x00000001 158 + #define XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY 0x00000002 159 + struct xenpf_efi_time set_wakeup_time; 160 + 161 + #define XEN_EFI_VARIABLE_NON_VOLATILE 0x00000001 162 + #define XEN_EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 163 + #define XEN_EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 164 + struct { 165 + GUEST_HANDLE(void) name; /* UCS-2/UTF-16 string */ 166 + xen_ulong_t size; 167 + GUEST_HANDLE(void) data; 168 + struct xenpf_efi_guid { 169 + uint32_t data1; 170 + uint16_t data2; 171 + uint16_t data3; 172 + uint8_t data4[8]; 173 + } vendor_guid; 174 + } get_variable, set_variable; 175 + 176 + struct { 177 + xen_ulong_t size; 178 + GUEST_HANDLE(void) name; /* UCS-2/UTF-16 string */ 179 + struct xenpf_efi_guid vendor_guid; 180 + } get_next_variable_name; 181 + 182 + struct { 183 + uint32_t attr; 184 + uint64_t max_store_size; 185 + uint64_t remain_store_size; 186 + uint64_t max_size; 187 + } query_variable_info; 188 + 189 + struct { 190 + GUEST_HANDLE(void) capsule_header_array; 191 + xen_ulong_t capsule_count; 192 + uint64_t max_capsule_size; 193 + uint32_t reset_type; 194 + } query_capsule_capabilities; 195 + 196 + struct { 197 + GUEST_HANDLE(void) capsule_header_array; 198 + xen_ulong_t capsule_count; 199 + uint64_t sg_list; /* machine address */ 200 + } update_capsule; 201 + } u; 202 + }; 203 + DEFINE_GUEST_HANDLE_STRUCT(xenpf_efi_runtime_call); 204 + 205 + #define XEN_FW_EFI_VERSION 0 206 + #define XEN_FW_EFI_CONFIG_TABLE 1 207 + #define XEN_FW_EFI_VENDOR 2 208 + #define XEN_FW_EFI_MEM_INFO 3 209 + #define XEN_FW_EFI_RT_VERSION 4 210 + 111 211 #define XENPF_firmware_info 50 112 212 #define XEN_FW_DISK_INFO 1 /* from int 13 AH=08/41/48 */ 113 213 #define XEN_FW_DISK_MBR_SIGNATURE 2 /* from MBR offset 0x1b8 */ 114 214 #define XEN_FW_VBEDDC_INFO 3 /* from int 10 AX=4f15 */ 215 + #define XEN_FW_EFI_INFO 4 /* from EFI */ 115 216 #define XEN_FW_KBD_SHIFT_FLAGS 5 /* Int16, Fn02: Get keyboard shift flags. */ 217 + 116 218 struct xenpf_firmware_info { 117 219 /* IN variables. */ 118 220 uint32_t type; ··· 245 143 /* must refer to 128-byte buffer */ 246 144 GUEST_HANDLE(uchar) edid; 247 145 } vbeddc_info; /* XEN_FW_VBEDDC_INFO */ 146 + 147 + union xenpf_efi_info { 148 + uint32_t version; 149 + struct { 150 + uint64_t addr; /* EFI_CONFIGURATION_TABLE */ 151 + uint32_t nent; 152 + } cfg; 153 + struct { 154 + uint32_t revision; 155 + uint32_t bufsz; /* input, in bytes */ 156 + GUEST_HANDLE(void) name; 157 + /* UCS-2/UTF-16 string */ 158 + } vendor; 159 + struct { 160 + uint64_t addr; 161 + uint64_t size; 162 + uint64_t attr; 163 + uint32_t type; 164 + } mem; 165 + } efi_info; /* XEN_FW_EFI_INFO */ 248 166 249 167 uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */ 250 168 } u; ··· 484 362 struct xenpf_read_memtype read_memtype; 485 363 struct xenpf_microcode_update microcode; 486 364 struct xenpf_platform_quirk platform_quirk; 365 + struct xenpf_efi_runtime_call efi_runtime_call; 487 366 struct xenpf_firmware_info firmware_info; 488 367 struct xenpf_enter_acpi_sleep enter_acpi_sleep; 489 368 struct xenpf_change_freq change_freq;
+11
include/xen/xen-ops.h
··· 3 3 4 4 #include <linux/percpu.h> 5 5 #include <linux/notifier.h> 6 + #include <linux/efi.h> 6 7 #include <asm/xen/interface.h> 7 8 8 9 DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); ··· 36 35 int numpgs, struct page **pages); 37 36 38 37 bool xen_running_on_version_or_later(unsigned int major, unsigned int minor); 38 + 39 + #ifdef CONFIG_XEN_EFI 40 + extern efi_system_table_t *xen_efi_probe(void); 41 + #else 42 + static inline efi_system_table_t __init *xen_efi_probe(void) 43 + { 44 + return NULL; 45 + } 46 + #endif 47 + 39 48 #endif /* INCLUDE_XEN_OPS_H */