Commit 620b0327 authored by Pavel Machek's avatar Pavel Machek Committed by Linus Torvalds

[PATCH] properly stop devices before poweroff

Without this patch, Linux provokes emergency disk shutdowns and
similar nastiness. It was in SuSE kernels for some time, IIRC.
Signed-off-by: default avatarPavel Machek <pavel@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 5ce47e59
...@@ -103,7 +103,8 @@ extern int pm_active; ...@@ -103,7 +103,8 @@ extern int pm_active;
/* /*
* Register a device with power management * Register a device with power management
*/ */
struct pm_dev __deprecated *pm_register(pm_dev_t type, unsigned long id, pm_callback callback); struct pm_dev __deprecated *
pm_register(pm_dev_t type, unsigned long id, pm_callback callback);
/* /*
* Unregister a device with power management * Unregister a device with power management
...@@ -190,17 +191,18 @@ typedef u32 __bitwise pm_message_t; ...@@ -190,17 +191,18 @@ typedef u32 __bitwise pm_message_t;
/* /*
* There are 4 important states driver can be in: * There are 4 important states driver can be in:
* ON -- driver is working * ON -- driver is working
* FREEZE -- stop operations and apply whatever policy is applicable to a suspended driver * FREEZE -- stop operations and apply whatever policy is applicable to a
* of that class, freeze queues for block like IDE does, drop packets for * suspended driver of that class, freeze queues for block like IDE
* ethernet, etc... stop DMA engine too etc... so a consistent image can be * does, drop packets for ethernet, etc... stop DMA engine too etc...
* saved; but do not power any hardware down. * so a consistent image can be saved; but do not power any hardware
* SUSPEND - like FREEZE, but hardware is doing as much powersaving as possible. Roughly * down.
* pci D3. * SUSPEND - like FREEZE, but hardware is doing as much powersaving as
* possible. Roughly pci D3.
* *
* Unfortunately, current drivers only recognize numeric values 0 (ON) and 3 (SUSPEND). * Unfortunately, current drivers only recognize numeric values 0 (ON) and 3
* We'll need to fix the drivers. So yes, putting 3 to all diferent defines is intentional, * (SUSPEND). We'll need to fix the drivers. So yes, putting 3 to all different
* and will go away as soon as drivers are fixed. Also note that typedef is neccessary, * defines is intentional, and will go away as soon as drivers are fixed. Also
* we'll probably want to switch to * note that typedef is neccessary, we'll probably want to switch to
* typedef struct pm_message_t { int event; int flags; } pm_message_t * typedef struct pm_message_t { int event; int flags; } pm_message_t
* or something similar soon. * or something similar soon.
*/ */
...@@ -222,11 +224,18 @@ struct dev_pm_info { ...@@ -222,11 +224,18 @@ struct dev_pm_info {
extern void device_pm_set_parent(struct device * dev, struct device * parent); extern void device_pm_set_parent(struct device * dev, struct device * parent);
extern int device_suspend(pm_message_t state);
extern int device_power_down(pm_message_t state); extern int device_power_down(pm_message_t state);
extern void device_power_up(void); extern void device_power_up(void);
extern void device_resume(void); extern void device_resume(void);
#ifdef CONFIG_PM
extern int device_suspend(pm_message_t state);
#else
static inline int device_suspend(pm_message_t state)
{
return 0;
}
#endif
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
...@@ -405,6 +405,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -405,6 +405,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
case LINUX_REBOOT_CMD_HALT: case LINUX_REBOOT_CMD_HALT:
notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
system_state = SYSTEM_HALT; system_state = SYSTEM_HALT;
device_suspend(PMSG_SUSPEND);
device_shutdown(); device_shutdown();
printk(KERN_EMERG "System halted.\n"); printk(KERN_EMERG "System halted.\n");
machine_halt(); machine_halt();
...@@ -415,6 +416,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -415,6 +416,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
case LINUX_REBOOT_CMD_POWER_OFF: case LINUX_REBOOT_CMD_POWER_OFF:
notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
system_state = SYSTEM_POWER_OFF; system_state = SYSTEM_POWER_OFF;
device_suspend(PMSG_SUSPEND);
device_shutdown(); device_shutdown();
printk(KERN_EMERG "Power down.\n"); printk(KERN_EMERG "Power down.\n");
machine_power_off(); machine_power_off();
...@@ -431,6 +433,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -431,6 +433,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer); notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
system_state = SYSTEM_RESTART; system_state = SYSTEM_RESTART;
device_suspend(PMSG_FREEZE);
device_shutdown(); device_shutdown();
printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer); printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
machine_restart(buffer); machine_restart(buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment