This commit was manufactured by cvs2svn to create tag
[linux-2.6.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 <asm/smp.h>
11
12
13 /* address in low memory of the wakeup routine. */
14 unsigned long acpi_wakeup_address = 0;
15 unsigned long acpi_video_flags;
16 extern char wakeup_start, wakeup_end;
17
18 extern void zap_low_mappings(void);
19
20 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
21
22 static void map_low(pgd_t *pgd_base, unsigned long start, unsigned long end)
23 {
24         unsigned long vaddr;
25         pmd_t *pmd;
26         pgd_t *pgd;
27         int i, j;
28
29         pgd = pgd_base;
30
31         for (i = 0; i < PTRS_PER_PGD; pgd++, i++) {
32                 vaddr = i*PGDIR_SIZE;
33                 if (end && (vaddr >= end))
34                         break;
35                 pmd = pmd_offset(pgd, 0);
36                 for (j = 0; j < PTRS_PER_PMD; pmd++, j++) {
37                         vaddr = i*PGDIR_SIZE + j*PMD_SIZE;
38                         if (end && (vaddr >= end))
39                                 break;
40                         if (vaddr < start)
41                                 continue;
42                         set_pmd(pmd, __pmd(_KERNPG_TABLE + _PAGE_PSE +
43                                                                 vaddr - start));
44                 }
45         }
46 }
47
48 /**
49  * acpi_save_state_mem - save kernel state
50  *
51  * Create an identity mapped page table and copy the wakeup routine to
52  * low memory.
53  */
54 int acpi_save_state_mem (void)
55 {
56         if (!acpi_wakeup_address)
57                 return 1;
58         if (!cpu_has_pse)
59                 return 1;
60         map_low(swapper_pg_dir, 0, LOW_MAPPINGS_SIZE);
61         memcpy((void *) acpi_wakeup_address, &wakeup_start, &wakeup_end - &wakeup_start);
62         acpi_copy_wakeup_routine(acpi_wakeup_address);
63
64         return 0;
65 }
66
67 /**
68  * acpi_save_state_disk - save kernel state to disk
69  *
70  */
71 int acpi_save_state_disk (void)
72 {
73         return 1;
74 }
75
76 /*
77  * acpi_restore_state
78  */
79 void acpi_restore_state_mem (void)
80 {
81         zap_low_mappings();
82 }
83
84 /**
85  * acpi_reserve_bootmem - do _very_ early ACPI initialisation
86  *
87  * We allocate a page from the first 1MB of memory for the wakeup
88  * routine for when we come back from a sleep state. The
89  * runtime allocator allows specification of <16MB pages, but not
90  * <1MB pages.
91  */
92 void __init acpi_reserve_bootmem(void)
93 {
94         if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
95                 printk(KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n");
96                 return;
97         }
98 #ifdef CONFIG_X86_PAE
99         printk(KERN_ERR "ACPI: S3 and PAE do not like each other for now, S3 disabled.\n");
100         return;
101 #endif
102         acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
103         if (!acpi_wakeup_address)
104                 printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
105 }
106
107 static int __init acpi_sleep_setup(char *str)
108 {
109         while ((str != NULL) && (*str != '\0')) {
110                 if (strncmp(str, "s3_bios", 7) == 0)
111                         acpi_video_flags = 1;
112                 if (strncmp(str, "s3_mode", 7) == 0)
113                         acpi_video_flags |= 2;
114                 str = strchr(str, ',');
115                 if (str != NULL)
116                         str += strspn(str, ", \t");
117         }
118         return 1;
119 }
120
121
122 __setup("acpi_sleep=", acpi_sleep_setup);