swsusp.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 64-bit swsusp implementation
  4. *
  5. * Copyright IBM Corp. 2009
  6. *
  7. * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
  8. * Michael Holzheu <holzheu@linux.vnet.ibm.com>
  9. */
  10. #include <linux/linkage.h>
  11. #include <asm/page.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/thread_info.h>
  14. #include <asm/asm-offsets.h>
  15. #include <asm/nospec-insn.h>
  16. #include <asm/sigp.h>
  17. /*
  18. * Save register context in absolute 0 lowcore and call swsusp_save() to
  19. * create in-memory kernel image. The context is saved in the designated
  20. * "store status" memory locations (see POP).
  21. * We return from this function twice. The first time during the suspend to
  22. * disk process. The second time via the swsusp_arch_resume() function
  23. * (see below) in the resume process.
  24. * This function runs with disabled interrupts.
  25. */
  26. GEN_BR_THUNK %r14
  27. .section .text
  28. ENTRY(swsusp_arch_suspend)
  29. stmg %r6,%r15,__SF_GPRS(%r15)
  30. lgr %r1,%r15
  31. aghi %r15,-STACK_FRAME_OVERHEAD
  32. stg %r1,__SF_BACKCHAIN(%r15)
  33. /* Store FPU registers */
  34. brasl %r14,save_fpu_regs
  35. /* Deactivate DAT */
  36. stnsm __SF_EMPTY(%r15),0xfb
  37. /* Store prefix register on stack */
  38. stpx __SF_EMPTY(%r15)
  39. /* Save prefix register contents for lowcore copy */
  40. llgf %r10,__SF_EMPTY(%r15)
  41. /* Get pointer to save area */
  42. lghi %r1,0x1000
  43. /* Save CPU address */
  44. stap __LC_EXT_CPU_ADDR(%r0)
  45. /* Store registers */
  46. mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
  47. stam %a0,%a15,0x340(%r1) /* store access registers */
  48. stctg %c0,%c15,0x380(%r1) /* store control registers */
  49. stmg %r0,%r15,0x280(%r1) /* store general registers */
  50. stpt 0x328(%r1) /* store timer */
  51. stck __SF_EMPTY(%r15) /* store clock */
  52. stckc 0x330(%r1) /* store clock comparator */
  53. /* Update cputime accounting before going to sleep */
  54. lg %r0,__LC_LAST_UPDATE_TIMER
  55. slg %r0,0x328(%r1)
  56. alg %r0,__LC_SYSTEM_TIMER
  57. stg %r0,__LC_SYSTEM_TIMER
  58. mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
  59. lg %r0,__LC_LAST_UPDATE_CLOCK
  60. slg %r0,__SF_EMPTY(%r15)
  61. alg %r0,__LC_STEAL_TIMER
  62. stg %r0,__LC_STEAL_TIMER
  63. mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
  64. /* Activate DAT */
  65. stosm __SF_EMPTY(%r15),0x04
  66. /* Set prefix page to zero */
  67. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  68. spx __SF_EMPTY(%r15)
  69. /* Save absolute zero pages */
  70. larl %r2,suspend_zero_pages
  71. lg %r2,0(%r2)
  72. lghi %r4,0
  73. lghi %r3,2*PAGE_SIZE
  74. lghi %r5,2*PAGE_SIZE
  75. 1: mvcle %r2,%r4,0
  76. jo 1b
  77. /* Copy lowcore to absolute zero lowcore */
  78. lghi %r2,0
  79. lgr %r4,%r10
  80. lghi %r3,2*PAGE_SIZE
  81. lghi %r5,2*PAGE_SIZE
  82. 1: mvcle %r2,%r4,0
  83. jo 1b
  84. /* Save image */
  85. brasl %r14,swsusp_save
  86. /* Restore prefix register and return */
  87. lghi %r1,0x1000
  88. spx 0x318(%r1)
  89. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  90. lghi %r2,0
  91. BR_EX %r14
  92. /*
  93. * Restore saved memory image to correct place and restore register context.
  94. * Then we return to the function that called swsusp_arch_suspend().
  95. * swsusp_arch_resume() runs with disabled interrupts.
  96. */
  97. ENTRY(swsusp_arch_resume)
  98. stmg %r6,%r15,__SF_GPRS(%r15)
  99. lgr %r1,%r15
  100. aghi %r15,-STACK_FRAME_OVERHEAD
  101. stg %r1,__SF_BACKCHAIN(%r15)
  102. /* Make all free pages stable */
  103. lghi %r2,1
  104. brasl %r14,arch_set_page_states
  105. /* Deactivate DAT */
  106. stnsm __SF_EMPTY(%r15),0xfb
  107. /* Set prefix page to zero */
  108. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  109. spx __SF_EMPTY(%r15)
  110. /* Restore saved image */
  111. larl %r1,restore_pblist
  112. lg %r1,0(%r1)
  113. ltgr %r1,%r1
  114. jz 2f
  115. 0:
  116. lg %r2,8(%r1)
  117. lg %r4,0(%r1)
  118. iske %r0,%r4
  119. lghi %r3,PAGE_SIZE
  120. lghi %r5,PAGE_SIZE
  121. 1:
  122. mvcle %r2,%r4,0
  123. jo 1b
  124. lg %r2,8(%r1)
  125. sske %r0,%r2
  126. lg %r1,16(%r1)
  127. ltgr %r1,%r1
  128. jnz 0b
  129. 2:
  130. ptlb /* flush tlb */
  131. /* Reset System */
  132. larl %r1,restart_entry
  133. larl %r2,.Lrestart_diag308_psw
  134. og %r1,0(%r2)
  135. stg %r1,0(%r0)
  136. larl %r1,.Lnew_pgm_check_psw
  137. epsw %r2,%r3
  138. stm %r2,%r3,0(%r1)
  139. mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
  140. lghi %r0,0
  141. diag %r0,%r0,0x308
  142. restart_entry:
  143. lhi %r1,1
  144. sigp %r1,%r0,SIGP_SET_ARCHITECTURE
  145. sam64
  146. #ifdef CONFIG_SMP
  147. larl %r1,smp_cpu_mt_shift
  148. icm %r1,15,0(%r1)
  149. jz smt_done
  150. llgfr %r1,%r1
  151. smt_loop:
  152. sigp %r1,%r0,SIGP_SET_MULTI_THREADING
  153. brc 8,smt_done /* accepted */
  154. brc 2,smt_loop /* busy, try again */
  155. smt_done:
  156. #endif
  157. larl %r1,.Lnew_pgm_check_psw
  158. lpswe 0(%r1)
  159. pgm_check_entry:
  160. /* Switch to original suspend CPU */
  161. larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
  162. stap 0(%r1)
  163. llgh %r2,0(%r1)
  164. llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
  165. cgr %r1,%r2
  166. je restore_registers /* r1 = r2 -> nothing to do */
  167. larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
  168. mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
  169. 3:
  170. sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
  171. brc 8,4f /* accepted */
  172. brc 2,3b /* busy, try again */
  173. /* Suspend CPU not available -> panic */
  174. larl %r15,init_thread_union
  175. aghi %r15,1<<(PAGE_SHIFT+THREAD_SIZE_ORDER)
  176. aghi %r15,-STACK_FRAME_OVERHEAD
  177. larl %r2,.Lpanic_string
  178. brasl %r14,sclp_early_printk_force
  179. larl %r3,.Ldisabled_wait_31
  180. lpsw 0(%r3)
  181. 4:
  182. /* Switch to suspend CPU */
  183. sigp %r9,%r1,SIGP_RESTART /* sigp restart to suspend CPU */
  184. brc 2,4b /* busy, try again */
  185. 5:
  186. sigp %r9,%r2,SIGP_STOP /* sigp stop to current resume CPU */
  187. brc 2,5b /* busy, try again */
  188. 6: j 6b
  189. restart_suspend:
  190. larl %r1,.Lresume_cpu
  191. llgh %r2,0(%r1)
  192. 7:
  193. sigp %r9,%r2,SIGP_SENSE /* sigp sense, wait for resume CPU */
  194. brc 8,7b /* accepted, status 0, still running */
  195. brc 2,7b /* busy, try again */
  196. tmll %r9,0x40 /* Test if resume CPU is stopped */
  197. jz 7b
  198. restore_registers:
  199. /* Restore registers */
  200. lghi %r13,0x1000 /* %r1 = pointer to save area */
  201. /* Ignore time spent in suspended state. */
  202. llgf %r1,0x318(%r13)
  203. stck __LC_LAST_UPDATE_CLOCK(%r1)
  204. spt 0x328(%r13) /* reprogram timer */
  205. //sckc 0x330(%r13) /* set clock comparator */
  206. lctlg %c0,%c15,0x380(%r13) /* load control registers */
  207. lam %a0,%a15,0x340(%r13) /* load access registers */
  208. /* Load old stack */
  209. lg %r15,0x2f8(%r13)
  210. /* Save prefix register */
  211. mvc __SF_EMPTY(4,%r15),0x318(%r13)
  212. /* Restore absolute zero pages */
  213. lghi %r2,0
  214. larl %r4,suspend_zero_pages
  215. lg %r4,0(%r4)
  216. lghi %r3,2*PAGE_SIZE
  217. lghi %r5,2*PAGE_SIZE
  218. 1: mvcle %r2,%r4,0
  219. jo 1b
  220. /* Restore prefix register */
  221. spx __SF_EMPTY(%r15)
  222. /* Activate DAT */
  223. stosm __SF_EMPTY(%r15),0x04
  224. /* Make all free pages unstable */
  225. lghi %r2,0
  226. brasl %r14,arch_set_page_states
  227. /* Call arch specific early resume code */
  228. brasl %r14,s390_early_resume
  229. /* Return 0 */
  230. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  231. lghi %r2,0
  232. BR_EX %r14
  233. .section .data..nosave,"aw",@progbits
  234. .align 8
  235. .Ldisabled_wait_31:
  236. .long 0x000a0000,0x00000000
  237. .Lpanic_string:
  238. .asciz "Resume not possible because suspend CPU is no longer available\n"
  239. .align 8
  240. .Lrestart_diag308_psw:
  241. .long 0x00080000,0x80000000
  242. .Lrestart_suspend_psw:
  243. .quad 0x0000000180000000,restart_suspend
  244. .Lnew_pgm_check_psw:
  245. .quad 0,pgm_check_entry
  246. .Lresume_cpu:
  247. .byte 0,0