reset-handler.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. */
  38. ENTRY(tegra_resume)
  39. bl v7_invalidate_l1
  40. cpu_id r0
  41. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  42. cmp r6, #TEGRA114
  43. beq no_cpu0_chk
  44. cmp r0, #0 @ CPU0?
  45. THUMB( it ne )
  46. bne cpu_resume @ no
  47. no_cpu0_chk:
  48. #ifndef CONFIG_ARCH_TEGRA_2x_SOC
  49. /* Are we on Tegra20? */
  50. cmp r6, #TEGRA20
  51. beq 1f @ Yes
  52. /* Clear the flow controller flags for this CPU. */
  53. cpu_to_csr_req r1, r0
  54. mov32 r2, TEGRA_FLOW_CTRL_BASE
  55. ldr r1, [r2, r1]
  56. /* Clear event & intr flag */
  57. orr r1, r1, \
  58. #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  59. movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
  60. @ & ext flags for CPU power mgnt
  61. bic r1, r1, r0
  62. str r1, [r2]
  63. 1:
  64. #endif
  65. check_cpu_part_num 0xc09, r8, r9
  66. bne not_ca9
  67. #ifdef CONFIG_HAVE_ARM_SCU
  68. /* enable SCU */
  69. mov32 r0, TEGRA_ARM_PERIF_BASE
  70. ldr r1, [r0]
  71. orr r1, r1, #1
  72. str r1, [r0]
  73. #endif
  74. /* L2 cache resume & re-enable */
  75. l2_cache_resume r0, r1, r2, l2x0_saved_regs_addr
  76. not_ca9:
  77. b cpu_resume
  78. ENDPROC(tegra_resume)
  79. #endif
  80. #ifdef CONFIG_CACHE_L2X0
  81. .globl l2x0_saved_regs_addr
  82. l2x0_saved_regs_addr:
  83. .long 0
  84. #endif
  85. .align L1_CACHE_SHIFT
  86. ENTRY(__tegra_cpu_reset_handler_start)
  87. /*
  88. * __tegra_cpu_reset_handler:
  89. *
  90. * Common handler for all CPU reset events.
  91. *
  92. * Register usage within the reset handler:
  93. *
  94. * Others: scratch
  95. * R6 = SoC ID
  96. * R7 = CPU present (to the OS) mask
  97. * R8 = CPU in LP1 state mask
  98. * R9 = CPU in LP2 state mask
  99. * R10 = CPU number
  100. * R11 = CPU mask
  101. * R12 = pointer to reset handler data
  102. *
  103. * NOTE: This code is copied to IRAM. All code and data accesses
  104. * must be position-independent.
  105. */
  106. .align L1_CACHE_SHIFT
  107. ENTRY(__tegra_cpu_reset_handler)
  108. cpsid aif, 0x13 @ SVC mode, interrupts disabled
  109. tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
  110. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  111. t20_check:
  112. cmp r6, #TEGRA20
  113. bne after_t20_check
  114. t20_errata:
  115. # Tegra20 is a Cortex-A9 r1p1
  116. mrc p15, 0, r0, c1, c0, 0 @ read system control register
  117. orr r0, r0, #1 << 14 @ erratum 716044
  118. mcr p15, 0, r0, c1, c0, 0 @ write system control register
  119. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  120. orr r0, r0, #1 << 4 @ erratum 742230
  121. orr r0, r0, #1 << 11 @ erratum 751472
  122. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  123. b after_errata
  124. after_t20_check:
  125. #endif
  126. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  127. t30_check:
  128. cmp r6, #TEGRA30
  129. bne after_t30_check
  130. t30_errata:
  131. # Tegra30 is a Cortex-A9 r2p9
  132. mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
  133. orr r0, r0, #1 << 6 @ erratum 743622
  134. orr r0, r0, #1 << 11 @ erratum 751472
  135. mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
  136. b after_errata
  137. after_t30_check:
  138. #endif
  139. after_errata:
  140. mrc p15, 0, r10, c0, c0, 5 @ MPIDR
  141. and r10, r10, #0x3 @ R10 = CPU number
  142. mov r11, #1
  143. mov r11, r11, lsl r10 @ R11 = CPU mask
  144. adr r12, __tegra_cpu_reset_handler_data
  145. #ifdef CONFIG_SMP
  146. /* Does the OS know about this CPU? */
  147. ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
  148. tst r7, r11 @ if !present
  149. bleq __die @ CPU not present (to OS)
  150. #endif
  151. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  152. /* Are we on Tegra20? */
  153. cmp r6, #TEGRA20
  154. bne 1f
  155. /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
  156. mov32 r5, TEGRA_PMC_BASE
  157. mov r0, #0
  158. cmp r10, #0
  159. strne r0, [r5, #PMC_SCRATCH41]
  160. 1:
  161. #endif
  162. /* Waking up from LP2? */
  163. ldr r9, [r12, #RESET_DATA(MASK_LP2)]
  164. tst r9, r11 @ if in_lp2
  165. beq __is_not_lp2
  166. ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
  167. cmp lr, #0
  168. bleq __die @ no LP2 startup handler
  169. bx lr
  170. __is_not_lp2:
  171. #ifdef CONFIG_SMP
  172. /*
  173. * Can only be secondary boot (initial or hotplug)
  174. * CPU0 can't be here for Tegra20/30
  175. */
  176. cmp r6, #TEGRA114
  177. beq __no_cpu0_chk
  178. cmp r10, #0
  179. bleq __die @ CPU0 cannot be here
  180. __no_cpu0_chk:
  181. ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
  182. cmp lr, #0
  183. bleq __die @ no secondary startup handler
  184. bx lr
  185. #endif
  186. /*
  187. * We don't know why the CPU reset. Just kill it.
  188. * The LR register will contain the address we died at + 4.
  189. */
  190. __die:
  191. sub lr, lr, #4
  192. mov32 r7, TEGRA_PMC_BASE
  193. str lr, [r7, #PMC_SCRATCH41]
  194. mov32 r7, TEGRA_CLK_RESET_BASE
  195. /* Are we on Tegra20? */
  196. cmp r6, #TEGRA20
  197. bne 1f
  198. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  199. mov32 r0, 0x1111
  200. mov r1, r0, lsl r10
  201. str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
  202. #endif
  203. 1:
  204. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  205. mov32 r6, TEGRA_FLOW_CTRL_BASE
  206. cmp r10, #0
  207. moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
  208. moveq r2, #FLOW_CTRL_CPU0_CSR
  209. movne r1, r10, lsl #3
  210. addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
  211. addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
  212. /* Clear CPU "event" and "interrupt" flags and power gate
  213. it when halting but not before it is in the "WFI" state. */
  214. ldr r0, [r6, +r2]
  215. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  216. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  217. str r0, [r6, +r2]
  218. /* Unconditionally halt this CPU */
  219. mov r0, #FLOW_CTRL_WAITEVENT
  220. str r0, [r6, +r1]
  221. ldr r0, [r6, +r1] @ memory barrier
  222. dsb
  223. isb
  224. wfi @ CPU should be power gated here
  225. /* If the CPU didn't power gate above just kill it's clock. */
  226. mov r0, r11, lsl #8
  227. str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
  228. #endif
  229. /* If the CPU still isn't dead, just spin here. */
  230. b .
  231. ENDPROC(__tegra_cpu_reset_handler)
  232. .align L1_CACHE_SHIFT
  233. .type __tegra_cpu_reset_handler_data, %object
  234. .globl __tegra_cpu_reset_handler_data
  235. __tegra_cpu_reset_handler_data:
  236. .rept TEGRA_RESET_DATA_SIZE
  237. .long 0
  238. .endr
  239. .align L1_CACHE_SHIFT
  240. ENTRY(__tegra_cpu_reset_handler_end)