Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 - Virtual Open Systems and Columbia University |
| 3 | * Author: Christoffer Dall <c.dall@virtualopensystems.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License, version 2, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | */ |
| 18 | #include <linux/compiler.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/kvm_host.h> |
| 22 | #include <linux/kvm.h> |
| 23 | |
| 24 | #include <asm/unified.h> |
| 25 | #include <asm/ptrace.h> |
| 26 | #include <asm/cputype.h> |
| 27 | #include <asm/kvm_arm.h> |
| 28 | #include <asm/kvm_coproc.h> |
| 29 | |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 30 | #include <kvm/arm_arch_timer.h> |
| 31 | |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 32 | /****************************************************************************** |
| 33 | * Cortex-A15 Reset Values |
| 34 | */ |
| 35 | |
| 36 | static const int a15_max_cpu_idx = 3; |
| 37 | |
| 38 | static struct kvm_regs a15_regs_reset = { |
| 39 | .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, |
| 40 | }; |
| 41 | |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 42 | static const struct kvm_irq_level a15_vtimer_irq = { |
Christoffer Dall | 6833d83 | 2013-08-19 14:16:57 -0700 | [diff] [blame] | 43 | { .irq = 27 }, |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 44 | .level = 1, |
| 45 | }; |
| 46 | |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 47 | |
| 48 | /******************************************************************************* |
| 49 | * Exported reset function |
| 50 | */ |
| 51 | |
| 52 | /** |
| 53 | * kvm_reset_vcpu - sets core registers and cp15 registers to reset value |
| 54 | * @vcpu: The VCPU pointer |
| 55 | * |
| 56 | * This function finds the right table above and sets the registers on the |
| 57 | * virtual CPU struct to their architectually defined reset values. |
| 58 | */ |
| 59 | int kvm_reset_vcpu(struct kvm_vcpu *vcpu) |
| 60 | { |
| 61 | struct kvm_regs *cpu_reset; |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 62 | const struct kvm_irq_level *cpu_vtimer_irq; |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 63 | |
| 64 | switch (vcpu->arch.target) { |
| 65 | case KVM_ARM_TARGET_CORTEX_A15: |
| 66 | if (vcpu->vcpu_id > a15_max_cpu_idx) |
| 67 | return -EINVAL; |
| 68 | cpu_reset = &a15_regs_reset; |
| 69 | vcpu->arch.midr = read_cpuid_id(); |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 70 | cpu_vtimer_irq = &a15_vtimer_irq; |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 71 | break; |
| 72 | default: |
| 73 | return -ENODEV; |
| 74 | } |
| 75 | |
| 76 | /* Reset core registers */ |
| 77 | memcpy(&vcpu->arch.regs, cpu_reset, sizeof(vcpu->arch.regs)); |
| 78 | |
| 79 | /* Reset CP15 registers */ |
| 80 | kvm_reset_coprocs(vcpu); |
| 81 | |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 82 | /* Reset arch_timer context */ |
| 83 | kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq); |
| 84 | |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 85 | return 0; |
| 86 | } |