]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/i386/kernel/acpi/sleep.c
Merge /spare/repo/linux-2.6/
[mirror_ubuntu-bionic-kernel.git] / arch / i386 / kernel / acpi / sleep.c
1 /*
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>
10 #include <linux/dmi.h>
11 #include <asm/smp.h>
12 #include <asm/tlbflush.h>
13
14 /* address in low memory of the wakeup routine. */
15 unsigned long acpi_wakeup_address = 0;
16 unsigned long acpi_video_flags;
17 extern char wakeup_start, wakeup_end;
18
19 extern void zap_low_mappings(void);
20
21 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
22
23 static void init_low_mapping(pgd_t *pgd, int pgd_limit)
24 {
25 int pgd_ofs = 0;
26
27 while ((pgd_ofs < pgd_limit) && (pgd_ofs + USER_PTRS_PER_PGD < PTRS_PER_PGD)) {
28 set_pgd(pgd, *(pgd+USER_PTRS_PER_PGD));
29 pgd_ofs++, pgd++;
30 }
31 flush_tlb_all();
32 }
33
34 /**
35 * acpi_save_state_mem - save kernel state
36 *
37 * Create an identity mapped page table and copy the wakeup routine to
38 * low memory.
39 */
40 int acpi_save_state_mem (void)
41 {
42 if (!acpi_wakeup_address)
43 return 1;
44 init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
45 memcpy((void *) acpi_wakeup_address, &wakeup_start, &wakeup_end - &wakeup_start);
46 acpi_copy_wakeup_routine(acpi_wakeup_address);
47
48 return 0;
49 }
50
51 /*
52 * acpi_restore_state - undo effects of acpi_save_state_mem
53 */
54 void acpi_restore_state_mem (void)
55 {
56 zap_low_mappings();
57 }
58
59 /**
60 * acpi_reserve_bootmem - do _very_ early ACPI initialisation
61 *
62 * We allocate a page from the first 1MB of memory for the wakeup
63 * routine for when we come back from a sleep state. The
64 * runtime allocator allows specification of <16MB pages, but not
65 * <1MB pages.
66 */
67 void __init acpi_reserve_bootmem(void)
68 {
69 if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
70 printk(KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n");
71 return;
72 }
73
74 acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
75 if (!acpi_wakeup_address)
76 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
77 }
78
79 static int __init acpi_sleep_setup(char *str)
80 {
81 while ((str != NULL) && (*str != '\0')) {
82 if (strncmp(str, "s3_bios", 7) == 0)
83 acpi_video_flags = 1;
84 if (strncmp(str, "s3_mode", 7) == 0)
85 acpi_video_flags |= 2;
86 str = strchr(str, ',');
87 if (str != NULL)
88 str += strspn(str, ", \t");
89 }
90 return 1;
91 }
92
93
94 __setup("acpi_sleep=", acpi_sleep_setup);
95
96
97 static __init int reset_videomode_after_s3(struct dmi_system_id *d)
98 {
99 acpi_video_flags |= 2;
100 return 0;
101 }
102
103 static __initdata struct dmi_system_id acpisleep_dmi_table[] = {
104 { /* Reset video mode after returning from ACPI S3 sleep */
105 .callback = reset_videomode_after_s3,
106 .ident = "Toshiba Satellite 4030cdt",
107 .matches = {
108 DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
109 },
110 },
111 { }
112 };
113
114 static int __init acpisleep_dmi_init(void)
115 {
116 dmi_check_system(acpisleep_dmi_table);
117 return 0;
118 }
119
120 core_initcall(acpisleep_dmi_init);