blob: 1da8b2d145501c0a9fd26cac7854f0c59107d4ef [file] [log] [blame]
Christoffer Dall749cf76c2013-01-20 18:28:06 -05001/*
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 Patel5ae7f872013-04-30 12:02:15 +053030#include <kvm/arm_arch_timer.h>
31
Christoffer Dall749cf76c2013-01-20 18:28:06 -050032/******************************************************************************
Jonathan Austine8c2d992013-09-26 16:49:28 +010033 * Cortex-A15 and Cortex-A7 Reset Values
Christoffer Dall749cf76c2013-01-20 18:28:06 -050034 */
35
Jonathan Austine8c2d992013-09-26 16:49:28 +010036static struct kvm_regs cortexa_regs_reset = {
Christoffer Dall749cf76c2013-01-20 18:28:06 -050037 .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT,
38};
39
Jintack Lima91d1852017-02-03 10:20:03 -050040static const struct kvm_irq_level cortexa_ptimer_irq = {
41 { .irq = 30 },
42 .level = 1,
43};
44
Jonathan Austine8c2d992013-09-26 16:49:28 +010045static const struct kvm_irq_level cortexa_vtimer_irq = {
Christoffer Dall6833d832013-08-19 14:16:57 -070046 { .irq = 27 },
Anup Patel5ae7f872013-04-30 12:02:15 +053047 .level = 1,
48};
49
Christoffer Dall749cf76c2013-01-20 18:28:06 -050050
51/*******************************************************************************
52 * Exported reset function
53 */
54
55/**
56 * kvm_reset_vcpu - sets core registers and cp15 registers to reset value
57 * @vcpu: The VCPU pointer
58 *
59 * This function finds the right table above and sets the registers on the
Andrea Gelmini6a727b02016-05-21 13:48:35 +020060 * virtual CPU struct to their architecturally defined reset values.
Christoffer Dall749cf76c2013-01-20 18:28:06 -050061 */
62int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
63{
Olof Johanssonac570e02013-09-11 15:27:41 -070064 struct kvm_regs *reset_regs;
Anup Patel5ae7f872013-04-30 12:02:15 +053065 const struct kvm_irq_level *cpu_vtimer_irq;
Jintack Lima91d1852017-02-03 10:20:03 -050066 const struct kvm_irq_level *cpu_ptimer_irq;
Christoffer Dall749cf76c2013-01-20 18:28:06 -050067
68 switch (vcpu->arch.target) {
Jonathan Austine8c2d992013-09-26 16:49:28 +010069 case KVM_ARM_TARGET_CORTEX_A7:
Christoffer Dall749cf76c2013-01-20 18:28:06 -050070 case KVM_ARM_TARGET_CORTEX_A15:
Gleb Natapov13acfd52013-10-17 17:04:47 +030071 reset_regs = &cortexa_regs_reset;
Christoffer Dall749cf76c2013-01-20 18:28:06 -050072 vcpu->arch.midr = read_cpuid_id();
Jonathan Austine8c2d992013-09-26 16:49:28 +010073 cpu_vtimer_irq = &cortexa_vtimer_irq;
Jintack Lima91d1852017-02-03 10:20:03 -050074 cpu_ptimer_irq = &cortexa_ptimer_irq;
Christoffer Dall749cf76c2013-01-20 18:28:06 -050075 break;
76 default:
77 return -ENODEV;
78 }
79
80 /* Reset core registers */
Marc Zyngierc2a8dab5072016-01-03 11:26:01 +000081 memcpy(&vcpu->arch.ctxt.gp_regs, reset_regs, sizeof(vcpu->arch.ctxt.gp_regs));
Christoffer Dall749cf76c2013-01-20 18:28:06 -050082
83 /* Reset CP15 registers */
84 kvm_reset_coprocs(vcpu);
85
Anup Patel5ae7f872013-04-30 12:02:15 +053086 /* Reset arch_timer context */
Jintack Lima91d1852017-02-03 10:20:03 -050087 return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq, cpu_ptimer_irq);
Christoffer Dall749cf76c2013-01-20 18:28:06 -050088}