swsusp_asm64.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/asm-offsets.h>
  12. /*
  13. * Save register context in absolute 0 lowcore and call swsusp_save() to
  14. * create in-memory kernel image. The context is saved in the designated
  15. * "store status" memory locations (see POP).
  16. * We return from this function twice. The first time during the suspend to
  17. * disk process. The second time via the swsusp_arch_resume() function
  18. * (see below) in the resume process.
  19. * This function runs with disabled interrupts.
  20. */
  21. .section .text
  22. .align 4
  23. .globl swsusp_arch_suspend
  24. 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. /* Store registers */
  38. mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
  39. stfpc 0x31c(%r1) /* store fpu control */
  40. std 0,0x200(%r1) /* store f0 */
  41. std 1,0x208(%r1) /* store f1 */
  42. std 2,0x210(%r1) /* store f2 */
  43. std 3,0x218(%r1) /* store f3 */
  44. std 4,0x220(%r1) /* store f4 */
  45. std 5,0x228(%r1) /* store f5 */
  46. std 6,0x230(%r1) /* store f6 */
  47. std 7,0x238(%r1) /* store f7 */
  48. std 8,0x240(%r1) /* store f8 */
  49. std 9,0x248(%r1) /* store f9 */
  50. std 10,0x250(%r1) /* store f10 */
  51. std 11,0x258(%r1) /* store f11 */
  52. std 12,0x260(%r1) /* store f12 */
  53. std 13,0x268(%r1) /* store f13 */
  54. std 14,0x270(%r1) /* store f14 */
  55. std 15,0x278(%r1) /* store f15 */
  56. stam %a0,%a15,0x340(%r1) /* store access registers */
  57. stctg %c0,%c15,0x380(%r1) /* store control registers */
  58. stmg %r0,%r15,0x280(%r1) /* store general registers */
  59. stpt 0x328(%r1) /* store timer */
  60. stckc 0x330(%r1) /* store clock comparator */
  61. /* Activate DAT */
  62. stosm __SF_EMPTY(%r15),0x04
  63. /* Set prefix page to zero */
  64. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  65. spx __SF_EMPTY(%r15)
  66. lghi %r2,0
  67. lghi %r3,2*PAGE_SIZE
  68. lghi %r5,2*PAGE_SIZE
  69. 1: mvcle %r2,%r4,0
  70. jo 1b
  71. /* Save image */
  72. brasl %r14,swsusp_save
  73. /* Restore prefix register and return */
  74. lghi %r1,0x1000
  75. spx 0x318(%r1)
  76. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  77. lghi %r2,0
  78. br %r14
  79. /*
  80. * Restore saved memory image to correct place and restore register context.
  81. * Then we return to the function that called swsusp_arch_suspend().
  82. * swsusp_arch_resume() runs with disabled interrupts.
  83. */
  84. .globl swsusp_arch_resume
  85. swsusp_arch_resume:
  86. stmg %r6,%r15,__SF_GPRS(%r15)
  87. lgr %r1,%r15
  88. aghi %r15,-STACK_FRAME_OVERHEAD
  89. stg %r1,__SF_BACKCHAIN(%r15)
  90. /* Make all free pages stable */
  91. lghi %r2,1
  92. brasl %r14,arch_set_page_states
  93. #ifdef CONFIG_SMP
  94. /* Save boot cpu number */
  95. brasl %r14,smp_get_phys_cpu_id
  96. larl %r1,saved_cpu_id
  97. st %r2,0(%r1)
  98. #endif
  99. /* Deactivate DAT */
  100. stnsm __SF_EMPTY(%r15),0xfb
  101. /* Set prefix page to zero */
  102. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  103. spx __SF_EMPTY(%r15)
  104. /* Restore saved image */
  105. larl %r1,restore_pblist
  106. lg %r1,0(%r1)
  107. ltgr %r1,%r1
  108. jz 2f
  109. 0:
  110. lg %r2,8(%r1)
  111. lg %r4,0(%r1)
  112. lghi %r3,PAGE_SIZE
  113. lghi %r5,PAGE_SIZE
  114. 1:
  115. mvcle %r2,%r4,0
  116. jo 1b
  117. lg %r1,16(%r1)
  118. ltgr %r1,%r1
  119. jnz 0b
  120. 2:
  121. ptlb /* flush tlb */
  122. /* Reset System */
  123. larl %r1,restart_entry
  124. larl %r2,restart_psw
  125. og %r1,0(%r2)
  126. stg %r1,0(%r0)
  127. larl %r1,saved_pgm_check_psw
  128. mvc 0(16,%r1),__LC_PGM_NEW_PSW(%r0)
  129. larl %r1,new_pgm_check_psw
  130. epsw %r2,%r3
  131. stm %r2,%r3,0(%r1)
  132. mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
  133. lghi %r0,0
  134. diag %r0,%r0,0x308
  135. restart_entry:
  136. lhi %r1,1
  137. sigp %r1,%r0,0x12
  138. sam64
  139. larl %r1,new_pgm_check_psw
  140. lpswe 0(%r1)
  141. pgm_check_entry:
  142. larl %r1,saved_pgm_check_psw
  143. mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
  144. /* Restore registers */
  145. lghi %r13,0x1000 /* %r1 = pointer to save arae */
  146. spt 0x328(%r13) /* reprogram timer */
  147. //sckc 0x330(%r13) /* set clock comparator */
  148. lctlg %c0,%c15,0x380(%r13) /* load control registers */
  149. lam %a0,%a15,0x340(%r13) /* load access registers */
  150. lfpc 0x31c(%r13) /* load fpu control */
  151. ld 0,0x200(%r13) /* load f0 */
  152. ld 1,0x208(%r13) /* load f1 */
  153. ld 2,0x210(%r13) /* load f2 */
  154. ld 3,0x218(%r13) /* load f3 */
  155. ld 4,0x220(%r13) /* load f4 */
  156. ld 5,0x228(%r13) /* load f5 */
  157. ld 6,0x230(%r13) /* load f6 */
  158. ld 7,0x238(%r13) /* load f7 */
  159. ld 8,0x240(%r13) /* load f8 */
  160. ld 9,0x248(%r13) /* load f9 */
  161. ld 10,0x250(%r13) /* load f10 */
  162. ld 11,0x258(%r13) /* load f11 */
  163. ld 12,0x260(%r13) /* load f12 */
  164. ld 13,0x268(%r13) /* load f13 */
  165. ld 14,0x270(%r13) /* load f14 */
  166. ld 15,0x278(%r13) /* load f15 */
  167. /* Load old stack */
  168. lg %r15,0x2f8(%r13)
  169. /* Pointer to save area */
  170. lghi %r13,0x1000
  171. #ifdef CONFIG_SMP
  172. /* Switch CPUs */
  173. larl %r1,saved_cpu_id
  174. llgf %r2,0(%r1)
  175. llgf %r3,0x318(%r13)
  176. brasl %r14,smp_switch_boot_cpu_in_resume
  177. #endif
  178. /* Restore prefix register */
  179. spx 0x318(%r13)
  180. /* Activate DAT */
  181. stosm __SF_EMPTY(%r15),0x04
  182. /* Make all free pages unstable */
  183. lghi %r2,0
  184. brasl %r14,arch_set_page_states
  185. /* Return 0 */
  186. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  187. lghi %r2,0
  188. br %r14
  189. .section .data.nosave,"aw",@progbits
  190. .align 8
  191. restart_psw:
  192. .long 0x00080000,0x80000000
  193. new_pgm_check_psw:
  194. .quad 0,pgm_check_entry
  195. saved_pgm_check_psw:
  196. .quad 0,0
  197. #ifdef CONFIG_SMP
  198. saved_cpu_id:
  199. .long 0
  200. #endif