1 /* SPDX-License-Identifier: GPL-2.0 */
3 * S390 64-bit swsusp implementation
5 * Copyright IBM Corp. 2009
7 * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
8 * Michael Holzheu <holzheu@linux.vnet.ibm.com>
11 #include <linux/linkage.h>
13 #include <asm/ptrace.h>
14 #include <asm/thread_info.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/nospec-insn.h>
20 * Save register context in absolute 0 lowcore and call swsusp_save() to
21 * create in-memory kernel image. The context is saved in the designated
22 * "store status" memory locations (see POP).
23 * We return from this function twice. The first time during the suspend to
24 * disk process. The second time via the swsusp_arch_resume() function
25 * (see below) in the resume process.
26 * This function runs with disabled interrupts.
31 ENTRY(swsusp_arch_suspend)
32 lg %r1,__LC_NODAT_STACK
33 stmg %r6,%r15,__SF_GPRS(%r1)
34 aghi %r1,-STACK_FRAME_OVERHEAD
35 stg %r15,__SF_BACKCHAIN(%r1)
38 /* Store FPU registers */
39 brasl %r14,save_fpu_regs
42 stnsm __SF_EMPTY(%r15),0xfb
44 /* Store prefix register on stack */
47 /* Save prefix register contents for lowcore copy */
48 llgf %r10,__SF_EMPTY(%r15)
50 /* Get pointer to save area */
53 /* Save CPU address */
54 stap __LC_EXT_CPU_ADDR(%r0)
57 mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
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 */
62 stpt 0x328(%r1) /* store timer */
63 stck __SF_EMPTY(%r15) /* store clock */
64 stckc 0x330(%r1) /* store clock comparator */
66 /* Update cputime accounting before going to sleep */
67 lg %r0,__LC_LAST_UPDATE_TIMER
69 alg %r0,__LC_SYSTEM_TIMER
70 stg %r0,__LC_SYSTEM_TIMER
71 mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
72 lg %r0,__LC_LAST_UPDATE_CLOCK
73 slg %r0,__SF_EMPTY(%r15)
74 alg %r0,__LC_STEAL_TIMER
75 stg %r0,__LC_STEAL_TIMER
76 mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
79 stosm __SF_EMPTY(%r15),0x04
81 /* Set prefix page to zero */
82 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
85 /* Save absolute zero pages */
86 larl %r2,suspend_zero_pages
94 /* Copy lowcore to absolute zero lowcore */
103 brasl %r14,swsusp_save
105 /* Restore prefix register and return */
108 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
113 * Restore saved memory image to correct place and restore register context.
114 * Then we return to the function that called swsusp_arch_suspend().
115 * swsusp_arch_resume() runs with disabled interrupts.
117 ENTRY(swsusp_arch_resume)
118 stmg %r6,%r15,__SF_GPRS(%r15)
120 aghi %r15,-STACK_FRAME_OVERHEAD
121 stg %r1,__SF_BACKCHAIN(%r15)
123 /* Make all free pages stable */
125 brasl %r14,arch_set_page_states
127 /* Set prefix page to zero */
128 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
132 stnsm __SF_EMPTY(%r15),0xfb
134 /* Restore saved image */
135 larl %r1,restore_pblist
157 larl %r1,restart_entry
158 larl %r2,.Lrestart_diag308_psw
161 larl %r1,.Lnew_pgm_check_psw
164 mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
169 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
172 larl %r1,smp_cpu_mt_shift
177 sigp %r1,%r0,SIGP_SET_MULTI_THREADING
178 brc 8,smt_done /* accepted */
179 brc 2,smt_loop /* busy, try again */
182 larl %r1,.Lnew_pgm_check_psw
186 /* Switch to original suspend CPU */
187 larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
190 llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
192 je restore_registers /* r1 = r2 -> nothing to do */
193 larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
194 mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
196 sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
197 brc 8,4f /* accepted */
198 brc 2,3b /* busy, try again */
200 /* Suspend CPU not available -> panic */
201 larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD
202 larl %r2,.Lpanic_string
203 brasl %r14,sclp_early_printk_force
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\n"
278 .Lrestart_diag308_psw:
279 .long 0x00080000,0x80000000
280 .Lrestart_suspend_psw:
281 .quad 0x0000000180000000,restart_suspend
283 .quad 0,pgm_check_entry