swsusp_asm64.S 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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(%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. .globl swsusp_arch_resume
  100. swsusp_arch_resume:
  101. stmg %r6,%r15,__SF_GPRS(%r15)
  102. lgr %r1,%r15
  103. aghi %r15,-STACK_FRAME_OVERHEAD
  104. stg %r1,__SF_BACKCHAIN(%r15)
  105. /* Make all free pages stable */
  106. lghi %r2,1
  107. brasl %r14,arch_set_page_states
  108. /* Deactivate DAT */
  109. stnsm __SF_EMPTY(%r15),0xfb
  110. /* Set prefix page to zero */
  111. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  112. spx __SF_EMPTY(%r15)
  113. /* Restore saved image */
  114. larl %r1,restore_pblist
  115. lg %r1,0(%r1)
  116. ltgr %r1,%r1
  117. jz 2f
  118. 0:
  119. lg %r2,8(%r1)
  120. lg %r4,0(%r1)
  121. lghi %r3,PAGE_SIZE
  122. lghi %r5,PAGE_SIZE
  123. 1:
  124. mvcle %r2,%r4,0
  125. jo 1b
  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,0x12
  145. sam64
  146. larl %r1,.Lnew_pgm_check_psw
  147. lpswe 0(%r1)
  148. pgm_check_entry:
  149. /* Switch to original suspend CPU */
  150. larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
  151. stap 0(%r1)
  152. llgh %r2,0(%r1)
  153. llgh %r1,__LC_CPU_ADDRESS(%r0) /* Suspend CPU address: r1 */
  154. cgr %r1,%r2
  155. je restore_registers /* r1 = r2 -> nothing to do */
  156. larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
  157. mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
  158. 3:
  159. sigp %r9,%r1,__SIGP_INITIAL_CPU_RESET
  160. brc 8,4f /* accepted */
  161. brc 2,3b /* busy, try again */
  162. /* Suspend CPU not available -> panic */
  163. larl %r15,init_thread_union
  164. ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER)
  165. larl %r2,.Lpanic_string
  166. larl %r3,_sclp_print_early
  167. lghi %r1,0
  168. sam31
  169. sigp %r1,%r0,0x12
  170. basr %r14,%r3
  171. larl %r3,.Ldisabled_wait_31
  172. lpsw 0(%r3)
  173. 4:
  174. /* Switch to suspend CPU */
  175. sigp %r9,%r1,__SIGP_RESTART /* start suspend CPU */
  176. brc 2,4b /* busy, try again */
  177. 5:
  178. sigp %r9,%r2,__SIGP_STOP /* stop resume (current) CPU */
  179. brc 2,5b /* busy, try again */
  180. 6: j 6b
  181. restart_suspend:
  182. larl %r1,.Lresume_cpu
  183. llgh %r2,0(%r1)
  184. 7:
  185. sigp %r9,%r2,__SIGP_SENSE /* Wait for resume CPU */
  186. brc 8,7b /* accepted, status 0, still running */
  187. brc 2,7b /* busy, try again */
  188. tmll %r9,0x40 /* Test if resume CPU is stopped */
  189. jz 7b
  190. restore_registers:
  191. /* Restore registers */
  192. lghi %r13,0x1000 /* %r1 = pointer to save area */
  193. /* Ignore time spent in suspended state. */
  194. llgf %r1,0x318(%r13)
  195. stck __LC_LAST_UPDATE_CLOCK(%r1)
  196. spt 0x328(%r13) /* reprogram timer */
  197. //sckc 0x330(%r13) /* set clock comparator */
  198. lctlg %c0,%c15,0x380(%r13) /* load control registers */
  199. lam %a0,%a15,0x340(%r13) /* load access registers */
  200. lfpc 0x31c(%r13) /* load fpu control */
  201. ld 0,0x200(%r13) /* load f0 */
  202. ld 1,0x208(%r13) /* load f1 */
  203. ld 2,0x210(%r13) /* load f2 */
  204. ld 3,0x218(%r13) /* load f3 */
  205. ld 4,0x220(%r13) /* load f4 */
  206. ld 5,0x228(%r13) /* load f5 */
  207. ld 6,0x230(%r13) /* load f6 */
  208. ld 7,0x238(%r13) /* load f7 */
  209. ld 8,0x240(%r13) /* load f8 */
  210. ld 9,0x248(%r13) /* load f9 */
  211. ld 10,0x250(%r13) /* load f10 */
  212. ld 11,0x258(%r13) /* load f11 */
  213. ld 12,0x260(%r13) /* load f12 */
  214. ld 13,0x268(%r13) /* load f13 */
  215. ld 14,0x270(%r13) /* load f14 */
  216. ld 15,0x278(%r13) /* load f15 */
  217. /* Load old stack */
  218. lg %r15,0x2f8(%r13)
  219. /* Restore prefix register */
  220. spx 0x318(%r13)
  221. /* Activate DAT */
  222. stosm __SF_EMPTY(%r15),0x04
  223. /* Make all free pages unstable */
  224. lghi %r2,0
  225. brasl %r14,arch_set_page_states
  226. /* Reinitialize the channel subsystem */
  227. brasl %r14,channel_subsystem_reinit
  228. /* Return 0 */
  229. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  230. lghi %r2,0
  231. br %r14
  232. .section .data..nosave,"aw",@progbits
  233. .align 8
  234. .Ldisabled_wait_31:
  235. .long 0x000a0000,0x00000000
  236. .Lpanic_string:
  237. .asciz "Resume not possible because suspend CPU is no longer available"
  238. .align 8
  239. .Lrestart_diag308_psw:
  240. .long 0x00080000,0x80000000
  241. .Lrestart_suspend_psw:
  242. .quad 0x0000000180000000,restart_suspend
  243. .Lnew_pgm_check_psw:
  244. .quad 0,pgm_check_entry
  245. .Lresume_cpu:
  246. .byte 0,0