reset-handler.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. * 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. mrc p15, 0, r10, c0, c0, 5 @ MPIDR
  102. and r10, r10, #0x3 @ R10 = CPU number
  103. mov r11, #1
  104. mov r11, r11, lsl r10 @ R11 = CPU mask
  105. adr r12, __tegra_cpu_reset_handler_data
  106. #ifdef CONFIG_SMP
  107. /* Does the OS know about this CPU? */
  108. ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
  109. tst r7, r11 @ if !present
  110. bleq __die @ CPU not present (to OS)
  111. #endif
  112. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  113. /* Are we on Tegra20? */
  114. mov32 r6, TEGRA_APB_MISC_BASE
  115. ldr r0, [r6, #APB_MISC_GP_HIDREV]
  116. and r0, r0, #0xff00
  117. cmp r0, #(0x20 << 8)
  118. bne 1f
  119. /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
  120. mov32 r6, TEGRA_PMC_BASE
  121. mov r0, #0
  122. cmp r10, #0
  123. strne r0, [r6, #PMC_SCRATCH41]
  124. 1:
  125. #endif
  126. /* Waking up from LP2? */
  127. ldr r9, [r12, #RESET_DATA(MASK_LP2)]
  128. tst r9, r11 @ if in_lp2
  129. beq __is_not_lp2
  130. ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
  131. cmp lr, #0
  132. bleq __die @ no LP2 startup handler
  133. bx lr
  134. __is_not_lp2:
  135. #ifdef CONFIG_SMP
  136. /*
  137. * Can only be secondary boot (initial or hotplug) but CPU 0
  138. * cannot be here.
  139. */
  140. cmp r10, #0
  141. bleq __die @ CPU0 cannot be here
  142. ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
  143. cmp lr, #0
  144. bleq __die @ no secondary startup handler
  145. bx lr
  146. #endif
  147. /*
  148. * We don't know why the CPU reset. Just kill it.
  149. * The LR register will contain the address we died at + 4.
  150. */
  151. __die:
  152. sub lr, lr, #4
  153. mov32 r7, TEGRA_PMC_BASE
  154. str lr, [r7, #PMC_SCRATCH41]
  155. mov32 r7, TEGRA_CLK_RESET_BASE
  156. /* Are we on Tegra20? */
  157. mov32 r6, TEGRA_APB_MISC_BASE
  158. ldr r0, [r6, #APB_MISC_GP_HIDREV]
  159. and r0, r0, #0xff00
  160. cmp r0, #(0x20 << 8)
  161. bne 1f
  162. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  163. mov32 r0, 0x1111
  164. mov r1, r0, lsl r10
  165. str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
  166. #endif
  167. 1:
  168. #ifdef CONFIG_ARCH_TEGRA_3x_SOC
  169. mov32 r6, TEGRA_FLOW_CTRL_BASE
  170. cmp r10, #0
  171. moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
  172. moveq r2, #FLOW_CTRL_CPU0_CSR
  173. movne r1, r10, lsl #3
  174. addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
  175. addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
  176. /* Clear CPU "event" and "interrupt" flags and power gate
  177. it when halting but not before it is in the "WFI" state. */
  178. ldr r0, [r6, +r2]
  179. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  180. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  181. str r0, [r6, +r2]
  182. /* Unconditionally halt this CPU */
  183. mov r0, #FLOW_CTRL_WAITEVENT
  184. str r0, [r6, +r1]
  185. ldr r0, [r6, +r1] @ memory barrier
  186. dsb
  187. isb
  188. wfi @ CPU should be power gated here
  189. /* If the CPU didn't power gate above just kill it's clock. */
  190. mov r0, r11, lsl #8
  191. str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
  192. #endif
  193. /* If the CPU still isn't dead, just spin here. */
  194. b .
  195. ENDPROC(__tegra_cpu_reset_handler)
  196. .align L1_CACHE_SHIFT
  197. .type __tegra_cpu_reset_handler_data, %object
  198. .globl __tegra_cpu_reset_handler_data
  199. __tegra_cpu_reset_handler_data:
  200. .rept TEGRA_RESET_DATA_SIZE
  201. .long 0
  202. .endr
  203. .align L1_CACHE_SHIFT
  204. ENTRY(__tegra_cpu_reset_handler_end)