aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/acpi/sleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/acpi/sleep.c')
-rw-r--r--arch/x86/kernel/acpi/sleep.c86
1 files changed, 21 insertions, 65 deletions
diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index 33cec152070d..103b6ab368d3 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -7,45 +7,39 @@
7 7
8#include <linux/acpi.h> 8#include <linux/acpi.h>
9#include <linux/bootmem.h> 9#include <linux/bootmem.h>
10#include <linux/memblock.h>
10#include <linux/dmi.h> 11#include <linux/dmi.h>
11#include <linux/cpumask.h> 12#include <linux/cpumask.h>
12#include <asm/segment.h> 13#include <asm/segment.h>
13#include <asm/desc.h> 14#include <asm/desc.h>
15#include <asm/pgtable.h>
16#include <asm/cacheflush.h>
14 17
15#include "realmode/wakeup.h" 18#include "realmode/wakeup.h"
16#include "sleep.h" 19#include "sleep.h"
17 20
18unsigned long acpi_wakeup_address;
19unsigned long acpi_realmode_flags; 21unsigned long acpi_realmode_flags;
20 22
21/* address in low memory of the wakeup routine. */
22static unsigned long acpi_realmode;
23
24#if defined(CONFIG_SMP) && defined(CONFIG_64BIT) 23#if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
25static char temp_stack[4096]; 24static char temp_stack[4096];
26#endif 25#endif
27 26
28/** 27/**
29 * acpi_save_state_mem - save kernel state 28 * acpi_suspend_lowlevel - save kernel state
30 * 29 *
31 * Create an identity mapped page table and copy the wakeup routine to 30 * Create an identity mapped page table and copy the wakeup routine to
32 * low memory. 31 * low memory.
33 *
34 * Note that this is too late to change acpi_wakeup_address.
35 */ 32 */
36int acpi_save_state_mem(void) 33int acpi_suspend_lowlevel(void)
37{ 34{
38 struct wakeup_header *header; 35 struct wakeup_header *header;
36 /* address in low memory of the wakeup routine. */
37 char *acpi_realmode;
39 38
40 if (!acpi_realmode) { 39 acpi_realmode = TRAMPOLINE_SYM(acpi_wakeup_code);
41 printk(KERN_ERR "Could not allocate memory during boot, "
42 "S3 disabled\n");
43 return -ENOMEM;
44 }
45 memcpy((void *)acpi_realmode, &wakeup_code_start, WAKEUP_SIZE);
46 40
47 header = (struct wakeup_header *)(acpi_realmode + HEADER_OFFSET); 41 header = (struct wakeup_header *)(acpi_realmode + WAKEUP_HEADER_OFFSET);
48 if (header->signature != 0x51ee1111) { 42 if (header->signature != WAKEUP_HEADER_SIGNATURE) {
49 printk(KERN_ERR "wakeup header does not match\n"); 43 printk(KERN_ERR "wakeup header does not match\n");
50 return -EINVAL; 44 return -EINVAL;
51 } 45 }
@@ -65,9 +59,7 @@ int acpi_save_state_mem(void)
65 /* GDT[0]: GDT self-pointer */ 59 /* GDT[0]: GDT self-pointer */
66 header->wakeup_gdt[0] = 60 header->wakeup_gdt[0] =
67 (u64)(sizeof(header->wakeup_gdt) - 1) + 61 (u64)(sizeof(header->wakeup_gdt) - 1) +
68 ((u64)(acpi_wakeup_address + 62 ((u64)__pa(&header->wakeup_gdt) << 16);
69 ((char *)&header->wakeup_gdt - (char *)acpi_realmode))
70 << 16);
71 /* GDT[1]: big real mode-like code segment */ 63 /* GDT[1]: big real mode-like code segment */
72 header->wakeup_gdt[1] = 64 header->wakeup_gdt[1] =
73 GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff); 65 GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff);
@@ -85,17 +77,23 @@ int acpi_save_state_mem(void)
85 77
86 header->pmode_cr0 = read_cr0(); 78 header->pmode_cr0 = read_cr0();
87 header->pmode_cr4 = read_cr4_safe(); 79 header->pmode_cr4 = read_cr4_safe();
80 header->pmode_behavior = 0;
81 if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
82 &header->pmode_misc_en_low,
83 &header->pmode_misc_en_high))
84 header->pmode_behavior |=
85 (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
88 header->realmode_flags = acpi_realmode_flags; 86 header->realmode_flags = acpi_realmode_flags;
89 header->real_magic = 0x12345678; 87 header->real_magic = 0x12345678;
90 88
91#ifndef CONFIG_64BIT 89#ifndef CONFIG_64BIT
92 header->pmode_entry = (u32)&wakeup_pmode_return; 90 header->pmode_entry = (u32)&wakeup_pmode_return;
93 header->pmode_cr3 = (u32)(swsusp_pg_dir - __PAGE_OFFSET); 91 header->pmode_cr3 = (u32)__pa(&initial_page_table);
94 saved_magic = 0x12345678; 92 saved_magic = 0x12345678;
95#else /* CONFIG_64BIT */ 93#else /* CONFIG_64BIT */
96 header->trampoline_segment = setup_trampoline() >> 4; 94 header->trampoline_segment = trampoline_address() >> 4;
97#ifdef CONFIG_SMP 95#ifdef CONFIG_SMP
98 stack_start.sp = temp_stack + sizeof(temp_stack); 96 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
99 early_gdt_descr.address = 97 early_gdt_descr.address =
100 (unsigned long)get_cpu_gdt_table(smp_processor_id()); 98 (unsigned long)get_cpu_gdt_table(smp_processor_id());
101 initial_gs = per_cpu_offset(smp_processor_id()); 99 initial_gs = per_cpu_offset(smp_processor_id());
@@ -104,47 +102,10 @@ int acpi_save_state_mem(void)
104 saved_magic = 0x123456789abcdef0L; 102 saved_magic = 0x123456789abcdef0L;
105#endif /* CONFIG_64BIT */ 103#endif /* CONFIG_64BIT */
106 104
105 do_suspend_lowlevel();
107 return 0; 106 return 0;
108} 107}
109 108
110/*
111 * acpi_restore_state - undo effects of acpi_save_state_mem
112 */
113void acpi_restore_state_mem(void)
114{
115}
116
117
118/**
119 * acpi_reserve_wakeup_memory - do _very_ early ACPI initialisation
120 *
121 * We allocate a page from the first 1MB of memory for the wakeup
122 * routine for when we come back from a sleep state. The
123 * runtime allocator allows specification of <16MB pages, but not
124 * <1MB pages.
125 */
126void __init acpi_reserve_wakeup_memory(void)
127{
128 unsigned long mem;
129
130 if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
131 printk(KERN_ERR
132 "ACPI: Wakeup code way too big, S3 disabled.\n");
133 return;
134 }
135
136 mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
137
138 if (mem == -1L) {
139 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
140 return;
141 }
142 acpi_realmode = (unsigned long) phys_to_virt(mem);
143 acpi_wakeup_address = mem;
144 reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
145}
146
147
148static int __init acpi_sleep_setup(char *str) 109static int __init acpi_sleep_setup(char *str)
149{ 110{
150 while ((str != NULL) && (*str != '\0')) { 111 while ((str != NULL) && (*str != '\0')) {
@@ -157,11 +118,6 @@ static int __init acpi_sleep_setup(char *str)
157#ifdef CONFIG_HIBERNATION 118#ifdef CONFIG_HIBERNATION
158 if (strncmp(str, "s4_nohwsig", 10) == 0) 119 if (strncmp(str, "s4_nohwsig", 10) == 0)
159 acpi_no_s4_hw_signature(); 120 acpi_no_s4_hw_signature();
160 if (strncmp(str, "s4_nonvs", 8) == 0) {
161 pr_warning("ACPI: acpi_sleep=s4_nonvs is deprecated, "
162 "please use acpi_sleep=nonvs instead");
163 acpi_nvs_nosave();
164 }
165#endif 121#endif
166 if (strncmp(str, "nonvs", 5) == 0) 122 if (strncmp(str, "nonvs", 5) == 0)
167 acpi_nvs_nosave(); 123 acpi_nvs_nosave();