29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/kernel.h>
35 #include <linux/export.h>
40 #include <linux/time.h>
42 #include <linux/reboot.h>
45 #include <asm/setup.h>
48 #include <asm/cacheflush.h>
49 #include <asm/tlbflush.h>
77 static inline bool efi_is_native(
void)
92 static int __init setup_add_efi_memmap(
char *
arg)
97 early_param(
"add_efi_memmap", setup_add_efi_memmap);
107 spin_unlock_irqrestore(&rtc_lock, flags);
118 spin_unlock_irqrestore(&rtc_lock, flags);
131 enabled, pending, tm);
132 spin_unlock_irqrestore(&rtc_lock, flags);
144 spin_unlock_irqrestore(&rtc_lock, flags);
159 static efi_status_t virt_efi_get_next_variable(
unsigned long *name_size,
164 name_size, name, vendor);
180 u64 *remaining_space,
181 u64 *max_variable_size)
187 remaining_space, max_variable_size);
195 static void virt_efi_reset_system(
int reset_type,
227 unsigned long memory_map_size,
228 unsigned long descriptor_size,
229 u32 descriptor_version,
236 memory_map_size, descriptor_size,
237 descriptor_version, virtual_map);
253 spin_unlock_irqrestore(&rtc_lock, flags);
259 int real_seconds, real_minutes;
266 pr_err(
"Oops: efitime: can't read time!\n");
270 real_seconds = nowtime % 60;
271 real_minutes = nowtime / 60;
272 if (((
abs(real_minutes - eft.
minute) + 15)/30) & 1)
275 eft.
minute = real_minutes;
276 eft.
second = real_seconds;
280 pr_err(
"Oops: efitime: can't write time!\n");
294 pr_err(
"Oops: efitime: can't read time!\n");
306 static void __init do_add_efi_memmap(
void)
357 pr_err(
"Memory map is above 4GB, disabling EFI.\n");
365 memmap.phys_map = (
void *)pmap;
376 static void __init print_efi_memmap(
void)
382 for (p =
memmap.map, i = 0;
384 p +=
memmap.desc_size, i++) {
386 pr_info(
"mem%02u: type=%u, attr=0x%llx, "
387 "range=[0x%016llx-0x%016llx) (%lluMB)\n",
419 memblock_dbg(
"Could not reserve boot range "
420 "[0x%010llx-0x%010llx]\n",
421 start, start+size-1);
439 if (!efi_is_native())
444 unsigned long long start = md->
phys_addr;
469 if (systab64 ==
NULL) {
470 pr_err(
"Couldn't map the system table!\n");
474 efi_systab.hdr = systab64->
hdr;
475 efi_systab.fw_vendor = systab64->
fw_vendor;
480 efi_systab.con_in = systab64->
con_in;
484 efi_systab.con_out = systab64->
con_out;
488 efi_systab.stderr = systab64->
stderr;
490 efi_systab.runtime = (
void *)(
unsigned long)systab64->
runtime;
492 efi_systab.boottime = (
void *)(
unsigned long)systab64->
boottime;
494 efi_systab.nr_tables = systab64->
nr_tables;
495 efi_systab.tables = systab64->
tables;
501 pr_err(
"EFI data located above 4GB, disabling EFI.\n");
510 if (systab32 ==
NULL) {
511 pr_err(
"Couldn't map the system table!\n");
515 efi_systab.hdr = systab32->
hdr;
516 efi_systab.fw_vendor = systab32->
fw_vendor;
519 efi_systab.con_in = systab32->
con_in;
521 efi_systab.con_out = systab32->
con_out;
523 efi_systab.stderr = systab32->
stderr;
524 efi_systab.runtime = (
void *)(
unsigned long)systab32->
runtime;
525 efi_systab.boottime = (
void *)(
unsigned long)systab32->
boottime;
526 efi_systab.nr_tables = systab32->
nr_tables;
527 efi_systab.tables = systab32->
tables;
538 pr_err(
"System table signature incorrect!\n");
542 pr_err(
"Warning: System table version "
543 "%d.%02d, expected 1.00 or greater!\n",
552 void *config_tables, *tablep;
564 if (config_tables ==
NULL) {
565 pr_err(
"Could not map Configuration table!\n");
569 tablep = config_tables;
583 pr_err(
"Table located above 4GB, disabling EFI.\n");
598 pr_cont(
" ACPI 2.0=0x%lx ", table);
601 pr_cont(
" ACPI=0x%lx ", table);
604 pr_cont(
" SMBIOS=0x%lx ", table);
608 pr_cont(
" UVsystab=0x%lx ", table);
612 pr_cont(
" HCDP=0x%lx ", table);
624 static int __init efi_runtime_init(
void)
637 pr_err(
"Could not map the runtime service table!\n");
646 efi_phys.set_virtual_address_map =
665 pr_err(
"Could not map the memory map!\n");
679 char vendor[100] =
"unknown";
686 pr_info(
"Table located above 4GB, disabling EFI.\n");
697 if (efi_systab_init(efi_phys.systab)) {
707 for (i = 0; i <
sizeof(
vendor) - 1 && *c16; ++
i)
711 pr_err(
"Could not map the firmware vendor!\n");
714 pr_info(
"EFI v%u.%.02u by %s\n",
728 if (!efi_is_native())
729 pr_info(
"No EFI runtime due to 32/64-bit mismatch with kernel\n");
730 else if (efi_runtime_init()) {
740 if (efi_is_native()) {
763 memrange_efi_to_native(&addr, &npages);
771 static void __init runtime_code_page_mkexec(
void)
807 if (phys_addr >= md->
phys_addr && phys_addr < end) {
820 npages =
round_up(size, page_shift) / page_shift;
821 memrange_efi_to_native(&addr, &npages);
839 void *
p, *
va, *new_memmap =
NULL;
849 if (!efi_is_native()) {
906 pr_err(
"ioremap of 0x%llX failed!\n",
911 systab = (
u64) (
unsigned long) efi_phys.systab;
912 if (md->
phys_addr <= systab && systab < end) {
917 (count + 1) *
memmap.desc_size,
926 status = phys_efi_set_virtual_address_map(
933 pr_alert(
"Unable to switch EFI into virtual mode "
934 "(status=%lx)!\n", status);
935 panic(
"EFI call to SetVirtualAddressMap() failed!");
959 runtime_code_page_mkexec();