diff options
author | Shaohua Li <shaohua.li@intel.com> | 2006-06-23 05:04:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-23 10:42:59 -0400 |
commit | ce4ab0012b32c1a4a1d6e934aeb73bf3151c48d9 (patch) | |
tree | 83b5ba44e93eeb8b72fe14028ac25943f77844fe /kernel/power | |
parent | 82dcaafc92fdfbe2c1d6c50b9f5e17d533caf950 (diff) |
[PATCH] swsusp: add architecture special saveable pages support
1. Add architecture specific pages save/restore support. Next two patches
will use this to save/restore 'ACPI NVS' pages.
2. Allow reserved pages 'nosave'. This could avoid save/restore BIOS
reserved pages.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@suspend2.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/power')
-rw-r--r-- | kernel/power/power.h | 4 | ||||
-rw-r--r-- | kernel/power/snapshot.c | 110 | ||||
-rw-r--r-- | kernel/power/swsusp.c | 18 |
3 files changed, 117 insertions, 15 deletions
diff --git a/kernel/power/power.h b/kernel/power/power.h index f06f12f21767..c81f0ed3eeba 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h | |||
@@ -105,6 +105,10 @@ extern struct bitmap_page *alloc_bitmap(unsigned int nr_bits); | |||
105 | extern unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap); | 105 | extern unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap); |
106 | extern void free_all_swap_pages(int swap, struct bitmap_page *bitmap); | 106 | extern void free_all_swap_pages(int swap, struct bitmap_page *bitmap); |
107 | 107 | ||
108 | extern unsigned int count_special_pages(void); | ||
109 | extern int save_special_mem(void); | ||
110 | extern int restore_special_mem(void); | ||
111 | |||
108 | extern int swsusp_check(void); | 112 | extern int swsusp_check(void); |
109 | extern int swsusp_shrink_memory(void); | 113 | extern int swsusp_shrink_memory(void); |
110 | extern void swsusp_free(void); | 114 | extern void swsusp_free(void); |
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 3eeedbb13b78..7f511d89c667 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c | |||
@@ -39,6 +39,88 @@ static unsigned int nr_copy_pages; | |||
39 | static unsigned int nr_meta_pages; | 39 | static unsigned int nr_meta_pages; |
40 | static unsigned long *buffer; | 40 | static unsigned long *buffer; |
41 | 41 | ||
42 | struct arch_saveable_page { | ||
43 | unsigned long start; | ||
44 | unsigned long end; | ||
45 | char *data; | ||
46 | struct arch_saveable_page *next; | ||
47 | }; | ||
48 | static struct arch_saveable_page *arch_pages; | ||
49 | |||
50 | int swsusp_add_arch_pages(unsigned long start, unsigned long end) | ||
51 | { | ||
52 | struct arch_saveable_page *tmp; | ||
53 | |||
54 | while (start < end) { | ||
55 | tmp = kzalloc(sizeof(struct arch_saveable_page), GFP_KERNEL); | ||
56 | if (!tmp) | ||
57 | return -ENOMEM; | ||
58 | tmp->start = start; | ||
59 | tmp->end = ((start >> PAGE_SHIFT) + 1) << PAGE_SHIFT; | ||
60 | if (tmp->end > end) | ||
61 | tmp->end = end; | ||
62 | tmp->next = arch_pages; | ||
63 | start = tmp->end; | ||
64 | arch_pages = tmp; | ||
65 | } | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static unsigned int count_arch_pages(void) | ||
70 | { | ||
71 | unsigned int count = 0; | ||
72 | struct arch_saveable_page *tmp = arch_pages; | ||
73 | while (tmp) { | ||
74 | count++; | ||
75 | tmp = tmp->next; | ||
76 | } | ||
77 | return count; | ||
78 | } | ||
79 | |||
80 | static int save_arch_mem(void) | ||
81 | { | ||
82 | char *kaddr; | ||
83 | struct arch_saveable_page *tmp = arch_pages; | ||
84 | int offset; | ||
85 | |||
86 | pr_debug("swsusp: Saving arch specific memory"); | ||
87 | while (tmp) { | ||
88 | tmp->data = (char *)__get_free_page(GFP_ATOMIC); | ||
89 | if (!tmp->data) | ||
90 | return -ENOMEM; | ||
91 | offset = tmp->start - (tmp->start & PAGE_MASK); | ||
92 | /* arch pages might haven't a 'struct page' */ | ||
93 | kaddr = kmap_atomic_pfn(tmp->start >> PAGE_SHIFT, KM_USER0); | ||
94 | memcpy(tmp->data + offset, kaddr + offset, | ||
95 | tmp->end - tmp->start); | ||
96 | kunmap_atomic(kaddr, KM_USER0); | ||
97 | |||
98 | tmp = tmp->next; | ||
99 | } | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | static int restore_arch_mem(void) | ||
104 | { | ||
105 | char *kaddr; | ||
106 | struct arch_saveable_page *tmp = arch_pages; | ||
107 | int offset; | ||
108 | |||
109 | while (tmp) { | ||
110 | if (!tmp->data) | ||
111 | continue; | ||
112 | offset = tmp->start - (tmp->start & PAGE_MASK); | ||
113 | kaddr = kmap_atomic_pfn(tmp->start >> PAGE_SHIFT, KM_USER0); | ||
114 | memcpy(kaddr + offset, tmp->data + offset, | ||
115 | tmp->end - tmp->start); | ||
116 | kunmap_atomic(kaddr, KM_USER0); | ||
117 | free_page((long)tmp->data); | ||
118 | tmp->data = NULL; | ||
119 | tmp = tmp->next; | ||
120 | } | ||
121 | return 0; | ||
122 | } | ||
123 | |||
42 | #ifdef CONFIG_HIGHMEM | 124 | #ifdef CONFIG_HIGHMEM |
43 | unsigned int count_highmem_pages(void) | 125 | unsigned int count_highmem_pages(void) |
44 | { | 126 | { |
@@ -150,8 +232,35 @@ int restore_highmem(void) | |||
150 | } | 232 | } |
151 | return 0; | 233 | return 0; |
152 | } | 234 | } |
235 | #else | ||
236 | static unsigned int count_highmem_pages(void) {return 0;} | ||
237 | static int save_highmem(void) {return 0;} | ||
238 | static int restore_highmem(void) {return 0;} | ||
153 | #endif | 239 | #endif |
154 | 240 | ||
241 | unsigned int count_special_pages(void) | ||
242 | { | ||
243 | return count_arch_pages() + count_highmem_pages(); | ||
244 | } | ||
245 | |||
246 | int save_special_mem(void) | ||
247 | { | ||
248 | int ret; | ||
249 | ret = save_arch_mem(); | ||
250 | if (!ret) | ||
251 | ret = save_highmem(); | ||
252 | return ret; | ||
253 | } | ||
254 | |||
255 | int restore_special_mem(void) | ||
256 | { | ||
257 | int ret; | ||
258 | ret = restore_arch_mem(); | ||
259 | if (!ret) | ||
260 | ret = restore_highmem(); | ||
261 | return ret; | ||
262 | } | ||
263 | |||
155 | static int pfn_is_nosave(unsigned long pfn) | 264 | static int pfn_is_nosave(unsigned long pfn) |
156 | { | 265 | { |
157 | unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT; | 266 | unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT; |
@@ -177,7 +286,6 @@ static int saveable(struct zone *zone, unsigned long *zone_pfn) | |||
177 | return 0; | 286 | return 0; |
178 | 287 | ||
179 | page = pfn_to_page(pfn); | 288 | page = pfn_to_page(pfn); |
180 | BUG_ON(PageReserved(page) && PageNosave(page)); | ||
181 | if (PageNosave(page)) | 289 | if (PageNosave(page)) |
182 | return 0; | 290 | return 0; |
183 | if (PageReserved(page) && pfn_is_nosave(pfn)) | 291 | if (PageReserved(page) && pfn_is_nosave(pfn)) |
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c index f9238faf76e4..78b6e71b0813 100644 --- a/kernel/power/swsusp.c +++ b/kernel/power/swsusp.c | |||
@@ -62,16 +62,6 @@ unsigned long image_size = 500 * 1024 * 1024; | |||
62 | 62 | ||
63 | int in_suspend __nosavedata = 0; | 63 | int in_suspend __nosavedata = 0; |
64 | 64 | ||
65 | #ifdef CONFIG_HIGHMEM | ||
66 | unsigned int count_highmem_pages(void); | ||
67 | int save_highmem(void); | ||
68 | int restore_highmem(void); | ||
69 | #else | ||
70 | static int save_highmem(void) { return 0; } | ||
71 | static int restore_highmem(void) { return 0; } | ||
72 | static unsigned int count_highmem_pages(void) { return 0; } | ||
73 | #endif | ||
74 | |||
75 | /** | 65 | /** |
76 | * The following functions are used for tracing the allocated | 66 | * The following functions are used for tracing the allocated |
77 | * swap pages, so that they can be freed in case of an error. | 67 | * swap pages, so that they can be freed in case of an error. |
@@ -192,7 +182,7 @@ int swsusp_shrink_memory(void) | |||
192 | 182 | ||
193 | printk("Shrinking memory... "); | 183 | printk("Shrinking memory... "); |
194 | do { | 184 | do { |
195 | size = 2 * count_highmem_pages(); | 185 | size = 2 * count_special_pages(); |
196 | size += size / 50 + count_data_pages(); | 186 | size += size / 50 + count_data_pages(); |
197 | size += (size + PBES_PER_PAGE - 1) / PBES_PER_PAGE + | 187 | size += (size + PBES_PER_PAGE - 1) / PBES_PER_PAGE + |
198 | PAGES_FOR_IO; | 188 | PAGES_FOR_IO; |
@@ -234,7 +224,7 @@ int swsusp_suspend(void) | |||
234 | goto Enable_irqs; | 224 | goto Enable_irqs; |
235 | } | 225 | } |
236 | 226 | ||
237 | if ((error = save_highmem())) { | 227 | if ((error = save_special_mem())) { |
238 | printk(KERN_ERR "swsusp: Not enough free pages for highmem\n"); | 228 | printk(KERN_ERR "swsusp: Not enough free pages for highmem\n"); |
239 | goto Restore_highmem; | 229 | goto Restore_highmem; |
240 | } | 230 | } |
@@ -245,7 +235,7 @@ int swsusp_suspend(void) | |||
245 | /* Restore control flow magically appears here */ | 235 | /* Restore control flow magically appears here */ |
246 | restore_processor_state(); | 236 | restore_processor_state(); |
247 | Restore_highmem: | 237 | Restore_highmem: |
248 | restore_highmem(); | 238 | restore_special_mem(); |
249 | device_power_up(); | 239 | device_power_up(); |
250 | Enable_irqs: | 240 | Enable_irqs: |
251 | local_irq_enable(); | 241 | local_irq_enable(); |
@@ -271,7 +261,7 @@ int swsusp_resume(void) | |||
271 | */ | 261 | */ |
272 | swsusp_free(); | 262 | swsusp_free(); |
273 | restore_processor_state(); | 263 | restore_processor_state(); |
274 | restore_highmem(); | 264 | restore_special_mem(); |
275 | touch_softlockup_watchdog(); | 265 | touch_softlockup_watchdog(); |
276 | device_power_up(); | 266 | device_power_up(); |
277 | local_irq_enable(); | 267 | local_irq_enable(); |