[S390] hibernation: reset system after resume
[safe/jmp/linux-2.6] / arch / s390 / kernel / swsusp_asm64.S
1 /*
2  * S390 64-bit swsusp implementation
3  *
4  * Copyright IBM Corp. 2009
5  *
6  * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
7  *            Michael Holzheu <holzheu@linux.vnet.ibm.com>
8  */
9
10 #include <asm/page.h>
11 #include <asm/ptrace.h>
12 #include <asm/asm-offsets.h>
13
14 /*
15  * Save register context in absolute 0 lowcore and call swsusp_save() to
16  * create in-memory kernel image. The context is saved in the designated
17  * "store status" memory locations (see POP).
18  * We return from this function twice. The first time during the suspend to
19  * disk process. The second time via the swsusp_arch_resume() function
20  * (see below) in the resume process.
21  * This function runs with disabled interrupts.
22  */
23         .section .text
24         .align  4
25         .globl swsusp_arch_suspend
26 swsusp_arch_suspend:
27         stmg    %r6,%r15,__SF_GPRS(%r15)
28         lgr     %r1,%r15
29         aghi    %r15,-STACK_FRAME_OVERHEAD
30         stg     %r1,__SF_BACKCHAIN(%r15)
31
32         /* Deactivate DAT */
33         stnsm   __SF_EMPTY(%r15),0xfb
34
35         /* Store prefix register on stack */
36         stpx    __SF_EMPTY(%r15)
37
38         /* Save prefix register contents for lowcore */
39         llgf    %r4,__SF_EMPTY(%r15)
40
41         /* Get pointer to save area */
42         lghi    %r1,0x1000
43
44         /* Store registers */
45         mvc     0x318(4,%r1),__SF_EMPTY(%r15)   /* move prefix to lowcore */
46         stfpc   0x31c(%r1)                      /* store fpu control */
47         std     0,0x200(%r1)                    /* store f0 */
48         std     1,0x208(%r1)                    /* store f1 */
49         std     2,0x210(%r1)                    /* store f2 */
50         std     3,0x218(%r1)                    /* store f3 */
51         std     4,0x220(%r1)                    /* store f4 */
52         std     5,0x228(%r1)                    /* store f5 */
53         std     6,0x230(%r1)                    /* store f6 */
54         std     7,0x238(%r1)                    /* store f7 */
55         std     8,0x240(%r1)                    /* store f8 */
56         std     9,0x248(%r1)                    /* store f9 */
57         std     10,0x250(%r1)                   /* store f10 */
58         std     11,0x258(%r1)                   /* store f11 */
59         std     12,0x260(%r1)                   /* store f12 */
60         std     13,0x268(%r1)                   /* store f13 */
61         std     14,0x270(%r1)                   /* store f14 */
62         std     15,0x278(%r1)                   /* store f15 */
63         stam    %a0,%a15,0x340(%r1)             /* store access registers */
64         stctg   %c0,%c15,0x380(%r1)             /* store control registers */
65         stmg    %r0,%r15,0x280(%r1)             /* store general registers */
66
67         stpt    0x328(%r1)                      /* store timer */
68         stckc   0x330(%r1)                      /* store clock comparator */
69
70         /* Activate DAT */
71         stosm   __SF_EMPTY(%r15),0x04
72
73         /* Set prefix page to zero */
74         xc      __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
75         spx     __SF_EMPTY(%r15)
76
77         lghi    %r2,0
78         lghi    %r3,2*PAGE_SIZE
79         lghi    %r5,2*PAGE_SIZE
80 1:      mvcle   %r2,%r4,0
81         jo      1b
82
83         /* Save image */
84         brasl   %r14,swsusp_save
85
86         /* Restore prefix register and return */
87         lghi    %r1,0x1000
88         spx     0x318(%r1)
89         lmg     %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
90         lghi    %r2,0
91         br      %r14
92
93 /*
94  * Restore saved memory image to correct place and restore register context.
95  * Then we return to the function that called swsusp_arch_suspend().
96  * swsusp_arch_resume() runs with disabled interrupts.
97  */
98         .globl swsusp_arch_resume
99 swsusp_arch_resume:
100         stmg    %r6,%r15,__SF_GPRS(%r15)
101         lgr     %r1,%r15
102         aghi    %r15,-STACK_FRAME_OVERHEAD
103         stg     %r1,__SF_BACKCHAIN(%r15)
104
105         /* Make all free pages stable */
106         lghi    %r2,1
107         brasl   %r14,arch_set_page_states
108 #ifdef CONFIG_SMP
109         /* Save boot cpu number */
110         brasl   %r14,smp_get_phys_cpu_id
111         larl    %r1,saved_cpu_id
112         st      %r2,0(%r1)
113 #endif
114         /* Deactivate DAT */
115         stnsm   __SF_EMPTY(%r15),0xfb
116
117         /* Set prefix page to zero */
118         xc      __SF_EMPTY(4,%r15),__SF_EMPTY(%r15)
119         spx     __SF_EMPTY(%r15)
120
121         /* Restore saved image */
122         larl    %r1,restore_pblist
123         lg      %r1,0(%r1)
124         ltgr    %r1,%r1
125         jz      2f
126 0:
127         lg      %r2,8(%r1)
128         lg      %r4,0(%r1)
129         lghi    %r3,PAGE_SIZE
130         lghi    %r5,PAGE_SIZE
131 1:
132         mvcle   %r2,%r4,0
133         jo      1b
134         lg      %r1,16(%r1)
135         ltgr    %r1,%r1
136         jnz     0b
137 2:
138         ptlb                            /* flush tlb */
139
140         /* Reset System */
141         larl    %r1,restart_entry
142         larl    %r2,restart_psw
143         og      %r1,0(%r2)
144         stg     %r1,0(%r0)
145         larl    %r1,saved_pgm_check_psw
146         mvc     0(16,%r1),__LC_PGM_NEW_PSW(%r0)
147         larl    %r1,new_pgm_check_psw
148         epsw    %r2,%r3
149         stm     %r2,%r3,0(%r1)
150         mvc     __LC_PGM_NEW_PSW(16,%r0),0(%r1)
151         lghi    %r0,0
152         diag    %r0,%r0,0x308
153 restart_entry:
154         lhi     %r1,1
155         sigp    %r1,%r0,0x12
156         sam64
157         larl    %r1,new_pgm_check_psw
158         lpswe   0(%r1)
159 pgm_check_entry:
160         larl    %r1,saved_pgm_check_psw
161         mvc     __LC_PGM_NEW_PSW(16,%r0),0(%r1)
162
163         /* Restore registers */
164         lghi    %r13,0x1000             /* %r1 = pointer to save arae */
165
166         spt     0x328(%r13)             /* reprogram timer */
167         //sckc  0x330(%r13)             /* set clock comparator */
168
169         lctlg   %c0,%c15,0x380(%r13)    /* load control registers */
170         lam     %a0,%a15,0x340(%r13)    /* load access registers */
171
172         lfpc    0x31c(%r13)             /* load fpu control */
173         ld      0,0x200(%r13)           /* load f0 */
174         ld      1,0x208(%r13)           /* load f1 */
175         ld      2,0x210(%r13)           /* load f2 */
176         ld      3,0x218(%r13)           /* load f3 */
177         ld      4,0x220(%r13)           /* load f4 */
178         ld      5,0x228(%r13)           /* load f5 */
179         ld      6,0x230(%r13)           /* load f6 */
180         ld      7,0x238(%r13)           /* load f7 */
181         ld      8,0x240(%r13)           /* load f8 */
182         ld      9,0x248(%r13)           /* load f9 */
183         ld      10,0x250(%r13)          /* load f10 */
184         ld      11,0x258(%r13)          /* load f11 */
185         ld      12,0x260(%r13)          /* load f12 */
186         ld      13,0x268(%r13)          /* load f13 */
187         ld      14,0x270(%r13)          /* load f14 */
188         ld      15,0x278(%r13)          /* load f15 */
189
190         /* Load old stack */
191         lg      %r15,0x2f8(%r13)
192
193         /* Pointer to save area */
194         lghi    %r13,0x1000
195
196 #ifdef CONFIG_SMP
197         /* Switch CPUs */
198         larl    %r1,saved_cpu_id
199         llgf    %r2,0(%r1)
200         llgf    %r3,0x318(%r13)
201         brasl   %r14,smp_switch_boot_cpu_in_resume
202 #endif
203         /* Restore prefix register */
204         spx     0x318(%r13)
205
206         /* Activate DAT */
207         stosm   __SF_EMPTY(%r15),0x04
208
209         /* Make all free pages unstable */
210         lghi    %r2,0
211         brasl   %r14,arch_set_page_states
212
213         /* Return 0 */
214         lmg     %r6,%r15,STACK_FRAME_OVERHEAD + __SF_GPRS(%r15)
215         lghi    %r2,0
216         br      %r14
217
218         .section .data.nosave,"aw",@progbits
219         .align  8
220 restart_psw:
221         .long   0x00080000,0x80000000
222 new_pgm_check_psw:
223         .quad   0,pgm_check_entry
224 saved_pgm_check_psw:
225         .quad   0,0
226 #ifdef CONFIG_SMP
227 saved_cpu_id:
228         .long   0
229 #endif