transition.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * (C) Copyright 2013
  3. * David Feng <fenghua@phytium.com.cn>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <asm-offsets.h>
  8. #include <config.h>
  9. #include <version.h>
  10. #include <linux/linkage.h>
  11. #include <asm/macro.h>
  12. ENTRY(armv8_switch_to_el2)
  13. switch_el x0, 1f, 0f, 0f
  14. 0: ret
  15. 1:
  16. mov x0, #0x5b1 /* Non-secure EL0/EL1 | HVC | 64bit EL2 */
  17. msr scr_el3, x0
  18. msr cptr_el3, xzr /* Disable coprocessor traps to EL3 */
  19. mov x0, #0x33ff
  20. msr cptr_el2, x0 /* Disable coprocessor traps to EL2 */
  21. /* Initialize SCTLR_EL2 */
  22. msr sctlr_el2, xzr
  23. /* Return to the EL2_SP2 mode from EL3 */
  24. mov x0, sp
  25. msr sp_el2, x0 /* Migrate SP */
  26. mrs x0, vbar_el3
  27. msr vbar_el2, x0 /* Migrate VBAR */
  28. mov x0, #0x3c9
  29. msr spsr_el3, x0 /* EL2_SP2 | D | A | I | F */
  30. msr elr_el3, lr
  31. eret
  32. ENDPROC(armv8_switch_to_el2)
  33. ENTRY(armv8_switch_to_el1)
  34. switch_el x0, 0f, 1f, 0f
  35. 0: ret
  36. 1:
  37. /* Initialize Generic Timers */
  38. mrs x0, cnthctl_el2
  39. orr x0, x0, #0x3 /* Enable EL1 access to timers */
  40. msr cnthctl_el2, x0
  41. msr cntvoff_el2, xzr
  42. mrs x0, cntkctl_el1
  43. orr x0, x0, #0x3 /* Enable EL0 access to timers */
  44. msr cntkctl_el1, x0
  45. /* Initilize MPID/MPIDR registers */
  46. mrs x0, midr_el1
  47. mrs x1, mpidr_el1
  48. msr vpidr_el2, x0
  49. msr vmpidr_el2, x1
  50. /* Disable coprocessor traps */
  51. mov x0, #0x33ff
  52. msr cptr_el2, x0 /* Disable coprocessor traps to EL2 */
  53. msr hstr_el2, xzr /* Disable coprocessor traps to EL2 */
  54. mov x0, #3 << 20
  55. msr cpacr_el1, x0 /* Enable FP/SIMD at EL1 */
  56. /* Initialize HCR_EL2 */
  57. mov x0, #(1 << 31) /* 64bit EL1 */
  58. orr x0, x0, #(1 << 29) /* Disable HVC */
  59. msr hcr_el2, x0
  60. /* SCTLR_EL1 initialization */
  61. mov x0, #0x0800
  62. movk x0, #0x30d0, lsl #16
  63. msr sctlr_el1, x0
  64. /* Return to the EL1_SP1 mode from EL2 */
  65. mov x0, sp
  66. msr sp_el1, x0 /* Migrate SP */
  67. mrs x0, vbar_el2
  68. msr vbar_el1, x0 /* Migrate VBAR */
  69. mov x0, #0x3c5
  70. msr spsr_el2, x0 /* EL1_SP1 | D | A | I | F */
  71. msr elr_el2, lr
  72. eret
  73. ENDPROC(armv8_switch_to_el1)