diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2006-12-06 23:34:29 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-07 11:39:28 -0500 |
commit | 2d4a34c9365c6e3f94a5b26ce296e1fce9b66c8b (patch) | |
tree | ad8303f7db40d963f7a7b120996d4fe658a43cce | |
parent | ff39593ad0ff7a79a3717edac6634407aa8200c2 (diff) |
[PATCH] swsusp: Support i386 systems with PAE or without PSE
Make swsusp support i386 systems with PAE or without PSE.
This is done by creating temporary page tables located in resume-safe page
frames before the suspend image is restored in the same way as x86_64 does
it.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Andi Kleen <ak@suse.de>
Cc: Dave Jones <davej@redhat.com>
Cc: Nigel Cunningham <ncunningham@linuxmail.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/i386/power/Makefile | 2 | ||||
-rw-r--r-- | arch/i386/power/suspend.c | 158 | ||||
-rw-r--r-- | arch/i386/power/swsusp.S | 9 | ||||
-rw-r--r-- | include/asm-i386/suspend.h | 13 | ||||
-rw-r--r-- | kernel/power/Kconfig | 2 |
5 files changed, 168 insertions, 16 deletions
diff --git a/arch/i386/power/Makefile b/arch/i386/power/Makefile index 8cfa4e8a719..2de7bbf03cd 100644 --- a/arch/i386/power/Makefile +++ b/arch/i386/power/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | obj-$(CONFIG_PM) += cpu.o | 1 | obj-$(CONFIG_PM) += cpu.o |
2 | obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o | 2 | obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o suspend.o |
diff --git a/arch/i386/power/suspend.c b/arch/i386/power/suspend.c new file mode 100644 index 00000000000..db5e98d2eb7 --- /dev/null +++ b/arch/i386/power/suspend.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * Suspend support specific for i386 - temporary page tables | ||
3 | * | ||
4 | * Distribute under GPLv2 | ||
5 | * | ||
6 | * Copyright (c) 2006 Rafael J. Wysocki <rjw@sisk.pl> | ||
7 | */ | ||
8 | |||
9 | #include <linux/suspend.h> | ||
10 | #include <linux/bootmem.h> | ||
11 | |||
12 | #include <asm/system.h> | ||
13 | #include <asm/page.h> | ||
14 | #include <asm/pgtable.h> | ||
15 | |||
16 | /* Defined in arch/i386/power/swsusp.S */ | ||
17 | extern int restore_image(void); | ||
18 | |||
19 | /* Pointer to the temporary resume page tables */ | ||
20 | pgd_t *resume_pg_dir; | ||
21 | |||
22 | /* The following three functions are based on the analogous code in | ||
23 | * arch/i386/mm/init.c | ||
24 | */ | ||
25 | |||
26 | /* | ||
27 | * Create a middle page table on a resume-safe page and put a pointer to it in | ||
28 | * the given global directory entry. This only returns the gd entry | ||
29 | * in non-PAE compilation mode, since the middle layer is folded. | ||
30 | */ | ||
31 | static pmd_t *resume_one_md_table_init(pgd_t *pgd) | ||
32 | { | ||
33 | pud_t *pud; | ||
34 | pmd_t *pmd_table; | ||
35 | |||
36 | #ifdef CONFIG_X86_PAE | ||
37 | pmd_table = (pmd_t *)get_safe_page(GFP_ATOMIC); | ||
38 | if (!pmd_table) | ||
39 | return NULL; | ||
40 | |||
41 | set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT)); | ||
42 | pud = pud_offset(pgd, 0); | ||
43 | |||
44 | BUG_ON(pmd_table != pmd_offset(pud, 0)); | ||
45 | #else | ||
46 | pud = pud_offset(pgd, 0); | ||
47 | pmd_table = pmd_offset(pud, 0); | ||
48 | #endif | ||
49 | |||
50 | return pmd_table; | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | * Create a page table on a resume-safe page and place a pointer to it in | ||
55 | * a middle page directory entry. | ||
56 | */ | ||
57 | static pte_t *resume_one_page_table_init(pmd_t *pmd) | ||
58 | { | ||
59 | if (pmd_none(*pmd)) { | ||
60 | pte_t *page_table = (pte_t *)get_safe_page(GFP_ATOMIC); | ||
61 | if (!page_table) | ||
62 | return NULL; | ||
63 | |||
64 | set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE)); | ||
65 | |||
66 | BUG_ON(page_table != pte_offset_kernel(pmd, 0)); | ||
67 | |||
68 | return page_table; | ||
69 | } | ||
70 | |||
71 | return pte_offset_kernel(pmd, 0); | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * This maps the physical memory to kernel virtual address space, a total | ||
76 | * of max_low_pfn pages, by creating page tables starting from address | ||
77 | * PAGE_OFFSET. The page tables are allocated out of resume-safe pages. | ||
78 | */ | ||
79 | static int resume_physical_mapping_init(pgd_t *pgd_base) | ||
80 | { | ||
81 | unsigned long pfn; | ||
82 | pgd_t *pgd; | ||
83 | pmd_t *pmd; | ||
84 | pte_t *pte; | ||
85 | int pgd_idx, pmd_idx; | ||
86 | |||
87 | pgd_idx = pgd_index(PAGE_OFFSET); | ||
88 | pgd = pgd_base + pgd_idx; | ||
89 | pfn = 0; | ||
90 | |||
91 | for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) { | ||
92 | pmd = resume_one_md_table_init(pgd); | ||
93 | if (!pmd) | ||
94 | return -ENOMEM; | ||
95 | |||
96 | if (pfn >= max_low_pfn) | ||
97 | continue; | ||
98 | |||
99 | for (pmd_idx = 0; pmd_idx < PTRS_PER_PMD; pmd++, pmd_idx++) { | ||
100 | if (pfn >= max_low_pfn) | ||
101 | break; | ||
102 | |||
103 | /* Map with big pages if possible, otherwise create | ||
104 | * normal page tables. | ||
105 | * NOTE: We can mark everything as executable here | ||
106 | */ | ||
107 | if (cpu_has_pse) { | ||
108 | set_pmd(pmd, pfn_pmd(pfn, PAGE_KERNEL_LARGE_EXEC)); | ||
109 | pfn += PTRS_PER_PTE; | ||
110 | } else { | ||
111 | pte_t *max_pte; | ||
112 | |||
113 | pte = resume_one_page_table_init(pmd); | ||
114 | if (!pte) | ||
115 | return -ENOMEM; | ||
116 | |||
117 | max_pte = pte + PTRS_PER_PTE; | ||
118 | for (; pte < max_pte; pte++, pfn++) { | ||
119 | if (pfn >= max_low_pfn) | ||
120 | break; | ||
121 | |||
122 | set_pte(pte, pfn_pte(pfn, PAGE_KERNEL_EXEC)); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static inline void resume_init_first_level_page_table(pgd_t *pg_dir) | ||
131 | { | ||
132 | #ifdef CONFIG_X86_PAE | ||
133 | int i; | ||
134 | |||
135 | /* Init entries of the first-level page table to the zero page */ | ||
136 | for (i = 0; i < PTRS_PER_PGD; i++) | ||
137 | set_pgd(pg_dir + i, | ||
138 | __pgd(__pa(empty_zero_page) | _PAGE_PRESENT)); | ||
139 | #endif | ||
140 | } | ||
141 | |||
142 | int swsusp_arch_resume(void) | ||
143 | { | ||
144 | int error; | ||
145 | |||
146 | resume_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC); | ||
147 | if (!resume_pg_dir) | ||
148 | return -ENOMEM; | ||
149 | |||
150 | resume_init_first_level_page_table(resume_pg_dir); | ||
151 | error = resume_physical_mapping_init(resume_pg_dir); | ||
152 | if (error) | ||
153 | return error; | ||
154 | |||
155 | /* We have got enough memory and from now on we cannot recover */ | ||
156 | restore_image(); | ||
157 | return 0; | ||
158 | } | ||
diff --git a/arch/i386/power/swsusp.S b/arch/i386/power/swsusp.S index 8a2b50a0aaa..53662e05b39 100644 --- a/arch/i386/power/swsusp.S +++ b/arch/i386/power/swsusp.S | |||
@@ -28,8 +28,9 @@ ENTRY(swsusp_arch_suspend) | |||
28 | call swsusp_save | 28 | call swsusp_save |
29 | ret | 29 | ret |
30 | 30 | ||
31 | ENTRY(swsusp_arch_resume) | 31 | ENTRY(restore_image) |
32 | movl $swsusp_pg_dir-__PAGE_OFFSET, %ecx | 32 | movl resume_pg_dir, %ecx |
33 | subl $__PAGE_OFFSET, %ecx | ||
33 | movl %ecx, %cr3 | 34 | movl %ecx, %cr3 |
34 | 35 | ||
35 | movl restore_pblist, %edx | 36 | movl restore_pblist, %edx |
@@ -51,6 +52,10 @@ copy_loop: | |||
51 | .p2align 4,,7 | 52 | .p2align 4,,7 |
52 | 53 | ||
53 | done: | 54 | done: |
55 | /* go back to the original page tables */ | ||
56 | movl $swapper_pg_dir, %ecx | ||
57 | subl $__PAGE_OFFSET, %ecx | ||
58 | movl %ecx, %cr3 | ||
54 | /* Flush TLB, including "global" things (vmalloc) */ | 59 | /* Flush TLB, including "global" things (vmalloc) */ |
55 | movl mmu_cr4_features, %eax | 60 | movl mmu_cr4_features, %eax |
56 | movl %eax, %edx | 61 | movl %eax, %edx |
diff --git a/include/asm-i386/suspend.h b/include/asm-i386/suspend.h index 08be1e5009d..c1da5caafaf 100644 --- a/include/asm-i386/suspend.h +++ b/include/asm-i386/suspend.h | |||
@@ -6,18 +6,7 @@ | |||
6 | #include <asm/desc.h> | 6 | #include <asm/desc.h> |
7 | #include <asm/i387.h> | 7 | #include <asm/i387.h> |
8 | 8 | ||
9 | static inline int | 9 | static inline int arch_prepare_suspend(void) { return 0; } |
10 | arch_prepare_suspend(void) | ||
11 | { | ||
12 | /* If you want to make non-PSE machine work, turn off paging | ||
13 | in swsusp_arch_suspend. swsusp_pg_dir should have identity mapping, so | ||
14 | it could work... */ | ||
15 | if (!cpu_has_pse) { | ||
16 | printk(KERN_ERR "PSE is required for swsusp.\n"); | ||
17 | return -EPERM; | ||
18 | } | ||
19 | return 0; | ||
20 | } | ||
21 | 10 | ||
22 | /* image of the saved processor state */ | 11 | /* image of the saved processor state */ |
23 | struct saved_context { | 12 | struct saved_context { |
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 825068ca347..710ed084e7c 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig | |||
@@ -78,7 +78,7 @@ config PM_SYSFS_DEPRECATED | |||
78 | 78 | ||
79 | config SOFTWARE_SUSPEND | 79 | config SOFTWARE_SUSPEND |
80 | bool "Software Suspend" | 80 | bool "Software Suspend" |
81 | depends on PM && SWAP && ((X86 && (!SMP || SUSPEND_SMP) && !X86_PAE) || ((FRV || PPC32) && !SMP)) | 81 | depends on PM && SWAP && ((X86 && (!SMP || SUSPEND_SMP)) || ((FRV || PPC32) && !SMP)) |
82 | ---help--- | 82 | ---help--- |
83 | Enable the possibility of suspending the machine. | 83 | Enable the possibility of suspending the machine. |
84 | It doesn't need ACPI or APM. | 84 | It doesn't need ACPI or APM. |