sleep44xx.S 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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/system.h>
  13. #include <asm/smp_scu.h>
  14. #include <asm/memory.h>
  15. #include <asm/hardware/cache-l2x0.h>
  16. #include <plat/omap44xx.h>
  17. #include <mach/omap-secure.h>
  18. #include "common.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. ppa_zero_params:
  27. .word 0x0
  28. ppa_por_params:
  29. .word 1, 0
  30. /*
  31. * =============================
  32. * == CPU suspend finisher ==
  33. * =============================
  34. *
  35. * void omap4_finish_suspend(unsigned long cpu_state)
  36. *
  37. * This function code saves the CPU context and performs the CPU
  38. * power down sequence. Calling WFI effectively changes the CPU
  39. * power domains states to the desired target power state.
  40. *
  41. * @cpu_state : contains context save state (r0)
  42. * 0 - No context lost
  43. * 1 - CPUx L1 and logic lost: MPUSS CSWR
  44. * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
  45. * 3 - CPUx L1 and logic lost + GIC + L2 lost: MPUSS OFF
  46. * @return: This function never returns for CPU OFF and DORMANT power states.
  47. * Post WFI, CPU transitions to DORMANT or OFF power state and on wake-up
  48. * from this follows a full CPU reset path via ROM code to CPU restore code.
  49. * The restore function pointer is stored at CPUx_WAKEUP_NS_PA_ADDR_OFFSET.
  50. * It returns to the caller for CPU INACTIVE and ON power states or in case
  51. * CPU failed to transition to targeted OFF/DORMANT state.
  52. */
  53. ENTRY(omap4_finish_suspend)
  54. stmfd sp!, {lr}
  55. cmp r0, #0x0
  56. beq do_WFI @ No lowpower state, jump to WFI
  57. /*
  58. * Flush all data from the L1 data cache before disabling
  59. * SCTLR.C bit.
  60. */
  61. bl omap4_get_sar_ram_base
  62. ldr r9, [r0, #OMAP_TYPE_OFFSET]
  63. cmp r9, #0x1 @ Check for HS device
  64. bne skip_secure_l1_clean
  65. mov r0, #SCU_PM_NORMAL
  66. mov r1, #0xFF @ clean seucre L1
  67. stmfd r13!, {r4-r12, r14}
  68. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  69. DO_SMC
  70. ldmfd r13!, {r4-r12, r14}
  71. skip_secure_l1_clean:
  72. bl v7_flush_dcache_all
  73. /*
  74. * Clear the SCTLR.C bit to prevent further data cache
  75. * allocation. Clearing SCTLR.C would make all the data accesses
  76. * strongly ordered and would not hit the cache.
  77. */
  78. mrc p15, 0, r0, c1, c0, 0
  79. bic r0, r0, #(1 << 2) @ Disable the C bit
  80. mcr p15, 0, r0, c1, c0, 0
  81. isb
  82. /*
  83. * Invalidate L1 data cache. Even though only invalidate is
  84. * necessary exported flush API is used here. Doing clean
  85. * on already clean cache would be almost NOP.
  86. */
  87. bl v7_flush_dcache_all
  88. /*
  89. * Switch the CPU from Symmetric Multiprocessing (SMP) mode
  90. * to AsymmetricMultiprocessing (AMP) mode by programming
  91. * the SCU power status to DORMANT or OFF mode.
  92. * This enables the CPU to be taken out of coherency by
  93. * preventing the CPU from receiving cache, TLB, or BTB
  94. * maintenance operations broadcast by other CPUs in the cluster.
  95. */
  96. bl omap4_get_sar_ram_base
  97. mov r8, r0
  98. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  99. cmp r9, #0x1 @ Check for HS device
  100. bne scu_gp_set
  101. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  102. ands r0, r0, #0x0f
  103. ldreq r0, [r8, #SCU_OFFSET0]
  104. ldrne r0, [r8, #SCU_OFFSET1]
  105. mov r1, #0x00
  106. stmfd r13!, {r4-r12, r14}
  107. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  108. DO_SMC
  109. ldmfd r13!, {r4-r12, r14}
  110. b skip_scu_gp_set
  111. scu_gp_set:
  112. mrc p15, 0, r0, c0, c0, 5 @ Read MPIDR
  113. ands r0, r0, #0x0f
  114. ldreq r1, [r8, #SCU_OFFSET0]
  115. ldrne r1, [r8, #SCU_OFFSET1]
  116. bl omap4_get_scu_base
  117. bl scu_power_mode
  118. skip_scu_gp_set:
  119. mrc p15, 0, r0, c1, c1, 2 @ Read NSACR data
  120. tst r0, #(1 << 18)
  121. mrcne p15, 0, r0, c1, c0, 1
  122. bicne r0, r0, #(1 << 6) @ Disable SMP bit
  123. mcrne p15, 0, r0, c1, c0, 1
  124. isb
  125. dsb
  126. #ifdef CONFIG_CACHE_L2X0
  127. /*
  128. * Clean and invalidate the L2 cache.
  129. * Common cache-l2x0.c functions can't be used here since it
  130. * uses spinlocks. We are out of coherency here with data cache
  131. * disabled. The spinlock implementation uses exclusive load/store
  132. * instruction which can fail without data cache being enabled.
  133. * OMAP4 hardware doesn't support exclusive monitor which can
  134. * overcome exclusive access issue. Because of this, CPU can
  135. * lead to deadlock.
  136. */
  137. bl omap4_get_sar_ram_base
  138. mov r8, r0
  139. mrc p15, 0, r5, c0, c0, 5 @ Read MPIDR
  140. ands r5, r5, #0x0f
  141. ldreq r0, [r8, #L2X0_SAVE_OFFSET0] @ Retrieve L2 state from SAR
  142. ldrne r0, [r8, #L2X0_SAVE_OFFSET1] @ memory.
  143. cmp r0, #3
  144. bne do_WFI
  145. #ifdef CONFIG_PL310_ERRATA_727915
  146. mov r0, #0x03
  147. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  148. DO_SMC
  149. #endif
  150. bl omap4_get_l2cache_base
  151. mov r2, r0
  152. ldr r0, =0xffff
  153. str r0, [r2, #L2X0_CLEAN_INV_WAY]
  154. wait:
  155. ldr r0, [r2, #L2X0_CLEAN_INV_WAY]
  156. ldr r1, =0xffff
  157. ands r0, r0, r1
  158. bne wait
  159. #ifdef CONFIG_PL310_ERRATA_727915
  160. mov r0, #0x00
  161. mov r12, #OMAP4_MON_L2X0_DBG_CTRL_INDEX
  162. DO_SMC
  163. #endif
  164. l2x_sync:
  165. bl omap4_get_l2cache_base
  166. mov r2, r0
  167. mov r0, #0x0
  168. str r0, [r2, #L2X0_CACHE_SYNC]
  169. sync:
  170. ldr r0, [r2, #L2X0_CACHE_SYNC]
  171. ands r0, r0, #0x1
  172. bne sync
  173. #endif
  174. do_WFI:
  175. bl omap_do_wfi
  176. /*
  177. * CPU is here when it failed to enter OFF/DORMANT or
  178. * no low power state was attempted.
  179. */
  180. mrc p15, 0, r0, c1, c0, 0
  181. tst r0, #(1 << 2) @ Check C bit enabled?
  182. orreq r0, r0, #(1 << 2) @ Enable the C bit
  183. mcreq p15, 0, r0, c1, c0, 0
  184. isb
  185. /*
  186. * Ensure the CPU power state is set to NORMAL in
  187. * SCU power state so that CPU is back in coherency.
  188. * In non-coherent mode CPU can lock-up and lead to
  189. * system deadlock.
  190. */
  191. mrc p15, 0, r0, c1, c0, 1
  192. tst r0, #(1 << 6) @ Check SMP bit enabled?
  193. orreq r0, r0, #(1 << 6)
  194. mcreq p15, 0, r0, c1, c0, 1
  195. isb
  196. bl omap4_get_sar_ram_base
  197. mov r8, r0
  198. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  199. cmp r9, #0x1 @ Check for HS device
  200. bne scu_gp_clear
  201. mov r0, #SCU_PM_NORMAL
  202. mov r1, #0x00
  203. stmfd r13!, {r4-r12, r14}
  204. ldr r12, =OMAP4_MON_SCU_PWR_INDEX
  205. DO_SMC
  206. ldmfd r13!, {r4-r12, r14}
  207. b skip_scu_gp_clear
  208. scu_gp_clear:
  209. bl omap4_get_scu_base
  210. mov r1, #SCU_PM_NORMAL
  211. bl scu_power_mode
  212. skip_scu_gp_clear:
  213. isb
  214. dsb
  215. ldmfd sp!, {pc}
  216. ENDPROC(omap4_finish_suspend)
  217. /*
  218. * ============================
  219. * == CPU resume entry point ==
  220. * ============================
  221. *
  222. * void omap4_cpu_resume(void)
  223. *
  224. * ROM code jumps to this function while waking up from CPU
  225. * OFF or DORMANT state. Physical address of the function is
  226. * stored in the SAR RAM while entering to OFF or DORMANT mode.
  227. * The restore function pointer is stored at CPUx_WAKEUP_NS_PA_ADDR_OFFSET.
  228. */
  229. ENTRY(omap4_cpu_resume)
  230. /*
  231. * Configure ACTRL and enable NS SMP bit access on CPU1 on HS device.
  232. * OMAP44XX EMU/HS devices - CPU0 SMP bit access is enabled in PPA
  233. * init and for CPU1, a secure PPA API provided. CPU0 must be ON
  234. * while executing NS_SMP API on CPU1 and PPA version must be 1.4.0+.
  235. * OMAP443X GP devices- SMP bit isn't accessible.
  236. * OMAP446X GP devices - SMP bit access is enabled on both CPUs.
  237. */
  238. ldr r8, =OMAP44XX_SAR_RAM_BASE
  239. ldr r9, [r8, #OMAP_TYPE_OFFSET]
  240. cmp r9, #0x1 @ Skip if GP device
  241. bne skip_ns_smp_enable
  242. mrc p15, 0, r0, c0, c0, 5
  243. ands r0, r0, #0x0f
  244. beq skip_ns_smp_enable
  245. ppa_actrl_retry:
  246. mov r0, #OMAP4_PPA_CPU_ACTRL_SMP_INDEX
  247. adr r3, ppa_zero_params @ Pointer to parameters
  248. mov r1, #0x0 @ Process ID
  249. mov r2, #0x4 @ Flag
  250. mov r6, #0xff
  251. mov r12, #0x00 @ Secure Service ID
  252. DO_SMC
  253. cmp r0, #0x0 @ API returns 0 on success.
  254. beq enable_smp_bit
  255. b ppa_actrl_retry
  256. enable_smp_bit:
  257. mrc p15, 0, r0, c1, c0, 1
  258. tst r0, #(1 << 6) @ Check SMP bit enabled?
  259. orreq r0, r0, #(1 << 6)
  260. mcreq p15, 0, r0, c1, c0, 1
  261. isb
  262. skip_ns_smp_enable:
  263. #ifdef CONFIG_CACHE_L2X0
  264. /*
  265. * Restore the L2 AUXCTRL and enable the L2 cache.
  266. * OMAP4_MON_L2X0_AUXCTRL_INDEX = Program the L2X0 AUXCTRL
  267. * OMAP4_MON_L2X0_CTRL_INDEX = Enable the L2 using L2X0 CTRL
  268. * register r0 contains value to be programmed.
  269. * L2 cache is already invalidate by ROM code as part
  270. * of MPUSS OFF wakeup path.
  271. */
  272. ldr r2, =OMAP44XX_L2CACHE_BASE
  273. ldr r0, [r2, #L2X0_CTRL]
  274. and r0, #0x0f
  275. cmp r0, #1
  276. beq skip_l2en @ Skip if already enabled
  277. ldr r3, =OMAP44XX_SAR_RAM_BASE
  278. ldr r1, [r3, #OMAP_TYPE_OFFSET]
  279. cmp r1, #0x1 @ Check for HS device
  280. bne set_gp_por
  281. ldr r0, =OMAP4_PPA_L2_POR_INDEX
  282. ldr r1, =OMAP44XX_SAR_RAM_BASE
  283. ldr r4, [r1, #L2X0_PREFETCH_CTRL_OFFSET]
  284. adr r3, 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. ENDPROC(omap4_cpu_resume)
  309. #endif
  310. #ifndef CONFIG_OMAP4_ERRATA_I688
  311. ENTRY(omap_bus_sync)
  312. mov pc, lr
  313. ENDPROC(omap_bus_sync)
  314. #endif
  315. ENTRY(omap_do_wfi)
  316. stmfd sp!, {lr}
  317. /* Drain interconnect write buffers. */
  318. bl omap_bus_sync
  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. ENDPROC(omap_do_wfi)