start.S 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
  3. *
  4. * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
  5. *
  6. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  7. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  8. * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
  9. * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
  10. * Copyright (c) 2003 Kshitij <kshitij@ti.com>
  11. * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <asm-offsets.h>
  16. #include <config.h>
  17. #include <asm/system.h>
  18. #include <linux/linkage.h>
  19. #include <asm/armv7.h>
  20. /*************************************************************************
  21. *
  22. * Startup Code (reset vector)
  23. *
  24. * Do important init only if we don't start from memory!
  25. * Setup memory and board specific bits prior to relocation.
  26. * Relocate armboot to ram. Setup stack.
  27. *
  28. *************************************************************************/
  29. .globl reset
  30. .globl save_boot_params_ret
  31. #ifdef CONFIG_ARMV7_LPAE
  32. .global switch_to_hypervisor_ret
  33. #endif
  34. reset:
  35. /* Allow the board to save important registers */
  36. b save_boot_params
  37. save_boot_params_ret:
  38. #ifdef CONFIG_ARMV7_LPAE
  39. /*
  40. * check for Hypervisor support
  41. */
  42. mrc p15, 0, r0, c0, c1, 1 @ read ID_PFR1
  43. and r0, r0, #CPUID_ARM_VIRT_MASK @ mask virtualization bits
  44. cmp r0, #(1 << CPUID_ARM_VIRT_SHIFT)
  45. beq switch_to_hypervisor
  46. switch_to_hypervisor_ret:
  47. #endif
  48. /*
  49. * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode,
  50. * except if in HYP mode already
  51. */
  52. mrs r0, cpsr
  53. and r1, r0, #0x1f @ mask mode bits
  54. teq r1, #0x1a @ test for HYP mode
  55. bicne r0, r0, #0x1f @ clear all mode bits
  56. orrne r0, r0, #0x13 @ set SVC mode
  57. orr r0, r0, #0xc0 @ disable FIQ and IRQ
  58. msr cpsr,r0
  59. /*
  60. * Setup vector:
  61. * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
  62. * Continue to use ROM code vector only in OMAP4 spl)
  63. */
  64. #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
  65. /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */
  66. mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register
  67. bic r0, #CR_V @ V = 0
  68. mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTLR Register
  69. /* Set vector address in CP15 VBAR register */
  70. ldr r0, =_start
  71. mcr p15, 0, r0, c12, c0, 0 @Set VBAR
  72. #endif
  73. /* the mask ROM code should have PLL and others stable */
  74. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  75. bl cpu_init_cp15
  76. #ifndef CONFIG_SKIP_LOWLEVEL_INIT_ONLY
  77. bl cpu_init_crit
  78. #endif
  79. #endif
  80. bl _main
  81. /*------------------------------------------------------------------------------*/
  82. ENTRY(c_runtime_cpu_setup)
  83. /*
  84. * If I-cache is enabled invalidate it
  85. */
  86. #ifndef CONFIG_SYS_ICACHE_OFF
  87. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  88. mcr p15, 0, r0, c7, c10, 4 @ DSB
  89. mcr p15, 0, r0, c7, c5, 4 @ ISB
  90. #endif
  91. bx lr
  92. ENDPROC(c_runtime_cpu_setup)
  93. /*************************************************************************
  94. *
  95. * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
  96. * __attribute__((weak));
  97. *
  98. * Stack pointer is not yet initialized at this moment
  99. * Don't save anything to stack even if compiled with -O0
  100. *
  101. *************************************************************************/
  102. ENTRY(save_boot_params)
  103. b save_boot_params_ret @ back to my caller
  104. ENDPROC(save_boot_params)
  105. .weak save_boot_params
  106. #ifdef CONFIG_ARMV7_LPAE
  107. ENTRY(switch_to_hypervisor)
  108. b switch_to_hypervisor_ret
  109. ENDPROC(switch_to_hypervisor)
  110. .weak switch_to_hypervisor
  111. #endif
  112. /*************************************************************************
  113. *
  114. * cpu_init_cp15
  115. *
  116. * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
  117. * CONFIG_SYS_ICACHE_OFF is defined.
  118. *
  119. *************************************************************************/
  120. ENTRY(cpu_init_cp15)
  121. /*
  122. * Invalidate L1 I/D
  123. */
  124. mov r0, #0 @ set up for MCR
  125. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  126. mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
  127. mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array
  128. mcr p15, 0, r0, c7, c10, 4 @ DSB
  129. mcr p15, 0, r0, c7, c5, 4 @ ISB
  130. /*
  131. * disable MMU stuff and caches
  132. */
  133. mrc p15, 0, r0, c1, c0, 0
  134. bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
  135. bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
  136. orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
  137. orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
  138. #ifdef CONFIG_SYS_ICACHE_OFF
  139. bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
  140. #else
  141. orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache
  142. #endif
  143. mcr p15, 0, r0, c1, c0, 0
  144. #ifdef CONFIG_ARM_ERRATA_716044
  145. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  146. orr r0, r0, #1 << 11 @ set bit #11
  147. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  148. #endif
  149. #if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072))
  150. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  151. orr r0, r0, #1 << 4 @ set bit #4
  152. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  153. #endif
  154. #ifdef CONFIG_ARM_ERRATA_743622
  155. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  156. orr r0, r0, #1 << 6 @ set bit #6
  157. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  158. #endif
  159. #ifdef CONFIG_ARM_ERRATA_751472
  160. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  161. orr r0, r0, #1 << 11 @ set bit #11
  162. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  163. #endif
  164. #ifdef CONFIG_ARM_ERRATA_761320
  165. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  166. orr r0, r0, #1 << 21 @ set bit #21
  167. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  168. #endif
  169. mov r5, lr @ Store my Caller
  170. mrc p15, 0, r1, c0, c0, 0 @ r1 has Read Main ID Register (MIDR)
  171. mov r3, r1, lsr #20 @ get variant field
  172. and r3, r3, #0xf @ r3 has CPU variant
  173. and r4, r1, #0xf @ r4 has CPU revision
  174. mov r2, r3, lsl #4 @ shift variant field for combined value
  175. orr r2, r4, r2 @ r2 has combined CPU variant + revision
  176. #ifdef CONFIG_ARM_ERRATA_798870
  177. cmp r2, #0x30 @ Applies to lower than R3p0
  178. bge skip_errata_798870 @ skip if not affected rev
  179. cmp r2, #0x20 @ Applies to including and above R2p0
  180. blt skip_errata_798870 @ skip if not affected rev
  181. mrc p15, 1, r0, c15, c0, 0 @ read l2 aux ctrl reg
  182. orr r0, r0, #1 << 7 @ Enable hazard-detect timeout
  183. push {r1-r5} @ Save the cpu info registers
  184. bl v7_arch_cp15_set_l2aux_ctrl
  185. isb @ Recommended ISB after l2actlr update
  186. pop {r1-r5} @ Restore the cpu info - fall through
  187. skip_errata_798870:
  188. #endif
  189. #ifdef CONFIG_ARM_ERRATA_801819
  190. cmp r2, #0x24 @ Applies to lt including R2p4
  191. bgt skip_errata_801819 @ skip if not affected rev
  192. cmp r2, #0x20 @ Applies to including and above R2p0
  193. blt skip_errata_801819 @ skip if not affected rev
  194. mrc p15, 0, r0, c0, c0, 6 @ pick up REVIDR reg
  195. and r0, r0, #1 << 3 @ check REVIDR[3]
  196. cmp r0, #1 << 3
  197. beq skip_errata_801819 @ skip erratum if REVIDR[3] is set
  198. mrc p15, 0, r0, c1, c0, 1 @ read auxilary control register
  199. orr r0, r0, #3 << 27 @ Disables streaming. All write-allocate
  200. @ lines allocate in the L1 or L2 cache.
  201. orr r0, r0, #3 << 25 @ Disables streaming. All write-allocate
  202. @ lines allocate in the L1 cache.
  203. push {r1-r5} @ Save the cpu info registers
  204. bl v7_arch_cp15_set_acr
  205. pop {r1-r5} @ Restore the cpu info - fall through
  206. skip_errata_801819:
  207. #endif
  208. #ifdef CONFIG_ARM_ERRATA_454179
  209. cmp r2, #0x21 @ Only on < r2p1
  210. bge skip_errata_454179
  211. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  212. orr r0, r0, #(0x3 << 6) @ Set DBSM(BIT7) and IBE(BIT6) bits
  213. push {r1-r5} @ Save the cpu info registers
  214. bl v7_arch_cp15_set_acr
  215. pop {r1-r5} @ Restore the cpu info - fall through
  216. skip_errata_454179:
  217. #endif
  218. #ifdef CONFIG_ARM_ERRATA_430973
  219. cmp r2, #0x21 @ Only on < r2p1
  220. bge skip_errata_430973
  221. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  222. orr r0, r0, #(0x1 << 6) @ Set IBE bit
  223. push {r1-r5} @ Save the cpu info registers
  224. bl v7_arch_cp15_set_acr
  225. pop {r1-r5} @ Restore the cpu info - fall through
  226. skip_errata_430973:
  227. #endif
  228. #ifdef CONFIG_ARM_ERRATA_621766
  229. cmp r2, #0x21 @ Only on < r2p1
  230. bge skip_errata_621766
  231. mrc p15, 0, r0, c1, c0, 1 @ Read ACR
  232. orr r0, r0, #(0x1 << 5) @ Set L1NEON bit
  233. push {r1-r5} @ Save the cpu info registers
  234. bl v7_arch_cp15_set_acr
  235. pop {r1-r5} @ Restore the cpu info - fall through
  236. skip_errata_621766:
  237. #endif
  238. mov pc, r5 @ back to my caller
  239. ENDPROC(cpu_init_cp15)
  240. #if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
  241. !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
  242. /*************************************************************************
  243. *
  244. * CPU_init_critical registers
  245. *
  246. * setup important registers
  247. * setup memory timing
  248. *
  249. *************************************************************************/
  250. ENTRY(cpu_init_crit)
  251. /*
  252. * Jump to board specific initialization...
  253. * The Mask ROM will have already initialized
  254. * basic memory. Go here to bump up clock rate and handle
  255. * wake up conditions.
  256. */
  257. b lowlevel_init @ go setup pll,mux,memory
  258. ENDPROC(cpu_init_crit)
  259. #endif