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 stmg %r6,%r15,__SF_GPRS(%r15)
34 aghi %r15,-STACK_FRAME_OVERHEAD
35 stg %r1,__SF_BACKCHAIN(%r15)
37 /* Store FPU registers */
38 brasl %r14,save_fpu_regs
41 stnsm __SF_EMPTY(%r15),0xfb
43 /* Store prefix register on stack */
46 /* Save prefix register contents for lowcore copy */
47 llgf %r10,__SF_EMPTY(%r15)
49 /* Get pointer to save area */
52 /* Save CPU address */
53 stap __LC_EXT_CPU_ADDR(%r0)
56 mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
57 stam %a0,%a15,0x340(%r1) /* store access registers */
58 stctg %c0,%c15,0x380(%r1) /* store control registers */
59 stmg %r0,%r15,0x280(%r1) /* store general registers */
61 stpt 0x328(%r1) /* store timer */
62 stck __SF_EMPTY(%r15) /* store clock */
63 stckc 0x330(%r1) /* store clock comparator */
65 /* Update cputime accounting before going to sleep */
66 lg %r0,__LC_LAST_UPDATE_TIMER
68 alg %r0,__LC_SYSTEM_TIMER
69 stg %r0,__LC_SYSTEM_TIMER
70 mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
71 lg %r0,__LC_LAST_UPDATE_CLOCK
72 slg %r0,__SF_EMPTY(%r15)
73 alg %r0,__LC_STEAL_TIMER
74 stg %r0,__LC_STEAL_TIMER
75 mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
78 stosm __SF_EMPTY(%r15),0x04
80 /* Set prefix page to zero */
81 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
84 /* Save absolute zero pages */
85 larl %r2,suspend_zero_pages
93 /* Copy lowcore to absolute zero lowcore */
102 brasl %r14,swsusp_save
104 /* Restore prefix register and return */
107 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
112 * Restore saved memory image to correct place and restore register context.
113 * Then we return to the function that called swsusp_arch_suspend().
114 * swsusp_arch_resume() runs with disabled interrupts.
116 ENTRY(swsusp_arch_resume)
117 stmg %r6,%r15,__SF_GPRS(%r15)
119 aghi %r15,-STACK_FRAME_OVERHEAD
120 stg %r1,__SF_BACKCHAIN(%r15)
122 /* Make all free pages stable */
124 brasl %r14,arch_set_page_states
127 stnsm __SF_EMPTY(%r15),0xfb
129 /* Set prefix page to zero */
130 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
133 /* Restore saved image */
134 larl %r1,restore_pblist
156 larl %r1,restart_entry
157 larl %r2,.Lrestart_diag308_psw
160 larl %r1,.Lnew_pgm_check_psw
163 mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
168 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
171 larl %r1,smp_cpu_mt_shift
176 sigp %r1,%r0,SIGP_SET_MULTI_THREADING
177 brc 8,smt_done /* accepted */
178 brc 2,smt_loop /* busy, try again */
181 larl %r1,.Lnew_pgm_check_psw
185 /* Switch to original suspend CPU */
186 larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
189 llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
191 je restore_registers /* r1 = r2 -> nothing to do */
192 larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
193 mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
195 sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
196 brc 8,4f /* accepted */
197 brc 2,3b /* busy, try again */
199 /* Suspend CPU not available -> panic */
200 larl %r15,init_thread_union
201 ahi %r15,1<<(PAGE_SHIFT+THREAD_SIZE_ORDER)
202 larl %r2,.Lpanic_string
205 sigp %r1,%r0,SIGP_SET_ARCHITECTURE
206 brasl %r14,sclp_early_printk
207 larl %r3,.Ldisabled_wait_31
210 /* Switch to suspend CPU */
211 sigp %r9,%r1,SIGP_RESTART /* sigp restart to suspend CPU */
212 brc 2,4b /* busy, try again */
214 sigp %r9,%r2,SIGP_STOP /* sigp stop to current resume CPU */
215 brc 2,5b /* busy, try again */
219 larl %r1,.Lresume_cpu
222 sigp %r9,%r2,SIGP_SENSE /* sigp sense, wait for resume CPU */
223 brc 8,7b /* accepted, status 0, still running */
224 brc 2,7b /* busy, try again */
225 tmll %r9,0x40 /* Test if resume CPU is stopped */
229 /* Restore registers */
230 lghi %r13,0x1000 /* %r1 = pointer to save area */
232 /* Ignore time spent in suspended state. */
234 stck __LC_LAST_UPDATE_CLOCK(%r1)
235 spt 0x328(%r13) /* reprogram timer */
236 //sckc 0x330(%r13) /* set clock comparator */
238 lctlg %c0,%c15,0x380(%r13) /* load control registers */
239 lam %a0,%a15,0x340(%r13) /* load access registers */
244 /* Save prefix register */
245 mvc __SF_EMPTY(4,%r15),0x318(%r13)
247 /* Restore absolute zero pages */
249 larl %r4,suspend_zero_pages
256 /* Restore prefix register */
260 stosm __SF_EMPTY(%r15),0x04
262 /* Make all free pages unstable */
264 brasl %r14,arch_set_page_states
266 /* Call arch specific early resume code */
267 brasl %r14,s390_early_resume
270 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
274 .section .data..nosave,"aw",@progbits
277 .long 0x000a0000,0x00000000
279 .asciz "Resume not possible because suspend CPU is no longer available\n"
281 .Lrestart_diag308_psw:
282 .long 0x00080000,0x80000000
283 .Lrestart_suspend_psw:
284 .quad 0x0000000180000000,restart_suspend
286 .quad 0,pgm_check_entry