2 * sleep.c - x86-specific ACPI sleep support.
4 * Copyright (C) 2001-2003 Patrick Mochel
5 * Copyright (C) 2001-2003 Pavel Machek <pavel@suse.cz>
8 #include <linux/acpi.h>
9 #include <linux/bootmem.h>
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;
18 extern void zap_low_mappings(void);
20 extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
22 static void map_low(pgd_t *pgd_base, unsigned long start, unsigned long end)
31 for (i = 0; i < PTRS_PER_PGD; pgd++, i++) {
33 if (end && (vaddr >= end))
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))
42 set_pmd(pmd, __pmd(_KERNPG_TABLE + _PAGE_PSE +
49 * acpi_save_state_mem - save kernel state
51 * Create an identity mapped page table and copy the wakeup routine to
54 int acpi_save_state_mem (void)
56 if (!acpi_wakeup_address)
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);
68 * acpi_save_state_disk - save kernel state to disk
71 int acpi_save_state_disk (void)
79 void acpi_restore_state_mem (void)
85 * acpi_reserve_bootmem - do _very_ early ACPI initialisation
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
92 void __init acpi_reserve_bootmem(void)
94 if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
95 printk(KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n");
99 printk(KERN_ERR "ACPI: S3 and PAE do not like each other for now, S3 disabled.\n");
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");
107 static int __init acpi_sleep_setup(char *str)
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, ',');
116 str += strspn(str, ", \t");
122 __setup("acpi_sleep=", acpi_sleep_setup);