2 * Copyright (C) 2012,2013 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/linkage.h>
20 #include <asm/assembler.h>
21 #include <asm/kvm_arm.h>
22 #include <asm/kvm_mmu.h>
23 #include <asm/pgtable-hwdef.h>
24 #include <asm/sysreg.h>
27 .pushsection .hyp.idmap.text, "ax"
32 ventry __invalid // Synchronous EL2t
33 ventry __invalid // IRQ EL2t
34 ventry __invalid // FIQ EL2t
35 ventry __invalid // Error EL2t
37 ventry __invalid // Synchronous EL2h
38 ventry __invalid // IRQ EL2h
39 ventry __invalid // FIQ EL2h
40 ventry __invalid // Error EL2h
42 ventry __do_hyp_init // Synchronous 64-bit EL1
43 ventry __invalid // IRQ 64-bit EL1
44 ventry __invalid // FIQ 64-bit EL1
45 ventry __invalid // Error 64-bit EL1
47 ventry __invalid // Synchronous 32-bit EL1
48 ventry __invalid // IRQ 32-bit EL1
49 ventry __invalid // FIQ 32-bit EL1
50 ventry __invalid // Error 32-bit EL1
70 #ifndef CONFIG_ARM64_VA_BITS_48
72 * If we are running with VA_BITS < 48, we may be running with an extra
73 * level of translation in the ID map. This is only the case if system
74 * RAM is out of range for the currently configured page size and number
75 * of translation levels, in which case we will also need the extra
76 * level for the HYP ID map, or we won't be able to enable the EL2 MMU.
78 * However, at EL2, there is only one TTBR register, and we can't switch
79 * between translation tables *and* update TCR_EL2.T0SZ at the same
80 * time. Bottom line: we need the extra level in *both* our translation
83 * So use the same T0SZ value we use for the ID map.
86 bfi x4, x5, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH
89 * Read the PARange bits from ID_AA64MMFR0_EL1 and set the PS bits in
92 mrs x5, ID_AA64MMFR0_EL1
101 /* Invalidate the stale TLBs from Bootloader */
106 and x4, x4, #SCTLR_ELx_EE // preserve endianness of EL2
107 ldr x5, =SCTLR_ELx_FLAGS
112 /* Set the stack and new vectors */
120 ENDPROC(__kvm_hyp_init)
123 * Reset kvm back to the hyp stub.
125 ENTRY(__kvm_hyp_reset)
126 /* We're now in idmap, disable MMU */
128 ldr x1, =SCTLR_ELx_FLAGS
129 bic x0, x0, x1 // Clear SCTL_M and etc
133 /* Install stub vectors */
134 adr_l x0, __hyp_stub_vectors
138 ENDPROC(__kvm_hyp_reset)