swsusp_asm64.S 7.2 KB

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