trp_entry.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include <services/rmmd_svc.h>
  8. #include <platform_def.h>
  9. #include "trp_private.h"
  10. .global trp_head
  11. .global trp_smc
  12. .section ".head.text", "ax"
  13. /* ---------------------------------------------
  14. * Populate the params in x0-x7 from the pointer
  15. * to the smc args structure in x0.
  16. * ---------------------------------------------
  17. */
  18. .macro restore_args_call_smc
  19. ldp x6, x7, [x0, #TRP_ARG6]
  20. ldp x4, x5, [x0, #TRP_ARG4]
  21. ldp x2, x3, [x0, #TRP_ARG2]
  22. ldp x0, x1, [x0, #TRP_ARG0]
  23. smc #0
  24. .endm
  25. /* ---------------------------------------------
  26. * Entry point for TRP
  27. * ---------------------------------------------
  28. */
  29. trp_head:
  30. /*
  31. * Stash arguments from previous boot stage
  32. */
  33. mov x20, x0
  34. mov x21, x1
  35. mov x22, x2
  36. mov x23, x3
  37. /*
  38. * Validate CPUId before allocating a stack.
  39. */
  40. cmp x20, #PLATFORM_CORE_COUNT
  41. b.lo 1f
  42. mov_imm x0, RMM_BOOT_COMPLETE
  43. mov_imm x1, E_RMM_BOOT_CPU_ID_OUT_OF_RANGE
  44. smc #0
  45. /* EL3 should never return back here, so panic if it does */
  46. b trp_panic
  47. 1:
  48. bl plat_set_my_stack
  49. /*
  50. * Find out whether this is a cold or warm boot
  51. */
  52. ldr x1, cold_boot_flag
  53. cbz x1, warm_boot
  54. /*
  55. * Update cold boot flag to indicate cold boot is done
  56. */
  57. adr x2, cold_boot_flag
  58. str xzr, [x2]
  59. /* ---------------------------------------------
  60. * Zero out BSS section
  61. * ---------------------------------------------
  62. */
  63. ldr x0, =__BSS_START__
  64. ldr x1, =__BSS_SIZE__
  65. bl zeromem
  66. mov x0, x20
  67. mov x1, x21
  68. mov x2, x22
  69. mov x3, x23
  70. bl trp_setup
  71. bl trp_main
  72. b 1f
  73. warm_boot:
  74. mov x0, x20
  75. mov x1, x21
  76. mov x2, x22
  77. mov x3, x23
  78. bl trp_validate_warmboot_args
  79. cbnz x0, trp_panic /* Failed to validate warmboot args */
  80. 1:
  81. mov_imm x0, RMM_BOOT_COMPLETE
  82. mov x1, xzr /* RMM_BOOT_SUCCESS */
  83. smc #0
  84. b trp_handler
  85. trp_panic:
  86. no_ret plat_panic_handler
  87. /*
  88. * Flag to mark if it is a cold boot.
  89. * 1: cold boot, 0: warmboot.
  90. */
  91. .align 3
  92. cold_boot_flag:
  93. .dword 1
  94. /* ---------------------------------------------
  95. * Direct SMC call to BL31 service provided by
  96. * RMM Dispatcher
  97. * ---------------------------------------------
  98. */
  99. func trp_smc
  100. restore_args_call_smc
  101. ret
  102. endfunc trp_smc
  103. /* ---------------------------------------------
  104. * RMI call handler
  105. * ---------------------------------------------
  106. */
  107. func trp_handler
  108. /*
  109. * Save Link Register and X4, as per SMCCC v1.2 its value
  110. * must be preserved unless it contains result, as specified
  111. * in the function definition.
  112. */
  113. stp x4, lr, [sp, #-16]!
  114. /*
  115. * Zero the space for X0-X3 in trp_smc_result structure
  116. * and pass its address as the last argument.
  117. */
  118. stp xzr, xzr, [sp, #-16]!
  119. stp xzr, xzr, [sp, #-16]!
  120. mov x7, sp
  121. bl trp_rmi_handler
  122. ldp x1, x2, [sp], #16
  123. ldp x3, x4, [sp], #16
  124. ldp x5, lr, [sp], #16
  125. ldr x0, =RMM_RMI_REQ_COMPLETE
  126. smc #0
  127. b trp_handler
  128. endfunc trp_handler