2 * sleep.c - ACPI sleep support.
4 * Copyright (c) 2000-2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
7 * This file is released under the GPLv2.
11 #include <linux/delay.h>
12 #include <linux/irq.h>
13 #include <linux/dmi.h>
14 #include <linux/device.h>
15 #include <linux/suspend.h>
16 #include <acpi/acpi_bus.h>
17 #include <acpi/acpi_drivers.h>
20 u8 sleep_states
[ACPI_S_STATE_COUNT
];
22 static struct pm_ops acpi_pm_ops
;
24 extern void do_suspend_lowlevel_s4bios(void);
25 extern void do_suspend_lowlevel(void);
27 static u32 acpi_suspend_states
[] = {
28 [PM_SUSPEND_ON
] = ACPI_STATE_S0
,
29 [PM_SUSPEND_STANDBY
] = ACPI_STATE_S1
,
30 [PM_SUSPEND_MEM
] = ACPI_STATE_S3
,
31 [PM_SUSPEND_DISK
] = ACPI_STATE_S4
,
34 static int init_8259A_after_S1
;
37 * acpi_pm_prepare - Do preliminary suspend work.
38 * @pm_state: suspend state we're entering.
40 * Make sure we support the state. If we do, and we need it, set the
41 * firmware waking vector and do arch-specific nastiness to get the
42 * wakeup code to the waking vector.
45 static int acpi_pm_prepare(u32 pm_state
)
47 u32 acpi_state
= acpi_suspend_states
[pm_state
];
49 if (!sleep_states
[acpi_state
])
52 /* do we have a wakeup address for S2 and S3? */
53 /* Here, we support only S4BIOS, those we set the wakeup address */
54 /* S4OS is only supported for now via swsusp.. */
55 if (pm_state
== PM_SUSPEND_MEM
|| pm_state
== PM_SUSPEND_DISK
) {
56 if (!acpi_wakeup_address
)
58 acpi_set_firmware_waking_vector(
59 (acpi_physical_address
) acpi_wakeup_address
);
61 ACPI_FLUSH_CPU_CACHE();
62 acpi_enable_wakeup_device_prep(acpi_state
);
63 acpi_enter_sleep_state_prep(acpi_state
);
69 * acpi_pm_enter - Actually enter a sleep state.
70 * @pm_state: State we're entering.
72 * Flush caches and go to sleep. For STR or STD, we have to call
73 * arch-specific assembly, which in turn call acpi_enter_sleep_state().
74 * It's unfortunate, but it works. Please fix if you're feeling frisky.
77 static int acpi_pm_enter(u32 pm_state
)
79 acpi_status status
= AE_OK
;
80 unsigned long flags
= 0;
81 u32 acpi_state
= acpi_suspend_states
[pm_state
];
83 ACPI_FLUSH_CPU_CACHE();
85 /* Do arch specific saving of state. */
86 if (pm_state
> PM_SUSPEND_STANDBY
) {
87 int error
= acpi_save_state_mem();
93 local_irq_save(flags
);
94 acpi_enable_wakeup_device(acpi_state
);
97 case PM_SUSPEND_STANDBY
:
99 status
= acpi_enter_sleep_state(acpi_state
);
103 do_suspend_lowlevel();
106 case PM_SUSPEND_DISK
:
107 if (acpi_pm_ops
.pm_disk_mode
== PM_DISK_PLATFORM
)
108 status
= acpi_enter_sleep_state(acpi_state
);
110 do_suspend_lowlevel_s4bios();
115 local_irq_restore(flags
);
116 printk(KERN_DEBUG
"Back to C!\n");
118 /* restore processor state
119 * We should only be here if we're coming back from STR or STD.
120 * And, in the case of the latter, the memory image should have already
121 * been loaded from disk.
123 if (pm_state
> PM_SUSPEND_STANDBY
)
124 acpi_restore_state_mem();
127 return ACPI_SUCCESS(status
) ? 0 : -EFAULT
;
132 * acpi_pm_finish - Finish up suspend sequence.
133 * @pm_state: State we're coming out of.
135 * This is called after we wake back up (or if entering the sleep state
139 static int acpi_pm_finish(u32 pm_state
)
141 u32 acpi_state
= acpi_suspend_states
[pm_state
];
143 acpi_leave_sleep_state(acpi_state
);
144 acpi_disable_wakeup_device(acpi_state
);
146 /* reset firmware waking vector */
147 acpi_set_firmware_waking_vector((acpi_physical_address
) 0);
149 if (init_8259A_after_S1
) {
150 printk("Broken toshiba laptop -> kicking interrupts\n");
157 int acpi_suspend(u32 acpi_state
)
160 [1] = PM_SUSPEND_STANDBY
,
161 [3] = PM_SUSPEND_MEM
,
162 [4] = PM_SUSPEND_DISK
,
165 if (acpi_state
<= 4 && states
[acpi_state
])
166 return pm_suspend(states
[acpi_state
]);
170 static struct pm_ops acpi_pm_ops
= {
171 .prepare
= acpi_pm_prepare
,
172 .enter
= acpi_pm_enter
,
173 .finish
= acpi_pm_finish
,
178 * Toshiba fails to preserve interrupts over S1, reinitialization
179 * of 8259 is needed after S1 resume.
181 static int __init
init_ints_after_s1(struct dmi_system_id
*d
)
183 printk(KERN_WARNING
"%s with broken S1 detected.\n", d
->ident
);
184 init_8259A_after_S1
= 1;
188 static struct dmi_system_id __initdata acpisleep_dmi_table
[] = {
190 .callback
= init_ints_after_s1
,
191 .ident
= "Toshiba Satellite 4030cdt",
192 .matches
= { DMI_MATCH(DMI_PRODUCT_NAME
, "S4030CDT/4.3"), },
197 static int __init
acpi_sleep_init(void)
201 dmi_check_system(acpisleep_dmi_table
);
206 printk(KERN_INFO PREFIX
"(supports");
207 for (i
=0; i
< ACPI_S_STATE_COUNT
; i
++) {
210 status
= acpi_get_sleep_type_data(i
, &type_a
, &type_b
);
211 if (ACPI_SUCCESS(status
)) {
215 if (i
== ACPI_STATE_S4
) {
216 if (acpi_gbl_FACS
->S4bios_f
) {
219 acpi_pm_ops
.pm_disk_mode
= PM_DISK_FIRMWARE
;
222 acpi_pm_ops
.pm_disk_mode
= PM_DISK_PLATFORM
;
227 pm_set_ops(&acpi_pm_ops
);
231 late_initcall(acpi_sleep_init
);