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>
13 #include <asm/sections.h>
14 #include <asm/system.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;
48 * For each page in the hibernation image one additional byte is
49 * stored in the most significant byte of the page frame number.
50 * On suspend no additional memory is required but on resume the
51 * keys need to be memorized until the page data has been restored.
52 * Only then can the storage keys be set to their old state.
54 unsigned long page_key_additional_pages(unsigned long pages)
56 return DIV_ROUND_UP(pages, PAGE_KEY_DATA_SIZE);
60 * Free page_key_data list of arrays.
62 void page_key_free(void)
64 struct page_key_data *pkd;
66 while (page_key_data) {
68 page_key_data = pkd->next;
69 free_page((unsigned long) pkd);
74 * Allocate page_key_data list of arrays with enough room to store
75 * one byte for each page in the hibernation image.
77 int page_key_alloc(unsigned long pages)
79 struct page_key_data *pk;
82 size = DIV_ROUND_UP(pages, PAGE_KEY_DATA_SIZE);
84 pk = (struct page_key_data *) get_zeroed_page(GFP_KERNEL);
89 pk->next = page_key_data;
92 page_key_rp = page_key_wp = page_key_data;
93 page_key_rx = page_key_wx = 0;
98 * Save the storage key into the upper 8 bits of the page frame number.
100 void page_key_read(unsigned long *pfn)
104 addr = (unsigned long) page_address(pfn_to_page(*pfn));
105 *(unsigned char *) pfn = (unsigned char) page_get_storage_key(addr);
109 * Extract the storage key from the upper 8 bits of the page frame number
110 * and store it in the page_key_data list of arrays.
112 void page_key_memorize(unsigned long *pfn)
114 page_key_wp->data[page_key_wx] = *(unsigned char *) pfn;
115 *(unsigned char *) pfn = 0;
116 if (++page_key_wx < PAGE_KEY_DATA_SIZE)
118 page_key_wp = page_key_wp->next;
123 * Get the next key from the page_key_data list of arrays and set the
124 * storage key of the page referred by @address. If @address refers to
125 * a "safe" page the swsusp_arch_resume code will transfer the storage
126 * key from the buffer page to the original page.
128 void page_key_write(void *address)
130 page_set_storage_key((unsigned long) address,
131 page_key_rp->data[page_key_rx], 0);
132 if (++page_key_rx >= PAGE_KEY_DATA_SIZE)
134 page_key_rp = page_key_rp->next;
138 int pfn_is_nosave(unsigned long pfn)
140 unsigned long nosave_begin_pfn = PFN_DOWN(__pa(&__nosave_begin));
141 unsigned long nosave_end_pfn = PFN_DOWN(__pa(&__nosave_end));
142 unsigned long eshared_pfn = PFN_DOWN(__pa(&_eshared)) - 1;
143 unsigned long stext_pfn = PFN_DOWN(__pa(&_stext));
145 /* Always save lowcore pages (LC protection might be enabled). */
148 if (pfn >= nosave_begin_pfn && pfn < nosave_end_pfn)
150 /* Skip memory holes and read-only pages (NSS, DCSS, ...). */
151 if (pfn >= stext_pfn && pfn <= eshared_pfn)
152 return ipl_info.type == IPL_TYPE_NSS ? 1 : 0;
153 if (tprot(PFN_PHYS(pfn)))
158 void save_processor_state(void)
160 /* swsusp_arch_suspend() actually saves all cpu register contents.
161 * Machine checks must be disabled since swsusp_arch_suspend() stores
162 * register contents to their lowcore save areas. That's the same
163 * place where register contents on machine checks would be saved.
164 * To avoid register corruption disable machine checks.
165 * We must also disable machine checks in the new psw mask for
166 * program checks, since swsusp_arch_suspend() may generate program
167 * checks. Disabling machine checks for all other new psw masks is
170 local_mcck_disable();
171 /* Disable lowcore protection */
172 __ctl_clear_bit(0,28);
173 S390_lowcore.external_new_psw.mask &= ~PSW_MASK_MCHECK;
174 S390_lowcore.svc_new_psw.mask &= ~PSW_MASK_MCHECK;
175 S390_lowcore.io_new_psw.mask &= ~PSW_MASK_MCHECK;
176 S390_lowcore.program_new_psw.mask &= ~PSW_MASK_MCHECK;
179 void restore_processor_state(void)
181 S390_lowcore.external_new_psw.mask |= PSW_MASK_MCHECK;
182 S390_lowcore.svc_new_psw.mask |= PSW_MASK_MCHECK;
183 S390_lowcore.io_new_psw.mask |= PSW_MASK_MCHECK;
184 S390_lowcore.program_new_psw.mask |= PSW_MASK_MCHECK;
185 /* Enable lowcore protection */