cp15-sr.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Original code:
  3. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  4. * Author: Christoffer Dall <c.dall@virtualopensystems.com>
  5. *
  6. * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <asm/kvm_hyp.h>
  21. static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx)
  22. {
  23. return (u64 *)(ctxt->cp15 + idx);
  24. }
  25. void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
  26. {
  27. ctxt->cp15[c0_MPIDR] = read_sysreg(VMPIDR);
  28. ctxt->cp15[c0_CSSELR] = read_sysreg(CSSELR);
  29. ctxt->cp15[c1_SCTLR] = read_sysreg(SCTLR);
  30. ctxt->cp15[c1_CPACR] = read_sysreg(CPACR);
  31. *cp15_64(ctxt, c2_TTBR0) = read_sysreg(TTBR0);
  32. *cp15_64(ctxt, c2_TTBR1) = read_sysreg(TTBR1);
  33. ctxt->cp15[c2_TTBCR] = read_sysreg(TTBCR);
  34. ctxt->cp15[c3_DACR] = read_sysreg(DACR);
  35. ctxt->cp15[c5_DFSR] = read_sysreg(DFSR);
  36. ctxt->cp15[c5_IFSR] = read_sysreg(IFSR);
  37. ctxt->cp15[c5_ADFSR] = read_sysreg(ADFSR);
  38. ctxt->cp15[c5_AIFSR] = read_sysreg(AIFSR);
  39. ctxt->cp15[c6_DFAR] = read_sysreg(DFAR);
  40. ctxt->cp15[c6_IFAR] = read_sysreg(IFAR);
  41. *cp15_64(ctxt, c7_PAR) = read_sysreg(PAR);
  42. ctxt->cp15[c10_PRRR] = read_sysreg(PRRR);
  43. ctxt->cp15[c10_NMRR] = read_sysreg(NMRR);
  44. ctxt->cp15[c10_AMAIR0] = read_sysreg(AMAIR0);
  45. ctxt->cp15[c10_AMAIR1] = read_sysreg(AMAIR1);
  46. ctxt->cp15[c12_VBAR] = read_sysreg(VBAR);
  47. ctxt->cp15[c13_CID] = read_sysreg(CID);
  48. ctxt->cp15[c13_TID_URW] = read_sysreg(TID_URW);
  49. ctxt->cp15[c13_TID_URO] = read_sysreg(TID_URO);
  50. ctxt->cp15[c13_TID_PRIV] = read_sysreg(TID_PRIV);
  51. ctxt->cp15[c14_CNTKCTL] = read_sysreg(CNTKCTL);
  52. }
  53. void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
  54. {
  55. write_sysreg(ctxt->cp15[c0_MPIDR], VMPIDR);
  56. write_sysreg(ctxt->cp15[c0_CSSELR], CSSELR);
  57. write_sysreg(ctxt->cp15[c1_SCTLR], SCTLR);
  58. write_sysreg(ctxt->cp15[c1_CPACR], CPACR);
  59. write_sysreg(*cp15_64(ctxt, c2_TTBR0), TTBR0);
  60. write_sysreg(*cp15_64(ctxt, c2_TTBR1), TTBR1);
  61. write_sysreg(ctxt->cp15[c2_TTBCR], TTBCR);
  62. write_sysreg(ctxt->cp15[c3_DACR], DACR);
  63. write_sysreg(ctxt->cp15[c5_DFSR], DFSR);
  64. write_sysreg(ctxt->cp15[c5_IFSR], IFSR);
  65. write_sysreg(ctxt->cp15[c5_ADFSR], ADFSR);
  66. write_sysreg(ctxt->cp15[c5_AIFSR], AIFSR);
  67. write_sysreg(ctxt->cp15[c6_DFAR], DFAR);
  68. write_sysreg(ctxt->cp15[c6_IFAR], IFAR);
  69. write_sysreg(*cp15_64(ctxt, c7_PAR), PAR);
  70. write_sysreg(ctxt->cp15[c10_PRRR], PRRR);
  71. write_sysreg(ctxt->cp15[c10_NMRR], NMRR);
  72. write_sysreg(ctxt->cp15[c10_AMAIR0], AMAIR0);
  73. write_sysreg(ctxt->cp15[c10_AMAIR1], AMAIR1);
  74. write_sysreg(ctxt->cp15[c12_VBAR], VBAR);
  75. write_sysreg(ctxt->cp15[c13_CID], CID);
  76. write_sysreg(ctxt->cp15[c13_TID_URW], TID_URW);
  77. write_sysreg(ctxt->cp15[c13_TID_URO], TID_URO);
  78. write_sysreg(ctxt->cp15[c13_TID_PRIV], TID_PRIV);
  79. write_sysreg(ctxt->cp15[c14_CNTKCTL], CNTKCTL);
  80. }