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 | /****************************************************************************** |
Jonathan Austin | e8c2d99 | 2013-09-26 16:49:28 +0100 | [diff] [blame] | 33 | * Cortex-A15 and Cortex-A7 Reset Values |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 34 | */ |
| 35 | |
Jonathan Austin | e8c2d99 | 2013-09-26 16:49:28 +0100 | [diff] [blame] | 36 | static struct kvm_regs cortexa_regs_reset = { |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 37 | .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | /******************************************************************************* |
| 42 | * Exported reset function |
| 43 | */ |
| 44 | |
| 45 | /** |
| 46 | * kvm_reset_vcpu - sets core registers and cp15 registers to reset value |
| 47 | * @vcpu: The VCPU pointer |
| 48 | * |
| 49 | * This function finds the right table above and sets the registers on the |
Andrea Gelmini | 6a727b0 | 2016-05-21 13:48:35 +0200 | [diff] [blame] | 50 | * virtual CPU struct to their architecturally defined reset values. |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 51 | */ |
| 52 | int kvm_reset_vcpu(struct kvm_vcpu *vcpu) |
| 53 | { |
Olof Johansson | ac570e0 | 2013-09-11 15:27:41 -0700 | [diff] [blame] | 54 | struct kvm_regs *reset_regs; |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 55 | |
| 56 | switch (vcpu->arch.target) { |
Jonathan Austin | e8c2d99 | 2013-09-26 16:49:28 +0100 | [diff] [blame] | 57 | case KVM_ARM_TARGET_CORTEX_A7: |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 58 | case KVM_ARM_TARGET_CORTEX_A15: |
Gleb Natapov | 13acfd5 | 2013-10-17 17:04:47 +0300 | [diff] [blame] | 59 | reset_regs = &cortexa_regs_reset; |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 60 | vcpu->arch.midr = read_cpuid_id(); |
| 61 | break; |
| 62 | default: |
| 63 | return -ENODEV; |
| 64 | } |
| 65 | |
| 66 | /* Reset core registers */ |
Marc Zyngier | c2a8dab507 | 2016-01-03 11:26:01 +0000 | [diff] [blame] | 67 | memcpy(&vcpu->arch.ctxt.gp_regs, reset_regs, sizeof(vcpu->arch.ctxt.gp_regs)); |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 68 | |
| 69 | /* Reset CP15 registers */ |
| 70 | kvm_reset_coprocs(vcpu); |
| 71 | |
Anup Patel | 5ae7f87 | 2013-04-30 12:02:15 +0530 | [diff] [blame] | 72 | /* Reset arch_timer context */ |
Christoffer Dall | 85e69ad | 2017-05-02 20:14:06 +0200 | [diff] [blame] | 73 | return kvm_timer_vcpu_reset(vcpu); |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 74 | } |