arm64: dts: rockchip: amend usb-otg related nodes for rk3368-tb
[firefly-linux-kernel-4.4.55.git] / arch / arm64 / kvm / reset.c
1 /*
2  * Copyright (C) 2012,2013 - ARM Ltd
3  * Author: Marc Zyngier <marc.zyngier@arm.com>
4  *
5  * Derived from arch/arm/kvm/reset.c
6  * Copyright (C) 2012 - Virtual Open Systems and Columbia University
7  * Author: Christoffer Dall <c.dall@virtualopensystems.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #include <linux/errno.h>
23 #include <linux/kvm_host.h>
24 #include <linux/kvm.h>
25 #include <linux/hw_breakpoint.h>
26
27 #include <kvm/arm_arch_timer.h>
28
29 #include <asm/cputype.h>
30 #include <asm/ptrace.h>
31 #include <asm/kvm_arm.h>
32 #include <asm/kvm_asm.h>
33 #include <asm/kvm_coproc.h>
34 #include <asm/kvm_mmu.h>
35
36 /*
37  * ARMv8 Reset Values
38  */
39 static const struct kvm_regs default_regs_reset = {
40         .regs.pstate = (PSR_MODE_EL1h | PSR_A_BIT | PSR_I_BIT |
41                         PSR_F_BIT | PSR_D_BIT),
42 };
43
44 static const struct kvm_regs default_regs_reset32 = {
45         .regs.pstate = (COMPAT_PSR_MODE_SVC | COMPAT_PSR_A_BIT |
46                         COMPAT_PSR_I_BIT | COMPAT_PSR_F_BIT),
47 };
48
49 static const struct kvm_irq_level default_vtimer_irq = {
50         .irq    = 27,
51         .level  = 1,
52 };
53
54 static bool cpu_has_32bit_el1(void)
55 {
56         u64 pfr0;
57
58         pfr0 = read_system_reg(SYS_ID_AA64PFR0_EL1);
59         return !!(pfr0 & 0x20);
60 }
61
62 /**
63  * kvm_arch_dev_ioctl_check_extension
64  *
65  * We currently assume that the number of HW registers is uniform
66  * across all CPUs (see cpuinfo_sanity_check).
67  */
68 int kvm_arch_dev_ioctl_check_extension(long ext)
69 {
70         int r;
71
72         switch (ext) {
73         case KVM_CAP_ARM_EL1_32BIT:
74                 r = cpu_has_32bit_el1();
75                 break;
76         case KVM_CAP_GUEST_DEBUG_HW_BPS:
77                 r = get_num_brps();
78                 break;
79         case KVM_CAP_GUEST_DEBUG_HW_WPS:
80                 r = get_num_wrps();
81                 break;
82         case KVM_CAP_SET_GUEST_DEBUG:
83                 r = 1;
84                 break;
85         default:
86                 r = 0;
87         }
88
89         return r;
90 }
91
92 /**
93  * kvm_reset_vcpu - sets core registers and sys_regs to reset value
94  * @vcpu: The VCPU pointer
95  *
96  * This function finds the right table above and sets the registers on
97  * the virtual CPU struct to their architectually defined reset
98  * values.
99  */
100 int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
101 {
102         const struct kvm_irq_level *cpu_vtimer_irq;
103         const struct kvm_regs *cpu_reset;
104
105         switch (vcpu->arch.target) {
106         default:
107                 if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
108                         if (!cpu_has_32bit_el1())
109                                 return -EINVAL;
110                         cpu_reset = &default_regs_reset32;
111                 } else {
112                         cpu_reset = &default_regs_reset;
113                 }
114
115                 cpu_vtimer_irq = &default_vtimer_irq;
116                 break;
117         }
118
119         /* Reset core registers */
120         memcpy(vcpu_gp_regs(vcpu), cpu_reset, sizeof(*cpu_reset));
121
122         /* Reset system registers */
123         kvm_reset_sys_regs(vcpu);
124
125         /* Reset timer */
126         return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq);
127 }
128
129 extern char __hyp_idmap_text_start[];
130
131 phys_addr_t kvm_hyp_reset_entry(void)
132 {
133         unsigned long offset;
134
135         offset = (unsigned long)__kvm_hyp_reset
136                  - ((unsigned long)__hyp_idmap_text_start & PAGE_MASK);
137
138         return TRAMPOLINE_VA + offset;
139 }