This source file includes following definitions.
- page_key_additional_pages
- page_key_free
- page_key_alloc
- page_key_read
- page_key_memorize
- page_key_write
- pfn_is_nosave
- suspend_pm_cb
- suspend_pm_init
- save_processor_state
- restore_processor_state
- s390_early_resume
1
2
3
4
5
6
7
8
9
10 #include <linux/pfn.h>
11 #include <linux/suspend.h>
12 #include <linux/mm.h>
13 #include <linux/pci.h>
14 #include <asm/ctl_reg.h>
15 #include <asm/ipl.h>
16 #include <asm/cio.h>
17 #include <asm/sections.h>
18 #include "entry.h"
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 struct page_key_data {
36 struct page_key_data *next;
37 unsigned char data[];
38 };
39
40 #define PAGE_KEY_DATA_SIZE (PAGE_SIZE - sizeof(struct page_key_data *))
41
42 static struct page_key_data *page_key_data;
43 static struct page_key_data *page_key_rp, *page_key_wp;
44 static unsigned long page_key_rx, page_key_wx;
45 unsigned long suspend_zero_pages;
46
47
48
49
50
51
52
53
54 unsigned long page_key_additional_pages(unsigned long pages)
55 {
56 return DIV_ROUND_UP(pages, PAGE_KEY_DATA_SIZE);
57 }
58
59
60
61
62 void page_key_free(void)
63 {
64 struct page_key_data *pkd;
65
66 while (page_key_data) {
67 pkd = page_key_data;
68 page_key_data = pkd->next;
69 free_page((unsigned long) pkd);
70 }
71 }
72
73
74
75
76
77 int page_key_alloc(unsigned long pages)
78 {
79 struct page_key_data *pk;
80 unsigned long size;
81
82 size = DIV_ROUND_UP(pages, PAGE_KEY_DATA_SIZE);
83 while (size--) {
84 pk = (struct page_key_data *) get_zeroed_page(GFP_KERNEL);
85 if (!pk) {
86 page_key_free();
87 return -ENOMEM;
88 }
89 pk->next = page_key_data;
90 page_key_data = pk;
91 }
92 page_key_rp = page_key_wp = page_key_data;
93 page_key_rx = page_key_wx = 0;
94 return 0;
95 }
96
97
98
99
100 void page_key_read(unsigned long *pfn)
101 {
102 struct page *page;
103 unsigned long addr;
104 unsigned char key;
105
106 page = pfn_to_page(*pfn);
107 addr = (unsigned long) page_address(page);
108 key = (unsigned char) page_get_storage_key(addr) & 0x7f;
109 if (arch_test_page_nodat(page))
110 key |= 0x80;
111 *(unsigned char *) pfn = key;
112 }
113
114
115
116
117
118 void page_key_memorize(unsigned long *pfn)
119 {
120 page_key_wp->data[page_key_wx] = *(unsigned char *) pfn;
121 *(unsigned char *) pfn = 0;
122 if (++page_key_wx < PAGE_KEY_DATA_SIZE)
123 return;
124 page_key_wp = page_key_wp->next;
125 page_key_wx = 0;
126 }
127
128
129
130
131
132
133
134 void page_key_write(void *address)
135 {
136 struct page *page;
137 unsigned char key;
138
139 key = page_key_rp->data[page_key_rx];
140 page_set_storage_key((unsigned long) address, key & 0x7f, 0);
141 page = virt_to_page(address);
142 if (key & 0x80)
143 arch_set_page_nodat(page, 0);
144 else
145 arch_set_page_dat(page, 0);
146 if (++page_key_rx >= PAGE_KEY_DATA_SIZE)
147 return;
148 page_key_rp = page_key_rp->next;
149 page_key_rx = 0;
150 }
151
152 int pfn_is_nosave(unsigned long pfn)
153 {
154 unsigned long nosave_begin_pfn = PFN_DOWN(__pa(&__nosave_begin));
155 unsigned long nosave_end_pfn = PFN_DOWN(__pa(&__nosave_end));
156 unsigned long end_rodata_pfn = PFN_DOWN(__pa(__end_rodata)) - 1;
157 unsigned long stext_pfn = PFN_DOWN(__pa(_stext));
158
159
160 if (pfn <= LC_PAGES)
161 return 0;
162 if (pfn >= nosave_begin_pfn && pfn < nosave_end_pfn)
163 return 1;
164
165 if (pfn >= stext_pfn && pfn <= end_rodata_pfn)
166 return 0;
167 if (tprot(PFN_PHYS(pfn)))
168 return 1;
169 return 0;
170 }
171
172
173
174
175 static int suspend_pm_cb(struct notifier_block *nb, unsigned long action,
176 void *ptr)
177 {
178 switch (action) {
179 case PM_SUSPEND_PREPARE:
180 case PM_HIBERNATION_PREPARE:
181 suspend_zero_pages = __get_free_pages(GFP_KERNEL, LC_ORDER);
182 if (!suspend_zero_pages)
183 return NOTIFY_BAD;
184 break;
185 case PM_POST_SUSPEND:
186 case PM_POST_HIBERNATION:
187 free_pages(suspend_zero_pages, LC_ORDER);
188 break;
189 default:
190 return NOTIFY_DONE;
191 }
192 return NOTIFY_OK;
193 }
194
195 static int __init suspend_pm_init(void)
196 {
197 pm_notifier(suspend_pm_cb, 0);
198 return 0;
199 }
200 arch_initcall(suspend_pm_init);
201
202 void save_processor_state(void)
203 {
204
205
206
207
208
209
210
211
212
213
214 local_mcck_disable();
215
216 __ctl_clear_bit(0,28);
217 S390_lowcore.external_new_psw.mask &= ~PSW_MASK_MCHECK;
218 S390_lowcore.svc_new_psw.mask &= ~PSW_MASK_MCHECK;
219 S390_lowcore.io_new_psw.mask &= ~PSW_MASK_MCHECK;
220 S390_lowcore.program_new_psw.mask &= ~PSW_MASK_MCHECK;
221 }
222
223 void restore_processor_state(void)
224 {
225 S390_lowcore.external_new_psw.mask |= PSW_MASK_MCHECK;
226 S390_lowcore.svc_new_psw.mask |= PSW_MASK_MCHECK;
227 S390_lowcore.io_new_psw.mask |= PSW_MASK_MCHECK;
228 S390_lowcore.program_new_psw.mask |= PSW_MASK_MCHECK;
229
230 __ctl_set_bit(0,28);
231 local_mcck_enable();
232 }
233
234
235 void s390_early_resume(void)
236 {
237 lgr_info_log();
238 channel_subsystem_reinit();
239 zpci_rescan();
240 }