start.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. b reset
  20. #ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
  21. /*
  22. * Various SoCs need something special and SoC-specific up front in
  23. * order to boot, allow them to set that in their boot0.h file and then
  24. * use it here.
  25. */
  26. #include <asm/arch/boot0.h>
  27. ARM_SOC_BOOT0_HOOK
  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. /* Apply ARM core specific erratas */
  78. bl apply_core_errata
  79. /*
  80. * Cache/BPB/TLB Invalidate
  81. * i-cache is invalidated before enabled in icache_enable()
  82. * tlb is invalidated before mmu is enabled in dcache_enable()
  83. * d-cache is invalidated before enabled in dcache_enable()
  84. */
  85. /* Processor specific initialization */
  86. bl lowlevel_init
  87. #if CONFIG_IS_ENABLED(ARMV8_SPIN_TABLE)
  88. branch_if_master x0, x1, master_cpu
  89. b spin_table_secondary_jump
  90. /* never return */
  91. #elif defined(CONFIG_ARMV8_MULTIENTRY)
  92. branch_if_master x0, x1, master_cpu
  93. /*
  94. * Slave CPUs
  95. */
  96. slave_cpu:
  97. wfe
  98. ldr x1, =CPU_RELEASE_ADDR
  99. ldr x0, [x1]
  100. cbz x0, slave_cpu
  101. br x0 /* branch to the given address */
  102. #endif /* CONFIG_ARMV8_MULTIENTRY */
  103. master_cpu:
  104. bl _main
  105. #ifdef CONFIG_SYS_RESET_SCTRL
  106. reset_sctrl:
  107. switch_el x1, 3f, 2f, 1f
  108. 3:
  109. mrs x0, sctlr_el3
  110. b 0f
  111. 2:
  112. mrs x0, sctlr_el2
  113. b 0f
  114. 1:
  115. mrs x0, sctlr_el1
  116. 0:
  117. ldr x1, =0xfdfffffa
  118. and x0, x0, x1
  119. switch_el x1, 6f, 5f, 4f
  120. 6:
  121. msr sctlr_el3, x0
  122. b 7f
  123. 5:
  124. msr sctlr_el2, x0
  125. b 7f
  126. 4:
  127. msr sctlr_el1, x0
  128. 7:
  129. dsb sy
  130. isb
  131. b __asm_invalidate_tlb_all
  132. ret
  133. #endif
  134. /*-----------------------------------------------------------------------*/
  135. WEAK(apply_core_errata)
  136. mov x29, lr /* Save LR */
  137. /* For now, we support Cortex-A57 specific errata only */
  138. /* Check if we are running on a Cortex-A57 core */
  139. branch_if_a57_core x0, apply_a57_core_errata
  140. 0:
  141. mov lr, x29 /* Restore LR */
  142. ret
  143. apply_a57_core_errata:
  144. #ifdef CONFIG_ARM_ERRATA_828024
  145. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  146. /* Disable non-allocate hint of w-b-n-a memory type */
  147. orr x0, x0, #1 << 49
  148. /* Disable write streaming no L1-allocate threshold */
  149. orr x0, x0, #3 << 25
  150. /* Disable write streaming no-allocate threshold */
  151. orr x0, x0, #3 << 27
  152. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  153. #endif
  154. #ifdef CONFIG_ARM_ERRATA_826974
  155. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  156. /* Disable speculative load execution ahead of a DMB */
  157. orr x0, x0, #1 << 59
  158. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  159. #endif
  160. #ifdef CONFIG_ARM_ERRATA_833471
  161. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  162. /* FPSCR write flush.
  163. * Note that in some cases where a flush is unnecessary this
  164. could impact performance. */
  165. orr x0, x0, #1 << 38
  166. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  167. #endif
  168. #ifdef CONFIG_ARM_ERRATA_829520
  169. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  170. /* Disable Indirect Predictor bit will prevent this erratum
  171. from occurring
  172. * Note that in some cases where a flush is unnecessary this
  173. could impact performance. */
  174. orr x0, x0, #1 << 4
  175. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  176. #endif
  177. #ifdef CONFIG_ARM_ERRATA_833069
  178. mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
  179. /* Disable Enable Invalidates of BTB bit */
  180. and x0, x0, #0xE
  181. msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
  182. #endif
  183. b 0b
  184. ENDPROC(apply_core_errata)
  185. /*-----------------------------------------------------------------------*/
  186. WEAK(lowlevel_init)
  187. mov x29, lr /* Save LR */
  188. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  189. branch_if_slave x0, 1f
  190. ldr x0, =GICD_BASE
  191. bl gic_init_secure
  192. 1:
  193. #if defined(CONFIG_GICV3)
  194. ldr x0, =GICR_BASE
  195. bl gic_init_secure_percpu
  196. #elif defined(CONFIG_GICV2)
  197. ldr x0, =GICD_BASE
  198. ldr x1, =GICC_BASE
  199. bl gic_init_secure_percpu
  200. #endif
  201. #endif
  202. #ifdef CONFIG_ARMV8_MULTIENTRY
  203. branch_if_master x0, x1, 2f
  204. /*
  205. * Slave should wait for master clearing spin table.
  206. * This sync prevent salves observing incorrect
  207. * value of spin table and jumping to wrong place.
  208. */
  209. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  210. #ifdef CONFIG_GICV2
  211. ldr x0, =GICC_BASE
  212. #endif
  213. bl gic_wait_for_interrupt
  214. #endif
  215. /*
  216. * All slaves will enter EL2 and optionally EL1.
  217. */
  218. adr x3, lowlevel_in_el2
  219. ldr x4, =ES_TO_AARCH64
  220. bl armv8_switch_to_el2
  221. lowlevel_in_el2:
  222. #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
  223. adr x3, lowlevel_in_el1
  224. ldr x4, =ES_TO_AARCH64
  225. bl armv8_switch_to_el1
  226. lowlevel_in_el1:
  227. #endif
  228. #endif /* CONFIG_ARMV8_MULTIENTRY */
  229. 2:
  230. mov lr, x29 /* Restore LR */
  231. ret
  232. ENDPROC(lowlevel_init)
  233. WEAK(smp_kick_all_cpus)
  234. /* Kick secondary cpus up by SGI 0 interrupt */
  235. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  236. ldr x0, =GICD_BASE
  237. b gic_kick_secondary_cpus
  238. #endif
  239. ret
  240. ENDPROC(smp_kick_all_cpus)
  241. /*-----------------------------------------------------------------------*/
  242. ENTRY(c_runtime_cpu_setup)
  243. /* Relocate vBAR */
  244. adr x0, vectors
  245. switch_el x1, 3f, 2f, 1f
  246. 3: msr vbar_el3, x0
  247. b 0f
  248. 2: msr vbar_el2, x0
  249. b 0f
  250. 1: msr vbar_el1, x0
  251. 0:
  252. ret
  253. ENDPROC(c_runtime_cpu_setup)
  254. WEAK(save_boot_params)
  255. b save_boot_params_ret /* back to my caller */
  256. ENDPROC(save_boot_params)