Skip to content

Commit

Permalink
[arch][arm64] Make sure mpidr_el1 and mipr_el1 is configured
Browse files Browse the repository at this point in the history
When dropping from EL2 (or EL3), load vmpidr_el2 and vpidr_el2 with the
correct values to make sure EL1 sees the 'real' mpidr_el1 and midr_el1.

Though in most cases they're already configured by whatever firmware ran
before, there's no actual guarantee that it is, and it may be full of
random garbage.
  • Loading branch information
travisg committed Nov 10, 2024
1 parent 98a5703 commit 6e39e56
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arch/arm64/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ FUNCTION(arm64_elX_to_el1)
cmp x4, #(0b01 << 2)
bne .notEL1
/* Already in EL1 */
ret
ret

.notEL1:
cmp x4, #(0b10 << 2)
Expand All @@ -95,6 +95,7 @@ FUNCTION(arm64_elX_to_el1)
orr x4, x4, #(1<<10)
msr scr_el3, x4

/* prep this mode's ELR and SPSR to drop into EL1 */
adr x4, .Ltarget
msr elr_el3, x4

Expand All @@ -103,6 +104,7 @@ FUNCTION(arm64_elX_to_el1)
b .confEL1

.inEL2:
/* prep this mode's ELR and SPSR to drop into EL1 */
adr x4, .Ltarget
msr elr_el2, x4
mov x4, #((0b1111 << 6) | (0b0101)) /* EL1h runlevel */
Expand All @@ -113,14 +115,20 @@ FUNCTION(arm64_elX_to_el1)
mov x4, #0x33ff
msr cptr_el2, x4

/* set EL1 to 64bit */
/* set EL1 to 64bit and disable EL2 instruction traps */
mov x4, #(1<<31)
msr hcr_el2, x4

/* set up the EL1 bounce interrupt */
mov x4, sp
msr sp_el1, x4

/* make sure MPIDR_EL1 and MIDR_EL1 are set with the proper values */
mrs x4, mpidr_el1
msr vmpidr_el2, x4
mrs x4, midr_el1
msr vpidr_el2, x4

isb
eret

Expand Down

0 comments on commit 6e39e56

Please sign in to comment.