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)
111 ENDPROC(swsusp_arch_suspend)
114 * Restore saved memory image to correct place and restore register context.
115 * Then we return to the function that called swsusp_arch_suspend().
116 * swsusp_arch_resume() runs with disabled interrupts.
118 ENTRY(swsusp_arch_resume)
119 stmg %r6,%r15,__SF_GPRS(%r15)
121 aghi %r15,-STACK_FRAME_OVERHEAD
122 stg %r1,__SF_BACKCHAIN(%r15)
124 /* Make all free pages stable */
126 brasl %r14,arch_set_page_states
128 /* Set prefix page to zero */
129 xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
133 stnsm __SF_EMPTY(%r15),0xfb
135 /* Restore saved image */
136 larl %r1,restore_pblist
158 larl %r1,.Lnew_pgm_check_psw
161 mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
162 larl %r1,__swsusp_reset_dma
165 larl %r1,smp_cpu_mt_shift
170 sigp %r1,%r0,SIGP_SET_MULTI_THREADING
171 brc 8,smt_done /* accepted */
172 brc 2,smt_loop /* busy, try again */
174 larl %r1,.Lnew_pgm_check_psw
178 /* Switch to original suspend CPU */
179 larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
182 llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
184 je restore_registers /* r1 = r2 -> nothing to do */
185 larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
186 mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
188 sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
189 brc 8,4f /* accepted */
190 brc 2,3b /* busy, try again */
192 /* Suspend CPU not available -> panic */
193 larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD
194 larl %r2,.Lpanic_string
195 brasl %r14,sclp_early_printk_force
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 */
233 /* Save prefix register */
234 mvc __SF_EMPTY(4,%r15),0x318(%r13)
236 /* Restore absolute zero pages */
238 larl %r4,suspend_zero_pages
245 /* Restore prefix register */
249 stosm __SF_EMPTY(%r15),0x04
251 /* Make all free pages unstable */
253 brasl %r14,arch_set_page_states
255 /* Call arch specific early resume code */
256 brasl %r14,s390_early_resume
259 lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
262 ENDPROC(swsusp_arch_resume)
264 .section .data..nosave,"aw",@progbits
267 .long 0x000a0000,0x00000000
269 .asciz "Resume not possible because suspend CPU is no longer available\n"
271 .Lrestart_suspend_psw:
272 .quad 0x0000000180000000,restart_suspend
274 .quad 0,pgm_check_entry