2 * Suspend support specific for s390.
4 * Copyright IBM Corp. 2009
6 * Author(s): Hans-Joachim Picht <hans@linux.vnet.ibm.com>
10 #include <linux/suspend.h>
12 #include <asm/ctl_reg.h>
17 * References to section boundaries
19 extern const void __nosave_begin
, __nosave_end
;
22 * The restore of the saved pages in an hibernation image will set
23 * the change and referenced bits in the storage key for each page.
24 * Overindication of the referenced bits after an hibernation cycle
25 * does not cause any harm but the overindication of the change bits
26 * would cause trouble.
27 * Use the ARCH_SAVE_PAGE_KEYS hooks to save the storage key of each
28 * page to the most significant byte of the associated page frame
29 * number in the hibernation image.
33 * Key storage is allocated as a linked list of pages.
34 * The size of the keys array is (PAGE_SIZE - sizeof(long))
36 struct page_key_data
{
37 struct page_key_data
*next
;
41 #define PAGE_KEY_DATA_SIZE (PAGE_SIZE - sizeof(struct page_key_data *))
43 static struct page_key_data
*page_key_data
;
44 static struct page_key_data
*page_key_rp
, *page_key_wp
;
45 static unsigned long page_key_rx
, page_key_wx
;
46 unsigned long suspend_zero_pages
;
49 * For each page in the hibernation image one additional byte is
50 * stored in the most significant byte of the page frame number.
51 * On suspend no additional memory is required but on resume the
52 * keys need to be memorized until the page data has been restored.
53 * Only then can the storage keys be set to their old state.
55 unsigned long page_key_additional_pages(unsigned long pages
)
57 return DIV_ROUND_UP(pages
, PAGE_KEY_DATA_SIZE
);
61 * Free page_key_data list of arrays.
63 void page_key_free(void)
65 struct page_key_data
*pkd
;
67 while (page_key_data
) {
69 page_key_data
= pkd
->next
;
70 free_page((unsigned long) pkd
);
75 * Allocate page_key_data list of arrays with enough room to store
76 * one byte for each page in the hibernation image.
78 int page_key_alloc(unsigned long pages
)
80 struct page_key_data
*pk
;
83 size
= DIV_ROUND_UP(pages
, PAGE_KEY_DATA_SIZE
);
85 pk
= (struct page_key_data
*) get_zeroed_page(GFP_KERNEL
);
90 pk
->next
= page_key_data
;
93 page_key_rp
= page_key_wp
= page_key_data
;
94 page_key_rx
= page_key_wx
= 0;
99 * Save the storage key into the upper 8 bits of the page frame number.
101 void page_key_read(unsigned long *pfn
)
105 addr
= (unsigned long) page_address(pfn_to_page(*pfn
));
106 *(unsigned char *) pfn
= (unsigned char) page_get_storage_key(addr
);
110 * Extract the storage key from the upper 8 bits of the page frame number
111 * and store it in the page_key_data list of arrays.
113 void page_key_memorize(unsigned long *pfn
)
115 page_key_wp
->data
[page_key_wx
] = *(unsigned char *) pfn
;
116 *(unsigned char *) pfn
= 0;
117 if (++page_key_wx
< PAGE_KEY_DATA_SIZE
)
119 page_key_wp
= page_key_wp
->next
;
124 * Get the next key from the page_key_data list of arrays and set the
125 * storage key of the page referred by @address. If @address refers to
126 * a "safe" page the swsusp_arch_resume code will transfer the storage
127 * key from the buffer page to the original page.
129 void page_key_write(void *address
)
131 page_set_storage_key((unsigned long) address
,
132 page_key_rp
->data
[page_key_rx
], 0);
133 if (++page_key_rx
>= PAGE_KEY_DATA_SIZE
)
135 page_key_rp
= page_key_rp
->next
;
139 int pfn_is_nosave(unsigned long pfn
)
141 unsigned long nosave_begin_pfn
= PFN_DOWN(__pa(&__nosave_begin
));
142 unsigned long nosave_end_pfn
= PFN_DOWN(__pa(&__nosave_end
));
144 /* Always save lowcore pages (LC protection might be enabled). */
147 if (pfn
>= nosave_begin_pfn
&& pfn
< nosave_end_pfn
)
149 /* Skip memory holes and read-only pages (NSS, DCSS, ...). */
150 if (tprot(PFN_PHYS(pfn
)))
156 * PM notifier callback for suspend
158 static int suspend_pm_cb(struct notifier_block
*nb
, unsigned long action
,
162 case PM_SUSPEND_PREPARE
:
163 case PM_HIBERNATION_PREPARE
:
164 suspend_zero_pages
= __get_free_pages(GFP_KERNEL
, LC_ORDER
);
165 if (!suspend_zero_pages
)
168 case PM_POST_SUSPEND
:
169 case PM_POST_HIBERNATION
:
170 free_pages(suspend_zero_pages
, LC_ORDER
);
178 static int __init
suspend_pm_init(void)
180 pm_notifier(suspend_pm_cb
, 0);
183 arch_initcall(suspend_pm_init
);
185 void save_processor_state(void)
187 /* swsusp_arch_suspend() actually saves all cpu register contents.
188 * Machine checks must be disabled since swsusp_arch_suspend() stores
189 * register contents to their lowcore save areas. That's the same
190 * place where register contents on machine checks would be saved.
191 * To avoid register corruption disable machine checks.
192 * We must also disable machine checks in the new psw mask for
193 * program checks, since swsusp_arch_suspend() may generate program
194 * checks. Disabling machine checks for all other new psw masks is
197 local_mcck_disable();
198 /* Disable lowcore protection */
199 __ctl_clear_bit(0,28);
200 S390_lowcore
.external_new_psw
.mask
&= ~PSW_MASK_MCHECK
;
201 S390_lowcore
.svc_new_psw
.mask
&= ~PSW_MASK_MCHECK
;
202 S390_lowcore
.io_new_psw
.mask
&= ~PSW_MASK_MCHECK
;
203 S390_lowcore
.program_new_psw
.mask
&= ~PSW_MASK_MCHECK
;
206 void restore_processor_state(void)
208 S390_lowcore
.external_new_psw
.mask
|= PSW_MASK_MCHECK
;
209 S390_lowcore
.svc_new_psw
.mask
|= PSW_MASK_MCHECK
;
210 S390_lowcore
.io_new_psw
.mask
|= PSW_MASK_MCHECK
;
211 S390_lowcore
.program_new_psw
.mask
|= PSW_MASK_MCHECK
;
212 /* Enable lowcore protection */
217 /* Called at the end of swsusp_arch_resume */
218 void s390_early_resume(void)
221 channel_subsystem_reinit();
This page took 0.035277 seconds and 5 git commands to generate.