arm64: hyp/kvm: Make hyp-stub extensible
[linux-2.6-block.git] / arch / arm64 / kernel / hyp-stub.S
CommitLineData
712c6ff4
MZ
1/*
2 * Hypervisor stub
3 *
4 * Copyright (C) 2012 ARM Ltd.
5 * Author: Marc Zyngier <marc.zyngier@arm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/init.h>
21#include <linux/linkage.h>
021f6537 22#include <linux/irqchip/arm-gic-v3.h>
712c6ff4
MZ
23
24#include <asm/assembler.h>
ad72e59f 25#include <asm/kvm_arm.h>
712c6ff4
MZ
26#include <asm/ptrace.h>
27#include <asm/virt.h>
28
29 .text
30 .align 11
31
32ENTRY(__hyp_stub_vectors)
33 ventry el2_sync_invalid // Synchronous EL2t
34 ventry el2_irq_invalid // IRQ EL2t
35 ventry el2_fiq_invalid // FIQ EL2t
36 ventry el2_error_invalid // Error EL2t
37
38 ventry el2_sync_invalid // Synchronous EL2h
39 ventry el2_irq_invalid // IRQ EL2h
40 ventry el2_fiq_invalid // FIQ EL2h
41 ventry el2_error_invalid // Error EL2h
42
43 ventry el1_sync // Synchronous 64-bit EL1
44 ventry el1_irq_invalid // IRQ 64-bit EL1
45 ventry el1_fiq_invalid // FIQ 64-bit EL1
46 ventry el1_error_invalid // Error 64-bit EL1
47
48 ventry el1_sync_invalid // Synchronous 32-bit EL1
49 ventry el1_irq_invalid // IRQ 32-bit EL1
50 ventry el1_fiq_invalid // FIQ 32-bit EL1
51 ventry el1_error_invalid // Error 32-bit EL1
52ENDPROC(__hyp_stub_vectors)
53
54 .align 11
55
56el1_sync:
ad72e59f
GL
57 mrs x30, esr_el2
58 lsr x30, x30, #ESR_ELx_EC_SHIFT
59
60 cmp x30, #ESR_ELx_EC_HVC64
61 b.ne 9f // Not an HVC trap
62
63 cmp x0, #HVC_GET_VECTORS
64 b.ne 1f
65 mrs x0, vbar_el2
66 b 9f
67
681: cmp x0, #HVC_SET_VECTORS
69 b.ne 2f
70 msr vbar_el2, x1
71 b 9f
72
73 /* Unrecognised call type */
742: mov x0, xzr
75
769: eret
712c6ff4
MZ
77ENDPROC(el1_sync)
78
79.macro invalid_vector label
80\label:
81 b \label
82ENDPROC(\label)
83.endm
84
85 invalid_vector el2_sync_invalid
86 invalid_vector el2_irq_invalid
87 invalid_vector el2_fiq_invalid
88 invalid_vector el2_error_invalid
89 invalid_vector el1_sync_invalid
90 invalid_vector el1_irq_invalid
91 invalid_vector el1_fiq_invalid
92 invalid_vector el1_error_invalid
93
94/*
95 * __hyp_set_vectors: Call this after boot to set the initial hypervisor
96 * vectors as part of hypervisor installation. On an SMP system, this should
97 * be called on each CPU.
98 *
99 * x0 must be the physical address of the new vector table, and must be
100 * 2KB aligned.
101 *
102 * Before calling this, you must check that the stub hypervisor is installed
103 * everywhere, by waiting for any secondary CPUs to be brought up and then
104 * checking that is_hyp_mode_available() is true.
105 *
106 * If not, there is a pre-existing hypervisor, some CPUs failed to boot, or
107 * something else went wrong... in such cases, trying to install a new
108 * hypervisor is unlikely to work as desired.
109 *
110 * When you call into your shiny new hypervisor, sp_el2 will contain junk,
111 * so you will need to set that to something sensible at the new hypervisor's
112 * initialisation entry point.
113 */
114
115ENTRY(__hyp_get_vectors)
00a44cda 116 str lr, [sp, #-16]!
ad72e59f 117 mov x0, #HVC_GET_VECTORS
712c6ff4 118 hvc #0
00a44cda 119 ldr lr, [sp], #16
712c6ff4
MZ
120 ret
121ENDPROC(__hyp_get_vectors)
00a44cda
JM
122
123ENTRY(__hyp_set_vectors)
124 str lr, [sp, #-16]!
ad72e59f
GL
125 mov x1, x0
126 mov x0, #HVC_SET_VECTORS
00a44cda
JM
127 hvc #0
128 ldr lr, [sp], #16
129 ret
712c6ff4 130ENDPROC(__hyp_set_vectors)