Skip to content

Commit 14d8c95

Browse files
committed
ARM: LPAE: Add context switching support
With LPAE, TTBRx registers are 64-bit. The ASID is stored in TTBR0 rather than a separate Context ID register. This patch makes the necessary changes to handle context switching on LPAE. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent f7b8156 commit 14d8c95

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

arch/arm/mm/context.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ unsigned int cpu_last_asid = ASID_FIRST_VERSION;
2222
DEFINE_PER_CPU(struct mm_struct *, current_mm);
2323
#endif
2424

25+
#ifdef CONFIG_ARM_LPAE
26+
#define cpu_set_asid(asid) { \
27+
unsigned long ttbl, ttbh; \
28+
asm volatile( \
29+
" mrrc p15, 0, %0, %1, c2 @ read TTBR0\n" \
30+
" mov %1, %2, lsl #(48 - 32) @ set ASID\n" \
31+
" mcrr p15, 0, %0, %1, c2 @ set TTBR0\n" \
32+
: "=&r" (ttbl), "=&r" (ttbh) \
33+
: "r" (asid & ~ASID_MASK)); \
34+
}
35+
#else
36+
#define cpu_set_asid(asid) \
37+
asm(" mcr p15, 0, %0, c13, c0, 1\n" : : "r" (asid))
38+
#endif
39+
2540
/*
2641
* We fork()ed a process, and we need a new context for the child
2742
* to run in. We reserve version 0 for initial tasks so we will
@@ -37,7 +52,7 @@ void __init_new_context(struct task_struct *tsk, struct mm_struct *mm)
3752
static void flush_context(void)
3853
{
3954
/* set the reserved ASID before flushing the TLB */
40-
asm("mcr p15, 0, %0, c13, c0, 1\n" : : "r" (0));
55+
cpu_set_asid(0);
4156
isb();
4257
local_flush_tlb_all();
4358
if (icache_is_vivt_asid_tagged()) {
@@ -99,7 +114,7 @@ static void reset_context(void *info)
99114
set_mm_context(mm, asid);
100115

101116
/* set the new ASID */
102-
asm("mcr p15, 0, %0, c13, c0, 1\n" : : "r" (mm->context.id));
117+
cpu_set_asid(mm->context.id);
103118
isb();
104119
}
105120

0 commit comments

Comments
 (0)