reset.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <asm/unified.h>
  24. #include <asm/ptrace.h>
  25. #include <asm/cputype.h>
  26. #include <asm/kvm_arm.h>
  27. #include <asm/kvm_coproc.h>
  28. #include <kvm/arm_arch_timer.h>
  29. /******************************************************************************
  30. * Cortex-A15 and Cortex-A7 Reset Values
  31. */
  32. static const int cortexa_max_cpu_idx = 3;
  33. static struct kvm_regs cortexa_regs_reset = {
  34. .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT,
  35. };
  36. static const struct kvm_irq_level cortexa_vtimer_irq = {
  37. { .irq = 27 },
  38. .level = 1,
  39. };
  40. /*******************************************************************************
  41. * Exported reset function
  42. */
  43. /**
  44. * kvm_reset_vcpu - sets core registers and cp15 registers to reset value
  45. * @vcpu: The VCPU pointer
  46. *
  47. * This function finds the right table above and sets the registers on the
  48. * virtual CPU struct to their architectually defined reset values.
  49. */
  50. int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
  51. {
  52. struct kvm_regs *cpu_reset;
  53. const struct kvm_irq_level *cpu_vtimer_irq;
  54. switch (vcpu->arch.target) {
  55. case KVM_ARM_TARGET_CORTEX_A7:
  56. case KVM_ARM_TARGET_CORTEX_A15:
  57. if (vcpu->vcpu_id > cortexa_max_cpu_idx)
  58. return -EINVAL;
  59. cpu_reset = &cortexa_regs_reset;
  60. vcpu->arch.midr = read_cpuid_id();
  61. cpu_vtimer_irq = &cortexa_vtimer_irq;
  62. break;
  63. default:
  64. return -ENODEV;
  65. }
  66. /* Reset core registers */
  67. memcpy(&vcpu->arch.regs, cpu_reset, sizeof(vcpu->arch.regs));
  68. /* Reset CP15 registers */
  69. kvm_reset_coprocs(vcpu);
  70. /* Reset arch_timer context */
  71. kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq);
  72. return 0;
  73. }