blob: d941b62da4b60ca0ced0dc125881606232666486 [file] [log] [blame]
Pavel Machek4fc2fba2008-01-30 13:32:54 +01001/*
2 * sleep.c - x86-specific ACPI sleep support.
3 *
4 * Copyright (C) 2001-2003 Patrick Mochel
Pavel Macheka2531292010-07-18 14:27:13 +02005 * Copyright (C) 2001-2003 Pavel Machek <pavel@ucw.cz>
Pavel Machek4fc2fba2008-01-30 13:32:54 +01006 */
7
8#include <linux/acpi.h>
9#include <linux/bootmem.h>
Yinghai Lua9ce6bc2010-08-25 13:39:17 -070010#include <linux/memblock.h>
Pavel Machek4fc2fba2008-01-30 13:32:54 +010011#include <linux/dmi.h>
12#include <linux/cpumask.h>
H. Peter Anvin4fdf08b2008-07-17 11:29:24 -070013#include <asm/segment.h>
Rafael J. Wysocki3038eda2008-10-17 01:26:27 +020014#include <asm/desc.h>
Borislav Petkovb40827fa2010-08-28 15:58:33 +020015#include <asm/pgtable.h>
H. Peter Anvind344e382011-02-06 21:16:09 -080016#include <asm/cacheflush.h>
Jarkko Sakkinenc9b77cc2012-05-08 21:22:29 +030017#include <asm/realmode.h>
Borislav Petkovb40827fa2010-08-28 15:58:33 +020018
Jarkko Sakkinenc9b77cc2012-05-08 21:22:29 +030019#include "../../realmode/rm/wakeup/wakeup.h"
Pavel Macheke44b7b72008-04-10 23:28:10 +020020#include "sleep.h"
Pavel Machek4fc2fba2008-01-30 13:32:54 +010021
Pavel Machek4fc2fba2008-01-30 13:32:54 +010022unsigned long acpi_realmode_flags;
Pavel Machek4fc2fba2008-01-30 13:32:54 +010023
Marcin Slusarz9744f5a2008-08-03 19:25:48 +020024#if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
Matt Mackall5000cad2008-10-09 11:56:21 -050025static char temp_stack[4096];
Pavel Macheke44b7b72008-04-10 23:28:10 +020026#endif
Pavel Machek4fc2fba2008-01-30 13:32:54 +010027
Konrad Rzeszutek Wilkcd742572012-04-22 23:03:18 -040028asmlinkage void acpi_enter_s3(void)
29{
30 acpi_enter_sleep_state(3, wake_sleep_flags);
31}
Pavel Machek4fc2fba2008-01-30 13:32:54 +010032/**
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010033 * acpi_suspend_lowlevel - save kernel state
Pavel Machek4fc2fba2008-01-30 13:32:54 +010034 *
35 * Create an identity mapped page table and copy the wakeup routine to
36 * low memory.
37 */
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010038int acpi_suspend_lowlevel(void)
Pavel Machek4fc2fba2008-01-30 13:32:54 +010039{
Jarkko Sakkinenc9b77cc2012-05-08 21:22:29 +030040 struct wakeup_header *header =
41 (struct wakeup_header *) __va(real_mode_header.wakeup_header);
Pavel Macheke44b7b72008-04-10 23:28:10 +020042
H. Peter Anvind1ee4332011-02-14 15:42:46 -080043 if (header->signature != WAKEUP_HEADER_SIGNATURE) {
Pavel Macheke44b7b72008-04-10 23:28:10 +020044 printk(KERN_ERR "wakeup header does not match\n");
45 return -EINVAL;
46 }
47
48 header->video_mode = saved_video_mode;
49
50#ifndef CONFIG_64BIT
51 store_gdt((struct desc_ptr *)&header->pmode_gdt);
52
H. Peter Anvina7c4c0d2009-11-13 15:28:14 -080053 if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low,
54 &header->pmode_efer_high))
55 header->pmode_efer_low = header->pmode_efer_high = 0;
Pavel Macheke44b7b72008-04-10 23:28:10 +020056#endif /* !CONFIG_64BIT */
57
58 header->pmode_cr0 = read_cr0();
David Friese532c062008-08-17 23:03:40 -050059 header->pmode_cr4 = read_cr4_safe();
Kees Cook7a313662011-07-06 18:10:34 -070060 header->pmode_behavior = 0;
61 if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
62 &header->pmode_misc_en_low,
63 &header->pmode_misc_en_high))
64 header->pmode_behavior |=
65 (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
Pavel Macheke44b7b72008-04-10 23:28:10 +020066 header->realmode_flags = acpi_realmode_flags;
67 header->real_magic = 0x12345678;
68
69#ifndef CONFIG_64BIT
70 header->pmode_entry = (u32)&wakeup_pmode_return;
Borislav Petkovb40827fa2010-08-28 15:58:33 +020071 header->pmode_cr3 = (u32)__pa(&initial_page_table);
Pavel Macheke44b7b72008-04-10 23:28:10 +020072 saved_magic = 0x12345678;
73#else /* CONFIG_64BIT */
Ingo Molnar1ea598c2008-06-13 20:31:54 +020074#ifdef CONFIG_SMP
H. Peter Anvin11d4c3f2011-02-04 16:14:11 -080075 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
Rafael J. Wysocki3038eda2008-10-17 01:26:27 +020076 early_gdt_descr.address =
77 (unsigned long)get_cpu_gdt_table(smp_processor_id());
Tejun Heo004aa322009-01-13 20:41:35 +090078 initial_gs = per_cpu_offset(smp_processor_id());
Ingo Molnar1ea598c2008-06-13 20:31:54 +020079#endif
Pavel Macheke44b7b72008-04-10 23:28:10 +020080 initial_code = (unsigned long)wakeup_long64;
Jaswinder Singh Rajputce4b3c52009-04-18 13:44:57 +020081 saved_magic = 0x123456789abcdef0L;
Pavel Macheke44b7b72008-04-10 23:28:10 +020082#endif /* CONFIG_64BIT */
Pavel Machek4fc2fba2008-01-30 13:32:54 +010083
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010084 do_suspend_lowlevel();
Pavel Machek4fc2fba2008-01-30 13:32:54 +010085 return 0;
86}
87
Pavel Machek4fc2fba2008-01-30 13:32:54 +010088static int __init acpi_sleep_setup(char *str)
89{
90 while ((str != NULL) && (*str != '\0')) {
91 if (strncmp(str, "s3_bios", 7) == 0)
92 acpi_realmode_flags |= 1;
93 if (strncmp(str, "s3_mode", 7) == 0)
94 acpi_realmode_flags |= 2;
95 if (strncmp(str, "s3_beep", 7) == 0)
96 acpi_realmode_flags |= 4;
Shaohua Libdfe6b72008-07-23 21:28:41 -070097#ifdef CONFIG_HIBERNATION
98 if (strncmp(str, "s4_nohwsig", 10) == 0)
99 acpi_no_s4_hw_signature();
100#endif
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200101 if (strncmp(str, "nonvs", 5) == 0)
102 acpi_nvs_nosave();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200103 if (strncmp(str, "old_ordering", 12) == 0)
104 acpi_old_suspend_ordering();
Pavel Machek4fc2fba2008-01-30 13:32:54 +0100105 str = strchr(str, ',');
106 if (str != NULL)
107 str += strspn(str, ", \t");
108 }
109 return 1;
110}
111
112__setup("acpi_sleep=", acpi_sleep_setup);