init.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  3. * Author: Christoffer Dall <c.dall@virtualopensystems.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, write to the Free Software
  16. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include <linux/linkage.h>
  19. #include <asm/unified.h>
  20. #include <asm/asm-offsets.h>
  21. #include <asm/kvm_asm.h>
  22. #include <asm/kvm_arm.h>
  23. /********************************************************************
  24. * Hypervisor initialization
  25. * - should be called with:
  26. * r0,r1 = Hypervisor pgd pointer
  27. * r2 = top of Hyp stack (kernel VA)
  28. * r3 = pointer to hyp vectors
  29. */
  30. .text
  31. .pushsection .hyp.idmap.text,"ax"
  32. .align 5
  33. __kvm_hyp_init:
  34. .globl __kvm_hyp_init
  35. @ Hyp-mode exception vector
  36. W(b) .
  37. W(b) .
  38. W(b) .
  39. W(b) .
  40. W(b) .
  41. W(b) __do_hyp_init
  42. W(b) .
  43. W(b) .
  44. __do_hyp_init:
  45. @ Set the HTTBR to point to the hypervisor PGD pointer passed
  46. mcrr p15, 4, r0, r1, c2
  47. @ Set the HTCR and VTCR to the same shareability and cacheability
  48. @ settings as the non-secure TTBCR and with T0SZ == 0.
  49. mrc p15, 4, r0, c2, c0, 2 @ HTCR
  50. ldr r12, =HTCR_MASK
  51. bic r0, r0, r12
  52. mrc p15, 0, r1, c2, c0, 2 @ TTBCR
  53. and r1, r1, #(HTCR_MASK & ~TTBCR_T0SZ)
  54. orr r0, r0, r1
  55. mcr p15, 4, r0, c2, c0, 2 @ HTCR
  56. mrc p15, 4, r1, c2, c1, 2 @ VTCR
  57. ldr r12, =VTCR_MASK
  58. bic r1, r1, r12
  59. bic r0, r0, #(~VTCR_HTCR_SH) @ clear non-reusable HTCR bits
  60. orr r1, r0, r1
  61. orr r1, r1, #(KVM_VTCR_SL0 | KVM_VTCR_T0SZ | KVM_VTCR_S)
  62. mcr p15, 4, r1, c2, c1, 2 @ VTCR
  63. @ Use the same memory attributes for hyp. accesses as the kernel
  64. @ (copy MAIRx ro HMAIRx).
  65. mrc p15, 0, r0, c10, c2, 0
  66. mcr p15, 4, r0, c10, c2, 0
  67. mrc p15, 0, r0, c10, c2, 1
  68. mcr p15, 4, r0, c10, c2, 1
  69. @ Set the HSCTLR to:
  70. @ - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel)
  71. @ - Endianness: Kernel config
  72. @ - Fast Interrupt Features: Kernel config
  73. @ - Write permission implies XN: disabled
  74. @ - Instruction cache: enabled
  75. @ - Data/Unified cache: enabled
  76. @ - Memory alignment checks: enabled
  77. @ - MMU: enabled (this code must be run from an identity mapping)
  78. mrc p15, 4, r0, c1, c0, 0 @ HSCR
  79. ldr r12, =HSCTLR_MASK
  80. bic r0, r0, r12
  81. mrc p15, 0, r1, c1, c0, 0 @ SCTLR
  82. ldr r12, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C)
  83. and r1, r1, r12
  84. ARM( ldr r12, =(HSCTLR_M | HSCTLR_A) )
  85. THUMB( ldr r12, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE) )
  86. orr r1, r1, r12
  87. orr r0, r0, r1
  88. isb
  89. mcr p15, 4, r0, c1, c0, 0 @ HSCR
  90. isb
  91. @ Set stack pointer and return to the kernel
  92. mov sp, r2
  93. @ Set HVBAR to point to the HYP vectors
  94. mcr p15, 4, r3, c12, c0, 0 @ HVBAR
  95. eret
  96. .ltorg
  97. .globl __kvm_hyp_init_end
  98. __kvm_hyp_init_end:
  99. .popsection