Skip to contentSkip to conversation

PM: Rework suspend and hibernation code for devices (rev. 3)

RFC PATCH In review Rafael J. Wysocki 6 participants 58 messages Mar 29, 2008 – Apr 2, 2008

Subsystems (8)
x86 ACPI PCI Driver core +4 more subsystems
lore
Share & tools
lore
#0 lore raw

cover PM: Rework suspend and hibernation code for devices (rev. 3)

Hi,

The following three patches are intended to start the redesign of the suspend and hibernation framework for devices.

The first one is the 5th revision of the patch introducing new callbacks for suspend and hibernation.

The other two patches implement the new suspend and hibernation callbacks for the platform and PCI bus types (3rd revision of both).

The main differences between these patches and the previous revision:
* Dropped 'struct pm_noirq_ops' and introduced 'struct pm_ext_ops' that is a derivative of 'struct pm_ops' (adds the _noirq operations).
* Made device_pm_add() refuse to add devices for which dev->parent->power.status == DPM_INVALID
* Clarified (hopefully) the new platform and pci driver code

Please review.

Thanks,
Rafael

#1 lore raw

RFC PATCH 1/3 PM: Introduce new top level suspend and hibernation callbacks (rev. 5)

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  693 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 857 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  If a device marked as "invalid"
+ * is encountered during the preparation phase (i.e. when devices' @prepare()
+ * methods are executed), the transition will be aborted and -EINVAL will be
+ * returned. [The only way to recover from this situation is to unregister the
+ * "invalid" device(s).]
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +536 -157

