sleep44xx.S 9.9 KB

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