blob: 766150ac76edbc54ea9281bfbaf4a912ba8934fe [file] [log] [blame]
Marc Zyngierf4672752012-12-10 16:23:59 +00001/*
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
Marc Zyngier003300d2012-12-07 17:52:03 +000026#include <kvm/arm_arch_timer.h>
27
Marc Zyngierf4672752012-12-10 16:23:59 +000028#include <asm/cputype.h>
29#include <asm/ptrace.h>
30#include <asm/kvm_arm.h>
31#include <asm/kvm_coproc.h>
32
33/*
34 * ARMv8 Reset Values
35 */
36static const struct kvm_regs default_regs_reset = {
37 .regs.pstate = (PSR_MODE_EL1h | PSR_A_BIT | PSR_I_BIT |
38 PSR_F_BIT | PSR_D_BIT),
39};
40
Marc Zyngier003300d2012-12-07 17:52:03 +000041static const struct kvm_irq_level default_vtimer_irq = {
42 .irq = 27,
43 .level = 1,
44};
45
Marc Zyngierf4672752012-12-10 16:23:59 +000046int kvm_arch_dev_ioctl_check_extension(long ext)
47{
48 int r;
49
50 switch (ext) {
51 default:
52 r = 0;
53 }
54
55 return r;
56}
57
58/**
59 * kvm_reset_vcpu - sets core registers and sys_regs to reset value
60 * @vcpu: The VCPU pointer
61 *
62 * This function finds the right table above and sets the registers on
63 * the virtual CPU struct to their architectually defined reset
64 * values.
65 */
66int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
67{
Marc Zyngier003300d2012-12-07 17:52:03 +000068 const struct kvm_irq_level *cpu_vtimer_irq;
Marc Zyngierf4672752012-12-10 16:23:59 +000069 const struct kvm_regs *cpu_reset;
70
71 switch (vcpu->arch.target) {
72 default:
73 cpu_reset = &default_regs_reset;
Marc Zyngier003300d2012-12-07 17:52:03 +000074 cpu_vtimer_irq = &default_vtimer_irq;
Marc Zyngierf4672752012-12-10 16:23:59 +000075 break;
76 }
77
78 /* Reset core registers */
79 memcpy(vcpu_gp_regs(vcpu), cpu_reset, sizeof(*cpu_reset));
80
81 /* Reset system registers */
82 kvm_reset_sys_regs(vcpu);
83
Marc Zyngier003300d2012-12-07 17:52:03 +000084 /* Reset timer */
85 kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq);
86
Marc Zyngierf4672752012-12-10 16:23:59 +000087 return 0;
88}