License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-01-30 20:31:19 +08:00
|
|
|
/*
|
|
|
|
* x86_64 specific EFI support functions
|
|
|
|
* Based on Extensible Firmware Interface Specification version 1.0
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2008 Intel Co.
|
|
|
|
* Fenghua Yu <fenghua.yu@intel.com>
|
|
|
|
* Bibo Mao <bibo.mao@intel.com>
|
|
|
|
* Chandramouli Narayanan <mouli@linux.intel.com>
|
|
|
|
* Huang Ying <ying.huang@intel.com>
|
|
|
|
*
|
|
|
|
* Code to convert EFI to E820 map has been implemented in elilo bootloader
|
|
|
|
* based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table
|
|
|
|
* is setup appropriately for EFI runtime code.
|
|
|
|
* - mouli 06/14/2007.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-10-25 18:26:35 +08:00
|
|
|
#define pr_fmt(fmt) "efi: " fmt
|
|
|
|
|
2008-01-30 20:31:19 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/ioport.h>
|
2016-05-31 02:57:50 +08:00
|
|
|
#include <linux/mc146818rtc.h>
|
2008-01-30 20:31:19 +08:00
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/reboot.h>
|
2013-04-12 06:51:01 +08:00
|
|
|
#include <linux/slab.h>
|
2016-11-13 05:04:24 +08:00
|
|
|
#include <linux/ucs2_string.h>
|
2017-10-20 22:30:49 +08:00
|
|
|
#include <linux/mem_encrypt.h>
|
2008-01-30 20:31:19 +08:00
|
|
|
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/page.h>
|
2017-01-27 17:27:10 +08:00
|
|
|
#include <asm/e820/api.h>
|
2008-01-30 20:31:19 +08:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/efi.h>
|
2008-02-13 17:22:41 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2009-01-23 10:03:29 +08:00
|
|
|
#include <asm/fixmap.h>
|
2013-11-01 00:25:08 +08:00
|
|
|
#include <asm/realmode.h>
|
2014-01-11 02:48:30 +08:00
|
|
|
#include <asm/time.h>
|
2015-11-28 05:09:34 +08:00
|
|
|
#include <asm/pgalloc.h>
|
2008-01-30 20:31:19 +08:00
|
|
|
|
2013-11-01 00:25:08 +08:00
|
|
|
/*
|
2017-04-05 00:02:43 +08:00
|
|
|
* We allocate runtime services regions top-down, starting from -4G, i.e.
|
2013-11-01 00:25:08 +08:00
|
|
|
* 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
|
|
|
|
*/
|
2014-09-21 23:26:54 +08:00
|
|
|
static u64 efi_va = EFI_VA_START;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2015-11-28 05:09:33 +08:00
|
|
|
struct efi_scratch efi_scratch;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2011-05-06 03:19:43 +08:00
|
|
|
static void __init early_code_mapping_set_exec(int executable)
|
2008-01-30 20:31:19 +08:00
|
|
|
{
|
|
|
|
efi_memory_desc_t *md;
|
|
|
|
|
2008-01-30 20:33:55 +08:00
|
|
|
if (!(__supported_pte_mask & _PAGE_NX))
|
|
|
|
return;
|
|
|
|
|
x86, efi: Retain boot service code until after switching to virtual mode
UEFI stands for "Unified Extensible Firmware Interface", where "Firmware"
is an ancient African word meaning "Why do something right when you can
do it so wrong that children will weep and brave adults will cower before
you", and "UEI" is Celtic for "We missed DOS so we burned it into your
ROMs". The UEFI specification provides for runtime services (ie, another
way for the operating system to be forced to depend on the firmware) and
we rely on these for certain trivial tasks such as setting up the
bootloader. But some hardware fails to work if we attempt to use these
runtime services from physical mode, and so we have to switch into virtual
mode. So far so dreadful.
The specification makes it clear that the operating system is free to do
whatever it wants with boot services code after ExitBootServices() has been
called. SetVirtualAddressMap() can't be called until ExitBootServices() has
been. So, obviously, a whole bunch of EFI implementations call into boot
services code when we do that. Since we've been charmingly naive and
trusted that the specification may be somehow relevant to the real world,
we've already stuffed a picture of a penguin or something in that address
space. And just to make things more entertaining, we've also marked it
non-executable.
This patch allocates the boot services regions during EFI init and makes
sure that they're executable. Then, after SetVirtualAddressMap(), it
discards them and everyone lives happily ever after. Except for the ones
who have to work on EFI, who live sad lives haunted by the knowledge that
someone's eventually going to write yet another firmware specification.
[ hpa: adding this to urgent with a stable tag since it fixes currently-broken
hardware. However, I do not know what the dependencies are and so I do
not know which -stable versions this may be a candidate for. ]
Signed-off-by: Matthew Garrett <mjg@redhat.com>
Link: http://lkml.kernel.org/r/1306331593-28715-1-git-send-email-mjg@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: <stable@kernel.org>
2011-05-25 21:53:13 +08:00
|
|
|
/* Make EFI service code area executable */
|
2016-04-26 04:06:38 +08:00
|
|
|
for_each_efi_memory_desc(md) {
|
x86, efi: Retain boot service code until after switching to virtual mode
UEFI stands for "Unified Extensible Firmware Interface", where "Firmware"
is an ancient African word meaning "Why do something right when you can
do it so wrong that children will weep and brave adults will cower before
you", and "UEI" is Celtic for "We missed DOS so we burned it into your
ROMs". The UEFI specification provides for runtime services (ie, another
way for the operating system to be forced to depend on the firmware) and
we rely on these for certain trivial tasks such as setting up the
bootloader. But some hardware fails to work if we attempt to use these
runtime services from physical mode, and so we have to switch into virtual
mode. So far so dreadful.
The specification makes it clear that the operating system is free to do
whatever it wants with boot services code after ExitBootServices() has been
called. SetVirtualAddressMap() can't be called until ExitBootServices() has
been. So, obviously, a whole bunch of EFI implementations call into boot
services code when we do that. Since we've been charmingly naive and
trusted that the specification may be somehow relevant to the real world,
we've already stuffed a picture of a penguin or something in that address
space. And just to make things more entertaining, we've also marked it
non-executable.
This patch allocates the boot services regions during EFI init and makes
sure that they're executable. Then, after SetVirtualAddressMap(), it
discards them and everyone lives happily ever after. Except for the ones
who have to work on EFI, who live sad lives haunted by the knowledge that
someone's eventually going to write yet another firmware specification.
[ hpa: adding this to urgent with a stable tag since it fixes currently-broken
hardware. However, I do not know what the dependencies are and so I do
not know which -stable versions this may be a candidate for. ]
Signed-off-by: Matthew Garrett <mjg@redhat.com>
Link: http://lkml.kernel.org/r/1306331593-28715-1-git-send-email-mjg@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: <stable@kernel.org>
2011-05-25 21:53:13 +08:00
|
|
|
if (md->type == EFI_RUNTIME_SERVICES_CODE ||
|
|
|
|
md->type == EFI_BOOT_SERVICES_CODE)
|
2011-05-06 03:19:43 +08:00
|
|
|
efi_set_executable(md, executable);
|
2008-01-30 20:31:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:48:50 +08:00
|
|
|
pgd_t * __init efi_call_phys_prolog(void)
|
2008-01-30 20:31:19 +08:00
|
|
|
{
|
2017-05-26 19:36:50 +08:00
|
|
|
unsigned long vaddr, addr_pgd, addr_p4d, addr_pud;
|
|
|
|
pgd_t *save_pgd, *pgd_k, *pgd_efi;
|
|
|
|
p4d_t *p4d, *p4d_k, *p4d_efi;
|
|
|
|
pud_t *pud;
|
2015-03-03 14:48:50 +08:00
|
|
|
|
2013-01-08 23:02:43 +08:00
|
|
|
int pgd;
|
2017-05-26 19:36:50 +08:00
|
|
|
int n_pgds, i, j;
|
2008-01-30 20:31:19 +08:00
|
|
|
|
2015-11-28 05:09:33 +08:00
|
|
|
if (!efi_enabled(EFI_OLD_MEMMAP)) {
|
2017-06-13 01:26:14 +08:00
|
|
|
save_pgd = (pgd_t *)__read_cr3();
|
2015-11-28 05:09:33 +08:00
|
|
|
write_cr3((unsigned long)efi_scratch.efi_pgt);
|
|
|
|
goto out;
|
|
|
|
}
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2011-05-06 03:19:43 +08:00
|
|
|
early_code_mapping_set_exec(1);
|
2013-01-08 23:02:43 +08:00
|
|
|
|
|
|
|
n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
|
2016-08-25 17:34:03 +08:00
|
|
|
save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL);
|
2013-01-08 23:02:43 +08:00
|
|
|
|
2017-05-26 19:36:50 +08:00
|
|
|
/*
|
|
|
|
* Build 1:1 identity mapping for efi=old_map usage. Note that
|
|
|
|
* PAGE_OFFSET is PGDIR_SIZE aligned when KASLR is disabled, while
|
|
|
|
* it is PUD_SIZE ALIGNED with KASLR enabled. So for a given physical
|
|
|
|
* address X, the pud_index(X) != pud_index(__va(X)), we can only copy
|
|
|
|
* PUD entry of __va(X) to fill in pud entry of X to build 1:1 mapping.
|
|
|
|
* This means here we can only reuse the PMD tables of the direct mapping.
|
|
|
|
*/
|
2013-01-08 23:02:43 +08:00
|
|
|
for (pgd = 0; pgd < n_pgds; pgd++) {
|
2017-05-26 19:36:50 +08:00
|
|
|
addr_pgd = (unsigned long)(pgd * PGDIR_SIZE);
|
|
|
|
vaddr = (unsigned long)__va(pgd * PGDIR_SIZE);
|
|
|
|
pgd_efi = pgd_offset_k(addr_pgd);
|
|
|
|
save_pgd[pgd] = *pgd_efi;
|
|
|
|
|
|
|
|
p4d = p4d_alloc(&init_mm, pgd_efi, addr_pgd);
|
|
|
|
if (!p4d) {
|
|
|
|
pr_err("Failed to allocate p4d table!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PTRS_PER_P4D; i++) {
|
|
|
|
addr_p4d = addr_pgd + i * P4D_SIZE;
|
|
|
|
p4d_efi = p4d + p4d_index(addr_p4d);
|
|
|
|
|
|
|
|
pud = pud_alloc(&init_mm, p4d_efi, addr_p4d);
|
|
|
|
if (!pud) {
|
|
|
|
pr_err("Failed to allocate pud table!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < PTRS_PER_PUD; j++) {
|
|
|
|
addr_pud = addr_p4d + j * PUD_SIZE;
|
|
|
|
|
|
|
|
if (addr_pud > (max_pfn << PAGE_SHIFT))
|
|
|
|
break;
|
|
|
|
|
|
|
|
vaddr = (unsigned long)__va(addr_pud);
|
|
|
|
|
|
|
|
pgd_k = pgd_offset_k(vaddr);
|
|
|
|
p4d_k = p4d_offset(pgd_k, vaddr);
|
|
|
|
pud[j] = *pud_offset(p4d_k, vaddr);
|
|
|
|
}
|
|
|
|
}
|
2018-01-06 05:35:41 +08:00
|
|
|
pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX;
|
2013-01-08 23:02:43 +08:00
|
|
|
}
|
2018-01-06 05:35:41 +08:00
|
|
|
|
2015-11-28 05:09:33 +08:00
|
|
|
out:
|
2008-01-30 20:31:19 +08:00
|
|
|
__flush_tlb_all();
|
2015-03-03 14:48:50 +08:00
|
|
|
|
|
|
|
return save_pgd;
|
2008-01-30 20:31:19 +08:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:48:50 +08:00
|
|
|
void __init efi_call_phys_epilog(pgd_t *save_pgd)
|
2008-01-30 20:31:19 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* After the lock is released, the original page table is restored.
|
|
|
|
*/
|
2017-05-26 19:36:50 +08:00
|
|
|
int pgd_idx, i;
|
2015-03-03 14:48:50 +08:00
|
|
|
int nr_pgds;
|
2017-05-26 19:36:50 +08:00
|
|
|
pgd_t *pgd;
|
|
|
|
p4d_t *p4d;
|
|
|
|
pud_t *pud;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2015-11-28 05:09:33 +08:00
|
|
|
if (!efi_enabled(EFI_OLD_MEMMAP)) {
|
|
|
|
write_cr3((unsigned long)save_pgd);
|
|
|
|
__flush_tlb_all();
|
2013-11-01 00:25:08 +08:00
|
|
|
return;
|
2015-11-28 05:09:33 +08:00
|
|
|
}
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2015-03-03 14:48:50 +08:00
|
|
|
nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE);
|
|
|
|
|
2017-05-26 19:36:50 +08:00
|
|
|
for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++) {
|
|
|
|
pgd = pgd_offset_k(pgd_idx * PGDIR_SIZE);
|
2015-03-03 14:48:50 +08:00
|
|
|
set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]);
|
|
|
|
|
2017-05-26 19:36:50 +08:00
|
|
|
if (!(pgd_val(*pgd) & _PAGE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < PTRS_PER_P4D; i++) {
|
|
|
|
p4d = p4d_offset(pgd,
|
|
|
|
pgd_idx * PGDIR_SIZE + i * P4D_SIZE);
|
|
|
|
|
|
|
|
if (!(p4d_val(*p4d) & _PAGE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pud = (pud_t *)p4d_page_vaddr(*p4d);
|
|
|
|
pud_free(&init_mm, pud);
|
|
|
|
}
|
|
|
|
|
|
|
|
p4d = (p4d_t *)pgd_page_vaddr(*pgd);
|
|
|
|
p4d_free(&init_mm, p4d);
|
|
|
|
}
|
|
|
|
|
2013-01-08 23:02:43 +08:00
|
|
|
kfree(save_pgd);
|
2015-03-03 14:48:50 +08:00
|
|
|
|
2008-01-30 20:31:19 +08:00
|
|
|
__flush_tlb_all();
|
2011-05-06 03:19:43 +08:00
|
|
|
early_code_mapping_set_exec(0);
|
2008-01-30 20:31:19 +08:00
|
|
|
}
|
2011-12-12 08:12:42 +08:00
|
|
|
|
2015-11-28 05:09:34 +08:00
|
|
|
static pgd_t *efi_pgd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need our own copy of the higher levels of the page tables
|
|
|
|
* because we want to avoid inserting EFI region mappings (EFI_VA_END
|
|
|
|
* to EFI_VA_START) into the standard kernel page tables. Everything
|
|
|
|
* else can be shared, see efi_sync_low_kernel_mappings().
|
2017-12-04 22:07:39 +08:00
|
|
|
*
|
|
|
|
* We don't want the pgd on the pgd_list and cannot use pgd_alloc() for the
|
|
|
|
* allocation.
|
2015-11-28 05:09:34 +08:00
|
|
|
*/
|
|
|
|
int __init efi_alloc_page_tables(void)
|
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
2017-03-18 02:55:11 +08:00
|
|
|
p4d_t *p4d;
|
2015-11-28 05:09:34 +08:00
|
|
|
pud_t *pud;
|
|
|
|
gfp_t gfp_mask;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP))
|
|
|
|
return 0;
|
|
|
|
|
2017-11-16 09:35:54 +08:00
|
|
|
gfp_mask = GFP_KERNEL | __GFP_ZERO;
|
2017-12-04 22:07:39 +08:00
|
|
|
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
|
2015-11-28 05:09:34 +08:00
|
|
|
if (!efi_pgd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pgd = efi_pgd + pgd_index(EFI_VA_END);
|
2017-03-18 02:55:11 +08:00
|
|
|
p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
|
|
|
|
if (!p4d) {
|
|
|
|
free_page((unsigned long)efi_pgd);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-11-28 05:09:34 +08:00
|
|
|
|
2017-03-18 02:55:11 +08:00
|
|
|
pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
|
2015-11-28 05:09:34 +08:00
|
|
|
if (!pud) {
|
2017-03-18 02:55:11 +08:00
|
|
|
if (CONFIG_PGTABLE_LEVELS > 4)
|
|
|
|
free_page((unsigned long) pgd_page_vaddr(*pgd));
|
2015-11-28 05:09:34 +08:00
|
|
|
free_page((unsigned long)efi_pgd);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-01 00:25:08 +08:00
|
|
|
/*
|
|
|
|
* Add low kernel mappings for passing arguments to EFI functions.
|
|
|
|
*/
|
|
|
|
void efi_sync_low_kernel_mappings(void)
|
|
|
|
{
|
2015-11-28 05:09:34 +08:00
|
|
|
unsigned num_entries;
|
|
|
|
pgd_t *pgd_k, *pgd_efi;
|
2017-03-13 22:33:05 +08:00
|
|
|
p4d_t *p4d_k, *p4d_efi;
|
2015-11-28 05:09:34 +08:00
|
|
|
pud_t *pud_k, *pud_efi;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP))
|
|
|
|
return;
|
|
|
|
|
2015-11-28 05:09:34 +08:00
|
|
|
/*
|
|
|
|
* We can share all PGD entries apart from the one entry that
|
|
|
|
* covers the EFI runtime mapping space.
|
|
|
|
*
|
|
|
|
* Make sure the EFI runtime region mappings are guaranteed to
|
|
|
|
* only span a single PGD entry and that the entry also maps
|
|
|
|
* other important kernel regions.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(pgd_index(EFI_VA_END) != pgd_index(MODULES_END));
|
|
|
|
BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) !=
|
|
|
|
(EFI_VA_END & PGDIR_MASK));
|
|
|
|
|
|
|
|
pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET);
|
|
|
|
pgd_k = pgd_offset_k(PAGE_OFFSET);
|
|
|
|
|
|
|
|
num_entries = pgd_index(EFI_VA_END) - pgd_index(PAGE_OFFSET);
|
|
|
|
memcpy(pgd_efi, pgd_k, sizeof(pgd_t) * num_entries);
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2017-03-18 02:55:11 +08:00
|
|
|
/*
|
|
|
|
* As with PGDs, we share all P4D entries apart from the one entry
|
|
|
|
* that covers the EFI runtime mapping space.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(p4d_index(EFI_VA_END) != p4d_index(MODULES_END));
|
|
|
|
BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != (EFI_VA_END & P4D_MASK));
|
|
|
|
|
|
|
|
pgd_efi = efi_pgd + pgd_index(EFI_VA_END);
|
|
|
|
pgd_k = pgd_offset_k(EFI_VA_END);
|
|
|
|
p4d_efi = p4d_offset(pgd_efi, 0);
|
|
|
|
p4d_k = p4d_offset(pgd_k, 0);
|
|
|
|
|
|
|
|
num_entries = p4d_index(EFI_VA_END);
|
|
|
|
memcpy(p4d_efi, p4d_k, sizeof(p4d_t) * num_entries);
|
|
|
|
|
2015-11-28 05:09:34 +08:00
|
|
|
/*
|
|
|
|
* We share all the PUD entries apart from those that map the
|
|
|
|
* EFI regions. Copy around them.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON((EFI_VA_START & ~PUD_MASK) != 0);
|
|
|
|
BUILD_BUG_ON((EFI_VA_END & ~PUD_MASK) != 0);
|
|
|
|
|
2017-03-18 02:55:11 +08:00
|
|
|
p4d_efi = p4d_offset(pgd_efi, EFI_VA_END);
|
|
|
|
p4d_k = p4d_offset(pgd_k, EFI_VA_END);
|
2017-03-13 22:33:05 +08:00
|
|
|
pud_efi = pud_offset(p4d_efi, 0);
|
|
|
|
pud_k = pud_offset(p4d_k, 0);
|
2015-11-28 05:09:34 +08:00
|
|
|
|
|
|
|
num_entries = pud_index(EFI_VA_END);
|
|
|
|
memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
|
|
|
|
|
2017-03-13 22:33:05 +08:00
|
|
|
pud_efi = pud_offset(p4d_efi, EFI_VA_START);
|
|
|
|
pud_k = pud_offset(p4d_k, EFI_VA_START);
|
2015-11-28 05:09:34 +08:00
|
|
|
|
|
|
|
num_entries = PTRS_PER_PUD - pud_index(EFI_VA_START);
|
|
|
|
memcpy(pud_efi, pud_k, sizeof(pud_t) * num_entries);
|
2013-11-01 00:25:08 +08:00
|
|
|
}
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
/*
|
|
|
|
* Wrapper for slow_virt_to_phys() that handles NULL addresses.
|
|
|
|
*/
|
|
|
|
static inline phys_addr_t
|
|
|
|
virt_to_phys_or_null_size(void *va, unsigned long size)
|
|
|
|
{
|
|
|
|
bool bad_size;
|
|
|
|
|
|
|
|
if (!va)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (virt_addr_valid(va))
|
|
|
|
return virt_to_phys(va);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A fully aligned variable on the stack is guaranteed not to
|
|
|
|
* cross a page bounary. Try to catch strings on the stack by
|
|
|
|
* checking that 'size' is a power of two.
|
|
|
|
*/
|
|
|
|
bad_size = size > PAGE_SIZE || !is_power_of_2(size);
|
|
|
|
|
|
|
|
WARN_ON(!IS_ALIGNED((unsigned long)va, size) || bad_size);
|
|
|
|
|
|
|
|
return slow_virt_to_phys(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define virt_to_phys_or_null(addr) \
|
|
|
|
virt_to_phys_or_null_size((addr), sizeof(*(addr)))
|
|
|
|
|
2014-09-08 01:42:17 +08:00
|
|
|
int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
|
2013-11-01 00:25:08 +08:00
|
|
|
{
|
2017-07-18 05:10:15 +08:00
|
|
|
unsigned long pfn, text, pf;
|
2014-01-11 02:48:30 +08:00
|
|
|
struct page *page;
|
2014-03-06 02:15:37 +08:00
|
|
|
unsigned npages;
|
2014-01-18 19:48:17 +08:00
|
|
|
pgd_t *pgd;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP))
|
|
|
|
return 0;
|
|
|
|
|
2017-07-18 05:10:15 +08:00
|
|
|
/*
|
|
|
|
* Since the PGD is encrypted, set the encryption mask so that when
|
|
|
|
* this value is loaded into cr3 the PGD will be decrypted during
|
|
|
|
* the pagetable walk.
|
|
|
|
*/
|
|
|
|
efi_scratch.efi_pgt = (pgd_t *)__sme_pa(efi_pgd);
|
2015-11-28 05:09:34 +08:00
|
|
|
pgd = efi_pgd;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2014-01-18 19:48:17 +08:00
|
|
|
/*
|
|
|
|
* It can happen that the physical address of new_memmap lands in memory
|
|
|
|
* which is not mapped in the EFI page table. Therefore we need to go
|
|
|
|
* and ident-map those pages containing the map before calling
|
|
|
|
* phys_efi_set_virtual_address_map().
|
|
|
|
*/
|
2015-11-28 05:09:31 +08:00
|
|
|
pfn = pa_memmap >> PAGE_SHIFT;
|
2017-07-18 05:10:15 +08:00
|
|
|
pf = _PAGE_NX | _PAGE_RW | _PAGE_ENC;
|
|
|
|
if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, pf)) {
|
2014-01-18 19:48:17 +08:00
|
|
|
pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
efi_scratch.use_pgd = true;
|
|
|
|
|
2017-01-28 06:25:52 +08:00
|
|
|
/*
|
|
|
|
* Certain firmware versions are way too sentimential and still believe
|
|
|
|
* they are exclusive and unquestionable owners of the first physical page,
|
|
|
|
* even though they explicitly mark it as EFI_CONVENTIONAL_MEMORY
|
|
|
|
* (but then write-access it later during SetVirtualAddressMap()).
|
|
|
|
*
|
|
|
|
* Create a 1:1 mapping for this page, to avoid triple faults during early
|
|
|
|
* boot with such firmware. We are free to hand this page to the BIOS,
|
|
|
|
* as trim_bios_range() will reserve the first page and isolate it away
|
|
|
|
* from memory allocators anyway.
|
|
|
|
*/
|
2017-10-20 22:30:49 +08:00
|
|
|
pf = _PAGE_RW;
|
|
|
|
if (sev_active())
|
|
|
|
pf |= _PAGE_ENC;
|
|
|
|
|
|
|
|
if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) {
|
2017-01-28 06:25:52 +08:00
|
|
|
pr_err("Failed to create 1:1 mapping for the first page!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-11 02:48:30 +08:00
|
|
|
/*
|
|
|
|
* When making calls to the firmware everything needs to be 1:1
|
|
|
|
* mapped and addressable with 32-bit pointers. Map the kernel
|
|
|
|
* text and allocate a new stack because we can't rely on the
|
|
|
|
* stack pointer being < 4GB.
|
|
|
|
*/
|
2016-09-19 20:09:09 +08:00
|
|
|
if (!IS_ENABLED(CONFIG_EFI_MIXED) || efi_is_native())
|
2014-03-06 02:15:37 +08:00
|
|
|
return 0;
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
page = alloc_page(GFP_KERNEL|__GFP_DMA32);
|
|
|
|
if (!page)
|
|
|
|
panic("Unable to allocate EFI runtime stack < 4GB\n");
|
|
|
|
|
|
|
|
efi_scratch.phys_stack = virt_to_phys(page_address(page));
|
|
|
|
efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
|
|
|
|
|
2016-02-17 20:36:06 +08:00
|
|
|
npages = (_etext - _text) >> PAGE_SHIFT;
|
2014-01-11 02:48:30 +08:00
|
|
|
text = __pa(_text);
|
2015-11-28 05:09:31 +08:00
|
|
|
pfn = text >> PAGE_SHIFT;
|
2014-01-11 02:48:30 +08:00
|
|
|
|
2017-07-18 05:10:15 +08:00
|
|
|
pf = _PAGE_RW | _PAGE_ENC;
|
|
|
|
if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) {
|
2014-01-11 02:48:30 +08:00
|
|
|
pr_err("Failed to map kernel text 1:1\n");
|
2014-03-06 02:15:37 +08:00
|
|
|
return 1;
|
2014-01-11 02:48:30 +08:00
|
|
|
}
|
2014-01-18 19:48:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-01 00:25:08 +08:00
|
|
|
static void __init __map_region(efi_memory_desc_t *md, u64 va)
|
|
|
|
{
|
2016-02-17 20:36:04 +08:00
|
|
|
unsigned long flags = _PAGE_RW;
|
2015-11-28 05:09:31 +08:00
|
|
|
unsigned long pfn;
|
2015-11-28 05:09:34 +08:00
|
|
|
pgd_t *pgd = efi_pgd;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
|
|
|
if (!(md->attribute & EFI_MEMORY_WB))
|
2015-11-28 05:09:31 +08:00
|
|
|
flags |= _PAGE_PCD;
|
2013-11-01 00:25:08 +08:00
|
|
|
|
2017-10-20 22:30:49 +08:00
|
|
|
if (sev_active())
|
|
|
|
flags |= _PAGE_ENC;
|
|
|
|
|
2015-11-28 05:09:31 +08:00
|
|
|
pfn = md->phys_addr >> PAGE_SHIFT;
|
|
|
|
if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
|
2013-11-01 00:25:08 +08:00
|
|
|
pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
|
|
|
|
md->phys_addr, va);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init efi_map_region(efi_memory_desc_t *md)
|
|
|
|
{
|
|
|
|
unsigned long size = md->num_pages << PAGE_SHIFT;
|
|
|
|
u64 pa = md->phys_addr;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP))
|
|
|
|
return old_map_region(md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the 1:1 mappings are present as a catch-all for b0rked
|
|
|
|
* firmware which doesn't update all internal pointers after switching
|
|
|
|
* to virtual mode and would otherwise crap on us.
|
|
|
|
*/
|
|
|
|
__map_region(md, md->phys_addr);
|
|
|
|
|
2014-01-11 02:48:30 +08:00
|
|
|
/*
|
|
|
|
* Enforce the 1:1 mapping as the default virtual address when
|
|
|
|
* booting in EFI mixed mode, because even though we may be
|
|
|
|
* running a 64-bit kernel, the firmware may only be 32-bit.
|
|
|
|
*/
|
|
|
|
if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) {
|
|
|
|
md->virt_addr = md->phys_addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-01 00:25:08 +08:00
|
|
|
efi_va -= size;
|
|
|
|
|
|
|
|
/* Is PA 2M-aligned? */
|
|
|
|
if (!(pa & (PMD_SIZE - 1))) {
|
|
|
|
efi_va &= PMD_MASK;
|
|
|
|
} else {
|
|
|
|
u64 pa_offset = pa & (PMD_SIZE - 1);
|
|
|
|
u64 prev_va = efi_va;
|
|
|
|
|
|
|
|
/* get us the same offset within this 2M page */
|
|
|
|
efi_va = (efi_va & PMD_MASK) + pa_offset;
|
|
|
|
|
|
|
|
if (efi_va > prev_va)
|
|
|
|
efi_va -= PMD_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (efi_va < EFI_VA_END) {
|
|
|
|
pr_warn(FW_WARN "VA address range overflow!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the VA map */
|
|
|
|
__map_region(md, efi_va);
|
|
|
|
md->virt_addr = efi_va;
|
|
|
|
}
|
|
|
|
|
2013-12-20 18:02:14 +08:00
|
|
|
/*
|
|
|
|
* kexec kernel will use efi_map_region_fixed to map efi runtime memory ranges.
|
|
|
|
* md->virt_addr is the original virtual address which had been mapped in kexec
|
|
|
|
* 1st kernel.
|
|
|
|
*/
|
|
|
|
void __init efi_map_region_fixed(efi_memory_desc_t *md)
|
|
|
|
{
|
2016-08-06 07:59:35 +08:00
|
|
|
__map_region(md, md->phys_addr);
|
2013-12-20 18:02:14 +08:00
|
|
|
__map_region(md, md->virt_addr);
|
|
|
|
}
|
|
|
|
|
2011-12-12 08:12:42 +08:00
|
|
|
void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
|
2012-10-19 20:25:46 +08:00
|
|
|
u32 type, u64 attribute)
|
2011-12-12 08:12:42 +08:00
|
|
|
{
|
|
|
|
unsigned long last_map_pfn;
|
|
|
|
|
|
|
|
if (type == EFI_MEMORY_MAPPED_IO)
|
|
|
|
return ioremap(phys_addr, size);
|
|
|
|
|
|
|
|
last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
|
|
|
|
if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
|
|
|
|
unsigned long top = last_map_pfn << PAGE_SHIFT;
|
2012-10-19 20:25:46 +08:00
|
|
|
efi_ioremap(top, size - (top - phys_addr), type, attribute);
|
2011-12-12 08:12:42 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:25:46 +08:00
|
|
|
if (!(attribute & EFI_MEMORY_WB))
|
|
|
|
efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
|
|
|
|
|
2011-12-12 08:12:42 +08:00
|
|
|
return (void __iomem *)__va(phys_addr);
|
|
|
|
}
|
2013-12-20 18:02:19 +08:00
|
|
|
|
|
|
|
void __init parse_efi_setup(u64 phys_addr, u32 data_len)
|
|
|
|
{
|
|
|
|
efi_setup = phys_addr + sizeof(struct setup_data);
|
|
|
|
}
|
2014-02-14 15:24:24 +08:00
|
|
|
|
2017-01-31 21:21:37 +08:00
|
|
|
static int __init efi_update_mappings(efi_memory_desc_t *md, unsigned long pf)
|
2014-02-14 15:24:24 +08:00
|
|
|
{
|
2016-02-17 20:36:05 +08:00
|
|
|
unsigned long pfn;
|
|
|
|
pgd_t *pgd = efi_pgd;
|
2017-01-31 21:21:37 +08:00
|
|
|
int err1, err2;
|
|
|
|
|
|
|
|
/* Update the 1:1 mapping */
|
|
|
|
pfn = md->phys_addr >> PAGE_SHIFT;
|
|
|
|
err1 = kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, md->num_pages, pf);
|
|
|
|
if (err1) {
|
|
|
|
pr_err("Error while updating 1:1 mapping PA 0x%llx -> VA 0x%llx!\n",
|
|
|
|
md->phys_addr, md->virt_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
err2 = kernel_map_pages_in_pgd(pgd, pfn, md->virt_addr, md->num_pages, pf);
|
|
|
|
if (err2) {
|
|
|
|
pr_err("Error while updating VA mapping PA 0x%llx -> VA 0x%llx!\n",
|
|
|
|
md->phys_addr, md->virt_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err1 || err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init efi_update_mem_attr(struct mm_struct *mm, efi_memory_desc_t *md)
|
|
|
|
{
|
|
|
|
unsigned long pf = 0;
|
|
|
|
|
|
|
|
if (md->attribute & EFI_MEMORY_XP)
|
|
|
|
pf |= _PAGE_NX;
|
|
|
|
|
|
|
|
if (!(md->attribute & EFI_MEMORY_RO))
|
|
|
|
pf |= _PAGE_RW;
|
|
|
|
|
2017-10-20 22:30:49 +08:00
|
|
|
if (sev_active())
|
|
|
|
pf |= _PAGE_ENC;
|
|
|
|
|
2017-01-31 21:21:37 +08:00
|
|
|
return efi_update_mappings(md, pf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init efi_runtime_update_mappings(void)
|
|
|
|
{
|
2016-02-17 20:36:05 +08:00
|
|
|
efi_memory_desc_t *md;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP)) {
|
|
|
|
if (__supported_pte_mask & _PAGE_NX)
|
|
|
|
runtime_code_page_mkexec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-31 21:21:37 +08:00
|
|
|
/*
|
|
|
|
* Use the EFI Memory Attribute Table for mapping permissions if it
|
|
|
|
* exists, since it is intended to supersede EFI_PROPERTIES_TABLE.
|
|
|
|
*/
|
|
|
|
if (efi_enabled(EFI_MEM_ATTR)) {
|
|
|
|
efi_memattr_apply_permissions(NULL, efi_update_mem_attr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EFI_MEMORY_ATTRIBUTES_TABLE is intended to replace
|
|
|
|
* EFI_PROPERTIES_TABLE. So, use EFI_PROPERTIES_TABLE to update
|
|
|
|
* permissions only if EFI_MEMORY_ATTRIBUTES_TABLE is not
|
|
|
|
* published by the firmware. Even if we find a buggy implementation of
|
|
|
|
* EFI_MEMORY_ATTRIBUTES_TABLE, don't fall back to
|
|
|
|
* EFI_PROPERTIES_TABLE, because of the same reason.
|
|
|
|
*/
|
|
|
|
|
2016-02-17 20:36:05 +08:00
|
|
|
if (!efi_enabled(EFI_NX_PE_DATA))
|
2014-02-14 15:24:24 +08:00
|
|
|
return;
|
|
|
|
|
2016-04-26 04:06:38 +08:00
|
|
|
for_each_efi_memory_desc(md) {
|
2016-02-17 20:36:05 +08:00
|
|
|
unsigned long pf = 0;
|
|
|
|
|
|
|
|
if (!(md->attribute & EFI_MEMORY_RUNTIME))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(md->attribute & EFI_MEMORY_WB))
|
|
|
|
pf |= _PAGE_PCD;
|
|
|
|
|
|
|
|
if ((md->attribute & EFI_MEMORY_XP) ||
|
|
|
|
(md->type == EFI_RUNTIME_SERVICES_DATA))
|
|
|
|
pf |= _PAGE_NX;
|
|
|
|
|
|
|
|
if (!(md->attribute & EFI_MEMORY_RO) &&
|
|
|
|
(md->type != EFI_RUNTIME_SERVICES_CODE))
|
|
|
|
pf |= _PAGE_RW;
|
|
|
|
|
2017-10-20 22:30:49 +08:00
|
|
|
if (sev_active())
|
|
|
|
pf |= _PAGE_ENC;
|
|
|
|
|
2017-01-31 21:21:37 +08:00
|
|
|
efi_update_mappings(md, pf);
|
2016-02-17 20:36:05 +08:00
|
|
|
}
|
2014-02-14 15:24:24 +08:00
|
|
|
}
|
2014-01-18 19:48:15 +08:00
|
|
|
|
|
|
|
void __init efi_dump_pagetable(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_EFI_PGT_DUMP
|
2017-06-02 21:52:06 +08:00
|
|
|
if (efi_enabled(EFI_OLD_MEMMAP))
|
|
|
|
ptdump_walk_pgd_level(NULL, swapper_pg_dir);
|
|
|
|
else
|
|
|
|
ptdump_walk_pgd_level(NULL, efi_pgd);
|
2014-01-18 19:48:15 +08:00
|
|
|
#endif
|
|
|
|
}
|
2014-03-06 02:15:37 +08:00
|
|
|
|
2014-01-11 02:48:30 +08:00
|
|
|
#ifdef CONFIG_EFI_MIXED
|
|
|
|
extern efi_status_t efi64_thunk(u32, ...);
|
|
|
|
|
|
|
|
#define runtime_service32(func) \
|
|
|
|
({ \
|
|
|
|
u32 table = (u32)(unsigned long)efi.systab; \
|
|
|
|
u32 *rt, *___f; \
|
|
|
|
\
|
|
|
|
rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \
|
|
|
|
___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \
|
|
|
|
*___f; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to the EFI page tables early so that we can access the 1:1
|
|
|
|
* runtime services mappings which are not mapped in any other page
|
|
|
|
* tables. This function must be called before runtime_service32().
|
|
|
|
*
|
|
|
|
* Also, disable interrupts because the IDT points to 64-bit handlers,
|
|
|
|
* which aren't going to function correctly when we switch to 32-bit.
|
|
|
|
*/
|
|
|
|
#define efi_thunk(f, ...) \
|
|
|
|
({ \
|
|
|
|
efi_status_t __s; \
|
2016-06-25 15:20:29 +08:00
|
|
|
unsigned long __flags; \
|
|
|
|
u32 __func; \
|
2014-01-11 02:48:30 +08:00
|
|
|
\
|
2016-06-25 15:20:29 +08:00
|
|
|
local_irq_save(__flags); \
|
|
|
|
arch_efi_call_virt_setup(); \
|
2014-01-11 02:48:30 +08:00
|
|
|
\
|
2016-06-25 15:20:29 +08:00
|
|
|
__func = runtime_service32(f); \
|
|
|
|
__s = efi64_thunk(__func, __VA_ARGS__); \
|
2014-01-11 02:48:30 +08:00
|
|
|
\
|
2016-06-25 15:20:29 +08:00
|
|
|
arch_efi_call_virt_teardown(); \
|
|
|
|
local_irq_restore(__flags); \
|
2014-01-11 02:48:30 +08:00
|
|
|
\
|
|
|
|
__s; \
|
|
|
|
})
|
|
|
|
|
|
|
|
efi_status_t efi_thunk_set_virtual_address_map(
|
|
|
|
void *phys_set_virtual_address_map,
|
|
|
|
unsigned long memory_map_size,
|
|
|
|
unsigned long descriptor_size,
|
|
|
|
u32 descriptor_version,
|
|
|
|
efi_memory_desc_t *virtual_map)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 func;
|
|
|
|
|
|
|
|
efi_sync_low_kernel_mappings();
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2017-06-13 01:26:14 +08:00
|
|
|
efi_scratch.prev_cr3 = __read_cr3();
|
2014-01-11 02:48:30 +08:00
|
|
|
write_cr3((unsigned long)efi_scratch.efi_pgt);
|
|
|
|
__flush_tlb_all();
|
|
|
|
|
|
|
|
func = (u32)(unsigned long)phys_set_virtual_address_map;
|
|
|
|
status = efi64_thunk(func, memory_map_size, descriptor_size,
|
|
|
|
descriptor_version, virtual_map);
|
|
|
|
|
|
|
|
write_cr3(efi_scratch.prev_cr3);
|
|
|
|
__flush_tlb_all();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_tm, phys_tc;
|
|
|
|
|
|
|
|
spin_lock(&rtc_lock);
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_tm = virt_to_phys_or_null(tm);
|
|
|
|
phys_tc = virt_to_phys_or_null(tc);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(get_time, phys_tm, phys_tc);
|
|
|
|
|
|
|
|
spin_unlock(&rtc_lock);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t efi_thunk_set_time(efi_time_t *tm)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_tm;
|
|
|
|
|
|
|
|
spin_lock(&rtc_lock);
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_tm = virt_to_phys_or_null(tm);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(set_time, phys_tm);
|
|
|
|
|
|
|
|
spin_unlock(&rtc_lock);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
|
|
|
|
efi_time_t *tm)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_enabled, phys_pending, phys_tm;
|
|
|
|
|
|
|
|
spin_lock(&rtc_lock);
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_enabled = virt_to_phys_or_null(enabled);
|
|
|
|
phys_pending = virt_to_phys_or_null(pending);
|
|
|
|
phys_tm = virt_to_phys_or_null(tm);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(get_wakeup_time, phys_enabled,
|
|
|
|
phys_pending, phys_tm);
|
|
|
|
|
|
|
|
spin_unlock(&rtc_lock);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_tm;
|
|
|
|
|
|
|
|
spin_lock(&rtc_lock);
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_tm = virt_to_phys_or_null(tm);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(set_wakeup_time, enabled, phys_tm);
|
|
|
|
|
|
|
|
spin_unlock(&rtc_lock);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
static unsigned long efi_name_size(efi_char16_t *name)
|
|
|
|
{
|
|
|
|
return ucs2_strsize(name, EFI_VAR_NAME_LEN) + 1;
|
|
|
|
}
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
|
|
|
|
u32 *attr, unsigned long *data_size, void *data)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_name, phys_vendor, phys_attr;
|
|
|
|
u32 phys_data_size, phys_data;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_data_size = virt_to_phys_or_null(data_size);
|
|
|
|
phys_vendor = virt_to_phys_or_null(vendor);
|
|
|
|
phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
|
|
|
|
phys_attr = virt_to_phys_or_null(attr);
|
|
|
|
phys_data = virt_to_phys_or_null_size(data, *data_size);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(get_variable, phys_name, phys_vendor,
|
|
|
|
phys_attr, phys_data_size, phys_data);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
|
|
|
|
u32 attr, unsigned long data_size, void *data)
|
|
|
|
{
|
|
|
|
u32 phys_name, phys_vendor, phys_data;
|
|
|
|
efi_status_t status;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
|
|
|
|
phys_vendor = virt_to_phys_or_null(vendor);
|
|
|
|
phys_data = virt_to_phys_or_null_size(data, data_size);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
/* If data_size is > sizeof(u32) we've got problems */
|
|
|
|
status = efi_thunk(set_variable, phys_name, phys_vendor,
|
|
|
|
attr, data_size, phys_data);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_get_next_variable(unsigned long *name_size,
|
|
|
|
efi_char16_t *name,
|
|
|
|
efi_guid_t *vendor)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_name_size, phys_name, phys_vendor;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_name_size = virt_to_phys_or_null(name_size);
|
|
|
|
phys_vendor = virt_to_phys_or_null(vendor);
|
|
|
|
phys_name = virt_to_phys_or_null_size(name, *name_size);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
status = efi_thunk(get_next_variable, phys_name_size,
|
|
|
|
phys_name, phys_vendor);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_get_next_high_mono_count(u32 *count)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_count;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_count = virt_to_phys_or_null(count);
|
2014-01-11 02:48:30 +08:00
|
|
|
status = efi_thunk(get_next_high_mono_count, phys_count);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
efi_thunk_reset_system(int reset_type, efi_status_t status,
|
|
|
|
unsigned long data_size, efi_char16_t *data)
|
|
|
|
{
|
|
|
|
u32 phys_data;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_data = virt_to_phys_or_null_size(data, data_size);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
|
|
|
efi_thunk(reset_system, reset_type, status, data_size, phys_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_update_capsule(efi_capsule_header_t **capsules,
|
|
|
|
unsigned long count, unsigned long sg_list)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To properly support this function we would need to repackage
|
|
|
|
* 'capsules' because the firmware doesn't understand 64-bit
|
|
|
|
* pointers.
|
|
|
|
*/
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_query_variable_info(u32 attr, u64 *storage_space,
|
|
|
|
u64 *remaining_space,
|
|
|
|
u64 *max_variable_size)
|
|
|
|
{
|
|
|
|
efi_status_t status;
|
|
|
|
u32 phys_storage, phys_remaining, phys_max;
|
|
|
|
|
|
|
|
if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
|
2016-11-13 05:04:24 +08:00
|
|
|
phys_storage = virt_to_phys_or_null(storage_space);
|
|
|
|
phys_remaining = virt_to_phys_or_null(remaining_space);
|
|
|
|
phys_max = virt_to_phys_or_null(max_variable_size);
|
2014-01-11 02:48:30 +08:00
|
|
|
|
2014-03-17 01:46:46 +08:00
|
|
|
status = efi_thunk(query_variable_info, attr, phys_storage,
|
2014-01-11 02:48:30 +08:00
|
|
|
phys_remaining, phys_max);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static efi_status_t
|
|
|
|
efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules,
|
|
|
|
unsigned long count, u64 *max_size,
|
|
|
|
int *reset_type)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To properly support this function we would need to repackage
|
|
|
|
* 'capsules' because the firmware doesn't understand 64-bit
|
|
|
|
* pointers.
|
|
|
|
*/
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efi_thunk_runtime_setup(void)
|
|
|
|
{
|
|
|
|
efi.get_time = efi_thunk_get_time;
|
|
|
|
efi.set_time = efi_thunk_set_time;
|
|
|
|
efi.get_wakeup_time = efi_thunk_get_wakeup_time;
|
|
|
|
efi.set_wakeup_time = efi_thunk_set_wakeup_time;
|
|
|
|
efi.get_variable = efi_thunk_get_variable;
|
|
|
|
efi.get_next_variable = efi_thunk_get_next_variable;
|
|
|
|
efi.set_variable = efi_thunk_set_variable;
|
|
|
|
efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count;
|
|
|
|
efi.reset_system = efi_thunk_reset_system;
|
|
|
|
efi.query_variable_info = efi_thunk_query_variable_info;
|
|
|
|
efi.update_capsule = efi_thunk_update_capsule;
|
|
|
|
efi.query_capsule_caps = efi_thunk_query_capsule_caps;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_EFI_MIXED */
|