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>
28 .pushsection .hyp.idmap.text, "ax"
33 ventry __invalid // Synchronous EL2t
34 ventry __invalid // IRQ EL2t
35 ventry __invalid // FIQ EL2t
36 ventry __invalid // Error EL2t
38 ventry __invalid // Synchronous EL2h
39 ventry __invalid // IRQ EL2h
40 ventry __invalid // FIQ EL2h
41 ventry __invalid // Error EL2h
43 ventry __do_hyp_init // Synchronous 64-bit EL1
44 ventry __invalid // IRQ 64-bit EL1
45 ventry __invalid // FIQ 64-bit EL1
46 ventry __invalid // Error 64-bit EL1
48 ventry __invalid // Synchronous 32-bit EL1
49 ventry __invalid // IRQ 32-bit EL1
50 ventry __invalid // FIQ 32-bit EL1
51 ventry __invalid // Error 32-bit EL1
63 /* Check for a stub HVC call */
64 cmp x0, #HVC_STUB_HCALL_NR
65 b.lo __kvm_handle_stub_hvc
77 * The ID map may be configured to use an extended virtual address
78 * range. This is only the case if system RAM is out of range for the
79 * currently configured page size and VA_BITS, in which case we will
80 * also need the extended virtual range for the HYP ID map, or we won't
81 * be able to enable the EL2 MMU.
83 * However, at EL2, there is only one TTBR register, and we can't switch
84 * between translation tables *and* update TCR_EL2.T0SZ at the same
85 * time. Bottom line: we need to use the extended range with *both* our
88 * So use the same T0SZ value we use for the ID map.
91 bfi x4, x5, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH
94 * Set the PS bits in TCR_EL2.
96 tcr_compute_pa_size x4, #TCR_EL2_PS_SHIFT, x5, x6
104 /* Invalidate the stale TLBs from Bootloader */
109 * Preserve all the RES1 bits while setting the default flags,
110 * as well as the EE bit on BE. Drop the A flag since the compiler
111 * is allowed to generate unaligned accesses.
113 ldr x4, =(SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A))
114 CPU_BE( orr x4, x4, #SCTLR_ELx_EE)
118 /* Set the stack and new vectors */
123 /* Set tpidr_el2 for use by HYP */
128 ENDPROC(__kvm_hyp_init)
130 ENTRY(__kvm_handle_stub_hvc)
131 cmp x0, #HVC_SOFT_RESTART
134 /* This is where we're about to jump, staying at EL2 */
136 mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT | PSR_MODE_EL2h)
139 /* Shuffle the arguments, and don't come back */
145 1: cmp x0, #HVC_RESET_VECTORS
149 * Reset kvm back to the hyp stub. Do not clobber x0-x4 in
150 * case we coming via HVC_SOFT_RESTART.
153 ldr x6, =SCTLR_ELx_FLAGS
154 bic x5, x5, x6 // Clear SCTL_M and etc
155 pre_disable_mmu_workaround
159 /* Install stub vectors */
160 adr_l x5, __hyp_stub_vectors
165 1: /* Bad stub call */
166 ldr x0, =HVC_STUB_ERR
169 ENDPROC(__kvm_handle_stub_hvc)