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