hyp-stub.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Hypervisor stub
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Marc Zyngier <marc.zyngier@arm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/linkage.h>
  21. #include <linux/irqchip/arm-gic-v3.h>
  22. #include <asm/assembler.h>
  23. #include <asm/kvm_arm.h>
  24. #include <asm/kvm_asm.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/virt.h>
  27. .text
  28. .align 11
  29. ENTRY(__hyp_stub_vectors)
  30. ventry el2_sync_invalid // Synchronous EL2t
  31. ventry el2_irq_invalid // IRQ EL2t
  32. ventry el2_fiq_invalid // FIQ EL2t
  33. ventry el2_error_invalid // Error EL2t
  34. ventry el2_sync_invalid // Synchronous EL2h
  35. ventry el2_irq_invalid // IRQ EL2h
  36. ventry el2_fiq_invalid // FIQ EL2h
  37. ventry el2_error_invalid // Error EL2h
  38. ventry el1_sync // Synchronous 64-bit EL1
  39. ventry el1_irq_invalid // IRQ 64-bit EL1
  40. ventry el1_fiq_invalid // FIQ 64-bit EL1
  41. ventry el1_error_invalid // Error 64-bit EL1
  42. ventry el1_sync_invalid // Synchronous 32-bit EL1
  43. ventry el1_irq_invalid // IRQ 32-bit EL1
  44. ventry el1_fiq_invalid // FIQ 32-bit EL1
  45. ventry el1_error_invalid // Error 32-bit EL1
  46. ENDPROC(__hyp_stub_vectors)
  47. .align 11
  48. el1_sync:
  49. mrs x30, esr_el2
  50. lsr x30, x30, #ESR_ELx_EC_SHIFT
  51. cmp x30, #ESR_ELx_EC_HVC64
  52. b.ne 9f // Not an HVC trap
  53. cmp x0, #HVC_GET_VECTORS
  54. b.ne 1f
  55. mrs x0, vbar_el2
  56. b 9f
  57. 1: cmp x0, #HVC_SET_VECTORS
  58. b.ne 2f
  59. msr vbar_el2, x1
  60. b 9f
  61. 2: cmp x0, #HVC_SOFT_RESTART
  62. b.ne 3f
  63. mov x0, x2
  64. mov x2, x4
  65. mov x4, x1
  66. mov x1, x3
  67. br x4 // no return
  68. /* Someone called kvm_call_hyp() against the hyp-stub... */
  69. 3: mov x0, #ARM_EXCEPTION_HYP_GONE
  70. 9: eret
  71. ENDPROC(el1_sync)
  72. .macro invalid_vector label
  73. \label:
  74. b \label
  75. ENDPROC(\label)
  76. .endm
  77. invalid_vector el2_sync_invalid
  78. invalid_vector el2_irq_invalid
  79. invalid_vector el2_fiq_invalid
  80. invalid_vector el2_error_invalid
  81. invalid_vector el1_sync_invalid
  82. invalid_vector el1_irq_invalid
  83. invalid_vector el1_fiq_invalid
  84. invalid_vector el1_error_invalid
  85. /*
  86. * __hyp_set_vectors: Call this after boot to set the initial hypervisor
  87. * vectors as part of hypervisor installation. On an SMP system, this should
  88. * be called on each CPU.
  89. *
  90. * x0 must be the physical address of the new vector table, and must be
  91. * 2KB aligned.
  92. *
  93. * Before calling this, you must check that the stub hypervisor is installed
  94. * everywhere, by waiting for any secondary CPUs to be brought up and then
  95. * checking that is_hyp_mode_available() is true.
  96. *
  97. * If not, there is a pre-existing hypervisor, some CPUs failed to boot, or
  98. * something else went wrong... in such cases, trying to install a new
  99. * hypervisor is unlikely to work as desired.
  100. *
  101. * When you call into your shiny new hypervisor, sp_el2 will contain junk,
  102. * so you will need to set that to something sensible at the new hypervisor's
  103. * initialisation entry point.
  104. */
  105. ENTRY(__hyp_get_vectors)
  106. str lr, [sp, #-16]!
  107. mov x0, #HVC_GET_VECTORS
  108. hvc #0
  109. ldr lr, [sp], #16
  110. ret
  111. ENDPROC(__hyp_get_vectors)
  112. ENTRY(__hyp_set_vectors)
  113. str lr, [sp, #-16]!
  114. mov x1, x0
  115. mov x0, #HVC_SET_VECTORS
  116. hvc #0
  117. ldr lr, [sp], #16
  118. ret
  119. ENDPROC(__hyp_set_vectors)