[arm][mm] Move ASID from TTBR0_EL1 to TTBR1_EL1
When mapping kernelspace and userspace with different
ASIDs, check if tcr_el1 is not getting updated (ie; set to 0)
In this case, move the ASID to TTBR1 else, this will result in
an invalid mapping
Test: Tested on kirin970 and hikey960 board. Device booted to shell
Change-Id: I8ac56a75fbedcfc43b9b0e0b912447201ea6ed70
diff --git a/kernel/arch/arm64/include/arch/arm64/mmu.h b/kernel/arch/arm64/include/arch/arm64/mmu.h
index 0ddc125..4798087 100644
--- a/kernel/arch/arm64/include/arch/arm64/mmu.h
+++ b/kernel/arch/arm64/include/arch/arm64/mmu.h
@@ -298,6 +298,9 @@
MMU_TCR_T0SZ(64 - MMU_IDENT_SIZE_SHIFT))
#define MMU_TCR_FLAGS_IDENT (MMU_TCR_IPS_DEFAULT | MMU_TCR_FLAGS1 | MMU_TCR_FLAGS0_IDENT)
+#define MMU_TCR_FLAGS_IDENT1 (MMU_TCR_IPS_DEFAULT | MMU_TCR_FLAGS1 | \
+ MMU_TCR_FLAGS0_IDENT | MMU_TCR_AS | MMU_TCR_A1)
+
#define MMU_TCR_FLAGS_KERNEL (MMU_TCR_IPS_DEFAULT | \
MMU_TCR_FLAGS1 | \
MMU_TCR_FLAGS0 | \
diff --git a/kernel/arch/arm64/start.S b/kernel/arch/arm64/start.S
index 4999aa3..961a3dc 100644
--- a/kernel/arch/arm64/start.S
+++ b/kernel/arch/arm64/start.S
@@ -184,6 +184,17 @@
movlit tmp, MMU_TCR_FLAGS_IDENT
msr tcr_el1, tmp
+ // When mapping kernelspace and userspace with different
+ // ASIDs, check if tcr_el1 is not getting updated (ie; set to 0)
+ // In this case, move the ASID to TTBR1 else, this will result in
+ // an invalid mapping
+ mrs tmp, tcr_el1
+ cbnz tmp, .Lttbr1_el1_asid
+
+ movlit tmp, MMU_TCR_FLAGS_IDENT1
+ msr tcr_el1, tmp
+
+.Lttbr1_el1_asid:
isb
/* Write ttbr with phys addr of the translation table */