reset-handler.S 6.6 KB

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