From df59dfec3b5a60258b73a8f437533746ee689020 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Sat, 28 Sep 2024 08:50:02 +0000 Subject: [PATCH] arm64: Set MMU granule sizes to a consistent value in bootloader. Change-Id: Ia36885df6dec5ac0ac9ce41271115aa7a8c3e6df Reviewed-on: https://review.haiku-os.org/c/haiku/+/8418 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- headers/private/kernel/arch/arm64/arm_registers.h | 7 +++++++ src/system/boot/platform/efi/arch/arm64/aarch64.h | 2 -- src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/headers/private/kernel/arch/arm64/arm_registers.h b/headers/private/kernel/arch/arm64/arm_registers.h index 7bfd1bc911..80bcc7a5b0 100644 --- a/headers/private/kernel/arch/arm64/arm_registers.h +++ b/headers/private/kernel/arch/arm64/arm_registers.h @@ -607,10 +607,17 @@ #define TCR_IPS_44BIT (4 << TCR_IPS_SHIFT) #define TCR_IPS_48BIT (5 << TCR_IPS_SHIFT) +#define TCR_TG0_SHIFT 14 +#define TCR_TG0_4K (0 << TCR_TG0_SHIFT) +#define TCR_TG0_64K (1 << TCR_TG0_SHIFT) +#define TCR_TG0_16K (2 << TCR_TG0_SHIFT) +#define TCR_TG0_MASK (3 << TCR_TG0_SHIFT) + #define TCR_TG1_SHIFT 30 #define TCR_TG1_16K (1 << TCR_TG1_SHIFT) #define TCR_TG1_4K (2 << TCR_TG1_SHIFT) #define TCR_TG1_64K (3 << TCR_TG1_SHIFT) +#define TCR_TG1_MASK (3 << TCR_TG1_SHIFT) #define TCR_SH1_SHIFT 28 #define TCR_SH1_IS (0x3UL << TCR_SH1_SHIFT) diff --git a/src/system/boot/platform/efi/arch/arm64/aarch64.h b/src/system/boot/platform/efi/arch/arm64/aarch64.h index 04efbb3945..4d72f30b94 100644 --- a/src/system/boot/platform/efi/arch/arm64/aarch64.h +++ b/src/system/boot/platform/efi/arch/arm64/aarch64.h @@ -204,8 +204,6 @@ static inline uint32 arch_mmu_user_address_bits() static inline uint32 arch_mmu_user_granule() { - static constexpr uint64 TCR_TG0_SHIFT = 14u; - uint64 reg = _arch_mmu_get_tcr(); return ((reg >> TCR_TG0_SHIFT) & TG_MASK); } diff --git a/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp b/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp index e2c5bc567c..f824283554 100644 --- a/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp +++ b/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp @@ -122,6 +122,12 @@ void arch_mmu_setup_EL1(uint64 tcr) { // TODO: Compiler dependency? tcr |= TCR_T1SZ(__builtin_popcountl(KERNEL_BASE)); + // Set granule sizes to 4KB + tcr &= ~TCR_TG0_MASK; + tcr |= TCR_TG0_4K; + tcr &= ~TCR_TG1_MASK; + tcr |= TCR_TG1_4K; + // Set the maximum PA size to the maximum supported by the hardware. uint64_t pa_size = READ_SPECIALREG(ID_AA64MMFR0_EL1) & ID_AA64MMFR0_PA_RANGE_MASK;