Commit | Line | Data |
---|---|---|
4fc2fba8 PM |
1 | /* |
2 | * sleep.c - x86-specific ACPI sleep support. | |
3 | * | |
4 | * Copyright (C) 2001-2003 Patrick Mochel | |
a2531293 | 5 | * Copyright (C) 2001-2003 Pavel Machek <pavel@ucw.cz> |
4fc2fba8 PM |
6 | */ |
7 | ||
8 | #include <linux/acpi.h> | |
9 | #include <linux/bootmem.h> | |
a9ce6bc1 | 10 | #include <linux/memblock.h> |
4fc2fba8 PM |
11 | #include <linux/dmi.h> |
12 | #include <linux/cpumask.h> | |
4fdf08b5 | 13 | #include <asm/segment.h> |
3038edab | 14 | #include <asm/desc.h> |
b40827fa | 15 | #include <asm/pgtable.h> |
d344e38b | 16 | #include <asm/cacheflush.h> |
b40827fa | 17 | |
e44b7b75 PM |
18 | #include "realmode/wakeup.h" |
19 | #include "sleep.h" | |
4fc2fba8 | 20 | |
4fc2fba8 | 21 | unsigned long acpi_realmode_flags; |
4fc2fba8 | 22 | |
9744f5a3 | 23 | #if defined(CONFIG_SMP) && defined(CONFIG_64BIT) |
5000cadc | 24 | static char temp_stack[4096]; |
e44b7b75 | 25 | #endif |
4fc2fba8 | 26 | |
cd74257b KRW |
27 | asmlinkage void acpi_enter_s3(void) |
28 | { | |
29 | acpi_enter_sleep_state(3, wake_sleep_flags); | |
30 | } | |
4fc2fba8 | 31 | /** |
f1a2003e | 32 | * acpi_suspend_lowlevel - save kernel state |
4fc2fba8 PM |
33 | * |
34 | * Create an identity mapped page table and copy the wakeup routine to | |
35 | * low memory. | |
36 | */ | |
f1a2003e | 37 | int acpi_suspend_lowlevel(void) |
4fc2fba8 | 38 | { |
e44b7b75 | 39 | struct wakeup_header *header; |
d1ee4335 PA |
40 | /* address in low memory of the wakeup routine. */ |
41 | char *acpi_realmode; | |
e44b7b75 | 42 | |
d1ee4335 | 43 | acpi_realmode = TRAMPOLINE_SYM(acpi_wakeup_code); |
e44b7b75 | 44 | |
d1ee4335 PA |
45 | header = (struct wakeup_header *)(acpi_realmode + WAKEUP_HEADER_OFFSET); |
46 | if (header->signature != WAKEUP_HEADER_SIGNATURE) { | |
e44b7b75 PM |
47 | printk(KERN_ERR "wakeup header does not match\n"); |
48 | return -EINVAL; | |
49 | } | |
50 | ||
51 | header->video_mode = saved_video_mode; | |
52 | ||
4b4f7280 | 53 | header->wakeup_jmp_seg = acpi_wakeup_address >> 4; |
065cb3df PA |
54 | |
55 | /* | |
56 | * Set up the wakeup GDT. We set these up as Big Real Mode, | |
57 | * that is, with limits set to 4 GB. At least the Lenovo | |
58 | * Thinkpad X61 is known to need this for the video BIOS | |
59 | * initialization quirk to work; this is likely to also | |
60 | * be the case for other laptops or integrated video devices. | |
61 | */ | |
62 | ||
4b4f7280 PA |
63 | /* GDT[0]: GDT self-pointer */ |
64 | header->wakeup_gdt[0] = | |
65 | (u64)(sizeof(header->wakeup_gdt) - 1) + | |
d1ee4335 | 66 | ((u64)__pa(&header->wakeup_gdt) << 16); |
065cb3df | 67 | /* GDT[1]: big real mode-like code segment */ |
3bf2e774 PA |
68 | header->wakeup_gdt[1] = |
69 | GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff); | |
065cb3df | 70 | /* GDT[2]: big real mode-like data segment */ |
3bf2e774 PA |
71 | header->wakeup_gdt[2] = |
72 | GDT_ENTRY(0x8093, acpi_wakeup_address, 0xfffff); | |
4b4f7280 | 73 | |
e44b7b75 PM |
74 | #ifndef CONFIG_64BIT |
75 | store_gdt((struct desc_ptr *)&header->pmode_gdt); | |
76 | ||
a7c4c0d9 PA |
77 | if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low, |
78 | &header->pmode_efer_high)) | |
79 | header->pmode_efer_low = header->pmode_efer_high = 0; | |
e44b7b75 PM |
80 | #endif /* !CONFIG_64BIT */ |
81 | ||
82 | header->pmode_cr0 = read_cr0(); | |
e532c06f | 83 | header->pmode_cr4 = read_cr4_safe(); |
7a313666 KC |
84 | header->pmode_behavior = 0; |
85 | if (!rdmsr_safe(MSR_IA32_MISC_ENABLE, | |
86 | &header->pmode_misc_en_low, | |
87 | &header->pmode_misc_en_high)) | |
88 | header->pmode_behavior |= | |
89 | (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE); | |
e44b7b75 PM |
90 | header->realmode_flags = acpi_realmode_flags; |
91 | header->real_magic = 0x12345678; | |
92 | ||
93 | #ifndef CONFIG_64BIT | |
94 | header->pmode_entry = (u32)&wakeup_pmode_return; | |
b40827fa | 95 | header->pmode_cr3 = (u32)__pa(&initial_page_table); |
e44b7b75 PM |
96 | saved_magic = 0x12345678; |
97 | #else /* CONFIG_64BIT */ | |
d1ee4335 | 98 | header->trampoline_segment = trampoline_address() >> 4; |
1ea598c2 | 99 | #ifdef CONFIG_SMP |
11d4c3f9 | 100 | stack_start = (unsigned long)temp_stack + sizeof(temp_stack); |
3038edab RW |
101 | early_gdt_descr.address = |
102 | (unsigned long)get_cpu_gdt_table(smp_processor_id()); | |
004aa322 | 103 | initial_gs = per_cpu_offset(smp_processor_id()); |
1ea598c2 | 104 | #endif |
e44b7b75 | 105 | initial_code = (unsigned long)wakeup_long64; |
ce4b3c55 | 106 | saved_magic = 0x123456789abcdef0L; |
e44b7b75 | 107 | #endif /* CONFIG_64BIT */ |
4fc2fba8 | 108 | |
f1a2003e | 109 | do_suspend_lowlevel(); |
4fc2fba8 PM |
110 | return 0; |
111 | } | |
112 | ||
4fc2fba8 PM |
113 | static int __init acpi_sleep_setup(char *str) |
114 | { | |
115 | while ((str != NULL) && (*str != '\0')) { | |
116 | if (strncmp(str, "s3_bios", 7) == 0) | |
117 | acpi_realmode_flags |= 1; | |
118 | if (strncmp(str, "s3_mode", 7) == 0) | |
119 | acpi_realmode_flags |= 2; | |
120 | if (strncmp(str, "s3_beep", 7) == 0) | |
121 | acpi_realmode_flags |= 4; | |
bdfe6b7c SL |
122 | #ifdef CONFIG_HIBERNATION |
123 | if (strncmp(str, "s4_nohwsig", 10) == 0) | |
124 | acpi_no_s4_hw_signature(); | |
125 | #endif | |
72ad5d77 RW |
126 | if (strncmp(str, "nonvs", 5) == 0) |
127 | acpi_nvs_nosave(); | |
d8f3de0d RW |
128 | if (strncmp(str, "old_ordering", 12) == 0) |
129 | acpi_old_suspend_ordering(); | |
4fc2fba8 PM |
130 | str = strchr(str, ','); |
131 | if (str != NULL) | |
132 | str += strspn(str, ", \t"); | |
133 | } | |
134 | return 1; | |
135 | } | |
136 | ||
137 | __setup("acpi_sleep=", acpi_sleep_setup); |