reset-handler.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/init.h>
  18. #include <asm/cache.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/hardware/cache-l2x0.h>
  21. #include "flowctrl.h"
  22. #include "fuse.h"
  23. #include "iomap.h"
  24. #include "reset.h"
  25. #include "sleep.h"
  26. #define PMC_SCRATCH41 0x140
  27. #define RESET_DATA(x) ((TEGRA_RESET_##x)*4)
  28. #ifdef CONFIG_PM_SLEEP
  29. /*
  30. * tegra_resume
  31. *
  32. * CPU boot vector when restarting the a CPU following
  33. * an LP2 transition. Also branched to by LP0 and LP1 resume after
  34. * re-enabling sdram.
  35. *
  36. * r6: SoC ID
  37. * r8: CPU part number
  38. */
  39. ENTRY(tegra_resume)
  40. check_cpu_part_num 0xc09, r8, r9
  41. bleq v7_invalidate_l1
  42. blne tegra_init_l2_for_a15
  43. cpu_id r0
  44. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  45. cmp r6, #TEGRA114
  46. beq no_cpu0_chk
  47. cmp r0, #0 @ CPU0?
  48. THUMB( it ne )
  49. bne cpu_resume @ no
  50. no_cpu0_chk:
  51. /* Are we on Tegra20? */
  52. cmp r6, #TEGRA20
  53. beq 1f @ Yes
  54. /* Clear the flow controller flags for this CPU. */
  55. cpu_to_csr_reg r1, r0
  56. mov32 r2, TEGRA_FLOW_CTRL_BASE
  57. ldr r1, [r2, r1]
  58. /* Clear event & intr flag */
  59. orr r1, r1, \
  60. #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  61. movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
  62. @ & ext flags for CPU power mgnt
  63. bic r1, r1, r0
  64. str r1, [r2]
  65. 1:
  66. mov32 r9, 0xc09
  67. cmp r8, r9
  68. bne not_ca9
  69. #ifdef CONFIG_HAVE_ARM_SCU
  70. /* enable SCU */
  71. mov32 r0, TEGRA_ARM_PERIF_BASE
  72. ldr r1, [r0]
  73. orr r1, r1, #1
  74. str r1, [r0]
  75. #endif
  76. /* L2 cache resume & re-enable */
  77. l2_cache_resume r0, r1, r2, l2x0_saved_regs_addr
  78. not_ca9:
  79. b cpu_resume
  80. ENDPROC(tegra_resume)
  81. #endif
  82. #ifdef CONFIG_CACHE_L2X0
  83. .globl l2x0_saved_regs_addr
  84. l2x0_saved_regs_addr:
  85. .long 0
  86. #endif
  87. .align L1_CACHE_SHIFT
  88. ENTRY(__tegra_cpu_reset_handler_start)
  89. /*
  90. * __tegra_cpu_reset_handler:
  91. *
  92. * Common handler for all CPU reset events.
  93. *
  94. * Register usage within the reset handler:
  95. *
  96. * Others: scratch
  97. * R6 = SoC ID
  98. * R7 = CPU present (to the OS) mask
  99. * R8 = CPU in LP1 state mask
  100. * R9 = CPU in LP2 state mask
  101. * R10 = CPU number
  102. * R11 = CPU mask
  103. * R12 = pointer to reset handler data
  104. *
  105. * NOTE: This code is copied to IRAM. All code and data accesses
  106. * must be position-independent.
  107. */
  108. .align L1_CACHE_SHIFT
  109. ENTRY(__tegra_cpu_reset_handler)
  110. cpsid aif, 0x13 @ SVC mode, interrupts disabled
  111. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  112. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  113. t20_check:
  114. cmp r6, #TEGRA20
  115. bne after_t20_check
  116. t20_errata:
  117. # Tegra20 is a Cortex-A9 r1p1
  118. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  119. orr r0, r0, #1 << 14 @ erratum 716044
  120. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  121. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  122. orr r0, r0, #1 << 4 @ erratum 742230
  123. orr r0, r0, #1 << 11 @ erratum 751472
  124. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  125. b after_errata
  126. after_t20_check:
  127. #endif
  128. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  129. t30_check:
  130. cmp r6, #TEGRA30
  131. bne after_t30_check
  132. t30_errata:
  133. # Tegra30 is a Cortex-A9 r2p9
  134. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  135. orr r0, r0, #1 << 6 @ erratum 743622
  136. orr r0, r0, #1 << 11 @ erratum 751472
  137. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  138. b after_errata
  139. after_t30_check:
  140. #endif
  141. after_errata:
  142. mrc p15, 0, r10, c0, c0, 5 @ MPIDR
  143. and r10, r10, #0x3 @ R10 = CPU number
  144. mov r11, #1
  145. mov r11, r11, lsl r10 @ R11 = CPU mask
  146. adr r12, __tegra_cpu_reset_handler_data
  147. #ifdef CONFIG_SMP
  148. /* Does the OS know about this CPU? */
  149. ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
  150. tst r7, r11 @ if !present
  151. bleq __die @ CPU not present (to OS)
  152. #endif
  153. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  154. /* Are we on Tegra20? */
  155. cmp r6, #TEGRA20
  156. bne 1f
  157. /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
  158. mov32 r5, TEGRA_PMC_BASE
  159. mov r0, #0
  160. cmp r10, #0
  161. strne r0, [r5, #PMC_SCRATCH41]
  162. 1:
  163. #endif
  164. /* Waking up from LP1? */
  165. ldr r8, [r12, #RESET_DATA(MASK_LP1)]
  166. tst r8, r11 @ if in_lp1
  167. beq __is_not_lp1
  168. cmp r10, #0
  169. bne __die @ only CPU0 can be here
  170. ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
  171. cmp lr, #0
  172. bleq __die @ no LP1 startup handler
  173. THUMB( add lr, lr, #1 ) @ switch to Thumb mode
  174. bx lr
  175. __is_not_lp1:
  176. /* Waking up from LP2? */
  177. ldr r9, [r12, #RESET_DATA(MASK_LP2)]
  178. tst r9, r11 @ if in_lp2
  179. beq __is_not_lp2
  180. ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
  181. cmp lr, #0
  182. bleq __die @ no LP2 startup handler
  183. bx lr
  184. __is_not_lp2:
  185. #ifdef CONFIG_SMP
  186. /*
  187. * Can only be secondary boot (initial or hotplug)
  188. * CPU0 can't be here for Tegra20/30
  189. */
  190. cmp r6, #TEGRA114
  191. beq __no_cpu0_chk
  192. cmp r10, #0
  193. bleq __die @ CPU0 cannot be here
  194. __no_cpu0_chk:
  195. ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
  196. cmp lr, #0
  197. bleq __die @ no secondary startup handler
  198. bx lr
  199. #endif
  200. /*
  201. * We don't know why the CPU reset. Just kill it.
  202. * The LR register will contain the address we died at + 4.
  203. */
  204. __die:
  205. sub lr, lr, #4
  206. mov32 r7, TEGRA_PMC_BASE
  207. str lr, [r7, #PMC_SCRATCH41]
  208. mov32 r7, TEGRA_CLK_RESET_BASE
  209. /* Are we on Tegra20? */
  210. cmp r6, #TEGRA20
  211. bne 1f
  212. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  213. mov32 r0, 0x1111
  214. mov r1, r0, lsl r10
  215. str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
  216. #endif
  217. 1:
  218. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  219. mov32 r6, TEGRA_FLOW_CTRL_BASE
  220. cmp r10, #0
  221. moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
  222. moveq r2, #FLOW_CTRL_CPU0_CSR
  223. movne r1, r10, lsl #3
  224. addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
  225. addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
  226. /* Clear CPU "event" and "interrupt" flags and power gate
  227. it when halting but not before it is in the "WFI" state. */
  228. ldr r0, [r6, +r2]
  229. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  230. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  231. str r0, [r6, +r2]
  232. /* Unconditionally halt this CPU */
  233. mov r0, #FLOW_CTRL_WAITEVENT
  234. str r0, [r6, +r1]
  235. ldr r0, [r6, +r1] @ memory barrier
  236. dsb
  237. isb
  238. wfi @ CPU should be power gated here
  239. /* If the CPU didn't power gate above just kill it's clock. */
  240. mov r0, r11, lsl #8
  241. str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
  242. #endif
  243. /* If the CPU still isn't dead, just spin here. */
  244. b .
  245. ENDPROC(__tegra_cpu_reset_handler)
  246. .align L1_CACHE_SHIFT
  247. .type __tegra_cpu_reset_handler_data, %object
  248. .globl __tegra_cpu_reset_handler_data
  249. __tegra_cpu_reset_handler_data:
  250. .rept TEGRA_RESET_DATA_SIZE
  251. .long 0
  252. .endr
  253. .align L1_CACHE_SHIFT
  254. ENTRY(__tegra_cpu_reset_handler_end)