2009-06-16 08:30:52 +00:00
|
|
|
/*
|
|
|
|
* S390 64-bit swsusp implementation
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2009
|
|
|
|
*
|
|
|
|
* Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
|
|
|
|
* Michael Holzheu <holzheu@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2011-07-24 08:48:19 +00:00
|
|
|
#include <linux/linkage.h>
|
2009-06-16 08:30:52 +00:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/ptrace.h>
|
2009-09-22 20:58:53 +00:00
|
|
|
#include <asm/thread_info.h>
|
2009-06-16 08:30:52 +00:00
|
|
|
#include <asm/asm-offsets.h>
|
2012-06-04 13:05:43 +00:00
|
|
|
#include <asm/sigp.h>
|
2009-06-16 08:30:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save register context in absolute 0 lowcore and call swsusp_save() to
|
|
|
|
* create in-memory kernel image. The context is saved in the designated
|
|
|
|
* "store status" memory locations (see POP).
|
|
|
|
* We return from this function twice. The first time during the suspend to
|
|
|
|
* disk process. The second time via the swsusp_arch_resume() function
|
|
|
|
* (see below) in the resume process.
|
|
|
|
* This function runs with disabled interrupts.
|
|
|
|
*/
|
|
|
|
.section .text
|
2011-07-24 08:48:19 +00:00
|
|
|
ENTRY(swsusp_arch_suspend)
|
2009-06-16 08:30:52 +00:00
|
|
|
stmg %r6,%r15,__SF_GPRS(%r15)
|
|
|
|
lgr %r1,%r15
|
|
|
|
aghi %r15,-STACK_FRAME_OVERHEAD
|
|
|
|
stg %r1,__SF_BACKCHAIN(%r15)
|
|
|
|
|
2015-09-08 11:59:08 +00:00
|
|
|
/* Store FPU registers */
|
|
|
|
brasl %r14,save_fpu_regs
|
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Deactivate DAT */
|
|
|
|
stnsm __SF_EMPTY(%r15),0xfb
|
|
|
|
|
|
|
|
/* Store prefix register on stack */
|
|
|
|
stpx __SF_EMPTY(%r15)
|
|
|
|
|
2013-04-08 14:09:31 +00:00
|
|
|
/* Save prefix register contents for lowcore copy */
|
|
|
|
llgf %r10,__SF_EMPTY(%r15)
|
2009-06-16 08:30:52 +00:00
|
|
|
|
|
|
|
/* Get pointer to save area */
|
2009-07-24 10:39:49 +00:00
|
|
|
lghi %r1,0x1000
|
2009-06-16 08:30:52 +00:00
|
|
|
|
2009-09-22 20:58:53 +00:00
|
|
|
/* Save CPU address */
|
2012-03-11 15:59:25 +00:00
|
|
|
stap __LC_EXT_CPU_ADDR(%r0)
|
2009-09-22 20:58:53 +00:00
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Store registers */
|
|
|
|
mvc 0x318(4,%r1),__SF_EMPTY(%r15) /* move prefix to lowcore */
|
|
|
|
stam %a0,%a15,0x340(%r1) /* store access registers */
|
|
|
|
stctg %c0,%c15,0x380(%r1) /* store control registers */
|
|
|
|
stmg %r0,%r15,0x280(%r1) /* store general registers */
|
|
|
|
|
|
|
|
stpt 0x328(%r1) /* store timer */
|
2009-10-06 08:34:11 +00:00
|
|
|
stck __SF_EMPTY(%r15) /* store clock */
|
2009-06-16 08:30:52 +00:00
|
|
|
stckc 0x330(%r1) /* store clock comparator */
|
|
|
|
|
2009-10-06 08:34:11 +00:00
|
|
|
/* Update cputime accounting before going to sleep */
|
|
|
|
lg %r0,__LC_LAST_UPDATE_TIMER
|
|
|
|
slg %r0,0x328(%r1)
|
|
|
|
alg %r0,__LC_SYSTEM_TIMER
|
|
|
|
stg %r0,__LC_SYSTEM_TIMER
|
|
|
|
mvc __LC_LAST_UPDATE_TIMER(8),0x328(%r1)
|
|
|
|
lg %r0,__LC_LAST_UPDATE_CLOCK
|
|
|
|
slg %r0,__SF_EMPTY(%r15)
|
|
|
|
alg %r0,__LC_STEAL_TIMER
|
|
|
|
stg %r0,__LC_STEAL_TIMER
|
|
|
|
mvc __LC_LAST_UPDATE_CLOCK(8),__SF_EMPTY(%r15)
|
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Activate DAT */
|
|
|
|
stosm __SF_EMPTY(%r15),0x04
|
|
|
|
|
|
|
|
/* Set prefix page to zero */
|
|
|
|
xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
|
|
|
|
spx __SF_EMPTY(%r15)
|
|
|
|
|
2013-04-08 14:09:31 +00:00
|
|
|
/* Save absolute zero pages */
|
|
|
|
larl %r2,suspend_zero_pages
|
|
|
|
lg %r2,0(%r2)
|
|
|
|
lghi %r4,0
|
|
|
|
lghi %r3,2*PAGE_SIZE
|
|
|
|
lghi %r5,2*PAGE_SIZE
|
|
|
|
1: mvcle %r2,%r4,0
|
|
|
|
jo 1b
|
|
|
|
|
|
|
|
/* Copy lowcore to absolute zero lowcore */
|
2009-07-24 10:39:49 +00:00
|
|
|
lghi %r2,0
|
2013-04-08 14:09:31 +00:00
|
|
|
lgr %r4,%r10
|
2009-07-24 10:39:49 +00:00
|
|
|
lghi %r3,2*PAGE_SIZE
|
|
|
|
lghi %r5,2*PAGE_SIZE
|
|
|
|
1: mvcle %r2,%r4,0
|
|
|
|
jo 1b
|
2009-06-16 08:30:52 +00:00
|
|
|
|
|
|
|
/* Save image */
|
|
|
|
brasl %r14,swsusp_save
|
|
|
|
|
|
|
|
/* Restore prefix register and return */
|
|
|
|
lghi %r1,0x1000
|
|
|
|
spx 0x318(%r1)
|
|
|
|
lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
|
|
|
|
lghi %r2,0
|
|
|
|
br %r14
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore saved memory image to correct place and restore register context.
|
|
|
|
* Then we return to the function that called swsusp_arch_suspend().
|
|
|
|
* swsusp_arch_resume() runs with disabled interrupts.
|
|
|
|
*/
|
2011-07-24 08:48:19 +00:00
|
|
|
ENTRY(swsusp_arch_resume)
|
2009-06-16 08:30:52 +00:00
|
|
|
stmg %r6,%r15,__SF_GPRS(%r15)
|
|
|
|
lgr %r1,%r15
|
|
|
|
aghi %r15,-STACK_FRAME_OVERHEAD
|
|
|
|
stg %r1,__SF_BACKCHAIN(%r15)
|
|
|
|
|
2009-09-22 20:58:44 +00:00
|
|
|
/* Make all free pages stable */
|
|
|
|
lghi %r2,1
|
|
|
|
brasl %r14,arch_set_page_states
|
2009-09-22 20:58:53 +00:00
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Deactivate DAT */
|
|
|
|
stnsm __SF_EMPTY(%r15),0xfb
|
|
|
|
|
|
|
|
/* Set prefix page to zero */
|
|
|
|
xc __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
|
|
|
|
spx __SF_EMPTY(%r15)
|
|
|
|
|
|
|
|
/* Restore saved image */
|
|
|
|
larl %r1,restore_pblist
|
|
|
|
lg %r1,0(%r1)
|
|
|
|
ltgr %r1,%r1
|
|
|
|
jz 2f
|
|
|
|
0:
|
|
|
|
lg %r2,8(%r1)
|
|
|
|
lg %r4,0(%r1)
|
2011-08-17 18:42:24 +00:00
|
|
|
iske %r0,%r4
|
2009-06-16 08:30:52 +00:00
|
|
|
lghi %r3,PAGE_SIZE
|
|
|
|
lghi %r5,PAGE_SIZE
|
|
|
|
1:
|
|
|
|
mvcle %r2,%r4,0
|
|
|
|
jo 1b
|
2011-08-17 18:42:24 +00:00
|
|
|
lg %r2,8(%r1)
|
|
|
|
sske %r0,%r2
|
2009-06-16 08:30:52 +00:00
|
|
|
lg %r1,16(%r1)
|
|
|
|
ltgr %r1,%r1
|
|
|
|
jnz 0b
|
|
|
|
2:
|
|
|
|
ptlb /* flush tlb */
|
|
|
|
|
2009-09-22 20:58:45 +00:00
|
|
|
/* Reset System */
|
|
|
|
larl %r1,restart_entry
|
2009-09-22 20:58:53 +00:00
|
|
|
larl %r2,.Lrestart_diag308_psw
|
2009-09-22 20:58:45 +00:00
|
|
|
og %r1,0(%r2)
|
|
|
|
stg %r1,0(%r0)
|
2009-09-22 20:58:53 +00:00
|
|
|
larl %r1,.Lnew_pgm_check_psw
|
2009-09-22 20:58:45 +00:00
|
|
|
epsw %r2,%r3
|
|
|
|
stm %r2,%r3,0(%r1)
|
|
|
|
mvc __LC_PGM_NEW_PSW(16,%r0),0(%r1)
|
|
|
|
lghi %r0,0
|
|
|
|
diag %r0,%r0,0x308
|
|
|
|
restart_entry:
|
|
|
|
lhi %r1,1
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r1,%r0,SIGP_SET_ARCHITECTURE
|
2009-09-22 20:58:45 +00:00
|
|
|
sam64
|
2015-03-21 11:43:08 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
larl %r1,smp_cpu_mt_shift
|
|
|
|
icm %r1,15,0(%r1)
|
|
|
|
jz smt_done
|
|
|
|
llgfr %r1,%r1
|
|
|
|
smt_loop:
|
|
|
|
sigp %r1,%r0,SIGP_SET_MULTI_THREADING
|
|
|
|
brc 8,smt_done /* accepted */
|
|
|
|
brc 2,smt_loop /* busy, try again */
|
|
|
|
smt_done:
|
|
|
|
#endif
|
2009-09-22 20:58:53 +00:00
|
|
|
larl %r1,.Lnew_pgm_check_psw
|
2009-09-22 20:58:45 +00:00
|
|
|
lpswe 0(%r1)
|
|
|
|
pgm_check_entry:
|
|
|
|
|
2009-09-22 20:58:53 +00:00
|
|
|
/* Switch to original suspend CPU */
|
|
|
|
larl %r1,.Lresume_cpu /* Resume CPU address: r2 */
|
|
|
|
stap 0(%r1)
|
|
|
|
llgh %r2,0(%r1)
|
2012-03-11 15:59:25 +00:00
|
|
|
llgh %r1,__LC_EXT_CPU_ADDR(%r0) /* Suspend CPU address: r1 */
|
2009-09-22 20:58:53 +00:00
|
|
|
cgr %r1,%r2
|
|
|
|
je restore_registers /* r1 = r2 -> nothing to do */
|
|
|
|
larl %r4,.Lrestart_suspend_psw /* Set new restart PSW */
|
2010-02-26 21:37:33 +00:00
|
|
|
mvc __LC_RST_NEW_PSW(16,%r0),0(%r4)
|
2009-09-22 20:58:53 +00:00
|
|
|
3:
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r9,%r1,SIGP_INITIAL_CPU_RESET /* sigp initial cpu reset */
|
2012-03-11 15:59:26 +00:00
|
|
|
brc 8,4f /* accepted */
|
|
|
|
brc 2,3b /* busy, try again */
|
2009-09-22 20:58:53 +00:00
|
|
|
|
|
|
|
/* Suspend CPU not available -> panic */
|
|
|
|
larl %r15,init_thread_union
|
2016-11-14 13:39:16 +00:00
|
|
|
ahi %r15,1<<(PAGE_SHIFT+THREAD_SIZE_ORDER)
|
2009-09-22 20:58:53 +00:00
|
|
|
larl %r2,.Lpanic_string
|
2017-01-24 14:58:52 +00:00
|
|
|
larl %r3,sclp_early_printk
|
2009-09-22 20:58:53 +00:00
|
|
|
lghi %r1,0
|
|
|
|
sam31
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r1,%r0,SIGP_SET_ARCHITECTURE
|
2009-09-22 20:58:53 +00:00
|
|
|
basr %r14,%r3
|
|
|
|
larl %r3,.Ldisabled_wait_31
|
|
|
|
lpsw 0(%r3)
|
|
|
|
4:
|
|
|
|
/* Switch to suspend CPU */
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r9,%r1,SIGP_RESTART /* sigp restart to suspend CPU */
|
2009-09-22 20:58:53 +00:00
|
|
|
brc 2,4b /* busy, try again */
|
|
|
|
5:
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r9,%r2,SIGP_STOP /* sigp stop to current resume CPU */
|
2009-10-29 14:04:13 +00:00
|
|
|
brc 2,5b /* busy, try again */
|
2009-09-22 20:58:53 +00:00
|
|
|
6: j 6b
|
|
|
|
|
|
|
|
restart_suspend:
|
|
|
|
larl %r1,.Lresume_cpu
|
|
|
|
llgh %r2,0(%r1)
|
|
|
|
7:
|
2012-06-04 13:05:43 +00:00
|
|
|
sigp %r9,%r2,SIGP_SENSE /* sigp sense, wait for resume CPU */
|
2009-10-29 14:04:14 +00:00
|
|
|
brc 8,7b /* accepted, status 0, still running */
|
2009-09-22 20:58:53 +00:00
|
|
|
brc 2,7b /* busy, try again */
|
|
|
|
tmll %r9,0x40 /* Test if resume CPU is stopped */
|
|
|
|
jz 7b
|
|
|
|
|
|
|
|
restore_registers:
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Restore registers */
|
2009-10-06 08:34:11 +00:00
|
|
|
lghi %r13,0x1000 /* %r1 = pointer to save area */
|
2009-06-16 08:30:52 +00:00
|
|
|
|
2009-10-06 08:34:11 +00:00
|
|
|
/* Ignore time spent in suspended state. */
|
|
|
|
llgf %r1,0x318(%r13)
|
|
|
|
stck __LC_LAST_UPDATE_CLOCK(%r1)
|
2009-06-16 08:30:52 +00:00
|
|
|
spt 0x328(%r13) /* reprogram timer */
|
|
|
|
//sckc 0x330(%r13) /* set clock comparator */
|
|
|
|
|
|
|
|
lctlg %c0,%c15,0x380(%r13) /* load control registers */
|
|
|
|
lam %a0,%a15,0x340(%r13) /* load access registers */
|
|
|
|
|
|
|
|
/* Load old stack */
|
|
|
|
lg %r15,0x2f8(%r13)
|
|
|
|
|
2013-04-08 14:09:31 +00:00
|
|
|
/* Save prefix register */
|
|
|
|
mvc __SF_EMPTY(4,%r15),0x318(%r13)
|
|
|
|
|
|
|
|
/* Restore absolute zero pages */
|
|
|
|
lghi %r2,0
|
|
|
|
larl %r4,suspend_zero_pages
|
|
|
|
lg %r4,0(%r4)
|
|
|
|
lghi %r3,2*PAGE_SIZE
|
|
|
|
lghi %r5,2*PAGE_SIZE
|
|
|
|
1: mvcle %r2,%r4,0
|
|
|
|
jo 1b
|
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Restore prefix register */
|
2013-04-08 14:09:31 +00:00
|
|
|
spx __SF_EMPTY(%r15)
|
2009-06-16 08:30:52 +00:00
|
|
|
|
|
|
|
/* Activate DAT */
|
|
|
|
stosm __SF_EMPTY(%r15),0x04
|
|
|
|
|
2009-09-22 20:58:44 +00:00
|
|
|
/* Make all free pages unstable */
|
|
|
|
lghi %r2,0
|
|
|
|
brasl %r14,arch_set_page_states
|
|
|
|
|
2013-08-29 17:36:49 +00:00
|
|
|
/* Call arch specific early resume code */
|
|
|
|
brasl %r14,s390_early_resume
|
2010-04-22 15:17:04 +00:00
|
|
|
|
2009-06-16 08:30:52 +00:00
|
|
|
/* Return 0 */
|
|
|
|
lmg %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
|
|
|
|
lghi %r2,0
|
|
|
|
br %r14
|
2009-09-22 20:58:45 +00:00
|
|
|
|
2010-02-20 00:03:52 +00:00
|
|
|
.section .data..nosave,"aw",@progbits
|
2009-09-22 20:58:45 +00:00
|
|
|
.align 8
|
2009-09-22 20:58:53 +00:00
|
|
|
.Ldisabled_wait_31:
|
|
|
|
.long 0x000a0000,0x00000000
|
|
|
|
.Lpanic_string:
|
2017-02-02 09:33:20 +00:00
|
|
|
.asciz "Resume not possible because suspend CPU is no longer available\n"
|
2009-09-22 20:58:53 +00:00
|
|
|
.align 8
|
|
|
|
.Lrestart_diag308_psw:
|
2009-09-22 20:58:45 +00:00
|
|
|
.long 0x00080000,0x80000000
|
2009-09-22 20:58:53 +00:00
|
|
|
.Lrestart_suspend_psw:
|
|
|
|
.quad 0x0000000180000000,restart_suspend
|
|
|
|
.Lnew_pgm_check_psw:
|
2009-09-22 20:58:45 +00:00
|
|
|
.quad 0,pgm_check_entry
|
2009-09-22 20:58:53 +00:00
|
|
|
.Lresume_cpu:
|
|
|
|
.byte 0,0
|