blob: 11676cf65aee5ee51b64c8fadda0261c1f38599f [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
H. Peter Anvin73201db2012-09-26 15:02:34 -070046 header->pmode_behavior = 0;
47
Pavel Macheke44b7b72008-04-10 23:28:10 +020048#ifndef CONFIG_64BIT
49 store_gdt((struct desc_ptr *)&header->pmode_gdt);
50
H. Peter Anvin73201db2012-09-26 15:02:34 -070051 if (!rdmsr_safe(MSR_EFER,
52 &header->pmode_efer_low,
53 &header->pmode_efer_high))
54 header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
Pavel Macheke44b7b72008-04-10 23:28:10 +020055#endif /* !CONFIG_64BIT */
56
57 header->pmode_cr0 = read_cr0();
H. Peter Anvin73201db2012-09-26 15:02:34 -070058 if (__this_cpu_read(cpu_info.cpuid_level) >= 0) {
59 header->pmode_cr4 = read_cr4();
60 header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
61 }
Kees Cook7a313662011-07-06 18:10:34 -070062 if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
63 &header->pmode_misc_en_low,
64 &header->pmode_misc_en_high))
65 header->pmode_behavior |=
66 (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
Pavel Macheke44b7b72008-04-10 23:28:10 +020067 header->realmode_flags = acpi_realmode_flags;
68 header->real_magic = 0x12345678;
69
70#ifndef CONFIG_64BIT
71 header->pmode_entry = (u32)&wakeup_pmode_return;
Borislav Petkovb40827fa2010-08-28 15:58:33 +020072 header->pmode_cr3 = (u32)__pa(&initial_page_table);
Pavel Macheke44b7b72008-04-10 23:28:10 +020073 saved_magic = 0x12345678;
74#else /* CONFIG_64BIT */
Ingo Molnar1ea598c2008-06-13 20:31:54 +020075#ifdef CONFIG_SMP
H. Peter Anvin11d4c3f2011-02-04 16:14:11 -080076 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
Rafael J. Wysocki3038eda2008-10-17 01:26:27 +020077 early_gdt_descr.address =
78 (unsigned long)get_cpu_gdt_table(smp_processor_id());
Tejun Heo004aa322009-01-13 20:41:35 +090079 initial_gs = per_cpu_offset(smp_processor_id());
Ingo Molnar1ea598c2008-06-13 20:31:54 +020080#endif
Pavel Macheke44b7b72008-04-10 23:28:10 +020081 initial_code = (unsigned long)wakeup_long64;
Jaswinder Singh Rajputce4b3c52009-04-18 13:44:57 +020082 saved_magic = 0x123456789abcdef0L;
Pavel Macheke44b7b72008-04-10 23:28:10 +020083#endif /* CONFIG_64BIT */
Pavel Machek4fc2fba2008-01-30 13:32:54 +010084
Rafael J. Wysockif1a20032011-02-08 23:42:22 +010085 do_suspend_lowlevel();
Pavel Machek4fc2fba2008-01-30 13:32:54 +010086 return 0;
87}
88
Pavel Machek4fc2fba2008-01-30 13:32:54 +010089static int __init acpi_sleep_setup(char *str)
90{
91 while ((str != NULL) && (*str != '\0')) {
92 if (strncmp(str, "s3_bios", 7) == 0)
93 acpi_realmode_flags |= 1;
94 if (strncmp(str, "s3_mode", 7) == 0)
95 acpi_realmode_flags |= 2;
96 if (strncmp(str, "s3_beep", 7) == 0)
97 acpi_realmode_flags |= 4;
Shaohua Libdfe6b72008-07-23 21:28:41 -070098#ifdef CONFIG_HIBERNATION
99 if (strncmp(str, "s4_nohwsig", 10) == 0)
100 acpi_no_s4_hw_signature();
101#endif
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200102 if (strncmp(str, "nonvs", 5) == 0)
103 acpi_nvs_nosave();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200104 if (strncmp(str, "old_ordering", 12) == 0)
105 acpi_old_suspend_ordering();
Pavel Machek4fc2fba2008-01-30 13:32:54 +0100106 str = strchr(str, ',');
107 if (str != NULL)
108 str += strspn(str, ", \t");
109 }
110 return 1;
111}
112
113__setup("acpi_sleep=", acpi_sleep_setup);