swsusp_asm64.S 6.9 KB

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