vgic-v2-switch.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2012,2013 - ARM Ltd
  3. * Author: Marc Zyngier <marc.zyngier@arm.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, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/linkage.h>
  18. #include <linux/irqchip/arm-gic.h>
  19. #include <asm/assembler.h>
  20. #include <asm/memory.h>
  21. #include <asm/asm-offsets.h>
  22. #include <asm/kvm.h>
  23. #include <asm/kvm_asm.h>
  24. #include <asm/kvm_arm.h>
  25. #include <asm/kvm_mmu.h>
  26. .text
  27. .pushsection .hyp.text, "ax"
  28. /*
  29. * Save the VGIC CPU state into memory
  30. * x0: Register pointing to VCPU struct
  31. * Do not corrupt x1!!!
  32. */
  33. ENTRY(__save_vgic_v2_state)
  34. __save_vgic_v2_state:
  35. /* Get VGIC VCTRL base into x2 */
  36. ldr x2, [x0, #VCPU_KVM]
  37. kern_hyp_va x2
  38. ldr x2, [x2, #KVM_VGIC_VCTRL]
  39. kern_hyp_va x2
  40. cbz x2, 2f // disabled
  41. /* Compute the address of struct vgic_cpu */
  42. add x3, x0, #VCPU_VGIC_CPU
  43. /* Save all interesting registers */
  44. ldr w4, [x2, #GICH_HCR]
  45. ldr w5, [x2, #GICH_VMCR]
  46. ldr w6, [x2, #GICH_MISR]
  47. ldr w7, [x2, #GICH_EISR0]
  48. ldr w8, [x2, #GICH_EISR1]
  49. ldr w9, [x2, #GICH_ELRSR0]
  50. ldr w10, [x2, #GICH_ELRSR1]
  51. ldr w11, [x2, #GICH_APR]
  52. CPU_BE( rev w4, w4 )
  53. CPU_BE( rev w5, w5 )
  54. CPU_BE( rev w6, w6 )
  55. CPU_BE( rev w7, w7 )
  56. CPU_BE( rev w8, w8 )
  57. CPU_BE( rev w9, w9 )
  58. CPU_BE( rev w10, w10 )
  59. CPU_BE( rev w11, w11 )
  60. str w4, [x3, #VGIC_V2_CPU_HCR]
  61. str w5, [x3, #VGIC_V2_CPU_VMCR]
  62. str w6, [x3, #VGIC_V2_CPU_MISR]
  63. str w7, [x3, #VGIC_V2_CPU_EISR]
  64. str w8, [x3, #(VGIC_V2_CPU_EISR + 4)]
  65. str w9, [x3, #VGIC_V2_CPU_ELRSR]
  66. str w10, [x3, #(VGIC_V2_CPU_ELRSR + 4)]
  67. str w11, [x3, #VGIC_V2_CPU_APR]
  68. /* Clear GICH_HCR */
  69. str wzr, [x2, #GICH_HCR]
  70. /* Save list registers */
  71. add x2, x2, #GICH_LR0
  72. ldr w4, [x3, #VGIC_CPU_NR_LR]
  73. add x3, x3, #VGIC_V2_CPU_LR
  74. 1: ldr w5, [x2], #4
  75. CPU_BE( rev w5, w5 )
  76. str w5, [x3], #4
  77. sub w4, w4, #1
  78. cbnz w4, 1b
  79. 2:
  80. ret
  81. ENDPROC(__save_vgic_v2_state)
  82. /*
  83. * Restore the VGIC CPU state from memory
  84. * x0: Register pointing to VCPU struct
  85. */
  86. ENTRY(__restore_vgic_v2_state)
  87. __restore_vgic_v2_state:
  88. /* Get VGIC VCTRL base into x2 */
  89. ldr x2, [x0, #VCPU_KVM]
  90. kern_hyp_va x2
  91. ldr x2, [x2, #KVM_VGIC_VCTRL]
  92. kern_hyp_va x2
  93. cbz x2, 2f // disabled
  94. /* Compute the address of struct vgic_cpu */
  95. add x3, x0, #VCPU_VGIC_CPU
  96. /* We only restore a minimal set of registers */
  97. ldr w4, [x3, #VGIC_V2_CPU_HCR]
  98. ldr w5, [x3, #VGIC_V2_CPU_VMCR]
  99. ldr w6, [x3, #VGIC_V2_CPU_APR]
  100. CPU_BE( rev w4, w4 )
  101. CPU_BE( rev w5, w5 )
  102. CPU_BE( rev w6, w6 )
  103. str w4, [x2, #GICH_HCR]
  104. str w5, [x2, #GICH_VMCR]
  105. str w6, [x2, #GICH_APR]
  106. /* Restore list registers */
  107. add x2, x2, #GICH_LR0
  108. ldr w4, [x3, #VGIC_CPU_NR_LR]
  109. add x3, x3, #VGIC_V2_CPU_LR
  110. 1: ldr w5, [x3], #4
  111. CPU_BE( rev w5, w5 )
  112. str w5, [x2], #4
  113. sub w4, w4, #1
  114. cbnz w4, 1b
  115. 2:
  116. ret
  117. ENDPROC(__restore_vgic_v2_state)
  118. .popsection