hyp-init.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /*
  59. * Read the PARange bits from ID_AA64MMFR0_EL1 and set the PS bits in
  60. * VTCR_EL2.
  61. */
  62. mrs x5, ID_AA64MMFR0_EL1
  63. bfi x4, x5, #16, #3
  64. msr vtcr_el2, x4
  65. mrs x4, mair_el1
  66. msr mair_el2, x4
  67. isb
  68. /* Invalidate the stale TLBs from Bootloader */
  69. tlbi alle2
  70. dsb sy
  71. mrs x4, sctlr_el2
  72. and x4, x4, #SCTLR_EL2_EE // preserve endianness of EL2
  73. ldr x5, =SCTLR_EL2_FLAGS
  74. orr x4, x4, x5
  75. msr sctlr_el2, x4
  76. isb
  77. /* MMU is now enabled. Get ready for the trampoline dance */
  78. ldr x4, =TRAMPOLINE_VA
  79. adr x5, target
  80. bfi x4, x5, #0, #PAGE_SHIFT
  81. br x4
  82. target: /* We're now in the trampoline code, switch page tables */
  83. msr ttbr0_el2, x1
  84. isb
  85. /* Invalidate the old TLBs */
  86. tlbi alle2
  87. dsb sy
  88. /* Set the stack and new vectors */
  89. kern_hyp_va x2
  90. mov sp, x2
  91. kern_hyp_va x3
  92. msr vbar_el2, x3
  93. /* Hello, World! */
  94. eret
  95. ENDPROC(__kvm_hyp_init)
  96. .ltorg
  97. .popsection