blob: 1b8e5a03d942439c4b58a7470f181dcb99b29e85 [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 Sakkinenc4845472012-05-08 21:22:42 +030019#include "../../realmode/rm/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
28/**
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010029 * acpi_suspend_lowlevel - save kernel state
Pavel Machek4fc2fba2008-01-30 13:32:54 +010030 *
31 * Create an identity mapped page table and copy the wakeup routine to
32 * low memory.
33 */
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010034int acpi_suspend_lowlevel(void)
Pavel Machek4fc2fba2008-01-30 13:32:54 +010035{
Jarkko Sakkinenc9b77cc2012-05-08 21:22:29 +030036 struct wakeup_header *header =
Jarkko Sakkinenb429dbf2012-05-08 21:22:41 +030037 (struct wakeup_header *) __va(real_mode_header->wakeup_header);
Pavel Macheke44b7b72008-04-10 23:28:10 +020038
H. Peter Anvind1ee4332011-02-14 15:42:46 -080039 if (header->signature != WAKEUP_HEADER_SIGNATURE) {
Pavel Macheke44b7b72008-04-10 23:28:10 +020040 printk(KERN_ERR "wakeup header does not match\n");
41 return -EINVAL;
42 }
43
44 header->video_mode = saved_video_mode;
45
46#ifndef CONFIG_64BIT
47 store_gdt((struct desc_ptr *)&header->pmode_gdt);
48
H. Peter Anvina7c4c0d2009-11-13 15:28:14 -080049 if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low,
50 &header->pmode_efer_high))
51 header->pmode_efer_low = header->pmode_efer_high = 0;
Pavel Macheke44b7b72008-04-10 23:28:10 +020052#endif /* !CONFIG_64BIT */
53
54 header->pmode_cr0 = read_cr0();
David Friese532c062008-08-17 23:03:40 -050055 header->pmode_cr4 = read_cr4_safe();
Kees Cook7a313662011-07-06 18:10:34 -070056 header->pmode_behavior = 0;
57 if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
58 &header->pmode_misc_en_low,
59 &header->pmode_misc_en_high))
60 header->pmode_behavior |=
61 (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
Pavel Macheke44b7b72008-04-10 23:28:10 +020062 header->realmode_flags = acpi_realmode_flags;
63 header->real_magic = 0x12345678;
64
65#ifndef CONFIG_64BIT
66 header->pmode_entry = (u32)&wakeup_pmode_return;
Borislav Petkovb40827fa2010-08-28 15:58:33 +020067 header->pmode_cr3 = (u32)__pa(&initial_page_table);
Pavel Macheke44b7b72008-04-10 23:28:10 +020068 saved_magic = 0x12345678;
69#else /* CONFIG_64BIT */
Ingo Molnar1ea598c2008-06-13 20:31:54 +020070#ifdef CONFIG_SMP
H. Peter Anvin11d4c3f2011-02-04 16:14:11 -080071 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
Rafael J. Wysocki3038eda2008-10-17 01:26:27 +020072 early_gdt_descr.address =
73 (unsigned long)get_cpu_gdt_table(smp_processor_id());
Tejun Heo004aa322009-01-13 20:41:35 +090074 initial_gs = per_cpu_offset(smp_processor_id());
Ingo Molnar1ea598c2008-06-13 20:31:54 +020075#endif
Pavel Macheke44b7b72008-04-10 23:28:10 +020076 initial_code = (unsigned long)wakeup_long64;
Jaswinder Singh Rajputce4b3c52009-04-18 13:44:57 +020077 saved_magic = 0x123456789abcdef0L;
Pavel Macheke44b7b72008-04-10 23:28:10 +020078#endif /* CONFIG_64BIT */
Pavel Machek4fc2fba2008-01-30 13:32:54 +010079
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010080 do_suspend_lowlevel();
Pavel Machek4fc2fba2008-01-30 13:32:54 +010081 return 0;
82}
83
Pavel Machek4fc2fba2008-01-30 13:32:54 +010084static int __init acpi_sleep_setup(char *str)
85{
86 while ((str != NULL) && (*str != '\0')) {
87 if (strncmp(str, "s3_bios", 7) == 0)
88 acpi_realmode_flags |= 1;
89 if (strncmp(str, "s3_mode", 7) == 0)
90 acpi_realmode_flags |= 2;
91 if (strncmp(str, "s3_beep", 7) == 0)
92 acpi_realmode_flags |= 4;
Shaohua Libdfe6b72008-07-23 21:28:41 -070093#ifdef CONFIG_HIBERNATION
94 if (strncmp(str, "s4_nohwsig", 10) == 0)
95 acpi_no_s4_hw_signature();
96#endif
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +020097 if (strncmp(str, "nonvs", 5) == 0)
98 acpi_nvs_nosave();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +020099 if (strncmp(str, "old_ordering", 12) == 0)
100 acpi_old_suspend_ordering();
Pavel Machek4fc2fba2008-01-30 13:32:54 +0100101 str = strchr(str, ',');
102 if (str != NULL)
103 str += strspn(str, ", \t");
104 }
105 return 1;
106}
107
108__setup("acpi_sleep=", acpi_sleep_setup);