2019-02-02 17:41:15 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-11-30 20:28:18 +08:00
|
|
|
/*
|
|
|
|
* Extensible Firmware Interface
|
|
|
|
*
|
|
|
|
* Based on Extensible Firmware Interface Specification version 2.4
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - 2015 Linaro Ltd.
|
|
|
|
*/
|
|
|
|
|
2016-04-26 04:06:53 +08:00
|
|
|
#define pr_fmt(fmt) "efi: " fmt
|
|
|
|
|
2015-11-30 20:28:18 +08:00
|
|
|
#include <linux/efi.h>
|
2020-01-14 01:22:40 +08:00
|
|
|
#include <linux/fwnode.h>
|
2015-11-30 20:28:18 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/memblock.h>
|
|
|
|
#include <linux/mm_types.h>
|
|
|
|
#include <linux/of.h>
|
2020-01-14 01:22:40 +08:00
|
|
|
#include <linux/of_address.h>
|
2015-11-30 20:28:18 +08:00
|
|
|
#include <linux/of_fdt.h>
|
2016-04-26 04:06:55 +08:00
|
|
|
#include <linux/platform_device.h>
|
2016-04-26 04:06:53 +08:00
|
|
|
#include <linux/screen_info.h>
|
2015-11-30 20:28:18 +08:00
|
|
|
|
|
|
|
#include <asm/efi.h>
|
|
|
|
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
static int __init is_memory(efi_memory_desc_t *md)
|
2015-11-30 20:28:18 +08:00
|
|
|
{
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC))
|
2015-11-30 20:28:18 +08:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a EFI virtual address into a physical address: this is necessary,
|
|
|
|
* as some data members of the EFI system table are virtually remapped after
|
|
|
|
* SetVirtualAddressMap() has been called.
|
|
|
|
*/
|
2020-01-21 00:39:39 +08:00
|
|
|
static phys_addr_t __init efi_to_phys(unsigned long addr)
|
2015-11-30 20:28:18 +08:00
|
|
|
{
|
|
|
|
efi_memory_desc_t *md;
|
|
|
|
|
2016-04-26 04:06:39 +08:00
|
|
|
for_each_efi_memory_desc(md) {
|
2015-11-30 20:28:18 +08:00
|
|
|
if (!(md->attribute & EFI_MEMORY_RUNTIME))
|
|
|
|
continue;
|
|
|
|
if (md->virt_addr == 0)
|
|
|
|
/* no virtual mapping has been installed by the stub */
|
|
|
|
break;
|
|
|
|
if (md->virt_addr <= addr &&
|
|
|
|
(addr - md->virt_addr) < (md->num_pages << EFI_PAGE_SHIFT))
|
|
|
|
return md->phys_addr + addr - md->virt_addr;
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-04-26 04:06:53 +08:00
|
|
|
static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR;
|
efi/libstub: arm: Print CPU boot mode and MMU state at boot
On 32-bit ARM, we may boot at HYP mode, or with the MMU and caches off
(or both), even though the EFI spec does not actually support this.
While booting at HYP mode is something we might tolerate, fiddling
with the caches is a more serious issue, as disabling the caches is
tricky to do safely from C code, and running without the Dcache makes
it impossible to support unaligned memory accesses, which is another
explicit requirement imposed by the EFI spec.
So take note of the CPU mode and MMU state in the EFI stub diagnostic
output so that we can easily diagnose any issues that may arise from
this. E.g.,
EFI stub: Entering in SVC mode with MMU enabled
Also, capture the CPSR and SCTLR system register values at EFI stub
entry, and after ExitBootServices() returns, and check whether the
MMU and Dcache were disabled at any point. If this is the case, a
diagnostic message like the following will be emitted:
efi: [Firmware Bug]: EFI stub was entered with MMU and Dcache disabled, please fix your firmware!
efi: CPSR at EFI stub entry : 0x600001d3
efi: SCTLR at EFI stub entry : 0x00c51838
efi: CPSR after ExitBootServices() : 0x600001d3
efi: SCTLR after ExitBootServices(): 0x00c50838
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
2020-06-07 21:41:35 +08:00
|
|
|
static __initdata unsigned long cpu_state_table = EFI_INVALID_TABLE_ADDR;
|
2016-04-26 04:06:53 +08:00
|
|
|
|
2020-01-22 21:40:57 +08:00
|
|
|
static const efi_config_table_type_t arch_tables[] __initconst = {
|
2020-03-26 16:24:14 +08:00
|
|
|
{LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
|
efi/libstub: arm: Print CPU boot mode and MMU state at boot
On 32-bit ARM, we may boot at HYP mode, or with the MMU and caches off
(or both), even though the EFI spec does not actually support this.
While booting at HYP mode is something we might tolerate, fiddling
with the caches is a more serious issue, as disabling the caches is
tricky to do safely from C code, and running without the Dcache makes
it impossible to support unaligned memory accesses, which is another
explicit requirement imposed by the EFI spec.
So take note of the CPU mode and MMU state in the EFI stub diagnostic
output so that we can easily diagnose any issues that may arise from
this. E.g.,
EFI stub: Entering in SVC mode with MMU enabled
Also, capture the CPSR and SCTLR system register values at EFI stub
entry, and after ExitBootServices() returns, and check whether the
MMU and Dcache were disabled at any point. If this is the case, a
diagnostic message like the following will be emitted:
efi: [Firmware Bug]: EFI stub was entered with MMU and Dcache disabled, please fix your firmware!
efi: CPSR at EFI stub entry : 0x600001d3
efi: SCTLR at EFI stub entry : 0x00c51838
efi: CPSR after ExitBootServices() : 0x600001d3
efi: SCTLR after ExitBootServices(): 0x00c50838
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
2020-06-07 21:41:35 +08:00
|
|
|
{LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
|
2020-03-26 16:24:14 +08:00
|
|
|
{}
|
2016-04-26 04:06:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void __init init_screen_info(void)
|
|
|
|
{
|
|
|
|
struct screen_info *si;
|
|
|
|
|
2020-06-16 18:53:30 +08:00
|
|
|
if (IS_ENABLED(CONFIG_ARM) &&
|
|
|
|
screen_info_table != EFI_INVALID_TABLE_ADDR) {
|
2016-04-26 04:06:53 +08:00
|
|
|
si = early_memremap_ro(screen_info_table, sizeof(*si));
|
|
|
|
if (!si) {
|
|
|
|
pr_err("Could not map screen_info config table\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
screen_info = *si;
|
|
|
|
early_memunmap(si, sizeof(*si));
|
|
|
|
|
|
|
|
/* dummycon on ARM needs non-zero values for columns/lines */
|
|
|
|
screen_info.orig_video_cols = 80;
|
|
|
|
screen_info.orig_video_lines = 25;
|
|
|
|
}
|
2016-04-26 04:06:55 +08:00
|
|
|
|
|
|
|
if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
|
|
|
|
memblock_is_map_memory(screen_info.lfb_base))
|
|
|
|
memblock_mark_nomap(screen_info.lfb_base, screen_info.lfb_size);
|
2016-04-26 04:06:53 +08:00
|
|
|
}
|
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
static int __init uefi_init(u64 efi_system_table)
|
2015-11-30 20:28:18 +08:00
|
|
|
{
|
2020-01-22 21:40:57 +08:00
|
|
|
efi_config_table_t *config_tables;
|
2020-01-21 00:39:39 +08:00
|
|
|
efi_system_table_t *systab;
|
2015-11-30 20:28:19 +08:00
|
|
|
size_t table_size;
|
2020-01-20 17:49:11 +08:00
|
|
|
int retval;
|
2015-11-30 20:28:18 +08:00
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
systab = early_memremap_ro(efi_system_table, sizeof(efi_system_table_t));
|
|
|
|
if (systab == NULL) {
|
2015-11-30 20:28:18 +08:00
|
|
|
pr_warn("Unable to map EFI system table.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(EFI_BOOT, &efi.flags);
|
2015-11-30 20:28:19 +08:00
|
|
|
if (IS_ENABLED(CONFIG_64BIT))
|
|
|
|
set_bit(EFI_64BIT, &efi.flags);
|
2015-11-30 20:28:18 +08:00
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
retval = efi_systab_check_header(&systab->hdr, 2);
|
2020-01-20 17:49:11 +08:00
|
|
|
if (retval)
|
2015-11-30 20:28:18 +08:00
|
|
|
goto out;
|
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
efi.runtime = systab->runtime;
|
|
|
|
efi.runtime_version = systab->hdr.revision;
|
2015-11-30 20:28:18 +08:00
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
efi_systab_report_header(&systab->hdr, efi_to_phys(systab->fw_vendor));
|
2015-11-30 20:28:18 +08:00
|
|
|
|
2020-01-21 00:39:39 +08:00
|
|
|
table_size = sizeof(efi_config_table_t) * systab->nr_tables;
|
|
|
|
config_tables = early_memremap_ro(efi_to_phys(systab->tables),
|
2016-02-17 20:36:00 +08:00
|
|
|
table_size);
|
2015-11-30 20:28:18 +08:00
|
|
|
if (config_tables == NULL) {
|
|
|
|
pr_warn("Unable to map EFI config table array.\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-01-21 00:39:39 +08:00
|
|
|
retval = efi_config_parse_tables(config_tables, systab->nr_tables,
|
2020-06-16 18:53:30 +08:00
|
|
|
IS_ENABLED(CONFIG_ARM) ? arch_tables
|
|
|
|
: NULL);
|
2015-11-30 20:28:18 +08:00
|
|
|
|
|
|
|
early_memunmap(config_tables, table_size);
|
|
|
|
out:
|
2020-01-21 00:39:39 +08:00
|
|
|
early_memunmap(systab, sizeof(efi_system_table_t));
|
2015-11-30 20:28:18 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
* Return true for regions that can be used as System RAM.
|
2015-11-30 20:28:18 +08:00
|
|
|
*/
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
static __init int is_usable_memory(efi_memory_desc_t *md)
|
2015-11-30 20:28:18 +08:00
|
|
|
{
|
|
|
|
switch (md->type) {
|
|
|
|
case EFI_LOADER_CODE:
|
|
|
|
case EFI_LOADER_DATA:
|
efi/arm: Don't mark ACPI reclaim memory as MEMBLOCK_NOMAP
On ARM, regions of memory that are described by UEFI as having special
significance to the firmware itself are omitted from the linear mapping.
This is necessary since we cannot guarantee that alternate mappings of
the same physical region will use attributes that are compatible with
the ones we use for the linear mapping, and aliases with mismatched
attributes are prohibited by the architecture.
The above does not apply to ACPI reclaim regions: such regions have no
special significance to the firmware, and it is up to the OS to decide
whether or not to preserve them after it has consumed their contents,
and for how long, after which time the OS can use the memory in any way
it likes. In the Linux case, such regions are preserved indefinitely,
and are simply treated the same way as other 'reserved' memory types.
Punching holes into the linear mapping causes page table fragmentation,
which increases TLB pressure, and so we should avoid doing so if we can.
So add a special case for regions of type EFI_ACPI_RECLAIM_MEMORY, and
memblock_reserve() them instead of marking them MEMBLOCK_NOMAP.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20170818194947.19347-2-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-08-19 03:49:34 +08:00
|
|
|
case EFI_ACPI_RECLAIM_MEMORY:
|
2015-11-30 20:28:18 +08:00
|
|
|
case EFI_BOOT_SERVICES_CODE:
|
|
|
|
case EFI_BOOT_SERVICES_DATA:
|
|
|
|
case EFI_CONVENTIONAL_MEMORY:
|
|
|
|
case EFI_PERSISTENT_MEMORY:
|
2019-11-07 09:43:21 +08:00
|
|
|
/*
|
|
|
|
* Special purpose memory is 'soft reserved', which means it
|
|
|
|
* is set aside initially, but can be hotplugged back in or
|
|
|
|
* be assigned to the dax driver after boot.
|
|
|
|
*/
|
|
|
|
if (efi_soft_reserve_enabled() &&
|
|
|
|
(md->attribute & EFI_MEMORY_SP))
|
|
|
|
return false;
|
|
|
|
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
/*
|
|
|
|
* According to the spec, these regions are no longer reserved
|
|
|
|
* after calling ExitBootServices(). However, we can only use
|
|
|
|
* them as System RAM if they can be mapped writeback cacheable.
|
|
|
|
*/
|
|
|
|
return (md->attribute & EFI_MEMORY_WB);
|
2015-11-30 20:28:18 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
return false;
|
2015-11-30 20:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static __init void reserve_regions(void)
|
|
|
|
{
|
|
|
|
efi_memory_desc_t *md;
|
|
|
|
u64 paddr, npages, size;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_DBG))
|
|
|
|
pr_info("Processing EFI memory map:\n");
|
|
|
|
|
2016-04-09 06:50:23 +08:00
|
|
|
/*
|
|
|
|
* Discard memblocks discovered so far: if there are any at this
|
|
|
|
* point, they originate from memory nodes in the DT, and UEFI
|
|
|
|
* uses its own memory map instead.
|
|
|
|
*/
|
|
|
|
memblock_dump_all();
|
2018-06-15 06:28:02 +08:00
|
|
|
memblock_remove(0, PHYS_ADDR_MAX);
|
2016-04-09 06:50:23 +08:00
|
|
|
|
2016-04-26 04:06:39 +08:00
|
|
|
for_each_efi_memory_desc(md) {
|
2015-11-30 20:28:18 +08:00
|
|
|
paddr = md->phys_addr;
|
|
|
|
npages = md->num_pages;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_DBG)) {
|
|
|
|
char buf[64];
|
|
|
|
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
pr_info(" 0x%012llx-0x%012llx %s\n",
|
2015-11-30 20:28:18 +08:00
|
|
|
paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
efi_md_typeattr_format(buf, sizeof(buf), md));
|
2015-11-30 20:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
memrange_efi_to_native(&paddr, &npages);
|
|
|
|
size = npages << PAGE_SHIFT;
|
|
|
|
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
if (is_memory(md)) {
|
2015-11-30 20:28:18 +08:00
|
|
|
early_init_dt_add_memory_arch(paddr, size);
|
|
|
|
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
if (!is_usable_memory(md))
|
|
|
|
memblock_mark_nomap(paddr, size);
|
efi/arm: Don't mark ACPI reclaim memory as MEMBLOCK_NOMAP
On ARM, regions of memory that are described by UEFI as having special
significance to the firmware itself are omitted from the linear mapping.
This is necessary since we cannot guarantee that alternate mappings of
the same physical region will use attributes that are compatible with
the ones we use for the linear mapping, and aliases with mismatched
attributes are prohibited by the architecture.
The above does not apply to ACPI reclaim regions: such regions have no
special significance to the firmware, and it is up to the OS to decide
whether or not to preserve them after it has consumed their contents,
and for how long, after which time the OS can use the memory in any way
it likes. In the Linux case, such regions are preserved indefinitely,
and are simply treated the same way as other 'reserved' memory types.
Punching holes into the linear mapping causes page table fragmentation,
which increases TLB pressure, and so we should avoid doing so if we can.
So add a special case for regions of type EFI_ACPI_RECLAIM_MEMORY, and
memblock_reserve() them instead of marking them MEMBLOCK_NOMAP.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20170818194947.19347-2-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-08-19 03:49:34 +08:00
|
|
|
|
|
|
|
/* keep ACPI reclaim memory intact for kexec etc. */
|
|
|
|
if (md->type == EFI_ACPI_RECLAIM_MEMORY)
|
|
|
|
memblock_reserve(paddr, size);
|
efi/arm64: Treat regions with WT/WC set but WB cleared as memory
Currently, memory regions are only recorded in the memblock memory table
if they have the EFI_MEMORY_WB memory type attribute set. In case the
region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
will leave it out of the linear mapping.
However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
question is obviously backed by normal memory, but is not recorded in the
memblock memory table at all. Since it would be useful to be able to
identify any UEFI reported memory region using memblock_is_memory(), it
makes sense to add all memory to the memblock memory table, and simply mark
it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
While implementing this, let's refactor the code slightly to make it easier
to understand: replace is_normal_ram() with is_memory(), and make it return
true for each region that has any of the WB|WT|WC bits set. (This follows
the AArch64 bindings in the UEFI spec, which state that those are the
attributes that map to normal memory)
Also, replace is_reserve_region() with is_usable_memory(), and only invoke
it if the region in question was identified as memory by is_memory() in the
first place. The net result is the same (only reserved regions that are
backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
flag set) but carried out in a more straightforward way.
Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
clutters the code, and it serves no real purpose now that we no longer
temporarily reserve BootServices code and data regions like we did in the
early days of EFI support on arm64 Linux (which it inherited from the x86
implementation)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: James Morse <james.morse@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-08-26 00:17:09 +08:00
|
|
|
}
|
2015-11-30 20:28:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init efi_init(void)
|
|
|
|
{
|
2016-02-27 05:22:05 +08:00
|
|
|
struct efi_memory_map_data data;
|
2020-02-18 17:19:34 +08:00
|
|
|
u64 efi_system_table;
|
2015-11-30 20:28:18 +08:00
|
|
|
|
|
|
|
/* Grab UEFI information placed in FDT by stub */
|
2020-02-18 17:19:34 +08:00
|
|
|
efi_system_table = efi_get_fdt_params(&data);
|
|
|
|
if (!efi_system_table)
|
2015-11-30 20:28:18 +08:00
|
|
|
return;
|
|
|
|
|
2016-02-27 05:22:05 +08:00
|
|
|
if (efi_memmap_init_early(&data) < 0) {
|
2015-11-30 20:28:18 +08:00
|
|
|
/*
|
|
|
|
* If we are booting via UEFI, the UEFI memory map is the only
|
|
|
|
* description of memory we have, so there is little point in
|
|
|
|
* proceeding if we cannot access it.
|
|
|
|
*/
|
|
|
|
panic("Unable to map EFI memory map.\n");
|
|
|
|
}
|
|
|
|
|
2016-04-26 04:06:40 +08:00
|
|
|
WARN(efi.memmap.desc_version != 1,
|
|
|
|
"Unexpected EFI_MEMORY_DESCRIPTOR version %ld",
|
|
|
|
efi.memmap.desc_version);
|
|
|
|
|
2020-02-18 17:19:34 +08:00
|
|
|
if (uefi_init(efi_system_table) < 0) {
|
2016-10-18 22:33:13 +08:00
|
|
|
efi_memmap_unmap();
|
2015-11-30 20:28:18 +08:00
|
|
|
return;
|
2016-10-18 22:33:13 +08:00
|
|
|
}
|
2015-11-30 20:28:18 +08:00
|
|
|
|
|
|
|
reserve_regions();
|
2016-07-12 03:00:46 +08:00
|
|
|
efi_esrt_init();
|
2020-09-05 09:31:05 +08:00
|
|
|
efi_mokvar_table_init();
|
efi/arm64: Don't apply MEMBLOCK_NOMAP to UEFI memory map mapping
Commit 4dffbfc48d65 ("arm64/efi: mark UEFI reserved regions as
MEMBLOCK_NOMAP") updated the mapping logic of both the RuntimeServices
regions as well as the kernel's copy of the UEFI memory map to set the
MEMBLOCK_NOMAP flag, which causes these regions to be omitted from the
kernel direct mapping, and from being covered by a struct page.
For the RuntimeServices regions, this is an obvious win, since the contents
of these regions have significance to the firmware executable code itself,
and are mapped in the EFI page tables using attributes that are described in
the UEFI memory map, and which may differ from the attributes we use for
mapping system RAM. It also prevents the contents from being modified
inadvertently, since the EFI page tables are only live during runtime
service invocations.
None of these concerns apply to the allocation that covers the UEFI memory
map, since it is entirely owned by the kernel. Setting the MEMBLOCK_NOMAP on
the region did allow us to use ioremap_cache() to map it both on arm64 and
on ARM, since the latter does not allow ioremap_cache() to be used on
regions that are covered by a struct page.
The ioremap_cache() on ARM restriction will be lifted in the v4.7 timeframe,
but in the mean time, it has been reported that commit 4dffbfc48d65 causes
a regression on 64k granule kernels. This is due to the fact that, given
the 64 KB page size, the region that we end up removing from the kernel
direct mapping is rounded up to 64 KB, and this 64 KB page frame may be
shared with the initrd when booting via GRUB (which does not align its
EFI_LOADER_DATA allocations to 64 KB like the stub does). This will crash
the kernel as soon as it tries to access the initrd.
Since the issue is specific to arm64, revert back to memblock_reserve()'ing
the UEFI memory map when running on arm64. This is a temporary fix for v4.5
and v4.6, and will be superseded in the v4.7 timeframe when we will be able
to move back to memblock_reserve() unconditionally.
Fixes: 4dffbfc48d65 ("arm64/efi: mark UEFI reserved regions as MEMBLOCK_NOMAP")
Reported-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: Mark Langsdorf <mlangsdo@redhat.com>
Cc: <stable@vger.kernel.org> # v4.5
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
2016-03-30 15:46:23 +08:00
|
|
|
|
2020-02-18 17:19:34 +08:00
|
|
|
memblock_reserve(data.phys_map & PAGE_MASK,
|
|
|
|
PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
|
2016-04-26 04:06:53 +08:00
|
|
|
|
|
|
|
init_screen_info();
|
2018-11-15 01:55:41 +08:00
|
|
|
|
efi/libstub: arm: Print CPU boot mode and MMU state at boot
On 32-bit ARM, we may boot at HYP mode, or with the MMU and caches off
(or both), even though the EFI spec does not actually support this.
While booting at HYP mode is something we might tolerate, fiddling
with the caches is a more serious issue, as disabling the caches is
tricky to do safely from C code, and running without the Dcache makes
it impossible to support unaligned memory accesses, which is another
explicit requirement imposed by the EFI spec.
So take note of the CPU mode and MMU state in the EFI stub diagnostic
output so that we can easily diagnose any issues that may arise from
this. E.g.,
EFI stub: Entering in SVC mode with MMU enabled
Also, capture the CPSR and SCTLR system register values at EFI stub
entry, and after ExitBootServices() returns, and check whether the
MMU and Dcache were disabled at any point. If this is the case, a
diagnostic message like the following will be emitted:
efi: [Firmware Bug]: EFI stub was entered with MMU and Dcache disabled, please fix your firmware!
efi: CPSR at EFI stub entry : 0x600001d3
efi: SCTLR at EFI stub entry : 0x00c51838
efi: CPSR after ExitBootServices() : 0x600001d3
efi: SCTLR after ExitBootServices(): 0x00c50838
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
2020-06-07 21:41:35 +08:00
|
|
|
#ifdef CONFIG_ARM
|
2018-11-15 01:55:41 +08:00
|
|
|
/* ARM does not permit early mappings to persist across paging_init() */
|
efi/libstub: arm: Print CPU boot mode and MMU state at boot
On 32-bit ARM, we may boot at HYP mode, or with the MMU and caches off
(or both), even though the EFI spec does not actually support this.
While booting at HYP mode is something we might tolerate, fiddling
with the caches is a more serious issue, as disabling the caches is
tricky to do safely from C code, and running without the Dcache makes
it impossible to support unaligned memory accesses, which is another
explicit requirement imposed by the EFI spec.
So take note of the CPU mode and MMU state in the EFI stub diagnostic
output so that we can easily diagnose any issues that may arise from
this. E.g.,
EFI stub: Entering in SVC mode with MMU enabled
Also, capture the CPSR and SCTLR system register values at EFI stub
entry, and after ExitBootServices() returns, and check whether the
MMU and Dcache were disabled at any point. If this is the case, a
diagnostic message like the following will be emitted:
efi: [Firmware Bug]: EFI stub was entered with MMU and Dcache disabled, please fix your firmware!
efi: CPSR at EFI stub entry : 0x600001d3
efi: SCTLR at EFI stub entry : 0x00c51838
efi: CPSR after ExitBootServices() : 0x600001d3
efi: SCTLR after ExitBootServices(): 0x00c50838
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
2020-06-07 21:41:35 +08:00
|
|
|
efi_memmap_unmap();
|
|
|
|
|
|
|
|
if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
|
|
|
|
struct efi_arm_entry_state *state;
|
|
|
|
bool dump_state = true;
|
|
|
|
|
|
|
|
state = early_memremap_ro(cpu_state_table,
|
|
|
|
sizeof(struct efi_arm_entry_state));
|
|
|
|
if (state == NULL) {
|
|
|
|
pr_warn("Unable to map CPU entry state table.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state->sctlr_before_ebs & 1) == 0)
|
|
|
|
pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
|
|
|
|
else if ((state->sctlr_after_ebs & 1) == 0)
|
|
|
|
pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
|
|
|
|
else
|
|
|
|
dump_state = false;
|
|
|
|
|
|
|
|
if (dump_state || efi_enabled(EFI_DBG)) {
|
|
|
|
pr_info("CPSR at EFI stub entry : 0x%08x\n", state->cpsr_before_ebs);
|
|
|
|
pr_info("SCTLR at EFI stub entry : 0x%08x\n", state->sctlr_before_ebs);
|
|
|
|
pr_info("CPSR after ExitBootServices() : 0x%08x\n", state->cpsr_after_ebs);
|
|
|
|
pr_info("SCTLR after ExitBootServices(): 0x%08x\n", state->sctlr_after_ebs);
|
|
|
|
}
|
|
|
|
early_memunmap(state, sizeof(struct efi_arm_entry_state));
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-30 20:28:18 +08:00
|
|
|
}
|
2016-04-26 04:06:55 +08:00
|
|
|
|
2020-01-14 01:22:40 +08:00
|
|
|
static bool efifb_overlaps_pci_range(const struct of_pci_range *range)
|
|
|
|
{
|
|
|
|
u64 fb_base = screen_info.lfb_base;
|
|
|
|
|
|
|
|
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
|
|
|
|
fb_base |= (u64)(unsigned long)screen_info.ext_lfb_base << 32;
|
|
|
|
|
|
|
|
return fb_base >= range->cpu_addr &&
|
|
|
|
fb_base < (range->cpu_addr + range->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_node *find_pci_overlap_node(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
for_each_node_by_type(np, "pci") {
|
|
|
|
struct of_pci_range_parser parser;
|
|
|
|
struct of_pci_range range;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = of_pci_range_parser_init(&parser, np);
|
|
|
|
if (err) {
|
|
|
|
pr_warn("of_pci_range_parser_init() failed: %d\n", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_of_pci_range(&parser, &range)
|
|
|
|
if (efifb_overlaps_pci_range(&range))
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the efifb framebuffer is backed by a PCI graphics controller, we have
|
|
|
|
* to ensure that this relation is expressed using a device link when
|
|
|
|
* running in DT mode, or the probe order may be reversed, resulting in a
|
|
|
|
* resource reservation conflict on the memory window that the efifb
|
|
|
|
* framebuffer steals from the PCIe host bridge.
|
|
|
|
*/
|
2020-11-21 10:02:32 +08:00
|
|
|
static int efifb_add_links(struct fwnode_handle *fwnode)
|
2020-01-14 01:22:40 +08:00
|
|
|
{
|
|
|
|
struct device_node *sup_np;
|
|
|
|
|
|
|
|
sup_np = find_pci_overlap_node();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's no PCI graphics controller backing the efifb, we are
|
|
|
|
* done here.
|
|
|
|
*/
|
|
|
|
if (!sup_np)
|
|
|
|
return 0;
|
|
|
|
|
2020-11-21 10:02:30 +08:00
|
|
|
fwnode_link_add(fwnode, of_fwnode_handle(sup_np));
|
2020-01-14 01:22:40 +08:00
|
|
|
of_node_put(sup_np);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fwnode_operations efifb_fwnode_ops = {
|
|
|
|
.add_links = efifb_add_links,
|
|
|
|
};
|
|
|
|
|
2020-11-21 10:02:22 +08:00
|
|
|
static struct fwnode_handle efifb_fwnode;
|
2020-01-14 01:22:40 +08:00
|
|
|
|
2016-04-26 04:06:55 +08:00
|
|
|
static int __init register_gop_device(void)
|
|
|
|
{
|
2020-01-14 01:22:40 +08:00
|
|
|
struct platform_device *pd;
|
|
|
|
int err;
|
2016-04-26 04:06:55 +08:00
|
|
|
|
|
|
|
if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
|
|
|
|
return 0;
|
|
|
|
|
2020-01-14 01:22:40 +08:00
|
|
|
pd = platform_device_alloc("efi-framebuffer", 0);
|
|
|
|
if (!pd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-11-21 10:02:22 +08:00
|
|
|
if (IS_ENABLED(CONFIG_PCI)) {
|
|
|
|
fwnode_init(&efifb_fwnode, &efifb_fwnode_ops);
|
2020-01-14 01:22:40 +08:00
|
|
|
pd->dev.fwnode = &efifb_fwnode;
|
2020-11-21 10:02:22 +08:00
|
|
|
}
|
2020-01-14 01:22:40 +08:00
|
|
|
|
|
|
|
err = platform_device_add_data(pd, &screen_info, sizeof(screen_info));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return platform_device_add(pd);
|
2016-04-26 04:06:55 +08:00
|
|
|
}
|
|
|
|
subsys_initcall(register_gop_device);
|