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)
33 /* Store FPU registers */
34 brasl %r14,save_fpu_regs
37 stnsm __SF_EMPTY(%r15),0xfb
39 /* Store prefix register on stack */
42 /* Save prefix register contents for lowcore copy */
43 llgf %r10,__SF_EMPTY(%r15)
45 /* Get pointer to save area */
48 /* Save CPU address */
49 stap __LC_EXT_CPU_ADDR(%r0)
52 mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
53 stam %a0,%a15,0x340(%r1) /* store access registers */
54 stctg %c0,%c15,0x380(%r1) /* store control registers */
55 stmg %r0,%r15,0x280(%r1) /* store general registers */
57 stpt 0x328(%r1) /* store timer */
58 stck __SF_EMPTY(%r15) /* store clock */
59 stckc 0x330(%r1) /* store clock comparator */
61 /* Update cputime accounting before going to sleep */
62 lg %r0,__LC_LAST_UPDATE_TIMER
64 alg %r0,__LC_SYSTEM_TIMER
65 stg %r0,__LC_SYSTEM_TIMER
66 mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
67 lg %r0,__LC_LAST_UPDATE_CLOCK
68 slg %r0,__SF_EMPTY(%r15)
69 alg %r0,__LC_STEAL_TIMER
70 stg %r0,__LC_STEAL_TIMER
71 mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
74 stosm __SF_EMPTY(%r15),0x04
76 /* Set prefix page to zero */
77 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
80 /* Save absolute zero pages */
81 larl %r2,suspend_zero_pages
89 /* Copy lowcore to absolute zero lowcore */
98 brasl %r14,swsusp_save
100 /* Restore prefix register and return */
103 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
108 * Restore saved memory image to correct place and restore register context.
109 * Then we return to the function that called swsusp_arch_suspend().
110 * swsusp_arch_resume() runs with disabled interrupts.
112 ENTRY(swsusp_arch_resume)
113 stmg %r6,%r15,__SF_GPRS(%r15)
115 aghi %r15,-STACK_FRAME_OVERHEAD
116 stg %r1,__SF_BACKCHAIN(%r15)
118 /* Make all free pages stable */
120 brasl %r14,arch_set_page_states
123 stnsm __SF_EMPTY(%r15),0xfb
125 /* Set prefix page to zero */
126 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
129 /* Restore saved image */
130 larl %r1,restore_pblist
152 larl %r1,restart_entry
153 larl %r2,.Lrestart_diag308_psw
156 larl %r1,.Lnew_pgm_check_psw
159 mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
164 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
167 larl %r1,smp_cpu_mt_shift
172 sigp %r1,%r0,SIGP_SET_MULTI_THREADING
173 brc 8,smt_done /* accepted */
174 brc 2,smt_loop /* busy, try again */
177 larl %r1,.Lnew_pgm_check_psw
181 /* Switch to original suspend CPU */
182 larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
185 llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
187 je restore_registers /* r1 = r2 -> nothing to do */
188 larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
189 mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
191 sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
192 brc 8,4f /* accepted */
193 brc 2,3b /* busy, try again */
195 /* Suspend CPU not available -> panic */
196 larl %r15,init_thread_union
197 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER)
198 larl %r2,.Lpanic_string
199 larl %r3,_sclp_print_early
202 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
204 larl %r3,.Ldisabled_wait_31
207 /* Switch to suspend CPU */
208 sigp %r9,%r1,SIGP_RESTART /* sigp restart to suspend CPU */
209 brc 2,4b /* busy, try again */
211 sigp %r9,%r2,SIGP_STOP /* sigp stop to current resume CPU */
212 brc 2,5b /* busy, try again */
216 larl %r1,.Lresume_cpu
219 sigp %r9,%r2,SIGP_SENSE /* sigp sense, wait for resume CPU */
220 brc 8,7b /* accepted, status 0, still running */
221 brc 2,7b /* busy, try again */
222 tmll %r9,0x40 /* Test if resume CPU is stopped */
226 /* Restore registers */
227 lghi %r13,0x1000 /* %r1 = pointer to save area */
229 /* Ignore time spent in suspended state. */
231 stck __LC_LAST_UPDATE_CLOCK(%r1)
232 spt 0x328(%r13) /* reprogram timer */
233 //sckc 0x330(%r13) /* set clock comparator */
235 lctlg %c0,%c15,0x380(%r13) /* load control registers */
236 lam %a0,%a15,0x340(%r13) /* load access registers */
241 /* Save prefix register */
242 mvc __SF_EMPTY(4,%r15),0x318(%r13)
244 /* Restore absolute zero pages */
246 larl %r4,suspend_zero_pages
253 /* Restore prefix register */
257 stosm __SF_EMPTY(%r15),0x04
259 /* Make all free pages unstable */
261 brasl %r14,arch_set_page_states
263 /* Call arch specific early resume code */
264 brasl %r14,s390_early_resume
267 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
271 .section .data..nosave,"aw",@progbits
274 .long 0x000a0000,0x00000000
276 .asciz "Resume not possible because suspend CPU is no longer available"
278 .Lrestart_diag308_psw:
279 .long 0x00080000,0x80000000
280 .Lrestart_suspend_psw:
281 .quad 0x0000000180000000,restart_suspend
283 .quad 0,pgm_check_entry