sleep44xx.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. /*
  84. * Invalidate L1 data cache. Even though only invalidate is
  85. * necessary exported flush API is used here. Doing clean
  86. * on already clean cache would be almost NOP.
  87. */
  88. bl v7_flush_dcache_all
  89. /*
  90. * Switch the CPU from Symmetric Multiprocessing (SMP) mode
  91. * to AsymmetricMultiprocessing (AMP) mode by programming
  92. * the SCU power status to DORMANT or OFF mode.
  93. * This enables the CPU to be taken out of coherency by
  94. * preventing the CPU from receiving cache, TLB, or BTB
  95. * maintenance operations broadcast by other CPUs in the cluster.
  96. */
  97. bl omap4_get_sar_ram_base
  98. mov r8, r0
  99. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  100. cmp r9, #0x1 @ Check for HS device
  101. bne scu_gp_set
  102. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  103. ands r0, r0, #0x0f
  104. ldreq r0, [r8, #SCU_OFFSET0]
  105. ldrne r0, [r8, #SCU_OFFSET1]
  106. mov r1, #0x00
  107. stmfd r13!, {r4-r12, r14}
  108. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  109. DO_SMC
  110. ldmfd r13!, {r4-r12, r14}
  111. b skip_scu_gp_set
  112. scu_gp_set:
  113. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  114. ands r0, r0, #0x0f
  115. ldreq r1, [r8, #SCU_OFFSET0]
  116. ldrne r1, [r8, #SCU_OFFSET1]
  117. bl omap4_get_scu_base
  118. bl scu_power_mode
  119. skip_scu_gp_set:
  120. mrc p15, 0, r0, c1, c1, 2 @ Read NSACR data
  121. tst r0, #(1 << 18)
  122. mrcne p15, 0, r0, c1, c0, 1
  123. bicne r0, r0, #(1 << 6) @ Disable SMP bit
  124. mcrne p15, 0, r0, c1, c0, 1
  125. isb
  126. dsb
  127. #ifdef CONFIG_CACHE_L2X0
  128. /*
  129. * Clean and invalidate the L2 cache.
  130. * Common cache-l2x0.c functions can't be used here since it
  131. * uses spinlocks. We are out of coherency here with data cache
  132. * disabled. The spinlock implementation uses exclusive load/store
  133. * instruction which can fail without data cache being enabled.
  134. * OMAP4 hardware doesn't support exclusive monitor which can
  135. * overcome exclusive access issue. Because of this, CPU can
  136. * lead to deadlock.
  137. */
  138. bl omap4_get_sar_ram_base
  139. mov r8, r0
  140. mrc p15, 0, r5, c0, c0, 5 @ Read MPIDR
  141. ands r5, r5, #0x0f
  142. ldreq r0, [r8, #L2X0_SAVE_OFFSET0] @ Retrieve L2 state from SAR
  143. ldrne r0, [r8, #L2X0_SAVE_OFFSET1] @ memory.
  144. cmp r0, #3
  145. bne do_WFI
  146. #ifdef CONFIG_PL310_ERRATA_727915
  147. mov r0, #0x03
  148. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  149. DO_SMC
  150. #endif
  151. bl omap4_get_l2cache_base
  152. mov r2, r0
  153. ldr r0, =0xffff
  154. str r0, [r2, #L2X0_CLEAN_INV_WAY]
  155. wait:
  156. ldr r0, [r2, #L2X0_CLEAN_INV_WAY]
  157. ldr r1, =0xffff
  158. ands r0, r0, r1
  159. bne wait
  160. #ifdef CONFIG_PL310_ERRATA_727915
  161. mov r0, #0x00
  162. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  163. DO_SMC
  164. #endif
  165. l2x_sync:
  166. bl omap4_get_l2cache_base
  167. mov r2, r0
  168. mov r0, #0x0
  169. str r0, [r2, #L2X0_CACHE_SYNC]
  170. sync:
  171. ldr r0, [r2, #L2X0_CACHE_SYNC]
  172. ands r0, r0, #0x1
  173. bne sync
  174. #endif
  175. do_WFI:
  176. bl omap_do_wfi
  177. /*
  178. * CPU is here when it failed to enter OFF/DORMANT or
  179. * no low power state was attempted.
  180. */
  181. mrc p15, 0, r0, c1, c0, 0
  182. tst r0, #(1 << 2) @ Check C bit enabled?
  183. orreq r0, r0, #(1 << 2) @ Enable the C bit
  184. mcreq p15, 0, r0, c1, c0, 0
  185. isb
  186. /*
  187. * Ensure the CPU power state is set to NORMAL in
  188. * SCU power state so that CPU is back in coherency.
  189. * In non-coherent mode CPU can lock-up and lead to
  190. * system deadlock.
  191. */
  192. mrc p15, 0, r0, c1, c0, 1
  193. tst r0, #(1 << 6) @ Check SMP bit enabled?
  194. orreq r0, r0, #(1 << 6)
  195. mcreq p15, 0, r0, c1, c0, 1
  196. isb
  197. bl omap4_get_sar_ram_base
  198. mov r8, r0
  199. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  200. cmp r9, #0x1 @ Check for HS device
  201. bne scu_gp_clear
  202. mov r0, #SCU_PM_NORMAL
  203. mov r1, #0x00
  204. stmfd r13!, {r4-r12, r14}
  205. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  206. DO_SMC
  207. ldmfd r13!, {r4-r12, r14}
  208. b skip_scu_gp_clear
  209. scu_gp_clear:
  210. bl omap4_get_scu_base
  211. mov r1, #SCU_PM_NORMAL
  212. bl scu_power_mode
  213. skip_scu_gp_clear:
  214. isb
  215. dsb
  216. ldmfd sp!, {r4-r12, pc}
  217. ENDPROC(omap4_finish_suspend)
  218. /*
  219. * ============================
  220. * == CPU resume entry point ==
  221. * ============================
  222. *
  223. * void omap4_cpu_resume(void)
  224. *
  225. * ROM code jumps to this function while waking up from CPU
  226. * OFF or DORMANT state. Physical address of the function is
  227. * stored in the SAR RAM while entering to OFF or DORMANT mode.
  228. * The restore function pointer is stored at CPUx_WAKEUP_NS_PA_ADDR_OFFSET.
  229. */
  230. ENTRY(omap4_cpu_resume)
  231. /*
  232. * Configure ACTRL and enable NS SMP bit access on CPU1 on HS device.
  233. * OMAP44XX EMU/HS devices - CPU0 SMP bit access is enabled in PPA
  234. * init and for CPU1, a secure PPA API provided. CPU0 must be ON
  235. * while executing NS_SMP API on CPU1 and PPA version must be 1.4.0+.
  236. * OMAP443X GP devices- SMP bit isn't accessible.
  237. * OMAP446X GP devices - SMP bit access is enabled on both CPUs.
  238. */
  239. ldr r8, =OMAP44XX_SAR_RAM_BASE
  240. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  241. cmp r9, #0x1 @ Skip if GP device
  242. bne skip_ns_smp_enable
  243. mrc p15, 0, r0, c0, c0, 5
  244. ands r0, r0, #0x0f
  245. beq skip_ns_smp_enable
  246. ppa_actrl_retry:
  247. mov r0, #OMAP4_PPA_CPU_ACTRL_SMP_INDEX
  248. adr r1, ppa_zero_params_offset
  249. ldr r3, [r1]
  250. add r3, r3, r1 @ Pointer to ppa_zero_params
  251. mov r1, #0x0 @ Process ID
  252. mov r2, #0x4 @ Flag
  253. mov r6, #0xff
  254. mov r12, #0x00 @ Secure Service ID
  255. DO_SMC
  256. cmp r0, #0x0 @ API returns 0 on success.
  257. beq enable_smp_bit
  258. b ppa_actrl_retry
  259. enable_smp_bit:
  260. mrc p15, 0, r0, c1, c0, 1
  261. tst r0, #(1 << 6) @ Check SMP bit enabled?
  262. orreq r0, r0, #(1 << 6)
  263. mcreq p15, 0, r0, c1, c0, 1
  264. isb
  265. skip_ns_smp_enable:
  266. #ifdef CONFIG_CACHE_L2X0
  267. /*
  268. * Restore the L2 AUXCTRL and enable the L2 cache.
  269. * OMAP4_MON_L2X0_AUXCTRL_INDEX = Program the L2X0 AUXCTRL
  270. * OMAP4_MON_L2X0_CTRL_INDEX = Enable the L2 using L2X0 CTRL
  271. * register r0 contains value to be programmed.
  272. * L2 cache is already invalidate by ROM code as part
  273. * of MPUSS OFF wakeup path.
  274. */
  275. ldr r2, =OMAP44XX_L2CACHE_BASE
  276. ldr r0, [r2, #L2X0_CTRL]
  277. and r0, #0x0f
  278. cmp r0, #1
  279. beq skip_l2en @ Skip if already enabled
  280. ldr r3, =OMAP44XX_SAR_RAM_BASE
  281. ldr r1, [r3, #OMAP_TYPE_OFFSET]
  282. cmp r1, #0x1 @ Check for HS device
  283. bne set_gp_por
  284. ldr r0, =OMAP4_PPA_L2_POR_INDEX
  285. ldr r1, =OMAP44XX_SAR_RAM_BASE
  286. ldr r4, [r1, #L2X0_PREFETCH_CTRL_OFFSET]
  287. adr r1, ppa_por_params_offset
  288. ldr r3, [r1]
  289. add r3, r3, r1 @ Pointer to ppa_por_params
  290. str r4, [r3, #0x04]
  291. mov r1, #0x0 @ Process ID
  292. mov r2, #0x4 @ Flag
  293. mov r6, #0xff
  294. mov r12, #0x00 @ Secure Service ID
  295. DO_SMC
  296. b set_aux_ctrl
  297. set_gp_por:
  298. ldr r1, =OMAP44XX_SAR_RAM_BASE
  299. ldr r0, [r1, #L2X0_PREFETCH_CTRL_OFFSET]
  300. ldr r12, =OMAP4_MON_L2X0_PREFETCH_INDEX @ Setup L2 PREFETCH
  301. DO_SMC
  302. set_aux_ctrl:
  303. ldr r1, =OMAP44XX_SAR_RAM_BASE
  304. ldr r0, [r1, #L2X0_AUXCTRL_OFFSET]
  305. ldr r12, =OMAP4_MON_L2X0_AUXCTRL_INDEX @ Setup L2 AUXCTRL
  306. DO_SMC
  307. mov r0, #0x1
  308. ldr r12, =OMAP4_MON_L2X0_CTRL_INDEX @ Enable L2 cache
  309. DO_SMC
  310. skip_l2en:
  311. #endif
  312. b cpu_resume @ Jump to generic resume
  313. ppa_por_params_offset:
  314. .long ppa_por_params - .
  315. ENDPROC(omap4_cpu_resume)
  316. #endif /* CONFIG_ARCH_OMAP4 */
  317. #endif /* defined(CONFIG_SMP) && defined(CONFIG_PM) */
  318. ENTRY(omap_do_wfi)
  319. stmfd sp!, {lr}
  320. #ifdef CONFIG_OMAP_INTERCONNECT_BARRIER
  321. /* Drain interconnect write buffers. */
  322. bl omap_interconnect_sync
  323. #endif
  324. /*
  325. * Execute an ISB instruction to ensure that all of the
  326. * CP15 register changes have been committed.
  327. */
  328. isb
  329. /*
  330. * Execute a barrier instruction to ensure that all cache,
  331. * TLB and branch predictor maintenance operations issued
  332. * by any CPU in the cluster have completed.
  333. */
  334. dsb
  335. dmb
  336. /*
  337. * Execute a WFI instruction and wait until the
  338. * STANDBYWFI output is asserted to indicate that the
  339. * CPU is in idle and low power state. CPU can specualatively
  340. * prefetch the instructions so add NOPs after WFI. Sixteen
  341. * NOPs as per Cortex-A9 pipeline.
  342. */
  343. wfi @ Wait For Interrupt
  344. nop
  345. nop
  346. nop
  347. nop
  348. nop
  349. nop
  350. nop
  351. nop
  352. nop
  353. nop
  354. nop
  355. nop
  356. nop
  357. nop
  358. nop
  359. nop
  360. ldmfd sp!, {pc}
  361. ppa_zero_params_offset:
  362. .long ppa_zero_params - .
  363. ENDPROC(omap_do_wfi)
  364. .data
  365. ppa_zero_params:
  366. .word 0
  367. ppa_por_params:
  368. .word 1, 0