blob: 1cb2b186a3aff9ac0cbdc8f4540154a4f5e78e26 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sleep.c - x86-specific ACPI sleep support.
3 *
4 * Copyright (C) 2001-2003 Patrick Mochel
5 * Copyright (C) 2001-2003 Pavel Machek <pavel@suse.cz>
6 */
7
8#include <linux/acpi.h>
9#include <linux/bootmem.h>
Andrey Panin0f8133a2005-06-25 14:54:45 -070010#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/smp.h>
12#include <asm/tlbflush.h>
13
14/* address in low memory of the wakeup routine. */
15unsigned long acpi_wakeup_address = 0;
16unsigned long acpi_video_flags;
17extern char wakeup_start, wakeup_end;
18
19extern void zap_low_mappings(void);
20
21extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
22
Len Brown4be44fc2005-08-05 00:44:28 -040023static void init_low_mapping(pgd_t * pgd, int pgd_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
25 int pgd_ofs = 0;
26
Len Brown4be44fc2005-08-05 00:44:28 -040027 while ((pgd_ofs < pgd_limit)
28 && (pgd_ofs + USER_PTRS_PER_PGD < PTRS_PER_PGD)) {
29 set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 pgd_ofs++, pgd++;
31 }
32 flush_tlb_all();
33}
34
35/**
36 * acpi_save_state_mem - save kernel state
37 *
38 * Create an identity mapped page table and copy the wakeup routine to
39 * low memory.
40 */
Len Brown4be44fc2005-08-05 00:44:28 -040041int acpi_save_state_mem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 if (!acpi_wakeup_address)
44 return 1;
45 init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
Len Brown4be44fc2005-08-05 00:44:28 -040046 memcpy((void *)acpi_wakeup_address, &wakeup_start,
47 &wakeup_end - &wakeup_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 acpi_copy_wakeup_routine(acpi_wakeup_address);
49
50 return 0;
51}
52
53/*
54 * acpi_restore_state - undo effects of acpi_save_state_mem
55 */
Len Brown4be44fc2005-08-05 00:44:28 -040056void acpi_restore_state_mem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 zap_low_mappings();
59}
60
61/**
62 * acpi_reserve_bootmem - do _very_ early ACPI initialisation
63 *
64 * We allocate a page from the first 1MB of memory for the wakeup
65 * routine for when we come back from a sleep state. The
66 * runtime allocator allows specification of <16MB pages, but not
67 * <1MB pages.
68 */
69void __init acpi_reserve_bootmem(void)
70{
71 if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
Len Brown4be44fc2005-08-05 00:44:28 -040072 printk(KERN_ERR
73 "ACPI: Wakeup code way too big, S3 disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return;
75 }
76
77 acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
78 if (!acpi_wakeup_address)
79 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
80}
81
82static int __init acpi_sleep_setup(char *str)
83{
84 while ((str != NULL) && (*str != '\0')) {
85 if (strncmp(str, "s3_bios", 7) == 0)
86 acpi_video_flags = 1;
87 if (strncmp(str, "s3_mode", 7) == 0)
88 acpi_video_flags |= 2;
89 str = strchr(str, ',');
90 if (str != NULL)
91 str += strspn(str, ", \t");
92 }
93 return 1;
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096__setup("acpi_sleep=", acpi_sleep_setup);
Andrey Panin0f8133a2005-06-25 14:54:45 -070097
Andrey Panin0f8133a2005-06-25 14:54:45 -070098static __init int reset_videomode_after_s3(struct dmi_system_id *d)
99{
100 acpi_video_flags |= 2;
101 return 0;
102}
103
104static __initdata struct dmi_system_id acpisleep_dmi_table[] = {
Len Brown4be44fc2005-08-05 00:44:28 -0400105 { /* Reset video mode after returning from ACPI S3 sleep */
106 .callback = reset_videomode_after_s3,
107 .ident = "Toshiba Satellite 4030cdt",
108 .matches = {
109 DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
110 },
111 },
112 {}
Andrey Panin0f8133a2005-06-25 14:54:45 -0700113};
114
115static int __init acpisleep_dmi_init(void)
116{
117 dmi_check_system(acpisleep_dmi_table);
118 return 0;
119}
120
121core_initcall(acpisleep_dmi_init);