From f3e9b61a91db11e838fa166916e879bd315b224f Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 9 Dec 2020 16:49:04 -0800 Subject: [PATCH] x86: reserve the first megabyte A more comprehensive solution would use E820 enumeration, but we are unlikely to ever care that much, as we intend to use demand paging on microcontrollers and not PC-like hardware. This is really to just prevent QEMU from crashing. Signed-off-by: Andrew Boie --- arch/x86/core/x86_mmu.c | 20 ++++++++++++++++++++ soc/x86/apollo_lake/Kconfig.soc | 1 + soc/x86/atom/Kconfig.soc | 1 + soc/x86/ia32/Kconfig.soc | 1 + 4 files changed, 23 insertions(+) diff --git a/arch/x86/core/x86_mmu.c b/arch/x86/core/x86_mmu.c index ce9073c2e3..9ea2766abd 100644 --- a/arch/x86/core/x86_mmu.c +++ b/arch/x86/core/x86_mmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); @@ -1775,3 +1776,22 @@ void z_x86_current_stack_perms(void) #endif } #endif /* CONFIG_USERSPACE */ + +#ifdef CONFIG_ARCH_HAS_RESERVED_PAGE_FRAMES +/* Selected on PC-like targets at the SOC level. + * + * Best is to do some E820 or similar enumeration to specifically identify + * all page frames which are reserved by the hardware or firmware. + * + * For now, just reserve everything in the first megabyte of physical memory. + */ +void arch_reserved_pages_update(void) +{ + for (uintptr_t pos = 0; pos < (1024 * 1024); + pos += CONFIG_MMU_PAGE_SIZE) { + struct z_page_frame *pf = z_phys_to_page_frame(pos); + + pf->flags |= Z_PAGE_FRAME_RESERVED; + } +} +#endif /* CONFIG_ARCH_HAS_RESERVED_PAGE_FRAMES */ diff --git a/soc/x86/apollo_lake/Kconfig.soc b/soc/x86/apollo_lake/Kconfig.soc index acde2242e0..5440ce3e70 100644 --- a/soc/x86/apollo_lake/Kconfig.soc +++ b/soc/x86/apollo_lake/Kconfig.soc @@ -10,3 +10,4 @@ config SOC_APOLLO_LAKE select PCIE_MSI select DYNAMIC_INTERRUPTS select X86_MMU + select ARCH_HAS_RESERVED_PAGE_FRAMES diff --git a/soc/x86/atom/Kconfig.soc b/soc/x86/atom/Kconfig.soc index 4dde328ccc..ac396eec88 100644 --- a/soc/x86/atom/Kconfig.soc +++ b/soc/x86/atom/Kconfig.soc @@ -6,3 +6,4 @@ config SOC_ATOM select CPU_ATOM select X86_MMU select ARCH_HAS_USERSPACE + select ARCH_HAS_RESERVED_PAGE_FRAMES diff --git a/soc/x86/ia32/Kconfig.soc b/soc/x86/ia32/Kconfig.soc index 66cd91c8f9..8b00c5bf3e 100644 --- a/soc/x86/ia32/Kconfig.soc +++ b/soc/x86/ia32/Kconfig.soc @@ -4,3 +4,4 @@ config SOC_IA32 bool "Generic IA32 SoC" select X86 select CPU_MINUTEIA + select ARCH_HAS_RESERVED_PAGE_FRAMES if SRAM_BASE_ADDRESS = 0