diff options
-rw-r--r-- | arch/i386/kernel/setup.c | 106 | ||||
-rw-r--r-- | arch/x86_64/kernel/setup.c | 95 | ||||
-rw-r--r-- | include/linux/suspend.h | 1 | ||||
-rw-r--r-- | kernel/power/power.h | 4 | ||||
-rw-r--r-- | kernel/power/snapshot.c | 112 | ||||
-rw-r--r-- | kernel/power/swsusp.c | 18 |
6 files changed, 18 insertions, 318 deletions
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c index 6c1639836e06..6bef9273733e 100644 --- a/arch/i386/kernel/setup.c +++ b/arch/i386/kernel/setup.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #include <linux/crash_dump.h> | 48 | #include <linux/crash_dump.h> |
49 | #include <linux/dmi.h> | 49 | #include <linux/dmi.h> |
50 | #include <linux/pfn.h> | 50 | #include <linux/pfn.h> |
51 | #include <linux/suspend.h> | ||
52 | 51 | ||
53 | #include <video/edid.h> | 52 | #include <video/edid.h> |
54 | 53 | ||
@@ -1427,111 +1426,6 @@ static void set_mca_bus(int x) | |||
1427 | static void set_mca_bus(int x) { } | 1426 | static void set_mca_bus(int x) { } |
1428 | #endif | 1427 | #endif |
1429 | 1428 | ||
1430 | #ifdef CONFIG_SOFTWARE_SUSPEND | ||
1431 | static void __init mark_nosave_page_range(unsigned long start, unsigned long end) | ||
1432 | { | ||
1433 | struct page *page; | ||
1434 | while (start <= end) { | ||
1435 | page = pfn_to_page(start); | ||
1436 | SetPageNosave(page); | ||
1437 | start++; | ||
1438 | } | ||
1439 | } | ||
1440 | |||
1441 | static void __init e820_nosave_reserved_pages(void) | ||
1442 | { | ||
1443 | int i; | ||
1444 | unsigned long r_start = 0, r_end = 0; | ||
1445 | |||
1446 | /* Assume e820 map is sorted */ | ||
1447 | for (i = 0; i < e820.nr_map; i++) { | ||
1448 | struct e820entry *ei = &e820.map[i]; | ||
1449 | unsigned long start, end; | ||
1450 | |||
1451 | start = PFN_DOWN(ei->addr); | ||
1452 | end = PFN_UP(ei->addr + ei->size); | ||
1453 | if (start >= end) | ||
1454 | continue; | ||
1455 | if (ei->type == E820_RESERVED) | ||
1456 | continue; | ||
1457 | r_end = start; | ||
1458 | /* | ||
1459 | * Highmem 'Reserved' pages are marked as reserved, swsusp | ||
1460 | * will not save/restore them, so we ignore these pages here. | ||
1461 | */ | ||
1462 | if (r_end > max_low_pfn) | ||
1463 | r_end = max_low_pfn; | ||
1464 | if (r_end > r_start) | ||
1465 | mark_nosave_page_range(r_start, r_end-1); | ||
1466 | if (r_end >= max_low_pfn) | ||
1467 | break; | ||
1468 | r_start = end; | ||
1469 | } | ||
1470 | } | ||
1471 | |||
1472 | static void __init e820_save_acpi_pages(void) | ||
1473 | { | ||
1474 | int i; | ||
1475 | |||
1476 | /* Assume e820 map is sorted */ | ||
1477 | for (i = 0; i < e820.nr_map; i++) { | ||
1478 | struct e820entry *ei = &e820.map[i]; | ||
1479 | unsigned long start, end; | ||
1480 | |||
1481 | start = ei->addr; | ||
1482 | end = ei->addr + ei->size; | ||
1483 | if (start >= end) | ||
1484 | continue; | ||
1485 | if (ei->type != E820_ACPI && ei->type != E820_NVS) | ||
1486 | continue; | ||
1487 | /* | ||
1488 | * If the region is below max_low_pfn, it will be | ||
1489 | * saved/restored by swsusp follow 'RAM' type. | ||
1490 | */ | ||
1491 | if (start < (max_low_pfn << PAGE_SHIFT)) | ||
1492 | start = max_low_pfn << PAGE_SHIFT; | ||
1493 | /* | ||
1494 | * Highmem pages (ACPI NVS/Data) are reserved, but swsusp | ||
1495 | * highmem save/restore will not save/restore them. We marked | ||
1496 | * them as arch saveable pages here | ||
1497 | */ | ||
1498 | if (end > start) | ||
1499 | swsusp_add_arch_pages(start, end); | ||
1500 | } | ||
1501 | } | ||
1502 | |||
1503 | extern char __start_rodata, __end_rodata; | ||
1504 | /* | ||
1505 | * BIOS reserved region/hole - no save/restore | ||
1506 | * ACPI NVS - save/restore | ||
1507 | * ACPI Data - this is a little tricky, the mem could be used by OS after OS | ||
1508 | * reads tables from the region, but anyway save/restore the memory hasn't any | ||
1509 | * side effect and Linux runtime module load/unload might use it. | ||
1510 | * kernel rodata - no save/restore (kernel rodata isn't changed) | ||
1511 | */ | ||
1512 | static int __init mark_nosave_pages(void) | ||
1513 | { | ||
1514 | unsigned long pfn_start, pfn_end; | ||
1515 | |||
1516 | /* FIXME: provide a version for efi BIOS */ | ||
1517 | if (efi_enabled) | ||
1518 | return 0; | ||
1519 | /* BIOS reserved regions & holes */ | ||
1520 | e820_nosave_reserved_pages(); | ||
1521 | |||
1522 | /* kernel rodata */ | ||
1523 | pfn_start = PFN_UP(virt_to_phys(&__start_rodata)); | ||
1524 | pfn_end = PFN_DOWN(virt_to_phys(&__end_rodata)); | ||
1525 | mark_nosave_page_range(pfn_start, pfn_end-1); | ||
1526 | |||
1527 | /* record ACPI Data/NVS as saveable */ | ||
1528 | e820_save_acpi_pages(); | ||
1529 | |||
1530 | return 0; | ||
1531 | } | ||
1532 | core_initcall(mark_nosave_pages); | ||
1533 | #endif | ||
1534 | |||
1535 | /* | 1429 | /* |
1536 | * Determine if we were loaded by an EFI loader. If so, then we have also been | 1430 | * Determine if we were loaded by an EFI loader. If so, then we have also been |
1537 | * passed the efi memmap, systab, etc., so we should use these data structures | 1431 | * passed the efi memmap, systab, etc., so we should use these data structures |
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c index fdb82658b1a1..fb850b52b4da 100644 --- a/arch/x86_64/kernel/setup.c +++ b/arch/x86_64/kernel/setup.c | |||
@@ -47,7 +47,6 @@ | |||
47 | #include <linux/dmi.h> | 47 | #include <linux/dmi.h> |
48 | #include <linux/dma-mapping.h> | 48 | #include <linux/dma-mapping.h> |
49 | #include <linux/ctype.h> | 49 | #include <linux/ctype.h> |
50 | #include <linux/suspend.h> | ||
51 | 50 | ||
52 | #include <asm/mtrr.h> | 51 | #include <asm/mtrr.h> |
53 | #include <asm/uaccess.h> | 52 | #include <asm/uaccess.h> |
@@ -596,100 +595,6 @@ static void discover_ebda(void) | |||
596 | ebda_size = 64*1024; | 595 | ebda_size = 64*1024; |
597 | } | 596 | } |
598 | 597 | ||
599 | #ifdef CONFIG_SOFTWARE_SUSPEND | ||
600 | static void __init mark_nosave_page_range(unsigned long start, unsigned long end) | ||
601 | { | ||
602 | struct page *page; | ||
603 | while (start <= end) { | ||
604 | page = pfn_to_page(start); | ||
605 | SetPageNosave(page); | ||
606 | start++; | ||
607 | } | ||
608 | } | ||
609 | |||
610 | static void __init e820_nosave_reserved_pages(void) | ||
611 | { | ||
612 | int i; | ||
613 | unsigned long r_start = 0, r_end = 0; | ||
614 | |||
615 | /* Assume e820 map is sorted */ | ||
616 | for (i = 0; i < e820.nr_map; i++) { | ||
617 | struct e820entry *ei = &e820.map[i]; | ||
618 | unsigned long start, end; | ||
619 | |||
620 | start = round_down(ei->addr, PAGE_SIZE); | ||
621 | end = round_up(ei->addr + ei->size, PAGE_SIZE); | ||
622 | if (start >= end) | ||
623 | continue; | ||
624 | if (ei->type == E820_RESERVED) | ||
625 | continue; | ||
626 | r_end = start>>PAGE_SHIFT; | ||
627 | /* swsusp ignores invalid pfn, ignore these pages here */ | ||
628 | if (r_end > end_pfn) | ||
629 | r_end = end_pfn; | ||
630 | if (r_end > r_start) | ||
631 | mark_nosave_page_range(r_start, r_end-1); | ||
632 | if (r_end >= end_pfn) | ||
633 | break; | ||
634 | r_start = end>>PAGE_SHIFT; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | static void __init e820_save_acpi_pages(void) | ||
639 | { | ||
640 | int i; | ||
641 | |||
642 | /* Assume e820 map is sorted */ | ||
643 | for (i = 0; i < e820.nr_map; i++) { | ||
644 | struct e820entry *ei = &e820.map[i]; | ||
645 | unsigned long start, end; | ||
646 | |||
647 | start = ei->addr, PAGE_SIZE; | ||
648 | end = ei->addr + ei->size; | ||
649 | if (start >= end) | ||
650 | continue; | ||
651 | if (ei->type != E820_ACPI && ei->type != E820_NVS) | ||
652 | continue; | ||
653 | /* | ||
654 | * If the region is below end_pfn, it will be | ||
655 | * saved/restored by swsusp follow 'RAM' type. | ||
656 | */ | ||
657 | if (start < (end_pfn << PAGE_SHIFT)) | ||
658 | start = end_pfn << PAGE_SHIFT; | ||
659 | if (end > start) | ||
660 | swsusp_add_arch_pages(start, end); | ||
661 | } | ||
662 | } | ||
663 | |||
664 | extern char __start_rodata, __end_rodata; | ||
665 | /* | ||
666 | * BIOS reserved region/hole - no save/restore | ||
667 | * ACPI NVS - save/restore | ||
668 | * ACPI Data - this is a little tricky, the mem could be used by OS after OS | ||
669 | * reads tables from the region, but anyway save/restore the memory hasn't any | ||
670 | * side effect and Linux runtime module load/unload might use it. | ||
671 | * kernel rodata - no save/restore (kernel rodata isn't changed) | ||
672 | */ | ||
673 | static int __init mark_nosave_pages(void) | ||
674 | { | ||
675 | unsigned long pfn_start, pfn_end; | ||
676 | |||
677 | /* BIOS reserved regions & holes */ | ||
678 | e820_nosave_reserved_pages(); | ||
679 | |||
680 | /* kernel rodata */ | ||
681 | pfn_start = round_up(__pa_symbol(&__start_rodata), PAGE_SIZE) >> PAGE_SHIFT; | ||
682 | pfn_end = round_down(__pa_symbol(&__end_rodata), PAGE_SIZE) >> PAGE_SHIFT; | ||
683 | mark_nosave_page_range(pfn_start, pfn_end-1); | ||
684 | |||
685 | /* record ACPI Data/NVS as saveable */ | ||
686 | e820_save_acpi_pages(); | ||
687 | |||
688 | return 0; | ||
689 | } | ||
690 | core_initcall(mark_nosave_pages); | ||
691 | #endif | ||
692 | |||
693 | void __init setup_arch(char **cmdline_p) | 598 | void __init setup_arch(char **cmdline_p) |
694 | { | 599 | { |
695 | unsigned long kernel_end; | 600 | unsigned long kernel_end; |
diff --git a/include/linux/suspend.h b/include/linux/suspend.h index e82cb10fb3ea..96e31aa64cc7 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h | |||
@@ -71,7 +71,6 @@ struct saved_context; | |||
71 | void __save_processor_state(struct saved_context *ctxt); | 71 | void __save_processor_state(struct saved_context *ctxt); |
72 | void __restore_processor_state(struct saved_context *ctxt); | 72 | void __restore_processor_state(struct saved_context *ctxt); |
73 | unsigned long get_safe_page(gfp_t gfp_mask); | 73 | unsigned long get_safe_page(gfp_t gfp_mask); |
74 | int swsusp_add_arch_pages(unsigned long start, unsigned long end); | ||
75 | 74 | ||
76 | /* | 75 | /* |
77 | * XXX: We try to keep some more pages free so that I/O operations succeed | 76 | * XXX: We try to keep some more pages free so that I/O operations succeed |
diff --git a/kernel/power/power.h b/kernel/power/power.h index 98c41423f3b1..57a792982fb9 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h | |||
@@ -105,10 +105,6 @@ 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 | |||
112 | extern int swsusp_check(void); | 108 | extern int swsusp_check(void); |
113 | extern int swsusp_shrink_memory(void); | 109 | extern int swsusp_shrink_memory(void); |
114 | extern void swsusp_free(void); | 110 | extern void swsusp_free(void); |
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 3d9284100b22..24c96f354231 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c | |||
@@ -39,90 +39,8 @@ 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 | |||
124 | #ifdef CONFIG_HIGHMEM | 42 | #ifdef CONFIG_HIGHMEM |
125 | static unsigned int count_highmem_pages(void) | 43 | unsigned int count_highmem_pages(void) |
126 | { | 44 | { |
127 | struct zone *zone; | 45 | struct zone *zone; |
128 | unsigned long zone_pfn; | 46 | unsigned long zone_pfn; |
@@ -199,7 +117,7 @@ static int save_highmem_zone(struct zone *zone) | |||
199 | return 0; | 117 | return 0; |
200 | } | 118 | } |
201 | 119 | ||
202 | static int save_highmem(void) | 120 | int save_highmem(void) |
203 | { | 121 | { |
204 | struct zone *zone; | 122 | struct zone *zone; |
205 | int res = 0; | 123 | int res = 0; |
@@ -216,7 +134,7 @@ static int save_highmem(void) | |||
216 | return 0; | 134 | return 0; |
217 | } | 135 | } |
218 | 136 | ||
219 | static int restore_highmem(void) | 137 | int restore_highmem(void) |
220 | { | 138 | { |
221 | printk("swsusp: Restoring Highmem\n"); | 139 | printk("swsusp: Restoring Highmem\n"); |
222 | while (highmem_copy) { | 140 | while (highmem_copy) { |
@@ -238,29 +156,6 @@ static inline int save_highmem(void) {return 0;} | |||
238 | static inline int restore_highmem(void) {return 0;} | 156 | static inline int restore_highmem(void) {return 0;} |
239 | #endif | 157 | #endif |
240 | 158 | ||
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 | |||
264 | static int pfn_is_nosave(unsigned long pfn) | 159 | static int pfn_is_nosave(unsigned long pfn) |
265 | { | 160 | { |
266 | unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT; | 161 | unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT; |
@@ -286,6 +181,7 @@ static int saveable(struct zone *zone, unsigned long *zone_pfn) | |||
286 | return 0; | 181 | return 0; |
287 | 182 | ||
288 | page = pfn_to_page(pfn); | 183 | page = pfn_to_page(pfn); |
184 | BUG_ON(PageReserved(page) && PageNosave(page)); | ||
289 | if (PageNosave(page)) | 185 | if (PageNosave(page)) |
290 | return 0; | 186 | return 0; |
291 | if (PageReserved(page) && pfn_is_nosave(pfn)) | 187 | if (PageReserved(page) && pfn_is_nosave(pfn)) |
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c index f0ee4e7780d6..17f669c83012 100644 --- a/kernel/power/swsusp.c +++ b/kernel/power/swsusp.c | |||
@@ -62,6 +62,16 @@ 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 inline int save_highmem(void) { return 0; } | ||
71 | static inline int restore_highmem(void) { return 0; } | ||
72 | static inline unsigned int count_highmem_pages(void) { return 0; } | ||
73 | #endif | ||
74 | |||
65 | /** | 75 | /** |
66 | * The following functions are used for tracing the allocated | 76 | * The following functions are used for tracing the allocated |
67 | * swap pages, so that they can be freed in case of an error. | 77 | * swap pages, so that they can be freed in case of an error. |
@@ -182,7 +192,7 @@ int swsusp_shrink_memory(void) | |||
182 | 192 | ||
183 | printk("Shrinking memory... "); | 193 | printk("Shrinking memory... "); |
184 | do { | 194 | do { |
185 | size = 2 * count_special_pages(); | 195 | size = 2 * count_highmem_pages(); |
186 | size += size / 50 + count_data_pages(); | 196 | size += size / 50 + count_data_pages(); |
187 | size += (size + PBES_PER_PAGE - 1) / PBES_PER_PAGE + | 197 | size += (size + PBES_PER_PAGE - 1) / PBES_PER_PAGE + |
188 | PAGES_FOR_IO; | 198 | PAGES_FOR_IO; |
@@ -226,7 +236,7 @@ int swsusp_suspend(void) | |||
226 | goto Enable_irqs; | 236 | goto Enable_irqs; |
227 | } | 237 | } |
228 | 238 | ||
229 | if ((error = save_special_mem())) { | 239 | if ((error = save_highmem())) { |
230 | printk(KERN_ERR "swsusp: Not enough free pages for highmem\n"); | 240 | printk(KERN_ERR "swsusp: Not enough free pages for highmem\n"); |
231 | goto Restore_highmem; | 241 | goto Restore_highmem; |
232 | } | 242 | } |
@@ -237,7 +247,7 @@ int swsusp_suspend(void) | |||
237 | /* Restore control flow magically appears here */ | 247 | /* Restore control flow magically appears here */ |
238 | restore_processor_state(); | 248 | restore_processor_state(); |
239 | Restore_highmem: | 249 | Restore_highmem: |
240 | restore_special_mem(); | 250 | restore_highmem(); |
241 | device_power_up(); | 251 | device_power_up(); |
242 | Enable_irqs: | 252 | Enable_irqs: |
243 | local_irq_enable(); | 253 | local_irq_enable(); |
@@ -263,7 +273,7 @@ int swsusp_resume(void) | |||
263 | */ | 273 | */ |
264 | swsusp_free(); | 274 | swsusp_free(); |
265 | restore_processor_state(); | 275 | restore_processor_state(); |
266 | restore_special_mem(); | 276 | restore_highmem(); |
267 | touch_softlockup_watchdog(); | 277 | touch_softlockup_watchdog(); |
268 | device_power_up(); | 278 | device_power_up(); |
269 | local_irq_enable(); | 279 | local_irq_enable(); |