reset-handler.S 6.5 KB

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