2 * S390 64-bit swsusp implementation
4 * Copyright IBM Corp. 2009
6 * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
7 * Michael Holzheu <holzheu@linux.vnet.ibm.com>
10 #include <linux/linkage.h>
12 #include <asm/ptrace.h>
13 #include <asm/thread_info.h>
14 #include <asm/asm-offsets.h>
18 * Save register context in absolute 0 lowcore and call swsusp_save() to
19 * create in-memory kernel image. The context is saved in the designated
20 * "store status" memory locations (see POP).
21 * We return from this function twice. The first time during the suspend to
22 * disk process. The second time via the swsusp_arch_resume() function
23 * (see below) in the resume process.
24 * This function runs with disabled interrupts.
27 ENTRY(swsusp_arch_suspend)
28 stmg %r6,%r15,__SF_GPRS(%r15)
30 aghi %r15,-STACK_FRAME_OVERHEAD
31 stg %r1,__SF_BACKCHAIN(%r15)
34 stnsm __SF_EMPTY(%r15),0xfb
36 /* Store prefix register on stack */
39 /* Save prefix register contents for lowcore */
40 llgf %r4,__SF_EMPTY(%r15)
42 /* Get pointer to save area */
45 /* Save CPU address */
46 stap __LC_EXT_CPU_ADDR(%r0)
49 mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
50 stfpc 0x31c(%r1) /* store fpu control */
51 std 0,0x200(%r1) /* store f0 */
52 std 1,0x208(%r1) /* store f1 */
53 std 2,0x210(%r1) /* store f2 */
54 std 3,0x218(%r1) /* store f3 */
55 std 4,0x220(%r1) /* store f4 */
56 std 5,0x228(%r1) /* store f5 */
57 std 6,0x230(%r1) /* store f6 */
58 std 7,0x238(%r1) /* store f7 */
59 std 8,0x240(%r1) /* store f8 */
60 std 9,0x248(%r1) /* store f9 */
61 std 10,0x250(%r1) /* store f10 */
62 std 11,0x258(%r1) /* store f11 */
63 std 12,0x260(%r1) /* store f12 */
64 std 13,0x268(%r1) /* store f13 */
65 std 14,0x270(%r1) /* store f14 */
66 std 15,0x278(%r1) /* store f15 */
67 stam %a0,%a15,0x340(%r1) /* store access registers */
68 stctg %c0,%c15,0x380(%r1) /* store control registers */
69 stmg %r0,%r15,0x280(%r1) /* store general registers */
71 stpt 0x328(%r1) /* store timer */
72 stck __SF_EMPTY(%r15) /* store clock */
73 stckc 0x330(%r1) /* store clock comparator */
75 /* Update cputime accounting before going to sleep */
76 lg %r0,__LC_LAST_UPDATE_TIMER
78 alg %r0,__LC_SYSTEM_TIMER
79 stg %r0,__LC_SYSTEM_TIMER
80 mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
81 lg %r0,__LC_LAST_UPDATE_CLOCK
82 slg %r0,__SF_EMPTY(%r15)
83 alg %r0,__LC_STEAL_TIMER
84 stg %r0,__LC_STEAL_TIMER
85 mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
88 stosm __SF_EMPTY(%r15),0x04
90 /* Set prefix page to zero */
91 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
101 brasl %r14,swsusp_save
103 /* Restore prefix register and return */
106 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
111 * Restore saved memory image to correct place and restore register context.
112 * Then we return to the function that called swsusp_arch_suspend().
113 * swsusp_arch_resume() runs with disabled interrupts.
115 ENTRY(swsusp_arch_resume)
116 stmg %r6,%r15,__SF_GPRS(%r15)
118 aghi %r15,-STACK_FRAME_OVERHEAD
119 stg %r1,__SF_BACKCHAIN(%r15)
121 /* Make all free pages stable */
123 brasl %r14,arch_set_page_states
126 stnsm __SF_EMPTY(%r15),0xfb
128 /* Set prefix page to zero */
129 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
132 /* Restore saved image */
133 larl %r1,restore_pblist
155 larl %r1,restart_entry
156 larl %r2,.Lrestart_diag308_psw
159 larl %r1,.Lnew_pgm_check_psw
162 mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
167 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
169 larl %r1,.Lnew_pgm_check_psw
173 /* Switch to original suspend CPU */
174 larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
177 llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
179 je restore_registers /* r1 = r2 -> nothing to do */
180 larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
181 mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
183 sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
184 brc 8,4f /* accepted */
185 brc 2,3b /* busy, try again */
187 /* Suspend CPU not available -> panic */
188 larl %r15,init_thread_union
189 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER)
190 larl %r2,.Lpanic_string
191 larl %r3,_sclp_print_early
194 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
196 larl %r3,.Ldisabled_wait_31
199 /* Switch to suspend CPU */
200 sigp %r9,%r1,SIGP_RESTART /* sigp restart to suspend CPU */
201 brc 2,4b /* busy, try again */
203 sigp %r9,%r2,SIGP_STOP /* sigp stop to current resume CPU */
204 brc 2,5b /* busy, try again */
208 larl %r1,.Lresume_cpu
211 sigp %r9,%r2,SIGP_SENSE /* sigp sense, wait for resume CPU */
212 brc 8,7b /* accepted, status 0, still running */
213 brc 2,7b /* busy, try again */
214 tmll %r9,0x40 /* Test if resume CPU is stopped */
218 /* Restore registers */
219 lghi %r13,0x1000 /* %r1 = pointer to save area */
221 /* Ignore time spent in suspended state. */
223 stck __LC_LAST_UPDATE_CLOCK(%r1)
224 spt 0x328(%r13) /* reprogram timer */
225 //sckc 0x330(%r13) /* set clock comparator */
227 lctlg %c0,%c15,0x380(%r13) /* load control registers */
228 lam %a0,%a15,0x340(%r13) /* load access registers */
230 lfpc 0x31c(%r13) /* load fpu control */
231 ld 0,0x200(%r13) /* load f0 */
232 ld 1,0x208(%r13) /* load f1 */
233 ld 2,0x210(%r13) /* load f2 */
234 ld 3,0x218(%r13) /* load f3 */
235 ld 4,0x220(%r13) /* load f4 */
236 ld 5,0x228(%r13) /* load f5 */
237 ld 6,0x230(%r13) /* load f6 */
238 ld 7,0x238(%r13) /* load f7 */
239 ld 8,0x240(%r13) /* load f8 */
240 ld 9,0x248(%r13) /* load f9 */
241 ld 10,0x250(%r13) /* load f10 */
242 ld 11,0x258(%r13) /* load f11 */
243 ld 12,0x260(%r13) /* load f12 */
244 ld 13,0x268(%r13) /* load f13 */
245 ld 14,0x270(%r13) /* load f14 */
246 ld 15,0x278(%r13) /* load f15 */
251 /* Restore prefix register */
255 stosm __SF_EMPTY(%r15),0x04
257 /* Make all free pages unstable */
259 brasl %r14,arch_set_page_states
261 /* Log potential guest relocation */
262 brasl %r14,lgr_info_log
264 /* Reinitialize the channel subsystem */
265 brasl %r14,channel_subsystem_reinit
268 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
272 .section .data..nosave,"aw",@progbits
275 .long 0x000a0000,0x00000000
277 .asciz "Resume not possible because suspend CPU is no longer available"
279 .Lrestart_diag308_psw:
280 .long 0x00080000,0x80000000
281 .Lrestart_suspend_psw:
282 .quad 0x0000000180000000,restart_suspend
284 .quad 0,pgm_check_entry