diff options
author | Shaohua Li <shaohua.li@intel.com> | 2006-06-23 05:04:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-23 10:42:59 -0400 |
commit | 3e3318dee0878d42ed62a19c292a2ac284135db3 (patch) | |
tree | ad1656ed3ec0fc71012a14af087fd7fbb4fb601c | |
parent | b6370d96e09944c6e3ae8d5743ca8a8ab1f79f6c (diff) |
[PATCH] swsusp: x86_64 mark special saveable/unsaveable pages
Pages (Reserved/ACPI NVS/ACPI Data) below end_pfn will be saved/restored by S4
currently. We should mark 'Reserved' pages not saveable.
Pages (Reserved/ACPI NVS/ACPI Data) above end_pfn will not be saved/restored
by S4 currently. We should save the 'ACPI NVS/ACPI Data' 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>
-rw-r--r-- | arch/x86_64/kernel/setup.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c index 655b9192eeb3..b8d5116d7371 100644 --- a/arch/x86_64/kernel/setup.c +++ b/arch/x86_64/kernel/setup.c | |||
@@ -47,6 +47,7 @@ | |||
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> | ||
50 | 51 | ||
51 | #include <asm/mtrr.h> | 52 | #include <asm/mtrr.h> |
52 | #include <asm/uaccess.h> | 53 | #include <asm/uaccess.h> |
@@ -595,6 +596,100 @@ static void discover_ebda(void) | |||
595 | ebda_size = 64*1024; | 596 | ebda_size = 64*1024; |
596 | } | 597 | } |
597 | 598 | ||
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 | |||
598 | void __init setup_arch(char **cmdline_p) | 693 | void __init setup_arch(char **cmdline_p) |
599 | { | 694 | { |
600 | unsigned long kernel_end; | 695 | unsigned long kernel_end; |