916 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {
#2 lore raw

RFC PATCH 1/3 PM: Introduce new top level suspend and hibernation callbacks (rev. 5)

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  693 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 857 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  If a device marked as "invalid"
+ * is encountered during the preparation phase (i.e. when devices' @prepare()
+ * methods are executed), the transition will be aborted and -EINVAL will be
+ * returned. [The only way to recover from this situation is to unregister the
+ * "invalid" device(s).]
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +536 -157

916 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [RFC][PATCH 1/3] PM: Introduce new top level suspend and hibernation callbacks (rev. 5)

Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Fixed patch follows.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  693 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 857 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  If a device marked as "invalid"
+ * is encountered during the preparation phase (i.e. when devices' @prepare()
+ * methods are executed), the transition will be aborted and -EINVAL will be
+ * returned. [The only way to recover from this situation is to unregister the
+ * "invalid" device(s).]
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +536 -157

916 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {
#4 lore raw

Re: [RFC][PATCH 1/3] PM: Introduce new top level suspend and hibernation callbacks (rev. 5)

In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Fixed patch follows.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  693 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 857 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  If a device marked as "invalid"
+ * is encountered during the preparation phase (i.e. when devices' @prepare()
+ * methods are executed), the transition will be aborted and -EINVAL will be
+ * returned. [The only way to recover from this situation is to unregister the
+ * "invalid" device(s).]
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +536 -157

916 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

RFC PATCH 1/1 PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 12 lines · Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Quoted 5 lines

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

For this reason, I have changed the patch so that the "invalid" status of devices is cleared by the PM core in dpm_complete(). I have also added messages printed during a resume if an error is returned by a driver's callback.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  For now, during the completion
+ * phase of resume the PM core clears the "invalid" status of devices (this is
+ * done only because the legacy ->resume() callbacks of some drivers tend to
+ * return errors even if the "failing" devices work correctly after the
+ * resume).  Note, however, that this is going to change in the future.
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +549 -157

929 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {
#6 lore raw

RFC PATCH 1/1 PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Quoted 5 lines

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

For this reason, I have changed the patch so that the "invalid" status of devices is cleared by the PM core in dpm_complete(). I have also added messages printed during a resume if an error is returned by a driver's callback.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified.  This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)
include/linux/pm.h +290 -28
Index: linux-2.6/include/linux/pm.h
===================================================================
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).
+ *
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to
+ *	suspend earlier).
+ *	The PM core executes @complete() after it has executed the appropriate
+ *	resume callback for all devices.
+ *
+ * @suspend: Executed before putting the system into a sleep state in which the
+ *	contents of main memory are preserved.  Quiesce the device, put it into
+ *	a low power state appropriate for the upcoming system state (such as
+ *	PCI_D3hot), and enable wakeup events as appropriate.
+ *
+ * @resume: Executed after waking the system up from a sleep state in which the
+ *	contents of main memory were preserved.  Put the device into the
+ *	appropriate state, according to the information saved in memory by the
+ *	preceding @suspend().  The driver starts working again, responding to
+ *	hardware events and software requests.  The hardware may have gone
+ *	through a power-off reset, or it may have maintained state from the
+ *	previous suspend() which the driver may rely on while resuming.  On most
+ *	platforms, there are no restrictions on availability of resources like
+ *	clocks during @resume().
+ *
+ * @freeze: Hibernation-specific, executed before creating a hibernation image.
+ *	Quiesce operations so that a consistent image can be created, but do NOT
+ *	otherwise put the device into a low power device state and do NOT emit
+ *	system wakeup events.  Save in main memory the device settings to be
+ *	used by @restore() during the subsequent resume from hibernation or by
+ *	the subsequent @thaw(), if the creation of the image or the restoration
+ *	of main memory contents from it fails.
+ *
+ * @thaw: Hibernation-specific, executed after creating a hibernation image OR
+ *	if the creation of the image fails.  Also executed after a failing
+ *	attempt to restore the contents of main memory from such an image.
+ *	Undo the changes made by the preceding @freeze(), so the device can be
+ *	operated in the same way as immediately before the call to @freeze().
+ *
+ * @poweroff: Hibernation-specific, executed after saving a hibernation image.
+ *	Quiesce the device, put it into a low power state appropriate for the
+ *	upcoming system state (such as PCI_D3hot), and enable wakeup events as
+ *	appropriate.
+ *
+ * @restore: Hibernation-specific, executed after restoring the contents of main
+ *	memory from a hibernation image.  Driver starts working again,
+ *	responding to hardware events and software requests.  Drivers may NOT
+ *	make ANY assumptions about the hardware state right prior to @restore().
+ *	On most platforms, there are no restrictions on availability of
+ *	resources like clocks during @restore().
+ *
+ * All of the above callbacks, except for @complete(), return error codes.
+ * However, the error codes returned by the resume operations, @resume(),
+ * @thaw(), and @restore(), do not cause the PM core to abort the resume
+ * transition during which they are returned.  Instead, the PM core marks
+ * the devices for which they are returned and all of their children as
+ * "invalid" and doesn't attempt to execute any other suspend/hibernation
+ * callbacks for them (including @complete()).  For now, during the completion
+ * phase of resume the PM core clears the "invalid" status of devices (this is
+ * done only because the legacy ->resume() callbacks of some drivers tend to
+ * return errors even if the "failing" devices work correctly after the
+ * resume).  Note, however, that this is going to change in the future.
+ *
+ * It is allowed to unregister devices while the above callbacks are being
+ * executed.  However, it is not allowed to unregister a device from within any
+ * of its own callbacks.
+ */
+
+struct pm_ops {
+	int (*prepare)(struct device *dev);
+	void (*complete)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
+	int (*freeze)(struct device *dev);
+	int (*thaw)(struct device *dev);
+	int (*poweroff)(struct device *dev);
+	int (*restore)(struct device *dev);
+};
+
+/**
+ * struct pm_ext_ops - extended device PM callbacks
+ *
+ * Some devices require certain operations related to suspend and hibernation
+ * to be carried out with interrupts disabled.  Thus, 'struct pm_ext_ops' below
+ * is defined, adding callbacks to be executed with interrupts disabled to
+ * 'struct pm_ops'.
+ *
+ * The following callbacks included in 'struct pm_ext_ops' are executed with
+ * the nonboot CPUs switched off and with interrupts disabled on the only
+ * functional CPU.  They also are executed with the PM core list of devices
+ * locked, so they must NOT unregister any devices.
+ *
+ * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
+ *	actions required for suspending the device that need interrupts to be
+ *	disabled
+ *
+ * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
+ *	actions required for resuming the device that need interrupts to be
+ *	disabled
+ *
+ * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
+ *	actions required for freezing the device that need interrupts to be
+ *	disabled
+ *
+ * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
+ *	actions required for thawing the device that need interrupts to be
+ *	disabled
+ *
+ * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
+ *	actions required for handling the device that need interrupts to be
+ *	disabled
+ *
+ * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
+ *	actions required for restoring the operations of the device that need
+ *	interrupts to be disabled
+ *
+ * All of the above callbacks return error codes, but the error codes returned
+ * by the resume operations, @resume_noirq(), @thaw_noirq(), and
+ * @restore_noirq(), do not cause the PM core to abort the resume transition
+ * during which they are returned.  Instead, the PM core marks the devices for
+ * which they are returned and all of their children as "invalid" and doesn't
+ * attempt to execute any resume callbacks for them (including ->complete()).
+ */
+
+struct pm_ext_ops {
+	struct pm_ops base;
+	int (*suspend_noirq)(struct device *dev);
+	int (*resume_noirq)(struct device *dev);
+	int (*freeze_noirq)(struct device *dev);
+	int (*thaw_noirq)(struct device *dev);
+	int (*poweroff_noirq)(struct device *dev);
+	int (*restore_noirq)(struct device *dev);
+};
+
+/**
+ * PM_EVENT_ messages
+ *
+ * The following PM_EVENT_ messages are defined for the internal use of the PM
+ * core, in order to provide a mechanism allowing the high level suspend and
+ * hibernation code to convey the necessary information to the device PM core
+ * code:
+ *
+ * ON		No transition.
+ *
+ * FREEZE 	System is going to hibernate, call ->prepare() and ->freeze()
+ *		for all devices.
+ *
+ * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
+ *		for all devices.
+ *
+ * HIBERNATE	Hibernation image has been saved, call ->prepare() and
+ *		->poweroff() for all devices.
+ *
+ * QUIESCE	Contents of main memory are going to be restored from a (loaded)
+ *		hibernation image, call ->prepare() and ->freeze() for all
+ *		devices.
+ *
+ * RESUME	System is resuming, call ->resume() and ->complete() for all
+ *		devices.
+ *
+ * THAW		Hibernation image has been created, call ->thaw() and
+ *		->complete() for all devices.
+ *
+ * RESTORE	Contents of main memory have been restored from a hibernation
+ *		image, call ->restore() and ->complete() for all devices.
+ *
+ * RECOVER	Creation of a hibernation image or restoration of the main
+ *		memory contents from a hibernation image has failed, call
+ *		->thaw() and ->complete() for all devices.
+ */
+
+#define PM_EVENT_ON		0x0000
+#define PM_EVENT_FREEZE 	0x0001
+#define PM_EVENT_SUSPEND	0x0002
+#define PM_EVENT_HIBERNATE	0x0004
+#define PM_EVENT_QUIESCE	0x0008
+#define PM_EVENT_RESUME		0x0010
+#define PM_EVENT_THAW		0x0020
+#define PM_EVENT_RESTORE	0x0040
+#define PM_EVENT_RECOVER	0x0080
+
+#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
+
+#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
+#define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
+#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
+#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
+#define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
+#define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
+#define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
+#define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
+#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
+
+/**
+ * Device power management states
+ *
+ * These state labels are used internally by the PM core to indicate the current
+ * status of a device with respect to the PM core operations.
+ *
+ * DPM_INVALID		Device is not in a consistent state.  Set when one of
+ *			the device's resume callbacks, ->resume(), ->thaw(),
+ *			->restore(), ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq(), fails.  Also set when the device
+ *			parent's status turns out to be DPM_INVALID.
+ *
+ * DPM_ON		Device is regarded as operational.  Set this way
+ *			initially and when ->complete() is about to be called.
+ *			Also set when ->prepare() fails.
+ *
+ * DPM_PREPARING	Device is going to be prepared for a PM transition.  Set
+ *			when ->prepare() is about to be called.
+ *
+ * DPM_RESUMING		Device is going to be resumed.  Set when ->resume(),
+ *			->thaw(), or ->restore() is about to be called.
+ *
+ * DPM_SUSPENDING	Device has been prepared for a power transition.  Set
+ *			when ->prepare() has just succeeded.
+ *
+ * DPM_OFF		Device is regarded as inactive.  Set immediately after
+ *			->suspend(), ->freeze(), or ->poweroff() has succeeded.
+ *			Also set when ->resume()_noirq, ->thaw_noirq(), or
+ *			->restore_noirq() is about to be called.
+ *
+ * DPM_OFF_IRQ		Device is in a "deep sleep".  Set immediately after
+ *			->suspend_noirq(), ->freeze_noirq(), or
+ *			->poweroff_noirq() has just succeeded.
+ */
+
+enum dpm_state {
+	DPM_INVALID,
+	DPM_ON,
+	DPM_PREPARING,
+	DPM_RESUMING,
+	DPM_SUSPENDING,
+	DPM_OFF,
+	DPM_OFF_IRQ,
+};
+
+struct dev_pm_info {
+	pm_message_t		power_state;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
+	enum dpm_state		status;		/* Owned by the PM core */
+#ifdef	CONFIG_PM_SLEEP
+	struct list_head	entry;
+#endif
+};
+
+/*
+ * The PM_EVENT_ messages are also used by drivers implementing the legacy
+ * suspend framework, based on the ->suspend() and ->resume() callbacks common
+ * for suspend and hibernation transitions, according to the rules below.
+ */
+
+/* Necessary, because several drivers use PM_EVENT_PRETHAW */
+#define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
+
+/*
  * One transition is triggered by resume(), after a suspend() call; the
  * message is implicit:
  *
@@ -166,35 +450,13 @@ typedef struct pm_message {
  * or from system low-power states such as standby or suspend-to-RAM.
  */
 
-#define PM_EVENT_ON 0
-#define PM_EVENT_FREEZE 1
-#define PM_EVENT_SUSPEND 2
-#define PM_EVENT_HIBERNATE 4
-#define PM_EVENT_PRETHAW 8
-
-#define PM_EVENT_SLEEP	(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
-
-#define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
-#define PMSG_PRETHAW	((struct pm_message){ .event = PM_EVENT_PRETHAW, })
-#define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
-#define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
-#define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
-
-struct dev_pm_info {
-	pm_message_t		power_state;
-	unsigned		can_wakeup:1;
-	unsigned		should_wakeup:1;
-	bool			sleeping:1;	/* Owned by the PM core */
-#ifdef	CONFIG_PM_SLEEP
-	struct list_head	entry;
-#endif
-};
+#ifdef CONFIG_PM_SLEEP
+extern void device_pm_lock(void);
+extern void device_power_up(pm_message_t state);
+extern void device_resume(pm_message_t state);
 
+extern void device_pm_unlock(void);
 extern int device_power_down(pm_message_t state);
-extern void device_power_up(void);
-extern void device_resume(void);
-
-#ifdef CONFIG_PM_SLEEP
 extern int device_suspend(pm_message_t state);
 extern int device_prepare_suspend(pm_message_t state);
 
drivers/base/power/main.c +549 -157

929 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-2.6/include/linux/device.h
===================================================================
@@ -69,6 +69,8 @@ struct bus_type {
 	int (*resume_early)(struct device *dev);
 	int (*resume)(struct device *dev);
 
+	struct pm_ext_ops *pm;
+
 	struct bus_type_private *p;
 };
 
@@ -132,6 +134,8 @@ struct device_driver {
 	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
+	struct pm_ops *pm;
+
 	struct driver_private *p;
 };
 
@@ -202,6 +206,8 @@ struct class {
 
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 extern int __must_check class_register(struct class *class);
@@ -345,8 +351,11 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
+
 	int (*suspend)(struct device *dev, pm_message_t state);
 	int (*resume)(struct device *dev);
+
+	struct pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
kernel/power/disk.c +13 -7
Index: linux-2.6/kernel/power/disk.c
===================================================================
@@ -193,6 +193,7 @@ static int create_image(int platform_mod
 	if (error)
 		return error;
 
+	device_pm_lock();
 	local_irq_disable();
 	/* At this point, device_suspend() has been called, but *not*
 	 * device_power_down(). We *must* call device_power_down() now.
@@ -224,9 +225,10 @@ static int create_image(int platform_mod
 	/* NOTE:  device_power_up() is just a resume() for devices
 	 * that suspended with irqs off ... no overall powerup.
 	 */
-	device_power_up();
+	device_power_up(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -280,7 +282,7 @@ int hibernation_snapshot(int platform_mo
  Finish:
 	platform_finish(platform_mode);
  Resume_devices:
-	device_resume();
+	device_resume(in_suspend ? PMSG_RECOVER : PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
@@ -300,8 +302,9 @@ static int resume_target_kernel(void)
 {
 	int error;
 
+	device_pm_lock();
 	local_irq_disable();
-	error = device_power_down(PMSG_PRETHAW);
+	error = device_power_down(PMSG_QUIESCE);
 	if (error) {
 		printk(KERN_ERR "PM: Some devices failed to power down, "
 			"aborting resume\n");
@@ -329,9 +332,10 @@ static int resume_target_kernel(void)
 	swsusp_free();
 	restore_processor_state();
 	touch_softlockup_watchdog();
-	device_power_up();
+	device_power_up(PMSG_THAW);
  Enable_irqs:
 	local_irq_enable();
+	device_pm_unlock();
 	return error;
 }
 
@@ -350,7 +354,7 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
-	error = device_suspend(PMSG_PRETHAW);
+	error = device_suspend(PMSG_QUIESCE);
 	if (error)
 		goto Finish;
 
@@ -362,7 +366,7 @@ int hibernation_restore(int platform_mod
 		enable_nonboot_cpus();
 	}
 	platform_restore_cleanup(platform_mode);
-	device_resume();
+	device_resume(PMSG_RECOVER);
  Finish:
 	resume_console();
 	pm_restore_console();
@@ -403,6 +407,7 @@ int hibernation_platform_enter(void)
 	if (error)
 		goto Finish;
 
+	device_pm_lock();
 	local_irq_disable();
 	error = device_power_down(PMSG_HIBERNATE);
 	if (!error) {
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void)
 		while (1);
 	}
 	local_irq_enable();
+	device_pm_unlock();
 
 	/*
 	 * We don't need to reenable the nonboot CPUs or resume consoles, since
@@ -419,7 +425,7 @@ int hibernation_platform_enter(void)
  Finish:
 	hibernation_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESTORE);
  Resume_console:
 	resume_console();
  Close:
kernel/power/main.c +4 -2
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -228,6 +228,7 @@ static int suspend_enter(suspend_state_t
 {
 	int error = 0;
 
+	device_pm_lock();
 	arch_suspend_disable_irqs();
 	BUG_ON(!irqs_disabled());
 
@@ -239,10 +240,11 @@ static int suspend_enter(suspend_state_t
 	if (!suspend_test(TEST_CORE))
 		error = suspend_ops->enter(state);
 
-	device_power_up();
+	device_power_up(PMSG_RESUME);
  Done:
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
+	device_pm_unlock();
 	return error;
 }
 
@@ -291,7 +293,7 @@ int suspend_devices_and_enter(suspend_st
 	if (suspend_ops->finish)
 		suspend_ops->finish();
  Resume_devices:
-	device_resume();
+	device_resume(PMSG_RESUME);
  Resume_console:
 	resume_console();
  Close:
arch/x86/kernel/apm_32.c +2 -2
Index: linux-2.6/arch/x86/kernel/apm_32.c
===================================================================
@@ -1208,9 +1208,9 @@ static int suspend(int vetoable)
 	if (err != APM_SUCCESS)
 		apm_error("suspend", err);
 	err = (err == APM_SUCCESS) ? 0 : -EIO;
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
-	device_resume();
+	device_resume(PMSG_RESUME);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
 	spin_lock(&user_list_lock);
drivers/base/power/power.h +1 -1
Index: linux-2.6/drivers/base/power/power.h
===================================================================
@@ -4,7 +4,7 @@
  * main.c
  */
 
-extern struct list_head dpm_active;	/* The active device list */
+extern struct list_head dpm_list;	/* The active device list */
 
 static inline struct device *to_device(struct list_head *entry)
 {
drivers/base/power/trace.c +2 -2
Index: linux-2.6/drivers/base/power/trace.c
===================================================================
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int v
 static int show_dev_hash(unsigned int value)
 {
 	int match = 0;
-	struct list_head * entry = dpm_active.prev;
+	struct list_head *entry = dpm_list.prev;
 
-	while (entry != &dpm_active) {
+	while (entry != &dpm_list) {
 		struct device * dev = to_device(entry);
 		unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
 		if (hash == value) {

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Hi Rafael.

Please excuse me, but I'm going to ask the questions you get from someone who hasn't followed development to date, and is thus reading the explanation without prior knowledge. Hopefully that will be helpful when you come to finalising the commit message.

Quoted 5 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 4 lines

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

'Respectively' doesn't look like the right word to use, but I'm not sure I understand correctly what you're trying to say. The way it's written at the moment, it sounds to me like you're saying that suspend_late() and resume_early are deprecated, but you're modifying the PM core to use them.

Quoted 6 lines

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

s/particualr,/particular

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

Quoted 9 lines

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified. This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

Quoted 8 lines

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Do these changes allow for other power state possibilities besides suspend to ram and hibernate (eg on other platforms)?

Quoted 48 lines

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)

Index: linux-2.6/include/linux/pm.h
===================================================================

include/linux/pm.h +13 -1
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core

include/linux/pm.h typedef struct pm_message { · line 146

Quoted 10 lines
include/linux/pm.h +10 -0
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.

Why?

include/linux/pm.h typedef struct pm_message { · line 149

Quoted 3 lines
include/linux/pm.h +3 -0
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

include/linux/pm.h typedef struct pm_message { · line 156

Quoted 6 lines
include/linux/pm.h +6 -0
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to

s/unsucessfully/unsuccessfully

Regards,

Nigel

#8 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

Quoted 6 lines
Quoted 6 lines

+ * @complete: Undo the changes made by @prepare(). This method is executed for

+ *   all kinds of resume transitions, following one of the resume callbacks:
+ *   @resume(), @thaw(), @restore().  Also called if the state transition
+ *   fails before the driver's suspend callback (@suspend(), @freeze(),
+ *   @poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *   of the other devices that the PM core has unsucessfully attempted to

Ben.

#9 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

Pepare() is called after userspace has been frozen. (Of course, once the freezer goes away this won't matter any more.)

There is a separate notifier chain which drivers can subscribe to; notifications about impending sleeps are sent out while userspace is still alive. Drivers can use that for request_firmware, memory allocation, and other things.

Alan Stern

#10 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

Pepare() is called after userspace has been frozen. (Of course, once the freezer goes away this won't matter any more.)

There is a separate notifier chain which drivers can subscribe to; notifications about impending sleeps are sent out while userspace is still alive. Drivers can use that for request_firmware, memory allocation, and other things.

Alan Stern

#11 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Hi.

Quoted 13 lines · Alan Stern
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

Quoted 7 lines

Pepare() is called after userspace has been frozen. (Of course, once the freezer goes away this won't matter any more.)

There is a separate notifier chain which drivers can subscribe to; notifications about impending sleeps are sent out while userspace is still alive. Drivers can use that for request_firmware, memory allocation, and other things.

Then that should be mentioned here so that drivers authors can know that it is possible to request firmware, allocate memory and so on at a stage when you can still rely on userspace being alive.

Regards,

Nigel

#12 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern

Hi.

Quoted 13 lines · Alan Stern
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

Quoted 7 lines

Pepare() is called after userspace has been frozen. (Of course, once the freezer goes away this won't matter any more.)

There is a separate notifier chain which drivers can subscribe to; notifications about impending sleeps are sent out while userspace is still alive. Drivers can use that for request_firmware, memory allocation, and other things.

Then that should be mentioned here so that drivers authors can know that it is possible to request firmware, allocate memory and so on at a stage when you can still rely on userspace being alive.

Regards,

Nigel

#13 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

This documents the current state which is that we have the freezer and we have drivers that rely on it.

I can remove the comment, but then someone will invent ->prepare() relying on the availability of the user space at this point and that won't work.

Thanks,
Rafael

#14 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
+ *   However, drivers may NOT assume anything about the availability of the
+ *   user space at that time and it is not correct to request firmware from
+ *   within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Agreed. Prepare() should still allow request_firmware and full userspace communication / helper usage.

This documents the current state which is that we have the freezer and we have drivers that rely on it.

I can remove the comment, but then someone will invent ->prepare() relying on the availability of the user space at this point and that won't work.

Thanks,
Rafael

#15 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Nigel Cunningham
Quoted 1 line · Nigel Cunningham

Hi Rafael.

Hi,

Quoted 8 lines

Please excuse me, but I'm going to ask the questions you get from someone who hasn't followed development to date, and is thus reading the explanation without prior knowledge. Hopefully that will be helpful when you come to finalising the commit message.

Quoted 2 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Quoted 7 lines
Quoted 3 lines

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Quoted 10 lines
Quoted 4 lines

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

'Respectively' doesn't look like the right word to use, but I'm not sure I understand correctly what you're trying to say. The way it's written at the moment, it sounds to me like you're saying that suspend_late() and resume_early are deprecated, but you're modifying the PM core to use them.

Yes, the changelog is wrong, because I used a separate structure for the _noirq callbacks and (quite blindly) change the name of the structure in the changelog, instead of reworking it.

Quoted 8 lines
Quoted 6 lines

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

s/particualr,/particular

Yes, thanks.

Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

Quoted 18 lines
Quoted 9 lines

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified. This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

Quoted 8 lines

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Quoted 2 lines

Do these changes allow for other power state possibilities besides suspend to ram and hibernate (eg on other platforms)?

The other states fall into the "suspend" category.

Quoted 52 lines
Quoted 52 lines

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)

Index: linux-2.6/include/linux/pm.h
===================================================================

include/linux/pm.h +17 -1
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
Quoted 8 lines

include/linux/pm.h typedef struct pm_message { · line 146

Quoted 6 lines
include/linux/pm.h +6 -0
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.

Why?

Hmm, you're right. This is the other way around - if a device allocates too much RAM, we won't have enough memory to create the image.

Quoted 6 lines

include/linux/pm.h typedef struct pm_message { · line 149

Quoted 3 lines
include/linux/pm.h +3 -0
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Quoted 8 lines

include/linux/pm.h typedef struct pm_message { · line 156

Quoted 6 lines
include/linux/pm.h +6 -0
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to

s/unsucessfully/unsuccessfully

Thanks, will fix.

Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#16 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Nigel Cunningham
Quoted 1 line · Nigel Cunningham

Hi Rafael.

Hi,

Quoted 8 lines

Please excuse me, but I'm going to ask the questions you get from someone who hasn't followed development to date, and is thus reading the explanation without prior knowledge. Hopefully that will be helpful when you come to finalising the commit message.

Quoted 2 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Quoted 7 lines
Quoted 3 lines

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Quoted 10 lines
Quoted 4 lines

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

'Respectively' doesn't look like the right word to use, but I'm not sure I understand correctly what you're trying to say. The way it's written at the moment, it sounds to me like you're saying that suspend_late() and resume_early are deprecated, but you're modifying the PM core to use them.

Yes, the changelog is wrong, because I used a separate structure for the _noirq callbacks and (quite blindly) change the name of the structure in the changelog, instead of reworking it.

Quoted 8 lines
Quoted 6 lines

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

s/particualr,/particular

Yes, thanks.

Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

Quoted 18 lines
Quoted 9 lines

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified. This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

Quoted 8 lines

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Quoted 2 lines

Do these changes allow for other power state possibilities besides suspend to ram and hibernate (eg on other platforms)?

The other states fall into the "suspend" category.

Quoted 52 lines
Quoted 52 lines

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)

Index: linux-2.6/include/linux/pm.h
===================================================================

include/linux/pm.h +17 -1
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
Quoted 8 lines

include/linux/pm.h typedef struct pm_message { · line 146

Quoted 6 lines
include/linux/pm.h +6 -0
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.

Why?

Hmm, you're right. This is the other way around - if a device allocates too much RAM, we won't have enough memory to create the image.

Quoted 6 lines

include/linux/pm.h typedef struct pm_message { · line 149

Quoted 3 lines
include/linux/pm.h +3 -0
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Quoted 8 lines

include/linux/pm.h typedef struct pm_message { · line 156

Quoted 6 lines
include/linux/pm.h +6 -0
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to

s/unsucessfully/unsuccessfully

Thanks, will fix.

Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

Alan Stern

#18 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

Alan Stern

#19 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Hi.

Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Agreed.

Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

What if the same driver is handling multiple instances and only some of them fail to resume?

Regards,

Nigel

#20 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 9 lines · Nigel Cunningham

Hi.

Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Agreed.

This was a mistake explained in another message. The "don't" should not be present in the above sentence.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

What if the same driver is handling multiple instances and only some of them fail to resume?

->resume() will be called separately for each of them.

Thanks,
Rafael

#21 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Nigel Cunningham
Quoted 9 lines · Nigel Cunningham

Hi.

Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Agreed.

This was a mistake explained in another message. The "don't" should not be present in the above sentence.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

What if the same driver is handling multiple instances and only some of them fail to resume?

->resume() will be called separately for each of them.

Thanks,
Rafael

#22 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern

Hi.

Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

Agreed.

Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

What if the same driver is handling multiple instances and only some of them fail to resume?

Regards,

Nigel

#23 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern
Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

No, it has more pointers. Specifically, it is like

struct pm_ext_ops {
	struct pm_ops base;
	--additional pointers go here--
}
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

Yes, it does. In that cases, the error code would tell the PM core not to attempt to resume the device's children etc. Otherwise, it's quite meaningless to the PM core, because it really can mean anything and how's the PM core supposed to handle _that_?

Either we decide that the error codes returned by ->resume() mean critical errors or there's no point in returning error codes from ->resume() at all (other than logging the errors by the core).

Well, that's getting confused. I think I'll have to rework the patch not to really handle the errors returned by ->resume() and friends, after all, but I'll keep the reporting of them.

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Thanks,
Rafael

#24 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern
Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 6 lines
Quoted 2 lines

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks.

Something's wrong here. This seems to say that the "extended" version has _fewer_ method pointers -- in which case it should be called "restricted" instead.

No, it has more pointers. Specifically, it is like

struct pm_ext_ops {
	struct pm_ops base;
	--additional pointers go here--
}
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

I think so.

IMO, an error code returned by a driver's ->resume() should mean "the device hasn't resumed and is presumably dead". Otherwise, ->resume() should return success.

If the device is gone, it doesn't much matter what resume() returns.

Yes, it does. In that cases, the error code would tell the PM core not to attempt to resume the device's children etc. Otherwise, it's quite meaningless to the PM core, because it really can mean anything and how's the PM core supposed to handle _that_?

Either we decide that the error codes returned by ->resume() mean critical errors or there's no point in returning error codes from ->resume() at all (other than logging the errors by the core).

Well, that's getting confused. I think I'll have to rework the patch not to really handle the errors returned by ->resume() and friends, after all, but I'll keep the reporting of them.

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Thanks,
Rafael

#25 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line

If the device is gone, it doesn't much matter what resume() returns.

Yes, it does. In that cases, the error code would tell the PM core not to attempt to resume the device's children etc.

If the device is gone then so are its descendants, right? So it doesn't matter whether the PM core tries to resume them.

Quoted 3 lines

Otherwise, it's quite meaningless to the
PM core, because it really can mean anything and how's the PM core supposed to handle _that_?

Exactly. This is the point I was trying to make a week or so ago.

Quoted 4 lines

Either we decide that the error codes returned by ->resume() mean critical errors or there's no point in returning error codes from ->resume() at all (other than logging the errors by the core).

Quoted 8 lines

Well, that's getting confused. I think I'll have to rework the patch not to really handle the errors returned by ->resume() and friends, after all, but I'll keep the reporting of them.

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Agreed. The most important aspect is that drivers should _not_ return an error if the device is working correctly. We should fix the drivers which make this mistake.

Alan Stern

#26 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line

If the device is gone, it doesn't much matter what resume() returns.

Yes, it does. In that cases, the error code would tell the PM core not to attempt to resume the device's children etc.

If the device is gone then so are its descendants, right? So it doesn't matter whether the PM core tries to resume them.

Quoted 3 lines

Otherwise, it's quite meaningless to the
PM core, because it really can mean anything and how's the PM core supposed to handle _that_?

Exactly. This is the point I was trying to make a week or so ago.

Quoted 4 lines

Either we decide that the error codes returned by ->resume() mean critical errors or there's no point in returning error codes from ->resume() at all (other than logging the errors by the core).

Quoted 8 lines

Well, that's getting confused. I think I'll have to rework the patch not to really handle the errors returned by ->resume() and friends, after all, but I'll keep the reporting of them.

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Agreed. The most important aspect is that drivers should _not_ return an error if the device is working correctly. We should fix the drivers which make this mistake.

Alan Stern

#27 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Am Mittwoch, 2. April 2008 16:11:14 schrieb Alan Stern:

Quoted 8 lines
Quoted 4 lines

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Agreed.  The most important aspect is that drivers should _not_ return an error if the device is working correctly.  We should fix the drivers which make this mistake.

We need to do something about devices that don't want to be resumed. There's code like this:

static int usb_resume(struct device *dev)

{
	struct usb_device	*udev;

	if (!is_usb_device(dev))	/* Ignore PM for interfaces */
		return 0;
	udev = to_usb_device(dev);

	/* If udev->skip_sys_resume is set then udev was already suspended
	 * when the system suspend started, so we don't want to resume
	 * udev during this system wakeup.  However a reset-resume counts
	 * as a wakeup event, so allow a reset-resume to occur if remote
	 * wakeup is enabled. */
	if (udev->skip_sys_resume) {
		if (!(udev->reset_resume && udev->do_remote_wakeup))
			return -EHOSTUNREACH;
	}
	return usb_external_resume_device(udev);
}

Do we want to keep this in the subsystems?

Regards
Oliver

#28 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern

Am Mittwoch, 2. April 2008 16:11:14 schrieb Alan Stern:

Quoted 8 lines
Quoted 4 lines

However, I'd like to add a recommendation that the _new_ "resume" callbacks should only return errors in critical situations as the indication to the PM core that something went _really_ wrong and the device in question is quite surely unusable.

Agreed.  The most important aspect is that drivers should _not_ return an error if the device is working correctly.  We should fix the drivers which make this mistake.

We need to do something about devices that don't want to be resumed. There's code like this:

static int usb_resume(struct device *dev)

{
	struct usb_device	*udev;

	if (!is_usb_device(dev))	/* Ignore PM for interfaces */
		return 0;
	udev = to_usb_device(dev);

	/* If udev->skip_sys_resume is set then udev was already suspended
	 * when the system suspend started, so we don't want to resume
	 * udev during this system wakeup.  However a reset-resume counts
	 * as a wakeup event, so allow a reset-resume to occur if remote
	 * wakeup is enabled. */
	if (udev->skip_sys_resume) {
		if (!(udev->reset_resume && udev->do_remote_wakeup))
			return -EHOSTUNREACH;
	}
	return usb_external_resume_device(udev);
}

Do we want to keep this in the subsystems?

Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#29 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 24 lines · Oliver Neukum

We need to do something about devices that don't want to be resumed. There's code like this:

static int usb_resume(struct device *dev)

{
	struct usb_device	*udev;

	if (!is_usb_device(dev))	/* Ignore PM for interfaces */
		return 0;
	udev = to_usb_device(dev);

	/* If udev->skip_sys_resume is set then udev was already suspended
	 * when the system suspend started, so we don't want to resume
	 * udev during this system wakeup.  However a reset-resume counts
	 * as a wakeup event, so allow a reset-resume to occur if remote
	 * wakeup is enabled. */
	if (udev->skip_sys_resume) {
		if (!(udev->reset_resume && udev->do_remote_wakeup))
			return -EHOSTUNREACH;
	}
	return usb_external_resume_device(udev);
}
Quoted 1 line

Do we want to keep this in the subsystems?

Basically yes. Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

But under these circumstances we don't want to return an error code, since nothing really went wrong in the method. So the -EHOSTUNREACH should be changed to 0.

Alan Stern

#30 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Oliver Neukum
Quoted 24 lines · Oliver Neukum

We need to do something about devices that don't want to be resumed. There's code like this:

static int usb_resume(struct device *dev)

{
	struct usb_device	*udev;

	if (!is_usb_device(dev))	/* Ignore PM for interfaces */
		return 0;
	udev = to_usb_device(dev);

	/* If udev->skip_sys_resume is set then udev was already suspended
	 * when the system suspend started, so we don't want to resume
	 * udev during this system wakeup.  However a reset-resume counts
	 * as a wakeup event, so allow a reset-resume to occur if remote
	 * wakeup is enabled. */
	if (udev->skip_sys_resume) {
		if (!(udev->reset_resume && udev->do_remote_wakeup))
			return -EHOSTUNREACH;
	}
	return usb_external_resume_device(udev);
}
Quoted 1 line

Do we want to keep this in the subsystems?

Basically yes. Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

But under these circumstances we don't want to return an error code, since nothing really went wrong in the method. So the -EHOSTUNREACH should be changed to 0.

Alan Stern

#31 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Regards
Oliver

#32 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 10 lines · Oliver Neukum

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

Alan Stern

#33 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#34 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Am Mittwoch, 2. April 2008 18:42:15 schrieb Alan Stern:

Quoted 13 lines · Oliver Neukum
Quoted 11 lines

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Quoted 5 lines

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

But how is usb_autoresume_device() supposed to take to the driver? Furthermore suppose the interface woken up is storage. This will have to work across subsystem borders. Why not put it into generic code?

Regards
Oliver

#35 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern

Am Mittwoch, 2. April 2008 18:42:15 schrieb Alan Stern:

Quoted 13 lines · Oliver Neukum
Quoted 11 lines

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Quoted 5 lines

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

But how is usb_autoresume_device() supposed to take to the driver? Furthermore suppose the interface woken up is storage. This will have to work across subsystem borders. Why not put it into generic code?

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#36 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 20 lines · Oliver Neukum

Am Mittwoch, 2. April 2008 18:42:15 schrieb Alan Stern:

Quoted 13 lines · Oliver Neukum
Quoted 11 lines

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Quoted 5 lines

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

Quoted 3 lines

But how is usb_autoresume_device() supposed to take to the driver? Furthermore suppose the interface woken up is storage. This will have to work across subsystem borders. Why not put it into generic code?

I'm not sure exactly what you're asking. However it's worth mentioning that once the dust from Rafael's changes settles down, I intend to submit a patch creating new PM_EVENT_* codes:

PM_EVENT_USER_SUSPEND
PM_EVENT_USER_RESUME
PM_EVENT_REMOTE_WAKEUP
PM_EVENT_AUTOSUSPEND
PM_EVENT_AUTORESUME

(and the corresponding PMSG_* definitions). The PM core will never use the new codes, but subsystems like USB will be able to use them internally. Does that answer your question?

Alan Stern

#37 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Oliver Neukum
Quoted 20 lines · Oliver Neukum

Am Mittwoch, 2. April 2008 18:42:15 schrieb Alan Stern:

Quoted 13 lines · Oliver Neukum
Quoted 11 lines

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Quoted 5 lines

Which callbacks are you referring to? When lsusb opens a device and does an autoresume, it does not call the same routine as the PM core does when resuming from a system sleep. lsusb ends up calling usb_autoresume_device() whereas the PM core ends up calling usb_resume(), which is the function you quoted earlier.

Quoted 3 lines

But how is usb_autoresume_device() supposed to take to the driver? Furthermore suppose the interface woken up is storage. This will have to work across subsystem borders. Why not put it into generic code?

I'm not sure exactly what you're asking. However it's worth mentioning that once the dust from Rafael's changes settles down, I intend to submit a patch creating new PM_EVENT_* codes:

PM_EVENT_USER_SUSPEND
PM_EVENT_USER_RESUME
PM_EVENT_REMOTE_WAKEUP
PM_EVENT_AUTOSUSPEND
PM_EVENT_AUTORESUME

(and the corresponding PMSG_* definitions). The PM core will never use the new codes, but subsystems like USB will be able to use them internally. Does that answer your question?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#38 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Alan Stern

Am Mittwoch, 2. April 2008 17:13:11 schrieb Alan Stern:

Quoted 5 lines

Basically yes.  Subsystems and drivers are allowed to keep devices suspended if they were suspended before the system went to sleep. Remember, the purpose of the resume method is to let drivers know that the system is now awake, not to force them to put their devices into a high-power state.

Well, sometimes it is exactly that what we desire, eg. as a side effect of lsusb. Should the callbacks have different semantics depending on the reason you call them? And how should that information be transferred?

Regards
Oliver

#39 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Do you mean to say in the first sentence "...that _do_ need to implement..."? If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Regards,

Nigel

#40 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 10 lines · Nigel Cunningham

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Do you mean to say in the first sentence "...that _do_ need to implement..."?

Yes, sorry.

Quoted 12 lines

If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Quoted 6 lines
Quoted 1 line

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

Thanks,
Rafael

#41 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Hi.

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Nigel Cunningham

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Quoted 3 lines
Quoted 1 line

Do you mean to say in the first sentence "...that _do_ need to implement..."?

Yes, sorry.

Okay. Thanks!

Quoted 14 lines
Quoted 14 lines

If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Quoted 7 lines
Quoted 4 lines

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Hmm. Yet another notifier?

Quoted 7 lines
Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Quoted 6 lines

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

For suspend, I agree with dropping its use. For hibernation...

Nigel

#42 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 7 lines · Nigel Cunningham

Hi.

Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Nigel Cunningham

Hi Rafael etc.

On Tue, 2008-04-01 at 22:12 +0200, Rafael J. Wysocki wrote:

[--snip--]

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

Quoted 4 lines
Quoted 2 lines

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Hmm. Yet another notifier?

Well, perhaps it's better to disable user mode helpers directly from freeze_processes().

Still, let's do one thing at a time. :-)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Quoted 8 lines
Quoted 6 lines

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

For suspend, I agree with dropping its use. For hibernation...

I'm not sure and that's why I added the comment about the availability of the user space during ->prepare().

Besides, for now, the freezer is necessary anyway, even for suspend.

Thanks,
Rafael

#43 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Nigel Cunningham
Quoted 7 lines · Nigel Cunningham

Hi.

Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Nigel Cunningham

Hi Rafael etc.

On Tue, 2008-04-01 at 22:12 +0200, Rafael J. Wysocki wrote:

[--snip--]

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

Quoted 4 lines
Quoted 2 lines

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Hmm. Yet another notifier?

Well, perhaps it's better to disable user mode helpers directly from freeze_processes().

Still, let's do one thing at a time. :-)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Quoted 8 lines
Quoted 6 lines

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

For suspend, I agree with dropping its use. For hibernation...

I'm not sure and that's why I added the comment about the availability of the user space during ->prepare().

Besides, for now, the freezer is necessary anyway, even for suspend.

Thanks,
Rafael

#44 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki

Hi.

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Nigel Cunningham

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Quoted 3 lines
Quoted 1 line

Do you mean to say in the first sentence "...that _do_ need to implement..."?

Yes, sorry.

Okay. Thanks!

Quoted 14 lines
Quoted 14 lines

If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Quoted 7 lines
Quoted 4 lines

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Hmm. Yet another notifier?

Quoted 7 lines
Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Quoted 6 lines

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

For suspend, I agree with dropping its use. For hibernation...

Nigel

#45 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Nigel Cunningham
Quoted 10 lines · Nigel Cunningham

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Do you mean to say in the first sentence "...that _do_ need to implement..."?

Yes, sorry.

Quoted 12 lines

If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

Quoted 6 lines
Quoted 1 line

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

This is a tricky stuff, though, because the notifier is used for disabling the user mode helpers too ...

Quoted 6 lines

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Well, I'm just not sure if dropping the freezer entirely will actually work, but we won't know that if we don't try.

There's been a lot of pressure on going into this direction recently and in principle it seems to be doable at least for suspend. Hibernation is another issue, but IMO it's better to focus on suspend first.

Thanks,
Rafael

#46 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki

Hi Rafael etc.

Quoted 5 lines · Rafael J. Wysocki

'ext' means 'extended'. The idea is that the 'extended' version will be used by bus types / driver types that don't need to implement the _noirq callbacks. Both the platform and PCI bus types generally allow drivers to use _noirq callbacks, so they use 'struct pm_ext_ops', as well as their corresponding driver types.

Do you mean to say in the first sentence "...that _do_ need to implement..."? If not, then extended sounds like a misnomer and the two sentences seem to contradict one another.

[...]

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+ * However, drivers may NOT assume anything about the availability of the
+ * user space at that time and it is not correct to request firmware from
+ * within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

That will be possible when we drop the freezer.

Yeah, but right now, it seems to me to be a bogus limitation for drivers to have no way of automatically loading firmware when you're about to hibernate. (Of course I've since been reminded of the notifier chain - that should probably be mentioned here as the way of achieving this).

By the way, I'm going to go on record now as saying I think dropping the freezer is a silly idea. I'm therefore currently considering including the freezer in TuxOnice from the time it gets dropped from mainline. I know that will only make it less likely that TuxOnIce gets merged, but I've given up caring about that anyway - caring about merging is pointless when the people who decide if it gets merged don't care.

Regards,

Nigel

#47 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki

Hi Rafael.

Please excuse me, but I'm going to ask the questions you get from someone who hasn't followed development to date, and is thus reading the explanation without prior knowledge. Hopefully that will be helpful when you come to finalising the commit message.

Quoted 5 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Does ..._ext_... mean extended? (external?) If 'extended' (or if not), does that imply that they're mutually exclusive alternatives for drivers to use?

Quoted 4 lines

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

'Respectively' doesn't look like the right word to use, but I'm not sure I understand correctly what you're trying to say. The way it's written at the moment, it sounds to me like you're saying that suspend_late() and resume_early are deprecated, but you're modifying the PM core to use them.

Quoted 6 lines

Change the behavior of the PM core wrt the error codes returned by device drivers' ->resume() callbacks. Namely, if an error code is returned by one of them, the device for which it's been returned is regarded as "invalid" by the PM core which will refuse to handle it from that point on (in particualr, suspend/hibernation will not be started if there is an "invalid" device in the system).

s/particualr,/particular

So drivers can never validly fail to resume. That sounds fair enough. If the hardware has gone away while in lower power mode (USB, say), should the driver then just printk an error and return success?

Quoted 9 lines

The main purpose of doing this is to separate suspend (aka S2RAM and standby) callbacks from hibernation callbacks in such a way that the new callbacks won't take arguments and the semantics of each of them will be clearly specified. This has been requested for multiple times by many people, including Linus himself, and the reason is that within the current scheme if ->resume() is called, for example, it's difficult to say why it's been called (ie. is it a resume from RAM or from hibernation or a suspend/hibernation failure etc.?).

Quoted 8 lines

The second purpose is to make the suspend/hibernation callbacks more flexible so that device drivers can handle more than they can within the current scheme. For example, some drivers may need to prevent new children of the device from being registered before their ->suspend() callbacks are executed or they may want to carry out some operations requiring the availability of some other devices, not directly bound via the parent-child relationship, in order to prepare for the execution of ->suspend(), etc.

Do these changes allow for other power state possibilities besides suspend to ram and hibernate (eg on other platforms)?

Quoted 48 lines

Ultimately, we'd like to stop using the freezing of tasks for suspend and therefore the drivers' suspend/hibernation code will have to take care of the handling of the user space during suspend/hibernation. That, in turn, would be difficult within the current scheme, without the new ->prepare() and ->complete() callbacks.

---

 arch/x86/kernel/apm_32.c   |    4 
 drivers/base/power/main.c  |  706 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  318 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 870 insertions(+), 199 deletions(-)

Index: linux-2.6/include/linux/pm.h
===================================================================

include/linux/pm.h +13 -1
@@ -114,7 +114,9 @@ typedef struct pm_message {
 	int event;
 } pm_message_t;
 
-/*
+/**
+ * struct pm_ops - device PM callbacks
+ *
  * Several driver power state transitions are externally visible, affecting
  * the state of pending I/O queues and (for drivers that touch hardware)
  * interrupts, wakeups, DMA, and other hardware state.  There may also be
@@ -122,6 +124,288 @@ typedef struct pm_message {
  * to the rest of the driver stack (such as a driver that's ON gating off
  * clocks which are not in active use).
  *
+ * The externally visible transitions are handled with the help of the following
+ * callbacks included in this structure:
+ *
+ * @prepare: Prepare the device for the upcoming transition, but do NOT change
+ *	its hardware state.  Prevent new children of the device from being
+ *	registered after @prepare() returns (the driver's subsystem and
+ *	generally the rest of the kernel is supposed to prevent new calls to the
+ *	probe method from being made too once @prepare() has succeeded).  If
+ *	@prepare() detects a situation it cannot handle (e.g. registration of a
+ *	child already in progress), it may return -EAGAIN, so that the PM core

include/linux/pm.h typedef struct pm_message { · line 146

Quoted 10 lines
include/linux/pm.h +10 -0
+ *	can execute it once again (e.g. after the new child has been registered)
+ *	to recover from the race condition.  This method is executed for all
+ *	kinds of suspend transitions and is followed by one of the suspend
+ *	callbacks: @suspend(), @freeze(), or @poweroff().
+ *	The PM core executes @prepare() for all devices before starting to
+ *	execute suspend callbacks for any of them, so drivers may assume all of
+ *	the other devices to be present and functional while @prepare() is being
+ *	executed.  In particular, it is safe to make GFP_KERNEL memory
+ *	allocations from within @prepare(), although they are likely to fail in
+ *	case of hibernation, if a substantial amount of memory is requested.

Why?

include/linux/pm.h typedef struct pm_message { · line 149

Quoted 3 lines
include/linux/pm.h +3 -0
+ *	However, drivers may NOT assume anything about the availability of the
+ *	user space at that time and it is not correct to request firmware from
+ *	within @prepare() (it's too late to do that).

That doesn't sound good. It would be good to be able to get drivers to request firmware early in the process.

include/linux/pm.h typedef struct pm_message { · line 156

Quoted 6 lines
include/linux/pm.h +6 -0
+ * @complete: Undo the changes made by @prepare().  This method is executed for
+ *	all kinds of resume transitions, following one of the resume callbacks:
+ *	@resume(), @thaw(), @restore().  Also called if the state transition
+ *	fails before the driver's suspend callback (@suspend(), @freeze(),
+ *	@poweroff()) can be executed (e.g. if the suspend callback fails for one
+ *	of the other devices that the PM core has unsucessfully attempted to

s/unsucessfully/unsuccessfully

Regards,

Nigel

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#48 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 10 lines

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Quoted 5 lines
Quoted 1 line

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

The drivers should be fixed not to do that, no?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#49 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Rafael J. Wysocki
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 10 lines

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Quoted 5 lines
Quoted 1 line

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

The drivers should be fixed not to do that, no?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#50 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

Quoted 17 lines · Pavel Machek
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 10 lines

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

The drivers should be fixed not to do that, no?

The problem is we generally don't know which drivers do that. I know a few, but there probably are others.

So, the idea is to allow them to do that for some time, but log error messages indicating which drivers they are. These messages will then allow us to fix the drivers and once they've been fixed, we can apply a (very simple) patch to change the behavior of the core (this patch will be easy to revert if need be, whereas I really wouldn't like to be forced to revert the $subject patch by predictable regressions).

Thanks,
Rafael

#51 lore raw

Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 6)

In reply to Pavel Machek
Quoted 17 lines · Pavel Machek
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 10 lines

From: Rafael J. Wysocki <[email protected]>

Introduce 'struct pm_ops' and 'struct pm_ext_ops' representing suspend and hibernation operations for bus types, device classes and device types.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend() and ->resume() or, respectively, ->suspend_late() and ->resume_early() callbacks that will be considered as legacy and gradually phased out.

Unfortunately I forgot to set dev->power.status to DPM_PREPARING before calling ->prepare(), as documented. Also, dpm_prepare() could cleaned up a bit.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Fixed patch follows.

My testing shows that some drivers tend to return error codes from their ->resume() callbacks, even though the devices in question appear to work correctly after the seemingly failing suspend.

The drivers should be fixed not to do that, no?

The problem is we generally don't know which drivers do that. I know a few, but there probably are others.

So, the idea is to allow them to do that for some time, but log error messages indicating which drivers they are. These messages will then allow us to fix the drivers and once they've been fixed, we can apply a (very simple) patch to change the behavior of the core (this patch will be easy to revert if need be, whereas I really wouldn't like to be forced to revert the $subject patch by predictable regressions).

Thanks,
Rafael

#52 lore raw

RFC PATCH 2/3 PM: New suspend and hibernation callbacks for platform bus type (rev. 3)

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

---
 drivers/base/platform.c         |  296 ++++++++++++++++++++++++++++++++++++++--
 include/linux/platform_device.h |    1 
 2 files changed, 289 insertions(+), 8 deletions(-)
include/linux/platform_device.h +1 -0
Index: linux-2.6/include/linux/platform_device.h
===================================================================
@@ -53,6 +53,7 @@ struct platform_driver {
 	int (*suspend_late)(struct platform_device *, pm_message_t state);
 	int (*resume_early)(struct platform_device *);
 	int (*resume)(struct platform_device *);
+	struct pm_ext_ops *pm;
 	struct device_driver driver;
 };
 
drivers/base/platform.c +288 -8

337 lines not on this page · raw message

#53 lore raw

RFC PATCH 2/3 PM: New suspend and hibernation callbacks for platform bus type (rev. 3)

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

---
 drivers/base/platform.c         |  296 ++++++++++++++++++++++++++++++++++++++--
 include/linux/platform_device.h |    1 
 2 files changed, 289 insertions(+), 8 deletions(-)
include/linux/platform_device.h +1 -0
Index: linux-2.6/include/linux/platform_device.h
===================================================================
@@ -53,6 +53,7 @@ struct platform_driver {
 	int (*suspend_late)(struct platform_device *, pm_message_t state);
 	int (*resume_early)(struct platform_device *);
 	int (*resume)(struct platform_device *);
+	struct pm_ext_ops *pm;
 	struct device_driver driver;
 };
 
drivers/base/platform.c +288 -8

337 lines not on this page · raw message

#54 lore raw

Re: [RFC][PATCH 2/3] PM: New suspend and hibernation callbacks for platform bus type (rev. 3)

Quoted 4 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

I found a bug in this patch. Namely, platform_legacy_suspend_late() was used instead of platform_legacy_suspend() and vice versa in platform_pm_freeze() and platform_pm_freeze_noirq().

Corrected patch follows.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

---
 drivers/base/platform.c         |  296 ++++++++++++++++++++++++++++++++++++++--
 include/linux/platform_device.h |    1 
 2 files changed, 289 insertions(+), 8 deletions(-)
include/linux/platform_device.h +1 -0
Index: linux-2.6/include/linux/platform_device.h
===================================================================
@@ -53,6 +53,7 @@ struct platform_driver {
 	int (*suspend_late)(struct platform_device *, pm_message_t state);
 	int (*resume_early)(struct platform_device *);
 	int (*resume)(struct platform_device *);
+	struct pm_ext_ops *pm;
 	struct device_driver driver;
 };
 
drivers/base/platform.c +288 -8

337 lines not on this page · raw message

#55 lore raw

Re: [RFC][PATCH 2/3] PM: New suspend and hibernation callbacks for platform bus type (rev. 3)

In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

I found a bug in this patch. Namely, platform_legacy_suspend_late() was used instead of platform_legacy_suspend() and vice versa in platform_pm_freeze() and platform_pm_freeze_noirq().

Corrected patch follows.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the platform bus type.

---
 drivers/base/platform.c         |  296 ++++++++++++++++++++++++++++++++++++++--
 include/linux/platform_device.h |    1 
 2 files changed, 289 insertions(+), 8 deletions(-)
include/linux/platform_device.h +1 -0
Index: linux-2.6/include/linux/platform_device.h
===================================================================
@@ -53,6 +53,7 @@ struct platform_driver {
 	int (*suspend_late)(struct platform_device *, pm_message_t state);
 	int (*resume_early)(struct platform_device *);
 	int (*resume)(struct platform_device *);
+	struct pm_ext_ops *pm;
 	struct device_driver driver;
 };
 
drivers/base/platform.c +288 -8

337 lines not on this page · raw message

#56 lore raw

RFC PATCH 3/3 PM: New suspend and hibernation callbacks for PCI bus type (rev. 3)

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the PCI bus type.

---
 drivers/pci/pci-driver.c |  371 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 334 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +333 -38
Index: linux-2.6/drivers/pci/pci-driver.c
===================================================================
@@ -271,7 +271,52 @@ static int pci_device_remove(struct devi
 	return 0;
 }
 
-static int pci_device_suspend(struct device * dev, pm_message_t state)
+static void pci_device_shutdown(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+
+	if (drv && drv->shutdown)
+		drv->shutdown(pci_dev);
+}
+
+#ifdef CONFIG_PM_SLEEP
+
+/*
+ * Default "suspend" method for devices that have no driver provided suspend,
+ * or not even a driver at all.
+ */
+static void pci_default_pm_suspend(struct pci_dev *pci_dev)
+{
+	pci_save_state(pci_dev);
+	/*
+	 * mark its power state as "unknown", since we don't know if
+	 * e.g. the BIOS will change its device state when we suspend.
+	 */
+	if (pci_dev->current_state == PCI_D0)
+		pci_dev->current_state = PCI_UNKNOWN;
+}
+
+/*
+ * Default "resume" method for devices that have no driver provided resume,
+ * or not even a driver at all.
+ */
+static int pci_default_pm_resume(struct pci_dev *pci_dev)
+{
+	int retval = 0;
+
+	/* restore the PCI config space */
+	pci_restore_state(pci_dev);
+	/* if the device was enabled before suspend, reenable */
+	retval = pci_reenable_device(pci_dev);
+	/* if the device was busmaster before the suspend, make it busmaster again */
+	if (pci_dev->is_busmaster)
+		pci_set_master(pci_dev);
+
+	return retval;
+}
+
+static int pci_legacy_suspend(struct device * dev, pm_message_t state)
 {
 	struct pci_dev * pci_dev = to_pci_dev(dev);
 	struct pci_driver * drv = pci_dev->driver;
@@ -281,18 +326,12 @@ static int pci_device_suspend(struct dev
 		i = drv->suspend(pci_dev, state);
 		suspend_report_result(drv->suspend, i);
 	} else {
-		pci_save_state(pci_dev);
-		/*
-		 * mark its power state as "unknown", since we don't know if
-		 * e.g. the BIOS will change its device state when we suspend.
-		 */
-		if (pci_dev->current_state == PCI_D0)
-			pci_dev->current_state = PCI_UNKNOWN;
+		pci_default_pm_suspend(pci_dev);
 	}
 	return i;
 }
 
-static int pci_device_suspend_late(struct device * dev, pm_message_t state)
+static int pci_legacy_suspend_late(struct device * dev, pm_message_t state)
 {
 	struct pci_dev * pci_dev = to_pci_dev(dev);
 	struct pci_driver * drv = pci_dev->driver;
@@ -305,26 +344,7 @@ static int pci_device_suspend_late(struc
 	return i;
 }
 
-/*
- * Default resume method for devices that have no driver provided resume,
- * or not even a driver at all.
- */
-static int pci_default_resume(struct pci_dev *pci_dev)
-{
-	int retval = 0;
-
-	/* restore the PCI config space */
-	pci_restore_state(pci_dev);
-	/* if the device was enabled before suspend, reenable */
-	retval = pci_reenable_device(pci_dev);
-	/* if the device was busmaster before the suspend, make it busmaster again */
-	if (pci_dev->is_busmaster)
-		pci_set_master(pci_dev);
-
-	return retval;
-}
-
-static int pci_device_resume(struct device * dev)
+static int pci_legacy_resume(struct device * dev)
 {
 	int error;
 	struct pci_dev * pci_dev = to_pci_dev(dev);
@@ -333,11 +353,11 @@ static int pci_device_resume(struct devi
 	if (drv && drv->resume)
 		error = drv->resume(pci_dev);
 	else
-		error = pci_default_resume(pci_dev);
+		error = pci_default_pm_resume(pci_dev);
 	return error;
 }
 
-static int pci_device_resume_early(struct device * dev)
+static int pci_legacy_resume_early(struct device * dev)
 {
 	int error = 0;
 	struct pci_dev * pci_dev = to_pci_dev(dev);
@@ -350,15 +370,290 @@ static int pci_device_resume_early(struc
 	return error;
 }
 
-static void pci_device_shutdown(struct device *dev)
+static int pci_pm_prepare(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm && drv->pm->prepare)
+		error = drv->pm->prepare(dev);
+
+	return error;
+}
+
+static void pci_pm_complete(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+
+	if (drv && drv->pm && drv->pm->complete)
+		drv->pm->complete(dev);
+}
+
+#ifdef CONFIG_SUSPEND
+
+static int pci_pm_suspend(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->suspend) {
+			error = drv->pm->suspend(dev);
+			suspend_report_result(drv->pm->suspend, error);
+		} else {
+			pci_default_pm_suspend(pci_dev);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_SUSPEND);
+	}
+
+	return error;
+}
+
+static int pci_pm_suspend_noirq(struct device *dev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
 
-	if (drv && drv->shutdown)
-		drv->shutdown(pci_dev);
+	if (drv && drv->pm) {
+		if (drv->pm->suspend_noirq) {
+			error = drv->pm->suspend_noirq(dev);
+			suspend_report_result(drv->pm->suspend_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_SUSPEND);
+	}
+
+	return error;
 }
 
+static int pci_pm_resume(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error;
+
+	if (drv && drv->pm) {
+		error = drv->pm->resume ? drv->pm->resume(dev) :
+			pci_default_pm_resume(pci_dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_resume_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	pci_fixup_device(pci_fixup_resume, pci_dev);
+
+	if (drv && drv->pm) {
+		if (drv->pm->resume_noirq)
+			error = drv->pm->resume_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define pci_pm_suspend		NULL
+#define pci_pm_suspend_noirq	NULL
+#define pci_pm_resume		NULL
+#define pci_pm_resume_noirq	NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int pci_pm_freeze(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->freeze) {
+			error = drv->pm->freeze(dev);
+			suspend_report_result(drv->pm->freeze, error);
+		} else {
+			pci_default_pm_suspend(pci_dev);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_FREEZE);
+	}
+
+	return error;
+}
+
+static int pci_pm_freeze_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->freeze_noirq) {
+			error = drv->pm->freeze_noirq(dev);
+			suspend_report_result(drv->pm->freeze_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_FREEZE);
+	}
+
+	return error;
+}
+
+static int pci_pm_thaw(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw)
+			error =  drv->pm->thaw(dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_thaw_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw_noirq)
+			error = drv->pm->thaw_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_poweroff(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff) {
+			error = drv->pm->poweroff(dev);
+			suspend_report_result(drv->pm->poweroff, error);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
+	}
+
+	return error;
+}
+
+static int pci_pm_poweroff_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff_noirq) {
+			error = drv->pm->poweroff_noirq(dev);
+			suspend_report_result(drv->pm->poweroff_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
+	}
+
+	return error;
+}
+
+static int pci_pm_restore(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error;
+
+	if (drv && drv->pm) {
+		error = drv->pm->restore ? drv->pm->restore(dev) :
+			pci_default_pm_resume(pci_dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_restore_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	pci_fixup_device(pci_fixup_resume, pci_dev);
+
+	if (drv && drv->pm) {
+		if (drv->pm->restore_noirq)
+			error = drv->pm->restore_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define pci_pm_freeze		NULL
+#define pci_pm_freeze_noirq	NULL
+#define pci_pm_thaw		NULL
+#define pci_pm_thaw_noirq	NULL
+#define pci_pm_poweroff		NULL
+#define pci_pm_poweroff_noirq	NULL
+#define pci_pm_restore		NULL
+#define pci_pm_restore_noirq	NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+struct pm_ext_ops pci_pm_ops = {
+	.base = {
+		.prepare = pci_pm_prepare,
+		.complete = pci_pm_complete,
+		.suspend = pci_pm_suspend,
+		.resume = pci_pm_resume,
+		.freeze = pci_pm_freeze,
+		.thaw = pci_pm_thaw,
+		.poweroff = pci_pm_poweroff,
+		.restore = pci_pm_restore,
+	},
+	.suspend_noirq = pci_pm_suspend_noirq,
+	.resume_noirq = pci_pm_resume_noirq,
+	.freeze_noirq = pci_pm_freeze_noirq,
+	.thaw_noirq = pci_pm_thaw_noirq,
+	.poweroff_noirq = pci_pm_poweroff_noirq,
+	.restore_noirq = pci_pm_restore_noirq,
+};
+
+#define PCI_PM_OPS_PTR	&pci_pm_ops
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define PCI_PM_OPS_PTR	NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
 /**
  * __pci_register_driver - register a new pci driver
  * @drv: the driver structure to register
@@ -381,6 +676,9 @@ int __pci_register_driver(struct pci_dri
 	drv->driver.owner = owner;
 	drv->driver.mod_name = mod_name;
 
+	if (drv->pm)
+		drv->driver.pm = &drv->pm->base;
+
 	spin_lock_init(&drv->dynids.lock);
 	INIT_LIST_HEAD(&drv->dynids.list);
 
@@ -506,12 +804,9 @@ struct bus_type pci_bus_type = {
 	.uevent		= pci_uevent,
 	.probe		= pci_device_probe,
 	.remove		= pci_device_remove,
-	.suspend	= pci_device_suspend,
-	.suspend_late	= pci_device_suspend_late,
-	.resume_early	= pci_device_resume_early,
-	.resume		= pci_device_resume,
 	.shutdown	= pci_device_shutdown,
 	.dev_attrs	= pci_dev_attrs,
+	.pm		= PCI_PM_OPS_PTR,
 };
 
 static int __init pci_driver_init(void)
include/linux/pci.h +1 -1
Index: linux-2.6/include/linux/pci.h
===================================================================
@@ -381,7 +381,7 @@ struct pci_driver {
 	int  (*resume_early) (struct pci_dev *dev);
 	int  (*resume) (struct pci_dev *dev);	                /* Device woken up */
 	void (*shutdown) (struct pci_dev *dev);
-
+	struct pm_ext_ops *pm;
 	struct pci_error_handlers *err_handler;
 	struct device_driver	driver;
 	struct pci_dynids dynids;
#57 lore raw

RFC PATCH 3/3 PM: New suspend and hibernation callbacks for PCI bus type (rev. 3)

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Implement new suspend and hibernation callbacks for the PCI bus type.

---
 drivers/pci/pci-driver.c |  371 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 334 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +333 -38
Index: linux-2.6/drivers/pci/pci-driver.c
===================================================================
@@ -271,7 +271,52 @@ static int pci_device_remove(struct devi
 	return 0;
 }
 
-static int pci_device_suspend(struct device * dev, pm_message_t state)
+static void pci_device_shutdown(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+
+	if (drv && drv->shutdown)
+		drv->shutdown(pci_dev);
+}
+
+#ifdef CONFIG_PM_SLEEP
+
+/*
+ * Default "suspend" method for devices that have no driver provided suspend,
+ * or not even a driver at all.
+ */
+static void pci_default_pm_suspend(struct pci_dev *pci_dev)
+{
+	pci_save_state(pci_dev);
+	/*
+	 * mark its power state as "unknown", since we don't know if
+	 * e.g. the BIOS will change its device state when we suspend.
+	 */
+	if (pci_dev->current_state == PCI_D0)
+		pci_dev->current_state = PCI_UNKNOWN;
+}
+
+/*
+ * Default "resume" method for devices that have no driver provided resume,
+ * or not even a driver at all.
+ */
+static int pci_default_pm_resume(struct pci_dev *pci_dev)
+{
+	int retval = 0;
+
+	/* restore the PCI config space */
+	pci_restore_state(pci_dev);
+	/* if the device was enabled before suspend, reenable */
+	retval = pci_reenable_device(pci_dev);
+	/* if the device was busmaster before the suspend, make it busmaster again */
+	if (pci_dev->is_busmaster)
+		pci_set_master(pci_dev);
+
+	return retval;
+}
+
+static int pci_legacy_suspend(struct device * dev, pm_message_t state)
 {
 	struct pci_dev * pci_dev = to_pci_dev(dev);
 	struct pci_driver * drv = pci_dev->driver;
@@ -281,18 +326,12 @@ static int pci_device_suspend(struct dev
 		i = drv->suspend(pci_dev, state);
 		suspend_report_result(drv->suspend, i);
 	} else {
-		pci_save_state(pci_dev);
-		/*
-		 * mark its power state as "unknown", since we don't know if
-		 * e.g. the BIOS will change its device state when we suspend.
-		 */
-		if (pci_dev->current_state == PCI_D0)
-			pci_dev->current_state = PCI_UNKNOWN;
+		pci_default_pm_suspend(pci_dev);
 	}
 	return i;
 }
 
-static int pci_device_suspend_late(struct device * dev, pm_message_t state)
+static int pci_legacy_suspend_late(struct device * dev, pm_message_t state)
 {
 	struct pci_dev * pci_dev = to_pci_dev(dev);
 	struct pci_driver * drv = pci_dev->driver;
@@ -305,26 +344,7 @@ static int pci_device_suspend_late(struc
 	return i;
 }
 
-/*
- * Default resume method for devices that have no driver provided resume,
- * or not even a driver at all.
- */
-static int pci_default_resume(struct pci_dev *pci_dev)
-{
-	int retval = 0;
-
-	/* restore the PCI config space */
-	pci_restore_state(pci_dev);
-	/* if the device was enabled before suspend, reenable */
-	retval = pci_reenable_device(pci_dev);
-	/* if the device was busmaster before the suspend, make it busmaster again */
-	if (pci_dev->is_busmaster)
-		pci_set_master(pci_dev);
-
-	return retval;
-}
-
-static int pci_device_resume(struct device * dev)
+static int pci_legacy_resume(struct device * dev)
 {
 	int error;
 	struct pci_dev * pci_dev = to_pci_dev(dev);
@@ -333,11 +353,11 @@ static int pci_device_resume(struct devi
 	if (drv && drv->resume)
 		error = drv->resume(pci_dev);
 	else
-		error = pci_default_resume(pci_dev);
+		error = pci_default_pm_resume(pci_dev);
 	return error;
 }
 
-static int pci_device_resume_early(struct device * dev)
+static int pci_legacy_resume_early(struct device * dev)
 {
 	int error = 0;
 	struct pci_dev * pci_dev = to_pci_dev(dev);
@@ -350,15 +370,290 @@ static int pci_device_resume_early(struc
 	return error;
 }
 
-static void pci_device_shutdown(struct device *dev)
+static int pci_pm_prepare(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm && drv->pm->prepare)
+		error = drv->pm->prepare(dev);
+
+	return error;
+}
+
+static void pci_pm_complete(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+
+	if (drv && drv->pm && drv->pm->complete)
+		drv->pm->complete(dev);
+}
+
+#ifdef CONFIG_SUSPEND
+
+static int pci_pm_suspend(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->suspend) {
+			error = drv->pm->suspend(dev);
+			suspend_report_result(drv->pm->suspend, error);
+		} else {
+			pci_default_pm_suspend(pci_dev);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_SUSPEND);
+	}
+
+	return error;
+}
+
+static int pci_pm_suspend_noirq(struct device *dev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
 
-	if (drv && drv->shutdown)
-		drv->shutdown(pci_dev);
+	if (drv && drv->pm) {
+		if (drv->pm->suspend_noirq) {
+			error = drv->pm->suspend_noirq(dev);
+			suspend_report_result(drv->pm->suspend_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_SUSPEND);
+	}
+
+	return error;
 }
 
+static int pci_pm_resume(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error;
+
+	if (drv && drv->pm) {
+		error = drv->pm->resume ? drv->pm->resume(dev) :
+			pci_default_pm_resume(pci_dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_resume_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	pci_fixup_device(pci_fixup_resume, pci_dev);
+
+	if (drv && drv->pm) {
+		if (drv->pm->resume_noirq)
+			error = drv->pm->resume_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define pci_pm_suspend		NULL
+#define pci_pm_suspend_noirq	NULL
+#define pci_pm_resume		NULL
+#define pci_pm_resume_noirq	NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int pci_pm_freeze(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->freeze) {
+			error = drv->pm->freeze(dev);
+			suspend_report_result(drv->pm->freeze, error);
+		} else {
+			pci_default_pm_suspend(pci_dev);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_FREEZE);
+	}
+
+	return error;
+}
+
+static int pci_pm_freeze_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->freeze_noirq) {
+			error = drv->pm->freeze_noirq(dev);
+			suspend_report_result(drv->pm->freeze_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_FREEZE);
+	}
+
+	return error;
+}
+
+static int pci_pm_thaw(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw)
+			error =  drv->pm->thaw(dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_thaw_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw_noirq)
+			error = drv->pm->thaw_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_poweroff(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff) {
+			error = drv->pm->poweroff(dev);
+			suspend_report_result(drv->pm->poweroff, error);
+		}
+	} else {
+		error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
+	}
+
+	return error;
+}
+
+static int pci_pm_poweroff_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff_noirq) {
+			error = drv->pm->poweroff_noirq(dev);
+			suspend_report_result(drv->pm->poweroff_noirq, error);
+		}
+	} else {
+		error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
+	}
+
+	return error;
+}
+
+static int pci_pm_restore(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct device_driver *drv = dev->driver;
+	int error;
+
+	if (drv && drv->pm) {
+		error = drv->pm->restore ? drv->pm->restore(dev) :
+			pci_default_pm_resume(pci_dev);
+	} else {
+		error = pci_legacy_resume(dev);
+	}
+
+	return error;
+}
+
+static int pci_pm_restore_noirq(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+	int error = 0;
+
+	pci_fixup_device(pci_fixup_resume, pci_dev);
+
+	if (drv && drv->pm) {
+		if (drv->pm->restore_noirq)
+			error = drv->pm->restore_noirq(dev);
+	} else {
+		error = pci_legacy_resume_early(dev);
+	}
+
+	return error;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define pci_pm_freeze		NULL
+#define pci_pm_freeze_noirq	NULL
+#define pci_pm_thaw		NULL
+#define pci_pm_thaw_noirq	NULL
+#define pci_pm_poweroff		NULL
+#define pci_pm_poweroff_noirq	NULL
+#define pci_pm_restore		NULL
+#define pci_pm_restore_noirq	NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+struct pm_ext_ops pci_pm_ops = {
+	.base = {
+		.prepare = pci_pm_prepare,
+		.complete = pci_pm_complete,
+		.suspend = pci_pm_suspend,
+		.resume = pci_pm_resume,
+		.freeze = pci_pm_freeze,
+		.thaw = pci_pm_thaw,
+		.poweroff = pci_pm_poweroff,
+		.restore = pci_pm_restore,
+	},
+	.suspend_noirq = pci_pm_suspend_noirq,
+	.resume_noirq = pci_pm_resume_noirq,
+	.freeze_noirq = pci_pm_freeze_noirq,
+	.thaw_noirq = pci_pm_thaw_noirq,
+	.poweroff_noirq = pci_pm_poweroff_noirq,
+	.restore_noirq = pci_pm_restore_noirq,
+};
+
+#define PCI_PM_OPS_PTR	&pci_pm_ops
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define PCI_PM_OPS_PTR	NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
 /**
  * __pci_register_driver - register a new pci driver
  * @drv: the driver structure to register
@@ -381,6 +676,9 @@ int __pci_register_driver(struct pci_dri
 	drv->driver.owner = owner;
 	drv->driver.mod_name = mod_name;
 
+	if (drv->pm)
+		drv->driver.pm = &drv->pm->base;
+
 	spin_lock_init(&drv->dynids.lock);
 	INIT_LIST_HEAD(&drv->dynids.list);
 
@@ -506,12 +804,9 @@ struct bus_type pci_bus_type = {
 	.uevent		= pci_uevent,
 	.probe		= pci_device_probe,
 	.remove		= pci_device_remove,
-	.suspend	= pci_device_suspend,
-	.suspend_late	= pci_device_suspend_late,
-	.resume_early	= pci_device_resume_early,
-	.resume		= pci_device_resume,
 	.shutdown	= pci_device_shutdown,
 	.dev_attrs	= pci_dev_attrs,
+	.pm		= PCI_PM_OPS_PTR,
 };
 
 static int __init pci_driver_init(void)
include/linux/pci.h +1 -1
Index: linux-2.6/include/linux/pci.h
===================================================================
@@ -381,7 +381,7 @@ struct pci_driver {
 	int  (*resume_early) (struct pci_dev *dev);
 	int  (*resume) (struct pci_dev *dev);	                /* Device woken up */
 	void (*shutdown) (struct pci_dev *dev);
-
+	struct pm_ext_ops *pm;
 	struct pci_error_handlers *err_handler;
 	struct device_driver	driver;
 	struct pci_dynids dynids;