blob: c42b5ab49deb0dc58aaef80d91d01ed940091b9f [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>
Shaohua Li55b23552006-06-23 02:04:49 -070011#include <linux/cpumask.h>
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/* address in low memory of the wakeup routine. */
16unsigned long acpi_wakeup_address = 0;
Pavel Machek77afcf72007-07-19 01:47:41 -070017unsigned long acpi_realmode_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018extern char wakeup_start, wakeup_end;
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/**
23 * acpi_save_state_mem - save kernel state
24 *
25 * Create an identity mapped page table and copy the wakeup routine to
26 * low memory.
27 */
Len Brown4be44fc2005-08-05 00:44:28 -040028int acpi_save_state_mem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 if (!acpi_wakeup_address)
31 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -040032 memcpy((void *)acpi_wakeup_address, &wakeup_start,
33 &wakeup_end - &wakeup_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 acpi_copy_wakeup_routine(acpi_wakeup_address);
35
36 return 0;
37}
38
39/*
40 * acpi_restore_state - undo effects of acpi_save_state_mem
41 */
Len Brown4be44fc2005-08-05 00:44:28 -040042void acpi_restore_state_mem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46/**
47 * acpi_reserve_bootmem - do _very_ early ACPI initialisation
48 *
49 * We allocate a page from the first 1MB of memory for the wakeup
50 * routine for when we come back from a sleep state. The
51 * runtime allocator allows specification of <16MB pages, but not
52 * <1MB pages.
53 */
54void __init acpi_reserve_bootmem(void)
55{
56 if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
Len Brown4be44fc2005-08-05 00:44:28 -040057 printk(KERN_ERR
58 "ACPI: Wakeup code way too big, S3 disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return;
60 }
61
62 acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
63 if (!acpi_wakeup_address)
64 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
65}
66
67static int __init acpi_sleep_setup(char *str)
68{
69 while ((str != NULL) && (*str != '\0')) {
70 if (strncmp(str, "s3_bios", 7) == 0)
Pavel Machek77afcf72007-07-19 01:47:41 -070071 acpi_realmode_flags |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (strncmp(str, "s3_mode", 7) == 0)
Pavel Machek77afcf72007-07-19 01:47:41 -070073 acpi_realmode_flags |= 2;
74 if (strncmp(str, "s3_beep", 7) == 0)
75 acpi_realmode_flags |= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 str = strchr(str, ',');
77 if (str != NULL)
78 str += strspn(str, ", \t");
79 }
80 return 1;
81}
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083__setup("acpi_sleep=", acpi_sleep_setup);
Andrey Panin0f8133a2005-06-25 14:54:45 -070084
Pavel Machek77afcf72007-07-19 01:47:41 -070085/* Ouch, we want to delete this. We already have better version in userspace, in
86 s2ram from suspend.sf.net project */
Andrey Panin0f8133a2005-06-25 14:54:45 -070087static __init int reset_videomode_after_s3(struct dmi_system_id *d)
88{
Pavel Machek77afcf72007-07-19 01:47:41 -070089 acpi_realmode_flags |= 2;
Andrey Panin0f8133a2005-06-25 14:54:45 -070090 return 0;
91}
92
93static __initdata struct dmi_system_id acpisleep_dmi_table[] = {
Len Brown4be44fc2005-08-05 00:44:28 -040094 { /* Reset video mode after returning from ACPI S3 sleep */
95 .callback = reset_videomode_after_s3,
96 .ident = "Toshiba Satellite 4030cdt",
97 .matches = {
98 DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
99 },
100 },
101 {}
Andrey Panin0f8133a2005-06-25 14:54:45 -0700102};
103
104static int __init acpisleep_dmi_init(void)
105{
106 dmi_check_system(acpisleep_dmi_table);
107 return 0;
108}
109
110core_initcall(acpisleep_dmi_init);