reset.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /******************************************************************************
  29. * Cortex-A15 Reset Values
  30. */
  31. static const int a15_max_cpu_idx = 3;
  32. static struct kvm_regs a15_regs_reset = {
  33. .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT,
  34. };
  35. /*******************************************************************************
  36. * Exported reset function
  37. */
  38. /**
  39. * kvm_reset_vcpu - sets core registers and cp15 registers to reset value
  40. * @vcpu: The VCPU pointer
  41. *
  42. * This function finds the right table above and sets the registers on the
  43. * virtual CPU struct to their architectually defined reset values.
  44. */
  45. int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
  46. {
  47. struct kvm_regs *cpu_reset;
  48. switch (vcpu->arch.target) {
  49. case KVM_ARM_TARGET_CORTEX_A15:
  50. if (vcpu->vcpu_id > a15_max_cpu_idx)
  51. return -EINVAL;
  52. cpu_reset = &a15_regs_reset;
  53. vcpu->arch.midr = read_cpuid_id();
  54. break;
  55. default:
  56. return -ENODEV;
  57. }
  58. /* Reset core registers */
  59. memcpy(&vcpu->arch.regs, cpu_reset, sizeof(vcpu->arch.regs));
  60. /* Reset CP15 registers */
  61. kvm_reset_coprocs(vcpu);
  62. return 0;
  63. }