start.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 <linux/linkage.h>
  10. #include <asm/macro.h>
  11. #include <asm/armv8/mmu.h>
  12. /*************************************************************************
  13. *
  14. * Startup Code (reset vector)
  15. *
  16. *************************************************************************/
  17. .globl _start
  18. _start:
  19. #ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
  20. /*
  21. * Various SoCs need something special and SoC-specific up front in
  22. * order to boot, allow them to set that in their boot0.h file and then
  23. * use it here.
  24. */
  25. #include <asm/arch/boot0.h>
  26. #else
  27. b reset
  28. #endif
  29. .align 3
  30. .globl _TEXT_BASE
  31. _TEXT_BASE:
  32. .quad CONFIG_SYS_TEXT_BASE
  33. /*
  34. * These are defined in the linker script.
  35. */
  36. .globl _end_ofs
  37. _end_ofs:
  38. .quad _end - _start
  39. .globl _bss_start_ofs
  40. _bss_start_ofs:
  41. .quad __bss_start - _start
  42. .globl _bss_end_ofs
  43. _bss_end_ofs:
  44. .quad __bss_end - _start
  45. reset:
  46. /* Allow the board to save important registers */
  47. b save_boot_params
  48. .globl save_boot_params_ret
  49. save_boot_params_ret:
  50. #ifdef CONFIG_SYS_RESET_SCTRL
  51. bl reset_sctrl
  52. #endif
  53. /*
  54. * Could be EL3/EL2/EL1, Initial State:
  55. * Little Endian, MMU Disabled, i/dCache Disabled
  56. */
  57. adr x0, vectors
  58. switch_el x1, 3f, 2f, 1f
  59. 3: msr vbar_el3, x0
  60. mrs x0, scr_el3
  61. orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
  62. msr scr_el3, x0
  63. msr cptr_el3, xzr /* Enable FP/SIMD */
  64. #ifdef COUNTER_FREQUENCY
  65. ldr x0, =COUNTER_FREQUENCY
  66. msr cntfrq_el0, x0 /* Initialize CNTFRQ */
  67. #endif
  68. b 0f
  69. 2: msr vbar_el2, x0
  70. mov x0, #0x33ff
  71. msr cptr_el2, x0 /* Enable FP/SIMD */
  72. b 0f
  73. 1: msr vbar_el1, x0
  74. mov x0, #3 << 20
  75. msr cpacr_el1, x0 /* Enable FP/SIMD */
  76. 0:
  77. /*
  78. * Enable SMPEN bit for coherency.
  79. * This register is not architectural but at the moment
  80. * this bit should be set for A53/A57/A72.
  81. */
  82. #ifdef CONFIG_ARMV8_SET_SMPEN
  83. mrs x0, S3_1_c15_c2_1 /* cpuectlr_el1 */
  84. orr x0, x0, #0x40
  85. msr S3_1_c15_c2_1, x0
  86. #endif
  87. /* Apply ARM core specific erratas */
  88. bl apply_core_errata
  89. /*
  90. * Cache/BPB/TLB Invalidate
  91. * i-cache is invalidated before enabled in icache_enable()
  92. * tlb is invalidated before mmu is enabled in dcache_enable()
  93. * d-cache is invalidated before enabled in dcache_enable()
  94. */
  95. /* Processor specific initialization */
  96. bl lowlevel_init
  97. #if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
  98. branch_if_master x0, x1, master_cpu
  99. b spin_table_secondary_jump
  100. /* never return */
  101. #elif defined(CONFIG_ARMV8_MULTIENTRY)
  102. branch_if_master x0, x1, master_cpu
  103. /*
  104. * Slave CPUs
  105. */
  106. slave_cpu:
  107. wfe
  108. ldr x1, =CPU_RELEASE_ADDR
  109. ldr x0, [x1]
  110. cbz x0, slave_cpu
  111. br x0 /* branch to the given address */
  112. #endif /* CONFIG_ARMV8_MULTIENTRY */
  113. master_cpu:
  114. bl _main
  115. #ifdef CONFIG_SYS_RESET_SCTRL
  116. reset_sctrl:
  117. switch_el x1, 3f, 2f, 1f
  118. 3:
  119. mrs x0, sctlr_el3
  120. b 0f
  121. 2:
  122. mrs x0, sctlr_el2
  123. b 0f
  124. 1:
  125. mrs x0, sctlr_el1
  126. 0:
  127. ldr x1, =0xfdfffffa
  128. and x0, x0, x1
  129. switch_el x1, 6f, 5f, 4f
  130. 6:
  131. msr sctlr_el3, x0
  132. b 7f
  133. 5:
  134. msr sctlr_el2, x0
  135. b 7f
  136. 4:
  137. msr sctlr_el1, x0
  138. 7:
  139. dsb sy
  140. isb
  141. b __asm_invalidate_tlb_all
  142. ret
  143. #endif
  144. /*-----------------------------------------------------------------------*/
  145. WEAK(apply_core_errata)
  146. mov x29, lr /* Save LR */
  147. /* For now, we support Cortex-A57 specific errata only */
  148. /* Check if we are running on a Cortex-A57 core */
  149. branch_if_a57_core x0, apply_a57_core_errata
  150. 0:
  151. mov lr, x29 /* Restore LR */
  152. ret
  153. apply_a57_core_errata:
  154. #ifdef CONFIG_ARM_ERRATA_828024
  155. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  156. /* Disable non-allocate hint of w-b-n-a memory type */
  157. orr x0, x0, #1 << 49
  158. /* Disable write streaming no L1-allocate threshold */
  159. orr x0, x0, #3 << 25
  160. /* Disable write streaming no-allocate threshold */
  161. orr x0, x0, #3 << 27
  162. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  163. #endif
  164. #ifdef CONFIG_ARM_ERRATA_826974
  165. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  166. /* Disable speculative load execution ahead of a DMB */
  167. orr x0, x0, #1 << 59
  168. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  169. #endif
  170. #ifdef CONFIG_ARM_ERRATA_833471
  171. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  172. /* FPSCR write flush.
  173. * Note that in some cases where a flush is unnecessary this
  174. could impact performance. */
  175. orr x0, x0, #1 << 38
  176. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  177. #endif
  178. #ifdef CONFIG_ARM_ERRATA_829520
  179. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  180. /* Disable Indirect Predictor bit will prevent this erratum
  181. from occurring
  182. * Note that in some cases where a flush is unnecessary this
  183. could impact performance. */
  184. orr x0, x0, #1 << 4
  185. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  186. #endif
  187. #ifdef CONFIG_ARM_ERRATA_833069
  188. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  189. /* Disable Enable Invalidates of BTB bit */
  190. and x0, x0, #0xE
  191. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  192. #endif
  193. b 0b
  194. ENDPROC(apply_core_errata)
  195. /*-----------------------------------------------------------------------*/
  196. WEAK(lowlevel_init)
  197. mov x29, lr /* Save LR */
  198. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  199. branch_if_slave x0, 1f
  200. ldr x0, =GICD_BASE
  201. bl gic_init_secure
  202. 1:
  203. #if defined(CONFIG_GICV3)
  204. ldr x0, =GICR_BASE
  205. bl gic_init_secure_percpu
  206. #elif defined(CONFIG_GICV2)
  207. ldr x0, =GICD_BASE
  208. ldr x1, =GICC_BASE
  209. bl gic_init_secure_percpu
  210. #endif
  211. #endif
  212. #ifdef CONFIG_ARMV8_MULTIENTRY
  213. branch_if_master x0, x1, 2f
  214. /*
  215. * Slave should wait for master clearing spin table.
  216. * This sync prevent salves observing incorrect
  217. * value of spin table and jumping to wrong place.
  218. */
  219. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  220. #ifdef CONFIG_GICV2
  221. ldr x0, =GICC_BASE
  222. #endif
  223. bl gic_wait_for_interrupt
  224. #endif
  225. /*
  226. * All slaves will enter EL2 and optionally EL1.
  227. */
  228. adr x4, lowlevel_in_el2
  229. ldr x5, =ES_TO_AARCH64
  230. bl armv8_switch_to_el2
  231. lowlevel_in_el2:
  232. #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
  233. adr x4, lowlevel_in_el1
  234. ldr x5, =ES_TO_AARCH64
  235. bl armv8_switch_to_el1
  236. lowlevel_in_el1:
  237. #endif
  238. #endif /* CONFIG_ARMV8_MULTIENTRY */
  239. 2:
  240. mov lr, x29 /* Restore LR */
  241. ret
  242. ENDPROC(lowlevel_init)
  243. WEAK(smp_kick_all_cpus)
  244. /* Kick secondary cpus up by SGI 0 interrupt */
  245. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  246. ldr x0, =GICD_BASE
  247. b gic_kick_secondary_cpus
  248. #endif
  249. ret
  250. ENDPROC(smp_kick_all_cpus)
  251. /*-----------------------------------------------------------------------*/
  252. ENTRY(c_runtime_cpu_setup)
  253. /* Relocate vBAR */
  254. adr x0, vectors
  255. switch_el x1, 3f, 2f, 1f
  256. 3: msr vbar_el3, x0
  257. b 0f
  258. 2: msr vbar_el2, x0
  259. b 0f
  260. 1: msr vbar_el1, x0
  261. 0:
  262. ret
  263. ENDPROC(c_runtime_cpu_setup)
  264. WEAK(save_boot_params)
  265. b save_boot_params_ret /* back to my caller */
  266. ENDPROC(save_boot_params)