swsusp_asm64.S 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 <asm/page.h>
  10. #include <asm/ptrace.h>
  11. #include <asm/thread_info.h>
  12. #include <asm/asm-offsets.h>
  13. /*
  14. * Save register context in absolute 0 lowcore and call swsusp_save() to
  15. * create in-memory kernel image. The context is saved in the designated
  16. * "store status" memory locations (see POP).
  17. * We return from this function twice. The first time during the suspend to
  18. * disk process. The second time via the swsusp_arch_resume() function
  19. * (see below) in the resume process.
  20. * This function runs with disabled interrupts.
  21. */
  22. .section .text
  23. .align 4
  24. .globl swsusp_arch_suspend
  25. 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_CPU_ADDRESS(%r1)
  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. stckc 0x330(%r1) /* store clock comparator */
  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. lghi %r2,0
  70. lghi %r3,2*PAGE_SIZE
  71. lghi %r5,2*PAGE_SIZE
  72. 1: mvcle %r2,%r4,0
  73. jo 1b
  74. /* Save image */
  75. brasl %r14,swsusp_save
  76. /* Restore prefix register and return */
  77. lghi %r1,0x1000
  78. spx 0x318(%r1)
  79. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  80. lghi %r2,0
  81. br %r14
  82. /*
  83. * Restore saved memory image to correct place and restore register context.
  84. * Then we return to the function that called swsusp_arch_suspend().
  85. * swsusp_arch_resume() runs with disabled interrupts.
  86. */
  87. .globl swsusp_arch_resume
  88. swsusp_arch_resume:
  89. stmg %r6,%r15,__SF_GPRS(%r15)
  90. lgr %r1,%r15
  91. aghi %r15,-STACK_FRAME_OVERHEAD
  92. stg %r1,__SF_BACKCHAIN(%r15)
  93. /* Make all free pages stable */
  94. lghi %r2,1
  95. brasl %r14,arch_set_page_states
  96. /* Deactivate DAT */
  97. stnsm __SF_EMPTY(%r15),0xfb
  98. /* Set prefix page to zero */
  99. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  100. spx __SF_EMPTY(%r15)
  101. /* Restore saved image */
  102. larl %r1,restore_pblist
  103. lg %r1,0(%r1)
  104. ltgr %r1,%r1
  105. jz 2f
  106. 0:
  107. lg %r2,8(%r1)
  108. lg %r4,0(%r1)
  109. lghi %r3,PAGE_SIZE
  110. lghi %r5,PAGE_SIZE
  111. 1:
  112. mvcle %r2,%r4,0
  113. jo 1b
  114. lg %r1,16(%r1)
  115. ltgr %r1,%r1
  116. jnz 0b
  117. 2:
  118. ptlb /* flush tlb */
  119. /* Reset System */
  120. larl %r1,restart_entry
  121. larl %r2,.Lrestart_diag308_psw
  122. og %r1,0(%r2)
  123. stg %r1,0(%r0)
  124. larl %r1,.Lnew_pgm_check_psw
  125. epsw %r2,%r3
  126. stm %r2,%r3,0(%r1)
  127. mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
  128. lghi %r0,0
  129. diag %r0,%r0,0x308
  130. restart_entry:
  131. lhi %r1,1
  132. sigp %r1,%r0,0x12
  133. sam64
  134. larl %r1,.Lnew_pgm_check_psw
  135. lpswe 0(%r1)
  136. pgm_check_entry:
  137. /* Switch to original suspend CPU */
  138. larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
  139. stap 0(%r1)
  140. llgh %r2,0(%r1)
  141. lghi %r3,0x1000
  142. llgh %r1,__LC_CPU_ADDRESS(%r3) /* Suspend CPU address: r1 */
  143. cgr %r1,%r2
  144. je restore_registers /* r1 = r2 -> nothing to do */
  145. larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
  146. mvc __LC_RESTART_PSW(16,%r0),0(%r4)
  147. 3:
  148. sigp %r9,%r1,__SIGP_INITIAL_CPU_RESET
  149. brc 8,4f /* accepted */
  150. brc 2,3b /* busy, try again */
  151. /* Suspend CPU not available -> panic */
  152. larl %r15,init_thread_union
  153. ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER)
  154. larl %r2,.Lpanic_string
  155. larl %r3,_sclp_print_early
  156. lghi %r1,0
  157. sam31
  158. sigp %r1,%r0,0x12
  159. basr %r14,%r3
  160. larl %r3,.Ldisabled_wait_31
  161. lpsw 0(%r3)
  162. 4:
  163. /* Switch to suspend CPU */
  164. sigp %r9,%r1,__SIGP_RESTART /* start suspend CPU */
  165. brc 2,4b /* busy, try again */
  166. 5:
  167. sigp %r9,%r2,__SIGP_STOP /* stop resume (current) CPU */
  168. 6: j 6b
  169. restart_suspend:
  170. larl %r1,.Lresume_cpu
  171. llgh %r2,0(%r1)
  172. 7:
  173. sigp %r9,%r2,__SIGP_SENSE /* Wait for resume CPU */
  174. brc 2,7b /* busy, try again */
  175. tmll %r9,0x40 /* Test if resume CPU is stopped */
  176. jz 7b
  177. restore_registers:
  178. /* Restore registers */
  179. lghi %r13,0x1000 /* %r1 = pointer to save arae */
  180. spt 0x328(%r13) /* reprogram timer */
  181. //sckc 0x330(%r13) /* set clock comparator */
  182. lctlg %c0,%c15,0x380(%r13) /* load control registers */
  183. lam %a0,%a15,0x340(%r13) /* load access registers */
  184. lfpc 0x31c(%r13) /* load fpu control */
  185. ld 0,0x200(%r13) /* load f0 */
  186. ld 1,0x208(%r13) /* load f1 */
  187. ld 2,0x210(%r13) /* load f2 */
  188. ld 3,0x218(%r13) /* load f3 */
  189. ld 4,0x220(%r13) /* load f4 */
  190. ld 5,0x228(%r13) /* load f5 */
  191. ld 6,0x230(%r13) /* load f6 */
  192. ld 7,0x238(%r13) /* load f7 */
  193. ld 8,0x240(%r13) /* load f8 */
  194. ld 9,0x248(%r13) /* load f9 */
  195. ld 10,0x250(%r13) /* load f10 */
  196. ld 11,0x258(%r13) /* load f11 */
  197. ld 12,0x260(%r13) /* load f12 */
  198. ld 13,0x268(%r13) /* load f13 */
  199. ld 14,0x270(%r13) /* load f14 */
  200. ld 15,0x278(%r13) /* load f15 */
  201. /* Load old stack */
  202. lg %r15,0x2f8(%r13)
  203. /* Pointer to save area */
  204. lghi %r13,0x1000
  205. /* Restore prefix register */
  206. spx 0x318(%r13)
  207. /* Activate DAT */
  208. stosm __SF_EMPTY(%r15),0x04
  209. /* Make all free pages unstable */
  210. lghi %r2,0
  211. brasl %r14,arch_set_page_states
  212. /* Return 0 */
  213. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  214. lghi %r2,0
  215. br %r14
  216. .section .data.nosave,"aw",@progbits
  217. .align 8
  218. .Ldisabled_wait_31:
  219. .long 0x000a0000,0x00000000
  220. .Lpanic_string:
  221. .asciz "Resume not possible because suspend CPU is no longer available"
  222. .align 8
  223. .Lrestart_diag308_psw:
  224. .long 0x00080000,0x80000000
  225. .Lrestart_suspend_psw:
  226. .quad 0x0000000180000000,restart_suspend
  227. .Lnew_pgm_check_psw:
  228. .quad 0,pgm_check_entry
  229. .Lresume_cpu:
  230. .byte 0,0