aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Zyngier <marc.zyngier@arm.com>2016-06-30 13:40:47 -0400
committerChristoffer Dall <christoffer.dall@linaro.org>2016-07-03 17:41:27 -0400
commitcd602a37e80c791adf2a256d2aedec60b898cd51 (patch)
tree5af07f63d90e1b9eddc1b3d4a2afdb798a824c7e
parent26781f9ce16801a9c680dae1a7c1ca2fd3d112bd (diff)
arm: KVM: Simplify HYP init
Just like for arm64, we can now make the HYP setup a lot simpler, and we can now initialise it in one go (instead of the two phases we currently have). Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
-rw-r--r--arch/arm/include/asm/kvm_host.h15
-rw-r--r--arch/arm/kvm/init.S49
2 files changed, 14 insertions, 50 deletions
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 020f4eb14f0b..eafbfd5ad34a 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -250,18 +250,13 @@ static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
250 * code. The init code doesn't need to preserve these 250 * code. The init code doesn't need to preserve these
251 * registers as r0-r3 are already callee saved according to 251 * registers as r0-r3 are already callee saved according to
252 * the AAPCS. 252 * the AAPCS.
253 * Note that we slightly misuse the prototype by casing the 253 * Note that we slightly misuse the prototype by casting the
254 * stack pointer to a void *. 254 * stack pointer to a void *.
255 *
256 * We don't have enough registers to perform the full init in
257 * one go. Install the boot PGD first, and then install the
258 * runtime PGD, stack pointer and vectors. The PGDs are always
259 * passed as the third argument, in order to be passed into
260 * r2-r3 to the init code (yes, this is compliant with the
261 * PCS!).
262 */
263 255
264 kvm_call_hyp(NULL, 0, boot_pgd_ptr); 256 * The PGDs are always passed as the third argument, in order
257 * to be passed into r2-r3 to the init code (yes, this is
258 * compliant with the PCS!).
259 */
265 260
266 kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr); 261 kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr);
267} 262}
diff --git a/arch/arm/kvm/init.S b/arch/arm/kvm/init.S
index 1f9ae17476f9..b82a99dcfb61 100644
--- a/arch/arm/kvm/init.S
+++ b/arch/arm/kvm/init.S
@@ -32,23 +32,13 @@
32 * r2,r3 = Hypervisor pgd pointer 32 * r2,r3 = Hypervisor pgd pointer
33 * 33 *
34 * The init scenario is: 34 * The init scenario is:
35 * - We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd, 35 * - We jump in HYP with 3 parameters: runtime HYP pgd, runtime stack,
36 * runtime stack, runtime vectors 36 * runtime vectors
37 * - Enable the MMU with the boot pgd
38 * - Jump to a target into the trampoline page (remember, this is the same
39 * physical page!)
40 * - Now switch to the runtime pgd (same VA, and still the same physical
41 * page!)
42 * - Invalidate TLBs 37 * - Invalidate TLBs
43 * - Set stack and vectors 38 * - Set stack and vectors
39 * - Setup the page tables
40 * - Enable the MMU
44 * - Profit! (or eret, if you only care about the code). 41 * - Profit! (or eret, if you only care about the code).
45 *
46 * As we only have four registers available to pass parameters (and we
47 * need six), we split the init in two phases:
48 * - Phase 1: r0 = 0, r1 = 0, r2,r3 contain the boot PGD.
49 * Provides the basic HYP init, and enable the MMU.
50 * - Phase 2: r0 = ToS, r1 = vectors, r2,r3 contain the runtime PGD.
51 * Switches to the runtime PGD, set stack and vectors.
52 */ 42 */
53 43
54 .text 44 .text
@@ -68,8 +58,11 @@ __kvm_hyp_init:
68 W(b) . 58 W(b) .
69 59
70__do_hyp_init: 60__do_hyp_init:
71 cmp r0, #0 @ We have a SP? 61 @ Set stack pointer
72 bne phase2 @ Yes, second stage init 62 mov sp, r0
63
64 @ Set HVBAR to point to the HYP vectors
65 mcr p15, 4, r1, c12, c0, 0 @ HVBAR
73 66
74 @ Set the HTTBR to point to the hypervisor PGD pointer passed 67 @ Set the HTTBR to point to the hypervisor PGD pointer passed
75 mcrr p15, 4, rr_lo_hi(r2, r3), c2 68 mcrr p15, 4, rr_lo_hi(r2, r3), c2
@@ -114,33 +107,9 @@ __do_hyp_init:
114 THUMB( ldr r2, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE) ) 107 THUMB( ldr r2, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE) )
115 orr r1, r1, r2 108 orr r1, r1, r2
116 orr r0, r0, r1 109 orr r0, r0, r1
117 isb
118 mcr p15, 4, r0, c1, c0, 0 @ HSCR 110 mcr p15, 4, r0, c1, c0, 0 @ HSCR
119
120 @ End of init phase-1
121 eret
122
123phase2:
124 @ Set stack pointer
125 mov sp, r0
126
127 @ Set HVBAR to point to the HYP vectors
128 mcr p15, 4, r1, c12, c0, 0 @ HVBAR
129
130 @ Jump to the trampoline page
131 ldr r0, =TRAMPOLINE_VA
132 adr r1, target
133 bfi r0, r1, #0, #PAGE_SHIFT
134 ret r0
135
136target: @ We're now in the trampoline code, switch page tables
137 mcrr p15, 4, rr_lo_hi(r2, r3), c2
138 isb 111 isb
139 112
140 @ Invalidate the old TLBs
141 mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH
142 dsb ish
143
144 eret 113 eret
145 114
146 .ltorg 115 .ltorg