bl31_entrypoint.S 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch.h>
  8. #include <common/bl_common.h>
  9. #include <el3_common_macros.S>
  10. #include <lib/pmf/aarch64/pmf_asm_macros.S>
  11. #include <lib/runtime_instr.h>
  12. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  13. .globl bl31_entrypoint
  14. .globl bl31_warm_entrypoint
  15. /* -----------------------------------------------------
  16. * bl31_entrypoint() is the cold boot entrypoint,
  17. * executed only by the primary cpu.
  18. * -----------------------------------------------------
  19. */
  20. func bl31_entrypoint
  21. /* ---------------------------------------------------------------
  22. * Stash the previous bootloader arguments x0 - x3 for later use.
  23. * ---------------------------------------------------------------
  24. */
  25. mov x20, x0
  26. mov x21, x1
  27. mov x22, x2
  28. mov x23, x3
  29. #if !RESET_TO_BL31
  30. /* ---------------------------------------------------------------------
  31. * For !RESET_TO_BL31 systems, only the primary CPU ever reaches
  32. * bl31_entrypoint() during the cold boot flow, so the cold/warm boot
  33. * and primary/secondary CPU logic should not be executed in this case.
  34. *
  35. * Also, assume that the previous bootloader has already initialised the
  36. * SCTLR_EL3, including the endianness, and has initialised the memory.
  37. * ---------------------------------------------------------------------
  38. */
  39. el3_entrypoint_common \
  40. _init_sctlr=0 \
  41. _warm_boot_mailbox=0 \
  42. _secondary_cold_boot=0 \
  43. _init_memory=0 \
  44. _init_c_runtime=1 \
  45. _exception_vectors=runtime_exceptions \
  46. _pie_fixup_size=BL31_LIMIT - BL31_BASE
  47. #else
  48. /* ---------------------------------------------------------------------
  49. * For RESET_TO_BL31 systems which have a programmable reset address,
  50. * bl31_entrypoint() is executed only on the cold boot path so we can
  51. * skip the warm boot mailbox mechanism.
  52. * ---------------------------------------------------------------------
  53. */
  54. el3_entrypoint_common \
  55. _init_sctlr=1 \
  56. _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \
  57. _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \
  58. _init_memory=1 \
  59. _init_c_runtime=1 \
  60. _exception_vectors=runtime_exceptions \
  61. _pie_fixup_size=BL31_LIMIT - BL31_BASE
  62. #endif /* RESET_TO_BL31 */
  63. /* --------------------------------------------------------------------
  64. * Perform BL31 setup
  65. * --------------------------------------------------------------------
  66. */
  67. mov x0, x20
  68. mov x1, x21
  69. mov x2, x22
  70. mov x3, x23
  71. bl bl31_setup
  72. #if ENABLE_PAUTH
  73. /* --------------------------------------------------------------------
  74. * Program APIAKey_EL1 and enable pointer authentication
  75. * --------------------------------------------------------------------
  76. */
  77. bl pauth_init_enable_el3
  78. #endif /* ENABLE_PAUTH */
  79. /* --------------------------------------------------------------------
  80. * Jump to main function
  81. * --------------------------------------------------------------------
  82. */
  83. bl bl31_main
  84. /* --------------------------------------------------------------------
  85. * Clean the .data & .bss sections to main memory. This ensures
  86. * that any global data which was initialised by the primary CPU
  87. * is visible to secondary CPUs before they enable their data
  88. * caches and participate in coherency.
  89. * --------------------------------------------------------------------
  90. */
  91. adrp x0, __DATA_START__
  92. add x0, x0, :lo12:__DATA_START__
  93. adrp x1, __DATA_END__
  94. add x1, x1, :lo12:__DATA_END__
  95. sub x1, x1, x0
  96. bl clean_dcache_range
  97. adrp x0, __BSS_START__
  98. add x0, x0, :lo12:__BSS_START__
  99. adrp x1, __BSS_END__
  100. add x1, x1, :lo12:__BSS_END__
  101. sub x1, x1, x0
  102. bl clean_dcache_range
  103. b el3_exit
  104. endfunc bl31_entrypoint
  105. /* --------------------------------------------------------------------
  106. * This CPU has been physically powered up. It is either resuming from
  107. * suspend or has simply been turned on. In both cases, call the BL31
  108. * warmboot entrypoint
  109. * --------------------------------------------------------------------
  110. */
  111. func bl31_warm_entrypoint
  112. #if ENABLE_RUNTIME_INSTRUMENTATION
  113. /*
  114. * This timestamp update happens with cache off. The next
  115. * timestamp collection will need to do cache maintenance prior
  116. * to timestamp update.
  117. */
  118. pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_HW_LOW_PWR
  119. mrs x1, cntpct_el0
  120. str x1, [x0]
  121. #endif
  122. /*
  123. * On the warm boot path, most of the EL3 initialisations performed by
  124. * 'el3_entrypoint_common' must be skipped:
  125. *
  126. * - Only when the platform bypasses the BL1/BL31 entrypoint by
  127. * programming the reset address do we need to initialise SCTLR_EL3.
  128. * In other cases, we assume this has been taken care by the
  129. * entrypoint code.
  130. *
  131. * - No need to determine the type of boot, we know it is a warm boot.
  132. *
  133. * - Do not try to distinguish between primary and secondary CPUs, this
  134. * notion only exists for a cold boot.
  135. *
  136. * - No need to initialise the memory or the C runtime environment,
  137. * it has been done once and for all on the cold boot path.
  138. */
  139. el3_entrypoint_common \
  140. _init_sctlr=PROGRAMMABLE_RESET_ADDRESS \
  141. _warm_boot_mailbox=0 \
  142. _secondary_cold_boot=0 \
  143. _init_memory=0 \
  144. _init_c_runtime=0 \
  145. _exception_vectors=runtime_exceptions \
  146. _pie_fixup_size=0
  147. /*
  148. * We're about to enable MMU and participate in PSCI state coordination.
  149. *
  150. * The PSCI implementation invokes platform routines that enable CPUs to
  151. * participate in coherency. On a system where CPUs are not
  152. * cache-coherent without appropriate platform specific programming,
  153. * having caches enabled until such time might lead to coherency issues
  154. * (resulting from stale data getting speculatively fetched, among
  155. * others). Therefore we keep data caches disabled even after enabling
  156. * the MMU for such platforms.
  157. *
  158. * On systems with hardware-assisted coherency, or on single cluster
  159. * platforms, such platform specific programming is not required to
  160. * enter coherency (as CPUs already are); and there's no reason to have
  161. * caches disabled either.
  162. */
  163. #if HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY
  164. mov x0, xzr
  165. #else
  166. mov x0, #DISABLE_DCACHE
  167. #endif
  168. bl bl31_plat_enable_mmu
  169. #if ENABLE_RME
  170. /*
  171. * At warm boot GPT data structures have already been initialized in RAM
  172. * but the sysregs for this CPU need to be initialized. Note that the GPT
  173. * accesses are controlled attributes in GPCCR and do not depend on the
  174. * SCR_EL3.C bit.
  175. */
  176. bl gpt_enable
  177. cbz x0, 1f
  178. no_ret plat_panic_handler
  179. 1:
  180. #endif
  181. #if ENABLE_PAUTH
  182. /* --------------------------------------------------------------------
  183. * Program APIAKey_EL1 and enable pointer authentication
  184. * --------------------------------------------------------------------
  185. */
  186. bl pauth_init_enable_el3
  187. #endif /* ENABLE_PAUTH */
  188. bl psci_warmboot_entrypoint
  189. #if ENABLE_RUNTIME_INSTRUMENTATION
  190. pmf_calc_timestamp_addr rt_instr_svc, RT_INSTR_EXIT_PSCI
  191. mov x19, x0
  192. /*
  193. * Invalidate before updating timestamp to ensure previous timestamp
  194. * updates on the same cache line with caches disabled are properly
  195. * seen by the same core. Without the cache invalidate, the core might
  196. * write into a stale cache line.
  197. */
  198. mov x1, #PMF_TS_SIZE
  199. mov x20, x30
  200. bl inv_dcache_range
  201. mov x30, x20
  202. mrs x0, cntpct_el0
  203. str x0, [x19]
  204. #endif
  205. b el3_exit
  206. endfunc bl31_warm_entrypoint