hyp-init.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <asm/assembler.h>
  19. #include <asm/kvm_arm.h>
  20. #include <asm/kvm_mmu.h>
  21. .text
  22. .pushsection .hyp.idmap.text, "ax"
  23. .align 11
  24. ENTRY(__kvm_hyp_init)
  25. ventry __invalid // Synchronous EL2t
  26. ventry __invalid // IRQ EL2t
  27. ventry __invalid // FIQ EL2t
  28. ventry __invalid // Error EL2t
  29. ventry __invalid // Synchronous EL2h
  30. ventry __invalid // IRQ EL2h
  31. ventry __invalid // FIQ EL2h
  32. ventry __invalid // Error EL2h
  33. ventry __do_hyp_init // Synchronous 64-bit EL1
  34. ventry __invalid // IRQ 64-bit EL1
  35. ventry __invalid // FIQ 64-bit EL1
  36. ventry __invalid // Error 64-bit EL1
  37. ventry __invalid // Synchronous 32-bit EL1
  38. ventry __invalid // IRQ 32-bit EL1
  39. ventry __invalid // FIQ 32-bit EL1
  40. ventry __invalid // Error 32-bit EL1
  41. __invalid:
  42. b .
  43. /*
  44. * x0: HYP boot pgd
  45. * x1: HYP pgd
  46. * x2: HYP stack
  47. * x3: HYP vectors
  48. */
  49. __do_hyp_init:
  50. msr ttbr0_el2, x0
  51. mrs x4, tcr_el1
  52. ldr x5, =TCR_EL2_MASK
  53. and x4, x4, x5
  54. ldr x5, =TCR_EL2_FLAGS
  55. orr x4, x4, x5
  56. msr tcr_el2, x4
  57. ldr x4, =VTCR_EL2_FLAGS
  58. msr vtcr_el2, x4
  59. mrs x4, mair_el1
  60. msr mair_el2, x4
  61. isb
  62. mov x4, #SCTLR_EL2_FLAGS
  63. msr sctlr_el2, x4
  64. isb
  65. /* MMU is now enabled. Get ready for the trampoline dance */
  66. ldr x4, =TRAMPOLINE_VA
  67. adr x5, target
  68. bfi x4, x5, #0, #PAGE_SHIFT
  69. br x4
  70. target: /* We're now in the trampoline code, switch page tables */
  71. msr ttbr0_el2, x1
  72. isb
  73. /* Invalidate the old TLBs */
  74. tlbi alle2
  75. dsb sy
  76. /* Set the stack and new vectors */
  77. kern_hyp_va x2
  78. mov sp, x2
  79. kern_hyp_va x3
  80. msr vbar_el2, x3
  81. /* Hello, World! */
  82. eret
  83. ENDPROC(__kvm_hyp_init)
  84. .ltorg
  85. .popsection