sleep44xx.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * OMAP44xx sleep code.
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. *
  7. * This program is free software,you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/assembler.h>
  13. #include <asm/smp_scu.h>
  14. #include <asm/memory.h>
  15. #include <asm/hardware/cache-l2x0.h>
  16. #include "omap-secure.h"
  17. #include "common.h"
  18. #include "omap44xx.h"
  19. #include "omap4-sar-layout.h"
  20. #if defined(CONFIG_SMP) && defined(CONFIG_PM)
  21. .macro DO_SMC
  22. dsb
  23. smc #0
  24. dsb
  25. .endm
  26. #ifdef CONFIG_ARCH_OMAP4
  27. /*
  28. * =============================
  29. * == CPU suspend finisher ==
  30. * =============================
  31. *
  32. * void omap4_finish_suspend(unsigned long cpu_state)
  33. *
  34. * This function code saves the CPU context and performs the CPU
  35. * power down sequence. Calling WFI effectively changes the CPU
  36. * power domains states to the desired target power state.
  37. *
  38. * @cpu_state : contains context save state (r0)
  39. * 0 - No context lost
  40. * 1 - CPUx L1 and logic lost: MPUSS CSWR
  41. * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
  42. * 3 - CPUx L1 and logic lost + GIC + L2 lost: MPUSS OFF
  43. * @return: This function never returns for CPU OFF and DORMANT power states.
  44. * Post WFI, CPU transitions to DORMANT or OFF power state and on wake-up
  45. * from this follows a full CPU reset path via ROM code to CPU restore code.
  46. * The restore function pointer is stored at CPUx_WAKEUP_NS_PA_ADDR_OFFSET.
  47. * It returns to the caller for CPU INACTIVE and ON power states or in case
  48. * CPU failed to transition to targeted OFF/DORMANT state.
  49. *
  50. * omap4_finish_suspend() calls v7_flush_dcache_all() which doesn't save
  51. * stack frame and it expects the caller to take care of it. Hence the entire
  52. * stack frame is saved to avoid possible stack corruption.
  53. */
  54. ENTRY(omap4_finish_suspend)
  55. stmfd sp!, {r4-r12, lr}
  56. cmp r0, #0x0
  57. beq do_WFI @ No lowpower state, jump to WFI
  58. /*
  59. * Flush all data from the L1 data cache before disabling
  60. * SCTLR.C bit.
  61. */
  62. bl omap4_get_sar_ram_base
  63. ldr r9, [r0, #OMAP_TYPE_OFFSET]
  64. cmp r9, #0x1 @ Check for HS device
  65. bne skip_secure_l1_clean
  66. mov r0, #SCU_PM_NORMAL
  67. mov r1, #0xFF @ clean seucre L1
  68. stmfd r13!, {r4-r12, r14}
  69. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  70. DO_SMC
  71. ldmfd r13!, {r4-r12, r14}
  72. skip_secure_l1_clean:
  73. bl v7_flush_dcache_all
  74. /*
  75. * Clear the SCTLR.C bit to prevent further data cache
  76. * allocation. Clearing SCTLR.C would make all the data accesses
  77. * strongly ordered and would not hit the cache.
  78. */
  79. mrc p15, 0, r0, c1, c0, 0
  80. bic r0, r0, #(1 << 2) @ Disable the C bit
  81. mcr p15, 0, r0, c1, c0, 0
  82. isb
  83. bl v7_invalidate_l1
  84. /*
  85. * Switch the CPU from Symmetric Multiprocessing (SMP) mode
  86. * to AsymmetricMultiprocessing (AMP) mode by programming
  87. * the SCU power status to DORMANT or OFF mode.
  88. * This enables the CPU to be taken out of coherency by
  89. * preventing the CPU from receiving cache, TLB, or BTB
  90. * maintenance operations broadcast by other CPUs in the cluster.
  91. */
  92. bl omap4_get_sar_ram_base
  93. mov r8, r0
  94. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  95. cmp r9, #0x1 @ Check for HS device
  96. bne scu_gp_set
  97. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  98. ands r0, r0, #0x0f
  99. ldreq r0, [r8, #SCU_OFFSET0]
  100. ldrne r0, [r8, #SCU_OFFSET1]
  101. mov r1, #0x00
  102. stmfd r13!, {r4-r12, r14}
  103. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  104. DO_SMC
  105. ldmfd r13!, {r4-r12, r14}
  106. b skip_scu_gp_set
  107. scu_gp_set:
  108. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  109. ands r0, r0, #0x0f
  110. ldreq r1, [r8, #SCU_OFFSET0]
  111. ldrne r1, [r8, #SCU_OFFSET1]
  112. bl omap4_get_scu_base
  113. bl scu_power_mode
  114. skip_scu_gp_set:
  115. mrc p15, 0, r0, c1, c1, 2 @ Read NSACR data
  116. tst r0, #(1 << 18)
  117. mrcne p15, 0, r0, c1, c0, 1
  118. bicne r0, r0, #(1 << 6) @ Disable SMP bit
  119. mcrne p15, 0, r0, c1, c0, 1
  120. isb
  121. dsb
  122. #ifdef CONFIG_CACHE_L2X0
  123. /*
  124. * Clean and invalidate the L2 cache.
  125. * Common cache-l2x0.c functions can't be used here since it
  126. * uses spinlocks. We are out of coherency here with data cache
  127. * disabled. The spinlock implementation uses exclusive load/store
  128. * instruction which can fail without data cache being enabled.
  129. * OMAP4 hardware doesn't support exclusive monitor which can
  130. * overcome exclusive access issue. Because of this, CPU can
  131. * lead to deadlock.
  132. */
  133. bl omap4_get_sar_ram_base
  134. mov r8, r0
  135. mrc p15, 0, r5, c0, c0, 5 @ Read MPIDR
  136. ands r5, r5, #0x0f
  137. ldreq r0, [r8, #L2X0_SAVE_OFFSET0] @ Retrieve L2 state from SAR
  138. ldrne r0, [r8, #L2X0_SAVE_OFFSET1] @ memory.
  139. cmp r0, #3
  140. bne do_WFI
  141. #ifdef CONFIG_PL310_ERRATA_727915
  142. mov r0, #0x03
  143. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  144. DO_SMC
  145. #endif
  146. bl omap4_get_l2cache_base
  147. mov r2, r0
  148. ldr r0, =0xffff
  149. str r0, [r2, #L2X0_CLEAN_INV_WAY]
  150. wait:
  151. ldr r0, [r2, #L2X0_CLEAN_INV_WAY]
  152. ldr r1, =0xffff
  153. ands r0, r0, r1
  154. bne wait
  155. #ifdef CONFIG_PL310_ERRATA_727915
  156. mov r0, #0x00
  157. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  158. DO_SMC
  159. #endif
  160. l2x_sync:
  161. bl omap4_get_l2cache_base
  162. mov r2, r0
  163. mov r0, #0x0
  164. str r0, [r2, #L2X0_CACHE_SYNC]
  165. sync:
  166. ldr r0, [r2, #L2X0_CACHE_SYNC]
  167. ands r0, r0, #0x1
  168. bne sync
  169. #endif
  170. do_WFI:
  171. bl omap_do_wfi
  172. /*
  173. * CPU is here when it failed to enter OFF/DORMANT or
  174. * no low power state was attempted.
  175. */
  176. mrc p15, 0, r0, c1, c0, 0
  177. tst r0, #(1 << 2) @ Check C bit enabled?
  178. orreq r0, r0, #(1 << 2) @ Enable the C bit
  179. mcreq p15, 0, r0, c1, c0, 0
  180. isb
  181. /*
  182. * Ensure the CPU power state is set to NORMAL in
  183. * SCU power state so that CPU is back in coherency.
  184. * In non-coherent mode CPU can lock-up and lead to
  185. * system deadlock.
  186. */
  187. mrc p15, 0, r0, c1, c0, 1
  188. tst r0, #(1 << 6) @ Check SMP bit enabled?
  189. orreq r0, r0, #(1 << 6)
  190. mcreq p15, 0, r0, c1, c0, 1
  191. isb
  192. bl omap4_get_sar_ram_base
  193. mov r8, r0
  194. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  195. cmp r9, #0x1 @ Check for HS device
  196. bne scu_gp_clear
  197. mov r0, #SCU_PM_NORMAL
  198. mov r1, #0x00
  199. stmfd r13!, {r4-r12, r14}
  200. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  201. DO_SMC
  202. ldmfd r13!, {r4-r12, r14}
  203. b skip_scu_gp_clear
  204. scu_gp_clear:
  205. bl omap4_get_scu_base
  206. mov r1, #SCU_PM_NORMAL
  207. bl scu_power_mode
  208. skip_scu_gp_clear:
  209. isb
  210. dsb
  211. ldmfd sp!, {r4-r12, pc}
  212. ENDPROC(omap4_finish_suspend)
  213. /*
  214. * ============================
  215. * == CPU resume entry point ==
  216. * ============================
  217. *
  218. * void omap4_cpu_resume(void)
  219. *
  220. * ROM code jumps to this function while waking up from CPU
  221. * OFF or DORMANT state. Physical address of the function is
  222. * stored in the SAR RAM while entering to OFF or DORMANT mode.
  223. * The restore function pointer is stored at CPUx_WAKEUP_NS_PA_ADDR_OFFSET.
  224. */
  225. ENTRY(omap4_cpu_resume)
  226. /*
  227. * Configure ACTRL and enable NS SMP bit access on CPU1 on HS device.
  228. * OMAP44XX EMU/HS devices - CPU0 SMP bit access is enabled in PPA
  229. * init and for CPU1, a secure PPA API provided. CPU0 must be ON
  230. * while executing NS_SMP API on CPU1 and PPA version must be 1.4.0+.
  231. * OMAP443X GP devices- SMP bit isn't accessible.
  232. * OMAP446X GP devices - SMP bit access is enabled on both CPUs.
  233. */
  234. ldr r8, =OMAP44XX_SAR_RAM_BASE
  235. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  236. cmp r9, #0x1 @ Skip if GP device
  237. bne skip_ns_smp_enable
  238. mrc p15, 0, r0, c0, c0, 5
  239. ands r0, r0, #0x0f
  240. beq skip_ns_smp_enable
  241. ppa_actrl_retry:
  242. mov r0, #OMAP4_PPA_CPU_ACTRL_SMP_INDEX
  243. adr r1, ppa_zero_params_offset
  244. ldr r3, [r1]
  245. add r3, r3, r1 @ Pointer to ppa_zero_params
  246. mov r1, #0x0 @ Process ID
  247. mov r2, #0x4 @ Flag
  248. mov r6, #0xff
  249. mov r12, #0x00 @ Secure Service ID
  250. DO_SMC
  251. cmp r0, #0x0 @ API returns 0 on success.
  252. beq enable_smp_bit
  253. b ppa_actrl_retry
  254. enable_smp_bit:
  255. mrc p15, 0, r0, c1, c0, 1
  256. tst r0, #(1 << 6) @ Check SMP bit enabled?
  257. orreq r0, r0, #(1 << 6)
  258. mcreq p15, 0, r0, c1, c0, 1
  259. isb
  260. skip_ns_smp_enable:
  261. #ifdef CONFIG_CACHE_L2X0
  262. /*
  263. * Restore the L2 AUXCTRL and enable the L2 cache.
  264. * OMAP4_MON_L2X0_AUXCTRL_INDEX = Program the L2X0 AUXCTRL
  265. * OMAP4_MON_L2X0_CTRL_INDEX = Enable the L2 using L2X0 CTRL
  266. * register r0 contains value to be programmed.
  267. * L2 cache is already invalidate by ROM code as part
  268. * of MPUSS OFF wakeup path.
  269. */
  270. ldr r2, =OMAP44XX_L2CACHE_BASE
  271. ldr r0, [r2, #L2X0_CTRL]
  272. and r0, #0x0f
  273. cmp r0, #1
  274. beq skip_l2en @ Skip if already enabled
  275. ldr r3, =OMAP44XX_SAR_RAM_BASE
  276. ldr r1, [r3, #OMAP_TYPE_OFFSET]
  277. cmp r1, #0x1 @ Check for HS device
  278. bne set_gp_por
  279. ldr r0, =OMAP4_PPA_L2_POR_INDEX
  280. ldr r1, =OMAP44XX_SAR_RAM_BASE
  281. ldr r4, [r1, #L2X0_PREFETCH_CTRL_OFFSET]
  282. adr r1, ppa_por_params_offset
  283. ldr r3, [r1]
  284. add r3, r3, r1 @ Pointer to ppa_por_params
  285. str r4, [r3, #0x04]
  286. mov r1, #0x0 @ Process ID
  287. mov r2, #0x4 @ Flag
  288. mov r6, #0xff
  289. mov r12, #0x00 @ Secure Service ID
  290. DO_SMC
  291. b set_aux_ctrl
  292. set_gp_por:
  293. ldr r1, =OMAP44XX_SAR_RAM_BASE
  294. ldr r0, [r1, #L2X0_PREFETCH_CTRL_OFFSET]
  295. ldr r12, =OMAP4_MON_L2X0_PREFETCH_INDEX @ Setup L2 PREFETCH
  296. DO_SMC
  297. set_aux_ctrl:
  298. ldr r1, =OMAP44XX_SAR_RAM_BASE
  299. ldr r0, [r1, #L2X0_AUXCTRL_OFFSET]
  300. ldr r12, =OMAP4_MON_L2X0_AUXCTRL_INDEX @ Setup L2 AUXCTRL
  301. DO_SMC
  302. mov r0, #0x1
  303. ldr r12, =OMAP4_MON_L2X0_CTRL_INDEX @ Enable L2 cache
  304. DO_SMC
  305. skip_l2en:
  306. #endif
  307. b cpu_resume @ Jump to generic resume
  308. ppa_por_params_offset:
  309. .long ppa_por_params - .
  310. ENDPROC(omap4_cpu_resume)
  311. #endif /* CONFIG_ARCH_OMAP4 */
  312. #endif /* defined(CONFIG_SMP) && defined(CONFIG_PM) */
  313. ENTRY(omap_do_wfi)
  314. stmfd sp!, {lr}
  315. #ifdef CONFIG_OMAP_INTERCONNECT_BARRIER
  316. /* Drain interconnect write buffers. */
  317. bl omap_interconnect_sync
  318. #endif
  319. /*
  320. * Execute an ISB instruction to ensure that all of the
  321. * CP15 register changes have been committed.
  322. */
  323. isb
  324. /*
  325. * Execute a barrier instruction to ensure that all cache,
  326. * TLB and branch predictor maintenance operations issued
  327. * by any CPU in the cluster have completed.
  328. */
  329. dsb
  330. dmb
  331. /*
  332. * Execute a WFI instruction and wait until the
  333. * STANDBYWFI output is asserted to indicate that the
  334. * CPU is in idle and low power state. CPU can specualatively
  335. * prefetch the instructions so add NOPs after WFI. Sixteen
  336. * NOPs as per Cortex-A9 pipeline.
  337. */
  338. wfi @ Wait For Interrupt
  339. nop
  340. nop
  341. nop
  342. nop
  343. nop
  344. nop
  345. nop
  346. nop
  347. nop
  348. nop
  349. nop
  350. nop
  351. nop
  352. nop
  353. nop
  354. nop
  355. ldmfd sp!, {pc}
  356. ppa_zero_params_offset:
  357. .long ppa_zero_params - .
  358. ENDPROC(omap_do_wfi)
  359. .data
  360. .align 2
  361. ppa_zero_params:
  362. .word 0
  363. ppa_por_params:
  364. .word 1, 0