2014-04-16 09:59:30 +08:00
|
|
|
/*
|
|
|
|
* Extensible Firmware Interface
|
|
|
|
*
|
|
|
|
* Based on Extensible Firmware Interface Specification version 2.4
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, 2014 Linaro Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-10-04 23:46:43 +08:00
|
|
|
#include <linux/dmi.h>
|
2014-04-16 09:59:30 +08:00
|
|
|
#include <linux/efi.h>
|
2015-11-30 20:28:18 +08:00
|
|
|
#include <linux/init.h>
|
2014-04-16 09:59:30 +08:00
|
|
|
|
|
|
|
#include <asm/efi.h>
|
2014-10-04 23:46:43 +08:00
|
|
|
|
2016-04-26 04:06:43 +08:00
|
|
|
/*
|
|
|
|
* Only regions of type EFI_RUNTIME_SERVICES_CODE need to be
|
|
|
|
* executable, everything else can be mapped with the XN bits
|
|
|
|
* set. Also take the new (optional) RO/XP bits into account.
|
|
|
|
*/
|
|
|
|
static __init pteval_t create_mapping_protection(efi_memory_desc_t *md)
|
2015-11-30 20:28:19 +08:00
|
|
|
{
|
2016-04-26 04:06:43 +08:00
|
|
|
u64 attr = md->attribute;
|
|
|
|
u32 type = md->type;
|
2015-11-30 20:28:19 +08:00
|
|
|
|
2016-04-26 04:06:43 +08:00
|
|
|
if (type == EFI_MEMORY_MAPPED_IO)
|
|
|
|
return PROT_DEVICE_nGnRE;
|
|
|
|
|
|
|
|
if (WARN_ONCE(!PAGE_ALIGNED(md->phys_addr),
|
|
|
|
"UEFI Runtime regions are not aligned to 64 KB -- buggy firmware?"))
|
|
|
|
/*
|
|
|
|
* If the region is not aligned to the page size of the OS, we
|
|
|
|
* can not use strict permissions, since that would also affect
|
|
|
|
* the mapping attributes of the adjacent regions.
|
|
|
|
*/
|
|
|
|
return pgprot_val(PAGE_KERNEL_EXEC);
|
|
|
|
|
|
|
|
/* R-- */
|
|
|
|
if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) ==
|
|
|
|
(EFI_MEMORY_XP | EFI_MEMORY_RO))
|
|
|
|
return pgprot_val(PAGE_KERNEL_RO);
|
|
|
|
|
|
|
|
/* R-X */
|
|
|
|
if (attr & EFI_MEMORY_RO)
|
|
|
|
return pgprot_val(PAGE_KERNEL_ROX);
|
|
|
|
|
|
|
|
/* RW- */
|
|
|
|
if (attr & EFI_MEMORY_XP || type != EFI_RUNTIME_SERVICES_CODE)
|
|
|
|
return pgprot_val(PAGE_KERNEL);
|
|
|
|
|
|
|
|
/* RWX */
|
|
|
|
return pgprot_val(PAGE_KERNEL_EXEC);
|
|
|
|
}
|
|
|
|
|
2016-04-26 04:06:52 +08:00
|
|
|
/* we will fill this structure from the stub, so don't put it in .bss */
|
|
|
|
struct screen_info screen_info __section(.data);
|
|
|
|
|
2016-04-26 04:06:43 +08:00
|
|
|
int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
|
|
|
|
{
|
|
|
|
pteval_t prot_val = create_mapping_protection(md);
|
2015-11-30 20:28:19 +08:00
|
|
|
|
|
|
|
create_pgd_mapping(mm, md->phys_addr, md->virt_addr,
|
|
|
|
md->num_pages << EFI_PAGE_SHIFT,
|
2016-06-29 20:51:26 +08:00
|
|
|
__pgprot(prot_val | PTE_NG), true);
|
2015-11-30 20:28:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-04 23:46:43 +08:00
|
|
|
static int __init arm64_dmi_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* On arm64, DMI depends on UEFI, and dmi_scan_machine() needs to
|
|
|
|
* be called early because dmi_id_init(), which is an arch_initcall
|
|
|
|
* itself, depends on dmi_scan_machine() having been called already.
|
|
|
|
*/
|
|
|
|
dmi_scan_machine();
|
2014-10-15 15:36:50 +08:00
|
|
|
if (dmi_available)
|
|
|
|
dmi_set_dump_stack_arch_desc();
|
2014-10-04 23:46:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
core_initcall(arm64_dmi_init);
|
2014-10-20 22:27:26 +08:00
|
|
|
|
2015-03-06 22:49:24 +08:00
|
|
|
/*
|
|
|
|
* UpdateCapsule() depends on the system being shutdown via
|
|
|
|
* ResetSystem().
|
|
|
|
*/
|
|
|
|
bool efi_poweroff_required(void)
|
|
|
|
{
|
|
|
|
return efi_enabled(EFI_RUNTIME_SERVICES);
|
|
|
|
}
|