diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/power/Makefile | 9 | ||||
-rw-r--r-- | arch/x86/power/cpu_64.c (renamed from arch/x86/power/suspend_64.c) | 155 | ||||
-rw-r--r-- | arch/x86/power/hibernate_64.c | 169 |
3 files changed, 171 insertions, 162 deletions
diff --git a/arch/x86/power/Makefile b/arch/x86/power/Makefile index 2c95118e510a..9ff4d5b55ad1 100644 --- a/arch/x86/power/Makefile +++ b/arch/x86/power/Makefile | |||
@@ -1,7 +1,2 @@ | |||
1 | ifeq ($(CONFIG_X86_64),y) | 1 | obj-$(CONFIG_PM_SLEEP) += cpu_$(BITS).o |
2 | obj-$(CONFIG_PM) += suspend_64.o | 2 | obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o |
3 | obj-$(CONFIG_HIBERNATION) += hibernate_asm_64.o | ||
4 | else | ||
5 | obj-$(CONFIG_PM) += cpu_32.o | ||
6 | obj-$(CONFIG_HIBERNATION) += hibernate_32.o hibernate_asm_32.o | ||
7 | endif | ||
diff --git a/arch/x86/power/suspend_64.c b/arch/x86/power/cpu_64.c index d51dbf21d021..66bdfb591fd8 100644 --- a/arch/x86/power/suspend_64.c +++ b/arch/x86/power/cpu_64.c | |||
@@ -15,9 +15,6 @@ | |||
15 | #include <asm/pgtable.h> | 15 | #include <asm/pgtable.h> |
16 | #include <asm/mtrr.h> | 16 | #include <asm/mtrr.h> |
17 | 17 | ||
18 | /* References to section boundaries */ | ||
19 | extern const void __nosave_begin, __nosave_end; | ||
20 | |||
21 | static void fix_processor_context(void); | 18 | static void fix_processor_context(void); |
22 | 19 | ||
23 | struct saved_context saved_context; | 20 | struct saved_context saved_context; |
@@ -167,155 +164,3 @@ static void fix_processor_context(void) | |||
167 | loaddebug(¤t->thread, 7); | 164 | loaddebug(¤t->thread, 7); |
168 | } | 165 | } |
169 | } | 166 | } |
170 | |||
171 | #ifdef CONFIG_HIBERNATION | ||
172 | /* Defined in arch/x86_64/kernel/suspend_asm.S */ | ||
173 | extern int restore_image(void); | ||
174 | |||
175 | /* | ||
176 | * Address to jump to in the last phase of restore in order to get to the image | ||
177 | * kernel's text (this value is passed in the image header). | ||
178 | */ | ||
179 | unsigned long restore_jump_address; | ||
180 | |||
181 | /* | ||
182 | * Value of the cr3 register from before the hibernation (this value is passed | ||
183 | * in the image header). | ||
184 | */ | ||
185 | unsigned long restore_cr3; | ||
186 | |||
187 | pgd_t *temp_level4_pgt; | ||
188 | |||
189 | void *relocated_restore_code; | ||
190 | |||
191 | static int res_phys_pud_init(pud_t *pud, unsigned long address, unsigned long end) | ||
192 | { | ||
193 | long i, j; | ||
194 | |||
195 | i = pud_index(address); | ||
196 | pud = pud + i; | ||
197 | for (; i < PTRS_PER_PUD; pud++, i++) { | ||
198 | unsigned long paddr; | ||
199 | pmd_t *pmd; | ||
200 | |||
201 | paddr = address + i*PUD_SIZE; | ||
202 | if (paddr >= end) | ||
203 | break; | ||
204 | |||
205 | pmd = (pmd_t *)get_safe_page(GFP_ATOMIC); | ||
206 | if (!pmd) | ||
207 | return -ENOMEM; | ||
208 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); | ||
209 | for (j = 0; j < PTRS_PER_PMD; pmd++, j++, paddr += PMD_SIZE) { | ||
210 | unsigned long pe; | ||
211 | |||
212 | if (paddr >= end) | ||
213 | break; | ||
214 | pe = __PAGE_KERNEL_LARGE_EXEC | paddr; | ||
215 | pe &= __supported_pte_mask; | ||
216 | set_pmd(pmd, __pmd(pe)); | ||
217 | } | ||
218 | } | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static int set_up_temporary_mappings(void) | ||
223 | { | ||
224 | unsigned long start, end, next; | ||
225 | int error; | ||
226 | |||
227 | temp_level4_pgt = (pgd_t *)get_safe_page(GFP_ATOMIC); | ||
228 | if (!temp_level4_pgt) | ||
229 | return -ENOMEM; | ||
230 | |||
231 | /* It is safe to reuse the original kernel mapping */ | ||
232 | set_pgd(temp_level4_pgt + pgd_index(__START_KERNEL_map), | ||
233 | init_level4_pgt[pgd_index(__START_KERNEL_map)]); | ||
234 | |||
235 | /* Set up the direct mapping from scratch */ | ||
236 | start = (unsigned long)pfn_to_kaddr(0); | ||
237 | end = (unsigned long)pfn_to_kaddr(end_pfn); | ||
238 | |||
239 | for (; start < end; start = next) { | ||
240 | pud_t *pud = (pud_t *)get_safe_page(GFP_ATOMIC); | ||
241 | if (!pud) | ||
242 | return -ENOMEM; | ||
243 | next = start + PGDIR_SIZE; | ||
244 | if (next > end) | ||
245 | next = end; | ||
246 | if ((error = res_phys_pud_init(pud, __pa(start), __pa(next)))) | ||
247 | return error; | ||
248 | set_pgd(temp_level4_pgt + pgd_index(start), | ||
249 | mk_kernel_pgd(__pa(pud))); | ||
250 | } | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | int swsusp_arch_resume(void) | ||
255 | { | ||
256 | int error; | ||
257 | |||
258 | /* We have got enough memory and from now on we cannot recover */ | ||
259 | if ((error = set_up_temporary_mappings())) | ||
260 | return error; | ||
261 | |||
262 | relocated_restore_code = (void *)get_safe_page(GFP_ATOMIC); | ||
263 | if (!relocated_restore_code) | ||
264 | return -ENOMEM; | ||
265 | memcpy(relocated_restore_code, &core_restore_code, | ||
266 | &restore_registers - &core_restore_code); | ||
267 | |||
268 | restore_image(); | ||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | /* | ||
273 | * pfn_is_nosave - check if given pfn is in the 'nosave' section | ||
274 | */ | ||
275 | |||
276 | int pfn_is_nosave(unsigned long pfn) | ||
277 | { | ||
278 | unsigned long nosave_begin_pfn = __pa_symbol(&__nosave_begin) >> PAGE_SHIFT; | ||
279 | unsigned long nosave_end_pfn = PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT; | ||
280 | return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn); | ||
281 | } | ||
282 | |||
283 | struct restore_data_record { | ||
284 | unsigned long jump_address; | ||
285 | unsigned long cr3; | ||
286 | unsigned long magic; | ||
287 | }; | ||
288 | |||
289 | #define RESTORE_MAGIC 0x0123456789ABCDEFUL | ||
290 | |||
291 | /** | ||
292 | * arch_hibernation_header_save - populate the architecture specific part | ||
293 | * of a hibernation image header | ||
294 | * @addr: address to save the data at | ||
295 | */ | ||
296 | int arch_hibernation_header_save(void *addr, unsigned int max_size) | ||
297 | { | ||
298 | struct restore_data_record *rdr = addr; | ||
299 | |||
300 | if (max_size < sizeof(struct restore_data_record)) | ||
301 | return -EOVERFLOW; | ||
302 | rdr->jump_address = restore_jump_address; | ||
303 | rdr->cr3 = restore_cr3; | ||
304 | rdr->magic = RESTORE_MAGIC; | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * arch_hibernation_header_restore - read the architecture specific data | ||
310 | * from the hibernation image header | ||
311 | * @addr: address to read the data from | ||
312 | */ | ||
313 | int arch_hibernation_header_restore(void *addr) | ||
314 | { | ||
315 | struct restore_data_record *rdr = addr; | ||
316 | |||
317 | restore_jump_address = rdr->jump_address; | ||
318 | restore_cr3 = rdr->cr3; | ||
319 | return (rdr->magic == RESTORE_MAGIC) ? 0 : -EINVAL; | ||
320 | } | ||
321 | #endif /* CONFIG_HIBERNATION */ | ||
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c new file mode 100644 index 000000000000..05f28f0d684a --- /dev/null +++ b/arch/x86/power/hibernate_64.c | |||
@@ -0,0 +1,169 @@ | |||
1 | /* | ||
2 | * Hibernation support for x86-64 | ||
3 | * | ||
4 | * Distribute under GPLv2 | ||
5 | * | ||
6 | * Copyright (c) 2007 Rafael J. Wysocki <rjw@sisk.pl> | ||
7 | * Copyright (c) 2002 Pavel Machek <pavel@suse.cz> | ||
8 | * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org> | ||
9 | */ | ||
10 | |||
11 | #include <linux/smp.h> | ||
12 | #include <linux/suspend.h> | ||
13 | #include <asm/proto.h> | ||
14 | #include <asm/page.h> | ||
15 | #include <asm/pgtable.h> | ||
16 | #include <asm/mtrr.h> | ||
17 | |||
18 | /* References to section boundaries */ | ||
19 | extern const void __nosave_begin, __nosave_end; | ||
20 | |||
21 | /* Defined in arch/x86_64/kernel/suspend_asm.S */ | ||
22 | extern int restore_image(void); | ||
23 | |||
24 | /* | ||
25 | * Address to jump to in the last phase of restore in order to get to the image | ||
26 | * kernel's text (this value is passed in the image header). | ||
27 | */ | ||
28 | unsigned long restore_jump_address; | ||
29 | |||
30 | /* | ||
31 | * Value of the cr3 register from before the hibernation (this value is passed | ||
32 | * in the image header). | ||
33 | */ | ||
34 | unsigned long restore_cr3; | ||
35 | |||
36 | pgd_t *temp_level4_pgt; | ||
37 | |||
38 | void *relocated_restore_code; | ||
39 | |||
40 | static int res_phys_pud_init(pud_t *pud, unsigned long address, unsigned long end) | ||
41 | { | ||
42 | long i, j; | ||
43 | |||
44 | i = pud_index(address); | ||
45 | pud = pud + i; | ||
46 | for (; i < PTRS_PER_PUD; pud++, i++) { | ||
47 | unsigned long paddr; | ||
48 | pmd_t *pmd; | ||
49 | |||
50 | paddr = address + i*PUD_SIZE; | ||
51 | if (paddr >= end) | ||
52 | break; | ||
53 | |||
54 | pmd = (pmd_t *)get_safe_page(GFP_ATOMIC); | ||
55 | if (!pmd) | ||
56 | return -ENOMEM; | ||
57 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); | ||
58 | for (j = 0; j < PTRS_PER_PMD; pmd++, j++, paddr += PMD_SIZE) { | ||
59 | unsigned long pe; | ||
60 | |||
61 | if (paddr >= end) | ||
62 | break; | ||
63 | pe = __PAGE_KERNEL_LARGE_EXEC | paddr; | ||
64 | pe &= __supported_pte_mask; | ||
65 | set_pmd(pmd, __pmd(pe)); | ||
66 | } | ||
67 | } | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static int set_up_temporary_mappings(void) | ||
72 | { | ||
73 | unsigned long start, end, next; | ||
74 | int error; | ||
75 | |||
76 | temp_level4_pgt = (pgd_t *)get_safe_page(GFP_ATOMIC); | ||
77 | if (!temp_level4_pgt) | ||
78 | return -ENOMEM; | ||
79 | |||
80 | /* It is safe to reuse the original kernel mapping */ | ||
81 | set_pgd(temp_level4_pgt + pgd_index(__START_KERNEL_map), | ||
82 | init_level4_pgt[pgd_index(__START_KERNEL_map)]); | ||
83 | |||
84 | /* Set up the direct mapping from scratch */ | ||
85 | start = (unsigned long)pfn_to_kaddr(0); | ||
86 | end = (unsigned long)pfn_to_kaddr(end_pfn); | ||
87 | |||
88 | for (; start < end; start = next) { | ||
89 | pud_t *pud = (pud_t *)get_safe_page(GFP_ATOMIC); | ||
90 | if (!pud) | ||
91 | return -ENOMEM; | ||
92 | next = start + PGDIR_SIZE; | ||
93 | if (next > end) | ||
94 | next = end; | ||
95 | if ((error = res_phys_pud_init(pud, __pa(start), __pa(next)))) | ||
96 | return error; | ||
97 | set_pgd(temp_level4_pgt + pgd_index(start), | ||
98 | mk_kernel_pgd(__pa(pud))); | ||
99 | } | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | int swsusp_arch_resume(void) | ||
104 | { | ||
105 | int error; | ||
106 | |||
107 | /* We have got enough memory and from now on we cannot recover */ | ||
108 | if ((error = set_up_temporary_mappings())) | ||
109 | return error; | ||
110 | |||
111 | relocated_restore_code = (void *)get_safe_page(GFP_ATOMIC); | ||
112 | if (!relocated_restore_code) | ||
113 | return -ENOMEM; | ||
114 | memcpy(relocated_restore_code, &core_restore_code, | ||
115 | &restore_registers - &core_restore_code); | ||
116 | |||
117 | restore_image(); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * pfn_is_nosave - check if given pfn is in the 'nosave' section | ||
123 | */ | ||
124 | |||
125 | int pfn_is_nosave(unsigned long pfn) | ||
126 | { | ||
127 | unsigned long nosave_begin_pfn = __pa_symbol(&__nosave_begin) >> PAGE_SHIFT; | ||
128 | unsigned long nosave_end_pfn = PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT; | ||
129 | return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn); | ||
130 | } | ||
131 | |||
132 | struct restore_data_record { | ||
133 | unsigned long jump_address; | ||
134 | unsigned long cr3; | ||
135 | unsigned long magic; | ||
136 | }; | ||
137 | |||
138 | #define RESTORE_MAGIC 0x0123456789ABCDEFUL | ||
139 | |||
140 | /** | ||
141 | * arch_hibernation_header_save - populate the architecture specific part | ||
142 | * of a hibernation image header | ||
143 | * @addr: address to save the data at | ||
144 | */ | ||
145 | int arch_hibernation_header_save(void *addr, unsigned int max_size) | ||
146 | { | ||
147 | struct restore_data_record *rdr = addr; | ||
148 | |||
149 | if (max_size < sizeof(struct restore_data_record)) | ||
150 | return -EOVERFLOW; | ||
151 | rdr->jump_address = restore_jump_address; | ||
152 | rdr->cr3 = restore_cr3; | ||
153 | rdr->magic = RESTORE_MAGIC; | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | /** | ||
158 | * arch_hibernation_header_restore - read the architecture specific data | ||
159 | * from the hibernation image header | ||
160 | * @addr: address to read the data from | ||
161 | */ | ||
162 | int arch_hibernation_header_restore(void *addr) | ||
163 | { | ||
164 | struct restore_data_record *rdr = addr; | ||
165 | |||
166 | restore_jump_address = rdr->jump_address; | ||
167 | restore_cr3 = rdr->cr3; | ||
168 | return (rdr->magic == RESTORE_MAGIC) ? 0 : -EINVAL; | ||
169 | } | ||