sleep44xx.S 9.7 KB

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