plat_trampoline.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <plat/common/common_def.h>
  9. #include <memctrl_v2.h>
  10. #include <tegra_def.h>
  11. #define TEGRA194_STATE_SYSTEM_SUSPEND 0x5C7
  12. #define TEGRA194_STATE_SYSTEM_RESUME 0x600D
  13. #define TEGRA194_MC_CTX_SIZE 0xFB
  14. .align 4
  15. .globl tegra194_cpu_reset_handler
  16. /* CPU reset handler routine */
  17. func tegra194_cpu_reset_handler
  18. /* check if we are exiting system suspend state */
  19. adr x0, __tegra194_system_suspend_state
  20. ldr x1, [x0]
  21. mov x2, #TEGRA194_STATE_SYSTEM_SUSPEND
  22. lsl x2, x2, #16
  23. add x2, x2, #TEGRA194_STATE_SYSTEM_SUSPEND
  24. cmp x1, x2
  25. bne boot_cpu
  26. /* set system resume state */
  27. mov x1, #TEGRA194_STATE_SYSTEM_RESUME
  28. lsl x1, x1, #16
  29. mov x2, #TEGRA194_STATE_SYSTEM_RESUME
  30. add x1, x1, x2
  31. str x1, [x0]
  32. dsb sy
  33. /* prepare to relocate to TZSRAM */
  34. mov x0, #BL31_BASE
  35. adr x1, __tegra194_cpu_reset_handler_end
  36. adr x2, __tegra194_cpu_reset_handler_data
  37. ldr x2, [x2, #8]
  38. /* memcpy16 */
  39. m_loop16:
  40. cmp x2, #16
  41. b.lt m_loop1
  42. ldp x3, x4, [x1], #16
  43. stp x3, x4, [x0], #16
  44. sub x2, x2, #16
  45. b m_loop16
  46. /* copy byte per byte */
  47. m_loop1:
  48. cbz x2, boot_cpu
  49. ldrb w3, [x1], #1
  50. strb w3, [x0], #1
  51. subs x2, x2, #1
  52. b.ne m_loop1
  53. /*
  54. * Synchronization barriers to make sure that memory is flushed out
  55. * before we start execution in SysRAM.
  56. */
  57. dsb sy
  58. isb
  59. boot_cpu:
  60. adr x0, __tegra194_cpu_reset_handler_data
  61. ldr x0, [x0]
  62. br x0
  63. endfunc tegra194_cpu_reset_handler
  64. /*
  65. * Tegra194 reset data (offset 0x0 - 0x2490)
  66. *
  67. * 0x0000: secure world's entrypoint
  68. * 0x0008: BL31 size (RO + RW)
  69. * 0x0010: MC context start
  70. * 0x2490: MC context end
  71. */
  72. .align 4
  73. .type __tegra194_cpu_reset_handler_data, %object
  74. .globl __tegra194_cpu_reset_handler_data
  75. __tegra194_cpu_reset_handler_data:
  76. .quad tegra_secure_entrypoint
  77. .quad __BL31_END__ - BL31_BASE
  78. .globl __tegra194_system_suspend_state
  79. __tegra194_system_suspend_state:
  80. .quad 0
  81. .align 4
  82. __tegra194_mc_context:
  83. .rept TEGRA194_MC_CTX_SIZE
  84. .quad 0
  85. .endr
  86. .size __tegra194_cpu_reset_handler_data, \
  87. . - __tegra194_cpu_reset_handler_data
  88. .align 4
  89. .globl __tegra194_cpu_reset_handler_end
  90. __tegra194_cpu_reset_handler_end:
  91. .globl tegra194_get_cpu_reset_handler_size
  92. .globl tegra194_get_cpu_reset_handler_base
  93. .globl tegra194_get_mc_ctx_offset
  94. .globl tegra194_set_system_suspend_entry
  95. /* return size of the CPU reset handler */
  96. func tegra194_get_cpu_reset_handler_size
  97. adr x0, __tegra194_cpu_reset_handler_end
  98. adr x1, tegra194_cpu_reset_handler
  99. sub x0, x0, x1
  100. ret
  101. endfunc tegra194_get_cpu_reset_handler_size
  102. /* return the start address of the CPU reset handler */
  103. func tegra194_get_cpu_reset_handler_base
  104. adr x0, tegra194_cpu_reset_handler
  105. ret
  106. endfunc tegra194_get_cpu_reset_handler_base
  107. /* return the size of the MC context */
  108. func tegra194_get_mc_ctx_offset
  109. adr x0, __tegra194_mc_context
  110. adr x1, tegra194_cpu_reset_handler
  111. sub x0, x0, x1
  112. ret
  113. endfunc tegra194_get_mc_ctx_offset
  114. /* set system suspend state before SC7 entry */
  115. func tegra194_set_system_suspend_entry
  116. mov x0, #TEGRA_MC_BASE
  117. mov x3, #MC_SECURITY_CFG3_0
  118. ldr w1, [x0, x3]
  119. lsl x1, x1, #32
  120. mov x3, #MC_SECURITY_CFG0_0
  121. ldr w2, [x0, x3]
  122. orr x3, x1, x2 /* TZDRAM base */
  123. adr x0, __tegra194_system_suspend_state
  124. adr x1, tegra194_cpu_reset_handler
  125. sub x2, x0, x1 /* offset in TZDRAM */
  126. mov x0, #TEGRA194_STATE_SYSTEM_SUSPEND
  127. lsl x0, x0, #16
  128. add x0, x0, #TEGRA194_STATE_SYSTEM_SUSPEND
  129. str x0, [x3, x2] /* set value in TZDRAM */
  130. dsb sy
  131. ret
  132. endfunc tegra194_set_system_suspend_entry