swsusp_asm64.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 2
  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. /* Switch off lowcore protection */
  32. stctg %c0,%c0,__SF_EMPTY(%r15)
  33. ni __SF_EMPTY+4(%r15),0xef
  34. lctlg %c0,%c0,__SF_EMPTY(%r15)
  35. /* Store prefix register on stack */
  36. stpx __SF_EMPTY(%r15)
  37. /* Setup base register for lowcore (absolute 0) */
  38. llgf %r1,__SF_EMPTY(%r15)
  39. /* Get pointer to save area */
  40. aghi %r1,0x1000
  41. /* Store registers */
  42. mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
  43. stfpc 0x31c(%r1) /* store fpu control */
  44. std 0,0x200(%r1) /* store f0 */
  45. std 1,0x208(%r1) /* store f1 */
  46. std 2,0x210(%r1) /* store f2 */
  47. std 3,0x218(%r1) /* store f3 */
  48. std 4,0x220(%r1) /* store f4 */
  49. std 5,0x228(%r1) /* store f5 */
  50. std 6,0x230(%r1) /* store f6 */
  51. std 7,0x238(%r1) /* store f7 */
  52. std 8,0x240(%r1) /* store f8 */
  53. std 9,0x248(%r1) /* store f9 */
  54. std 10,0x250(%r1) /* store f10 */
  55. std 11,0x258(%r1) /* store f11 */
  56. std 12,0x260(%r1) /* store f12 */
  57. std 13,0x268(%r1) /* store f13 */
  58. std 14,0x270(%r1) /* store f14 */
  59. std 15,0x278(%r1) /* store f15 */
  60. stam %a0,%a15,0x340(%r1) /* store access registers */
  61. stctg %c0,%c15,0x380(%r1) /* store control registers */
  62. stmg %r0,%r15,0x280(%r1) /* store general registers */
  63. stpt 0x328(%r1) /* store timer */
  64. stckc 0x330(%r1) /* store clock comparator */
  65. /* Activate DAT */
  66. stosm __SF_EMPTY(%r15),0x04
  67. /* Set prefix page to zero */
  68. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  69. spx __SF_EMPTY(%r15)
  70. /* Setup lowcore */
  71. brasl %r14,setup_lowcore_early
  72. /* Save image */
  73. brasl %r14,swsusp_save
  74. /* Switch on lowcore protection */
  75. stctg %c0,%c0,__SF_EMPTY(%r15)
  76. oi __SF_EMPTY+4(%r15),0x10
  77. lctlg %c0,%c0,__SF_EMPTY(%r15)
  78. /* Restore prefix register and return */
  79. lghi %r1,0x1000
  80. spx 0x318(%r1)
  81. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  82. lghi %r2,0
  83. br %r14
  84. /*
  85. * Restore saved memory image to correct place and restore register context.
  86. * Then we return to the function that called swsusp_arch_suspend().
  87. * swsusp_arch_resume() runs with disabled interrupts.
  88. */
  89. .globl swsusp_arch_resume
  90. swsusp_arch_resume:
  91. stmg %r6,%r15,__SF_GPRS(%r15)
  92. lgr %r1,%r15
  93. aghi %r15,-STACK_FRAME_OVERHEAD
  94. stg %r1,__SF_BACKCHAIN(%r15)
  95. #ifdef CONFIG_SMP
  96. /* Save boot cpu number */
  97. brasl %r14,smp_get_phys_cpu_id
  98. lgr %r10,%r2
  99. #endif
  100. /* Deactivate DAT */
  101. stnsm __SF_EMPTY(%r15),0xfb
  102. /* Switch off lowcore protection */
  103. stctg %c0,%c0,__SF_EMPTY(%r15)
  104. ni __SF_EMPTY+4(%r15),0xef
  105. lctlg %c0,%c0,__SF_EMPTY(%r15)
  106. /* Set prefix page to zero */
  107. xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
  108. spx __SF_EMPTY(%r15)
  109. /* Restore saved image */
  110. larl %r1,restore_pblist
  111. lg %r1,0(%r1)
  112. ltgr %r1,%r1
  113. jz 2f
  114. 0:
  115. lg %r2,8(%r1)
  116. lg %r4,0(%r1)
  117. lghi %r3,PAGE_SIZE
  118. lghi %r5,PAGE_SIZE
  119. 1:
  120. mvcle %r2,%r4,0
  121. jo 1b
  122. lg %r1,16(%r1)
  123. ltgr %r1,%r1
  124. jnz 0b
  125. 2:
  126. ptlb /* flush tlb */
  127. /* Restore registers */
  128. lghi %r13,0x1000 /* %r1 = pointer to save arae */
  129. spt 0x328(%r13) /* reprogram timer */
  130. //sckc 0x330(%r13) /* set clock comparator */
  131. lctlg %c0,%c15,0x380(%r13) /* load control registers */
  132. lam %a0,%a15,0x340(%r13) /* load access registers */
  133. lfpc 0x31c(%r13) /* load fpu control */
  134. ld 0,0x200(%r13) /* load f0 */
  135. ld 1,0x208(%r13) /* load f1 */
  136. ld 2,0x210(%r13) /* load f2 */
  137. ld 3,0x218(%r13) /* load f3 */
  138. ld 4,0x220(%r13) /* load f4 */
  139. ld 5,0x228(%r13) /* load f5 */
  140. ld 6,0x230(%r13) /* load f6 */
  141. ld 7,0x238(%r13) /* load f7 */
  142. ld 8,0x240(%r13) /* load f8 */
  143. ld 9,0x248(%r13) /* load f9 */
  144. ld 10,0x250(%r13) /* load f10 */
  145. ld 11,0x258(%r13) /* load f11 */
  146. ld 12,0x260(%r13) /* load f12 */
  147. ld 13,0x268(%r13) /* load f13 */
  148. ld 14,0x270(%r13) /* load f14 */
  149. ld 15,0x278(%r13) /* load f15 */
  150. /* Load old stack */
  151. lg %r15,0x2f8(%r13)
  152. /* Pointer to save arae */
  153. lghi %r13,0x1000
  154. #ifdef CONFIG_SMP
  155. /* Switch CPUs */
  156. lgr %r2,%r10 /* get cpu id */
  157. llgf %r3,0x318(%r13)
  158. brasl %r14,smp_switch_boot_cpu_in_resume
  159. #endif
  160. /* Restore prefix register */
  161. spx 0x318(%r13)
  162. /* Switch on lowcore protection */
  163. stctg %c0,%c0,__SF_EMPTY(%r15)
  164. oi __SF_EMPTY+4(%r15),0x10
  165. lctlg %c0,%c0,__SF_EMPTY(%r15)
  166. /* Activate DAT */
  167. stosm __SF_EMPTY(%r15),0x04
  168. /* Return 0 */
  169. lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
  170. lghi %r2,0
  171. br %r14