Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 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 | |
Marc Zyngier | 003300d | 2012-12-07 17:52:03 +0000 | [diff] [blame] | 26 | #include <kvm/arm_arch_timer.h> |
| 27 | |
Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 28 | #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 | */ |
| 36 | static 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 Zyngier | 003300d | 2012-12-07 17:52:03 +0000 | [diff] [blame] | 41 | static const struct kvm_irq_level default_vtimer_irq = { |
| 42 | .irq = 27, |
| 43 | .level = 1, |
| 44 | }; |
| 45 | |
Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 46 | int 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 | */ |
| 66 | int kvm_reset_vcpu(struct kvm_vcpu *vcpu) |
| 67 | { |
Marc Zyngier | 003300d | 2012-12-07 17:52:03 +0000 | [diff] [blame] | 68 | const struct kvm_irq_level *cpu_vtimer_irq; |
Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 69 | const struct kvm_regs *cpu_reset; |
| 70 | |
| 71 | switch (vcpu->arch.target) { |
| 72 | default: |
| 73 | cpu_reset = &default_regs_reset; |
Marc Zyngier | 003300d | 2012-12-07 17:52:03 +0000 | [diff] [blame] | 74 | cpu_vtimer_irq = &default_vtimer_irq; |
Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 75 | 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 Zyngier | 003300d | 2012-12-07 17:52:03 +0000 | [diff] [blame] | 84 | /* Reset timer */ |
| 85 | kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq); |
| 86 | |
Marc Zyngier | f467275 | 2012-12-10 16:23:59 +0000 | [diff] [blame] | 87 | return 0; |
| 88 | } |