Skip to contentSkip to conversation

PM: New suspend and hibernation callbacks

PATCH Applied Rafael J. Wysocki 9 participants 108 messages Apr 3, 2008 – May 7, 2008

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

cover PM: New suspend and hibernation callbacks

Hi Greg,

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

The first one introduces new callbacks for suspend and hibernation (7th revision). It also updates the PM core to use the new callbacks at the top level, allowing it to use the existing callbacks if the new ones are not defined.

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

The patches allow platform and pci drivers to start using the new callbacks immediately and similar patches for the other bus types etc. will follow. Still, until drivers actually start to implement the new callbacks, no functional changes are expected to appear as a result of these patches.

I think the patches have stabilized sufficiently for being pushed upstream, so please add them to your queue.

Thanks,
Rafael

#1 lore raw

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

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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  |  692 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 847 insertions(+), 204 deletions(-)
include/linux/pm.h +286 -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,284 @@ 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().  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).  [To work around this limitation, drivers may
+ *	register suspend and hibernation notifiers that are executed before the
+ *	freezing of tasks.]
+ *
+ * @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 unsuccessfully 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.  The error codes returned in
+ * that cases are only printed by the PM core to the system logs for debugging
+ * purposes.  Still, it is recommended that drivers only return error codes
+ * from their resume methods in case of an unrecoverable failure (i.e. when the
+ * device being handled refuses to resume and becomes unusable) to allow us to
+ * modify the PM core in the future, so that it can avoid attempting to handle
+ * devices that failed to resume and their children.
+ *
+ * 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.  The error codes returned in that cases are
+ * only printed by the PM core to the system logs for debugging purposes.
+ * Still, as stated above, it is recommended that drivers only return error
+ * codes from their resume methods if the device being handled fails to resume
+ * and is not usable any more.
+ */
+
+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_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 +446,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 +530 -162

906 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

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

In reply to Rafael J. Wysocki

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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  |  692 ++++++++++++++++++++++++++++++++++-----------
 drivers/base/power/power.h |    2 
 drivers/base/power/trace.c |    4 
 include/linux/device.h     |    9 
 include/linux/pm.h         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 847 insertions(+), 204 deletions(-)
include/linux/pm.h +286 -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,284 @@ 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().  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).  [To work around this limitation, drivers may
+ *	register suspend and hibernation notifiers that are executed before the
+ *	freezing of tasks.]
+ *
+ * @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 unsuccessfully 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.  The error codes returned in
+ * that cases are only printed by the PM core to the system logs for debugging
+ * purposes.  Still, it is recommended that drivers only return error codes
+ * from their resume methods in case of an unrecoverable failure (i.e. when the
+ * device being handled refuses to resume and becomes unusable) to allow us to
+ * modify the PM core in the future, so that it can avoid attempting to handle
+ * devices that failed to resume and their children.
+ *
+ * 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.  The error codes returned in that cases are
+ * only printed by the PM core to the system logs for debugging purposes.
+ * Still, as stated above, it is recommended that drivers only return error
+ * codes from their resume methods if the device being handled fails to resume
+ * and is not usable any more.
+ */
+
+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_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 +446,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 +530 -162

906 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: [PATCH 1/3] PM: Introduce new top level suspend and hibernation callbacks (rev. 7)

Quoted 5 lines · Rafael J. Wysocki

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

<snip>

This is probably because I took a few days to merge this, but it doesn't apply to my tree anymore, with some wierd merge errors that I don't think I can easily resolve without having to totally guess as to what it should be (the apm_32.c area especially...)

Care to respin these patches? Sorry for the delay.

thanks,

greg k-h

#4 lore raw

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

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

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

<snip>

This is probably because I took a few days to merge this, but it doesn't apply to my tree anymore, with some wierd merge errors that I don't think I can easily resolve without having to totally guess as to what it should be (the apm_32.c area especially...)

Care to respin these patches? Sorry for the delay.

thanks,

greg k-h

#5 lore raw

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

Quoted 7 lines · Greg KH
Quoted 5 lines · Rafael J. Wysocki

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Quoted 8 lines

<snip>

This is probably because I took a few days to merge this, but it doesn't apply to my tree anymore, with some wierd merge errors that I don't think I can easily resolve without having to totally guess as to what it should be (the apm_32.c area especially...)

Care to respin these patches?

Sure, they'll go in replies to this message. They include a couple of fixes from Andrew that are in -mm.

I have tested them on top of the current linux-next with pm-remove-destroy_suspended_device.patch, so they should apply to your tree this time.

Quoted 1 line

Sorry for the delay.

No big deal.

Thanks,
Rafael

#6 lore raw

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

In reply to Greg KH
Quoted 7 lines · Greg KH
Quoted 5 lines · Rafael J. Wysocki

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Quoted 8 lines

<snip>

This is probably because I took a few days to merge this, but it doesn't apply to my tree anymore, with some wierd merge errors that I don't think I can easily resolve without having to totally guess as to what it should be (the apm_32.c area especially...)

Care to respin these patches?

Sure, they'll go in replies to this message. They include a couple of fixes from Andrew that are in -mm.

I have tested them on top of the current linux-next with pm-remove-destroy_suspended_device.patch, so they should apply to your tree this time.

Quoted 1 line

Sorry for the delay.

No big deal.

Thanks,
Rafael

#7 lore raw

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

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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   |    8 
 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         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 852 insertions(+), 204 deletions(-)
include/linux/pm.h +286 -28
Index: linux-next/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,284 @@ 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().  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).  [To work around this limitation, drivers may
+ *	register suspend and hibernation notifiers that are executed before the
+ *	freezing of tasks.]
+ *
+ * @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 unsuccessfully 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.  The error codes returned in
+ * that cases are only printed by the PM core to the system logs for debugging
+ * purposes.  Still, it is recommended that drivers only return error codes
+ * from their resume methods in case of an unrecoverable failure (i.e. when the
+ * device being handled refuses to resume and becomes unusable) to allow us to
+ * modify the PM core in the future, so that it can avoid attempting to handle
+ * devices that failed to resume and their children.
+ *
+ * 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.  The error codes returned in that cases are
+ * only printed by the PM core to the system logs for debugging purposes.
+ * Still, as stated above, it is recommended that drivers only return error
+ * codes from their resume methods if the device being handled fails to resume
+ * and is not usable any more.
+ */
+
+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_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 +446,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 +533 -160

904 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-next/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-next/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-next/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 +4 -4
Index: linux-next/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);
 	spin_lock(&user_list_lock);
 	for (as = user_list; as != NULL; as = as->next) {
@@ -1235,7 +1235,7 @@ static void standby(void)
 		apm_error("standby", err);
 
 	local_irq_disable();
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
 }
 
@@ -1321,7 +1321,7 @@ static void check_events(void)
 			ignore_bounce = 1;
 			if ((event != APM_NORMAL_RESUME)
 			    || (ignore_normal_resume == 0)) {
-				device_resume();
+				device_resume(PMSG_RESUME);
 				queue_event(event, NULL);
 			}
 			ignore_normal_resume = 0;
drivers/base/power/power.h +1 -1
Index: linux-next/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-next/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) {
#8 lore raw

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

In reply to Rafael J. Wysocki

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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   |    8 
 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         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 852 insertions(+), 204 deletions(-)
include/linux/pm.h +286 -28
Index: linux-next/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,284 @@ 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().  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).  [To work around this limitation, drivers may
+ *	register suspend and hibernation notifiers that are executed before the
+ *	freezing of tasks.]
+ *
+ * @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 unsuccessfully 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.  The error codes returned in
+ * that cases are only printed by the PM core to the system logs for debugging
+ * purposes.  Still, it is recommended that drivers only return error codes
+ * from their resume methods in case of an unrecoverable failure (i.e. when the
+ * device being handled refuses to resume and becomes unusable) to allow us to
+ * modify the PM core in the future, so that it can avoid attempting to handle
+ * devices that failed to resume and their children.
+ *
+ * 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.  The error codes returned in that cases are
+ * only printed by the PM core to the system logs for debugging purposes.
+ * Still, as stated above, it is recommended that drivers only return error
+ * codes from their resume methods if the device being handled fails to resume
+ * and is not usable any more.
+ */
+
+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_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 +446,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 +533 -160

904 lines not on this page · raw message

include/linux/device.h +9 -0
Index: linux-next/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-next/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-next/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 +4 -4
Index: linux-next/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);
 	spin_lock(&user_list_lock);
 	for (as = user_list; as != NULL; as = as->next) {
@@ -1235,7 +1235,7 @@ static void standby(void)
 		apm_error("standby", err);
 
 	local_irq_disable();
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
 }
 
@@ -1321,7 +1321,7 @@ static void check_events(void)
 			ignore_bounce = 1;
 			if ((event != APM_NORMAL_RESUME)
 			    || (ignore_normal_resume == 0)) {
-				device_resume();
+				device_resume(PMSG_RESUME);
 				queue_event(event, NULL);
 			}
 			ignore_normal_resume = 0;
drivers/base/power/power.h +1 -1
Index: linux-next/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-next/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

#9 lore raw

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

Quoted 10 lines · Rafael J. Wysocki
+ *     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().  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).  [To work around this limitation, drivers may
+ *     register suspend and hibernation notifiers that are executed before the
+ *     freezing of tasks.]

Can you tell me why you kept that limitation with user space ?

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

Ben.

#10 lore raw

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

Quoted 13 lines · Benjamin Herrenschmidt
Quoted 10 lines · Rafael J. Wysocki
+ *     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().  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).  [To work around this limitation, drivers may
+ *     register suspend and hibernation notifiers that are executed before the
+ *     freezing of tasks.]
Quoted 5 lines

Can you tell me why you kept that limitation with user space ?

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Thanks,
Rafael

#11 lore raw

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

Quoted 8 lines
Quoted 4 lines

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Can't we run the freezer after prepare() instead ?

Ben.

#12 lore raw

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

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

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Can't we run the freezer after prepare() instead ?

Ben.

#13 lore raw

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

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines
Quoted 4 lines

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Can't we run the freezer after prepare() instead ?

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

Thanks,
Rafael

#14 lore raw

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

Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

#15 lore raw

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

In reply to Rafael J. Wysocki
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

#16 lore raw

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

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Okay, so we have different opinions. :-)

Quoted 6 lines

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

From my point of view, they are as right as they can be at the moment.

Besides, maintainig a set of patches like this so that it always applies to a tree that's continuously changing under it is far from funny. I'm not going to do it much longer, that's for sure.

Quoted 3 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

Thanks,
Rafael

#17 lore raw

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

Quoted 6 lines · Rafael J. Wysocki

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

Most of the actual suspending of requests queues etc... has to be done in suspend. Nothing changed here. I don't see why it would change. prepare() is a way to preallocate things when needed, cache things when needed, etc... and possibly interact user space. At least that how I see it.

It -is- acceptable to stop servicing user space after prepare() in some well defined cases such as the DRM, as long as in-kernel users aren't affected. But that's not necessarily what I have in mind. In the case us userspace for example, the idea here is to perform the migration of all the dirty data in the VRAM (that will be lost during suspend) out to main memory (or AGP memory). That doesn't mean necessarily that the DRM will stop servicing anything from there, it can still perform things. It might mean that user space would have to disable some accelerations that rely on dirty data in VRAM though until complete() is called.

Quoted 3 lines

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

request_firmware() & caching the resulting firmware so that the driver can resume & start operating right away is an example (think about NFS over wireless here for example, or iSCSI). the DRM example above. In general, any driver that needs to interact with user space, perform large allocations, muck around with the VM, etc...

prepare() isn't intended to stop operations, but to preload/cache/prepare and have userspace available for drivers where this is needed. In some case, that might need the driver will continue operating in some degraded mode (for example, a multiqueue driver can degrade to a single queue with one pre-allocated request to avoid relying on allocations).

I would expect most simple drivers not to need it of course.

Cheers,
Ben.

#18 lore raw

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

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

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

Most of the actual suspending of requests queues etc... has to be done in suspend. Nothing changed here. I don't see why it would change. prepare() is a way to preallocate things when needed, cache things when needed, etc... and possibly interact user space. At least that how I see it.

It -is- acceptable to stop servicing user space after prepare() in some well defined cases such as the DRM, as long as in-kernel users aren't affected. But that's not necessarily what I have in mind. In the case us userspace for example, the idea here is to perform the migration of all the dirty data in the VRAM (that will be lost during suspend) out to main memory (or AGP memory). That doesn't mean necessarily that the DRM will stop servicing anything from there, it can still perform things. It might mean that user space would have to disable some accelerations that rely on dirty data in VRAM though until complete() is called.

Quoted 3 lines

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

request_firmware() & caching the resulting firmware so that the driver can resume & start operating right away is an example (think about NFS over wireless here for example, or iSCSI). the DRM example above. In general, any driver that needs to interact with user space, perform large allocations, muck around with the VM, etc...

prepare() isn't intended to stop operations, but to preload/cache/prepare and have userspace available for drivers where this is needed. In some case, that might need the driver will continue operating in some degraded mode (for example, a multiqueue driver can degrade to a single queue with one pre-allocated request to avoid relying on allocations).

I would expect most simple drivers not to need it of course.

Cheers,
Ben.

#19 lore raw

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

Quoted 35 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

Most of the actual suspending of requests queues etc... has to be done in suspend. Nothing changed here. I don't see why it would change. prepare() is a way to preallocate things when needed, cache things when needed, etc... and possibly interact user space. At least that how I see it.

It -is- acceptable to stop servicing user space after prepare() in some well defined cases such as the DRM, as long as in-kernel users aren't affected. But that's not necessarily what I have in mind. In the case us userspace for example, the idea here is to perform the migration of all the dirty data in the VRAM (that will be lost during suspend) out to main memory (or AGP memory). That doesn't mean necessarily that the DRM will stop servicing anything from there, it can still perform things. It might mean that user space would have to disable some accelerations that rely on dirty data in VRAM though until complete() is called.

Quoted 3 lines

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

request_firmware() & caching the resulting firmware so that the driver can resume & start operating right away is an example (think about NFS over wireless here for example, or iSCSI). the DRM example above. In general, any driver that needs to interact with user space, perform large allocations, muck around with the VM, etc...

Quoted 8 lines

prepare() isn't intended to stop operations, but to preload/cache/prepare and have userspace available for drivers where this is needed. In some case, that might need the driver will continue operating in some degraded mode (for example, a multiqueue driver can degrade to a single queue with one pre-allocated request to avoid relying on allocations).

I would expect most simple drivers not to need it of course.

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Since, as you said, there aren't too many drivers that will need anything like that, it seems perfectly doable to me.

Thanks,
Rafael

Quoted 8 lines

Cheers,
Ben.

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#20 lore raw

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

Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

I'm opposed to designing something around the freezer since we know it will ultimately go away.

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

Quoted 2 lines

Since, as you said, there aren't too many drivers that will need anything like that, it seems perfectly doable to me.

Ben.

#21 lore raw

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

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

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

I'm opposed to designing something around the freezer since we know it will ultimately go away.

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

Quoted 2 lines

Since, as you said, there aren't too many drivers that will need anything like that, it seems perfectly doable to me.

Ben.

#22 lore raw

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

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

Quoted 2 lines

I'm opposed to designing something around the freezer since we know it will ultimately go away.

Well, I think the freezer is not anything we can remove overnight. It's there and does something our users rely on, whether we like it or not. That means we have to provide the users with other things to rely on and _then_ remove the freezer, not the other way around. Hence, we need to design around it, otherwise the users will suffer.

Quoted 20 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Quoted 7 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

Thanks,
Rafael

#23 lore raw

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

Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Ben.

#24 lore raw

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

In reply to Rafael J. Wysocki
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Ben.

#25 lore raw

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

Am Montag, 14. April 2008 05:23:00 schrieb Benjamin Herrenschmidt:

Quoted 11 lines
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Which is the problem. Suspension is supposed to be transparent. We cannot start returning error codes for operations which never failed in practice (eg. switching configurations in USB), just because the system is about to be suspended.

If you want to request firmware in a PM callback, which makes a certain sense, as we should move to a comprehensive API, if we change the API at all, we need a model with 3 callbacks.

Regards
Oliver

#26 lore raw

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

In reply to Benjamin Herrenschmidt

Am Montag, 14. April 2008 05:23:00 schrieb Benjamin Herrenschmidt:

Quoted 11 lines
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Which is the problem. Suspension is supposed to be transparent. We cannot start returning error codes for operations which never failed in practice (eg. switching configurations in USB), just because the system is about to be suspended.

If you want to request firmware in a PM callback, which makes a certain sense, as we should move to a comprehensive API, if we change the API at all, we need a model with 3 callbacks.

Regards
Oliver

#27 lore raw

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

Quoted 5 lines · Oliver Neukum

Which is the problem. Suspension is supposed to be transparent. We cannot start returning error codes for operations which never failed in practice (eg. switching configurations in USB), just because the system is about to be suspended.

Returning errors is better than crashing in any way. So what I meant here is that the problem is not as bad as it sounds.

Quoted 4 lines

If you want to request firmware in a PM callback, which makes a certain
sense, as we should move to a comprehensive API, if we change the API at all, we need a model with 3 callbacks.

No. At this pace, we'll find reasons to have 98213674 callbacks and will still not be happy.

Prepare() should be the right place to call request_firmware() and if that is a problem because of bugs in some USB things, then those bugs should be fixed.

Ben.

#28 lore raw

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

Am Montag, 14. April 2008 09:23:36 schrieb Benjamin Herrenschmidt:

Quoted 8 lines · Oliver Neukum
Quoted 5 lines

If you want to request firmware in a PM callback, which makes a certain
sense, as we should move to a comprehensive API, if we change the API at all, we need a model with 3 callbacks.

Quoted 6 lines

No. At this pace, we'll find reasons to have 98213674 callbacks and will still not be happy.

Prepare() should be the right place to call request_firmware() and if that is a problem because of bugs in some USB things, then those bugs should be fixed.

This isn't a bug. USB simply needs to be able to register (and deregister) children to be fully operative. You cannot expect a subsystem to work while some core services are not available.

Regards
Oliver

#29 lore raw

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

In reply to Benjamin Herrenschmidt

Am Montag, 14. April 2008 09:23:36 schrieb Benjamin Herrenschmidt:

Quoted 8 lines · Oliver Neukum
Quoted 5 lines

If you want to request firmware in a PM callback, which makes a certain
sense, as we should move to a comprehensive API, if we change the API at all, we need a model with 3 callbacks.

Quoted 6 lines

No. At this pace, we'll find reasons to have 98213674 callbacks and will still not be happy.

Prepare() should be the right place to call request_firmware() and if that is a problem because of bugs in some USB things, then those bugs should be fixed.

This isn't a bug. USB simply needs to be able to register (and deregister) children to be fully operative. You cannot expect a subsystem to work while some core services are not available.

Regards
Oliver

#30 lore raw

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

Quoted 7 lines · Oliver Neukum
Quoted 3 lines

Prepare() should be the right place to call request_firmware() and if that is a problem because of bugs in some USB things, then those bugs should be fixed.

This isn't a bug. USB simply needs to be able to register (and deregister) children to be fully operative. You cannot expect a subsystem to work while some core services are not available.

No, and that's why the subsystem in question needs to nicely defer the operations that it cannot do immediately to until resume. Nothing new here.

In the case of USB, there are plenty of ways it could be done, from blocking in whatever ioctl is causing trouble, to putting to-be-added objects in a list that gets processed later...

Ben.

#31 lore raw

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

In reply to Oliver Neukum
Quoted 7 lines · Oliver Neukum
Quoted 3 lines

Prepare() should be the right place to call request_firmware() and if that is a problem because of bugs in some USB things, then those bugs should be fixed.

This isn't a bug. USB simply needs to be able to register (and deregister) children to be fully operative. You cannot expect a subsystem to work while some core services are not available.

No, and that's why the subsystem in question needs to nicely defer the operations that it cannot do immediately to until resume. Nothing new here.

In the case of USB, there are plenty of ways it could be done, from blocking in whatever ioctl is causing trouble, to putting to-be-added objects in a list that gets processed later...

Ben.

#32 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Okay, this was a shortcut. [If we're discussing things when there's 2 am here, I'm at a big disadvantage. :-)]

I think we agree that finally there should be no freezer and the things should go like this:

(1) notifiers
(2) platform ->begin()
(3) ->prepare()
(4) ->suspend()
(5) platform ->prepare()
(6) ->suspend_noirq()
(7) platform ->enter()
(8) (we are in the sleep state)
(9) ->resume_noirq()
(10) platform ->finish()
(11) ->resume()
(12) ->complete()
(13) platform ->end()
(14) notifiers

Now, the question arises how to reach that status from what we have at the moment and IMO there are two ways to go.

The first one is what I've implemented in the $subject patch:
(1) make ->prepare() be executed after the freezer with the current semantics (ie. you can assume the user space do be there when ->prepare() is running and use a notifier for things depending on that assumption)
(2) after we've dropped the freezer, change the semantics of ->prepare() (now you can assume that the user space is there)
(3) move code from notifiers to ->prepare() - this is entirely optional from the functionality point of view, the code can stay in the notifiers.
The advantage of this is that it doesn't require nontrivial modifications of the core suspend/hibernation code.

The second one is a bit more complicated:
(1) make ->prepare() be executed before the freezer with the semantics like "you can assume that the user space is there while ->prepare() is running, but you are supposed to prevent new children of the device from being registered from that point on _and_ you have to make sure that freezable tasks will be able to freeze after ->prepare() has run" (but why on Earth a driver writer is now required to know what's a freezable task etc.?)
(2) after we've dropped the freezer, change the semantics of ->prepare() (now there are no freezable tasks to care for)
(3) remove the code necessary to make the freezer happy from ->prepare() (if any) - this need not be totally optional, IMO
Also, to implement this we'd have to change the core code (ie. add two additional routines, device_prepare() and device_complete() to be called by it, rework the error paths, move the platform ->begin()/->end() invocations before/after the freezer etc.). In the end, we'll end up with a more complicated core in this case (we can simplify it afterwards, but that means one patchset more).

[See how the semantics of ->prepare() changes in both cases, BTW. We can't avoid changing it in the future, we can only choose _how_ to change it.]

I prefer the first one quite a lot.

Thanks,
Rafael

#33 lore raw

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

Quoted 5 lines · Rafael J. Wysocki

"you can assume that the user space is there while ->prepare() is running, but you are supposed to prevent new children of the device from being registered from that point on _and_ you have to make sure that freezable tasks will be able to freeze after ->prepare() has run" (but why on Earth a driver writer is now required to know what's a freezable task etc.?)

This reminds me... We're going to need a way to make certain activities mutually exclusive with system sleep. The simplest example is loading a kernel module; init and probe routines often end up causing new child devices to be registered.

The most straightforward approach is to use an rwsem like the one we used to have. However I'm concerned that under some circumstances there might be recursive read-locking. (For example, the init routine in a newly-loaded module decides to load yet another module. Can this actually happen? libusual does something much like it.)

So it's quite possible we'll end up needing a mechanism that resembles an rwsem but allows recursive (properly nested) read-locking. Does such a thing exist already, or would it have to be invented?

Alan Stern

#34 lore raw

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

Quoted 19 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki

"you can assume that the user space is there while ->prepare() is running, but you are supposed to prevent new children of the device from being registered from that point on _and_ you have to make sure that freezable tasks will be able to freeze after ->prepare() has run" (but why on Earth a driver writer is now required to know what's a freezable task etc.?)

This reminds me... We're going to need a way to make certain activities mutually exclusive with system sleep. The simplest example is loading a kernel module; init and probe routines often end up causing new child devices to be registered.

The most straightforward approach is to use an rwsem like the one we used to have. However I'm concerned that under some circumstances there might be recursive read-locking. (For example, the init routine in a newly-loaded module decides to load yet another module. Can this actually happen? libusual does something much like it.)

Quoted 3 lines

So it's quite possible we'll end up needing a mechanism that resembles an rwsem but allows recursive (properly nested) read-locking. Does such a thing exist already, or would it have to be invented?

Despite what Oliver says, that's a perfect example where the module load syscalls should return an error. Maybe something like -EAGAIN would do tho... that might need a minor update of the module init tools so they retry instead of failing.

Ben.

#35 lore raw

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

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

"you can assume that the user space is there while ->prepare() is running, but you are supposed to prevent new children of the device from being registered from that point on _and_ you have to make sure that freezable tasks will be able to freeze after ->prepare() has run" (but why on Earth a driver writer is now required to know what's a freezable task etc.?)

This reminds me... We're going to need a way to make certain activities mutually exclusive with system sleep. The simplest example is loading a kernel module; init and probe routines often end up causing new child devices to be registered.

The most straightforward approach is to use an rwsem like the one we used to have. However I'm concerned that under some circumstances there might be recursive read-locking. (For example, the init routine in a newly-loaded module decides to load yet another module. Can this actually happen? libusual does something much like it.)

So it's quite possible we'll end up needing a mechanism that resembles an rwsem but allows recursive (properly nested) read-locking. Does such a thing exist already, or would it have to be invented?

Alan Stern

#36 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB). In fact, it won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

Okay, this was a shortcut. [If we're discussing things when there's 2 am here, I'm at a big disadvantage. :-)]

I think we agree that finally there should be no freezer and the things should go like this:

(1) notifiers
(2) platform ->begin()
(3) ->prepare()
(4) ->suspend()
(5) platform ->prepare()
(6) ->suspend_noirq()
(7) platform ->enter()
(8) (we are in the sleep state)
(9) ->resume_noirq()
(10) platform ->finish()
(11) ->resume()
(12) ->complete()
(13) platform ->end()
(14) notifiers

Now, the question arises how to reach that status from what we have at the moment and IMO there are two ways to go.

The first one is what I've implemented in the $subject patch:
(1) make ->prepare() be executed after the freezer with the current semantics (ie. you can assume the user space do be there when ->prepare() is running and use a notifier for things depending on that assumption)
(2) after we've dropped the freezer, change the semantics of ->prepare() (now you can assume that the user space is there)
(3) move code from notifiers to ->prepare() - this is entirely optional from the functionality point of view, the code can stay in the notifiers.
The advantage of this is that it doesn't require nontrivial modifications of the core suspend/hibernation code.

The second one is a bit more complicated:
(1) make ->prepare() be executed before the freezer with the semantics like "you can assume that the user space is there while ->prepare() is running, but you are supposed to prevent new children of the device from being registered from that point on _and_ you have to make sure that freezable tasks will be able to freeze after ->prepare() has run" (but why on Earth a driver writer is now required to know what's a freezable task etc.?)
(2) after we've dropped the freezer, change the semantics of ->prepare() (now there are no freezable tasks to care for)
(3) remove the code necessary to make the freezer happy from ->prepare() (if any) - this need not be totally optional, IMO
Also, to implement this we'd have to change the core code (ie. add two additional routines, device_prepare() and device_complete() to be called by it, rework the error paths, move the platform ->begin()/->end() invocations before/after the freezer etc.). In the end, we'll end up with a more complicated core in this case (we can simplify it afterwards, but that means one patchset more).

[See how the semantics of ->prepare() changes in both cases, BTW. We can't avoid changing it in the future, we can only choose _how_ to change it.]

I prefer the first one quite a lot.

Thanks,
Rafael

#37 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB).

I used USB as an example simply because that's what I'm familiar with. Don't be so quick to assume the rest of the kernel is trouble-free.

Quoted 3 lines

In fact, it
won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

But it _would_ be a regression -- and everyone knows how much Linus and Andrew dislike regressions. :-)

Now, I don't see what the big deal is here. We all agree that it would be nice and appropriate if drivers could do things like request_firmware() during prepare(). But for the moment they can't. It's not like this is some tremendous hardship -- you aren't going to have to rip out all the existing prepare() implementations and rewrite them, because they don't exist yet!

All it means is that the full conversion to the new interface will be a multi-step process. Right now we add the new callbacks. Later on we make it safe to move the freezer after prepare. Later still we eliminate the freezer altogether from suspend. (Hibernation is a separate matter...)

Alan Stern

#38 lore raw

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

Am Montag, 14. April 2008 16:49:26 schrieb Alan Stern:

Quoted 6 lines

Now, I don't see what the big deal is here.  We all agree that it would be nice and appropriate if drivers could do things like request_firmware() during prepare().  But for the moment they can't. It's not like this is some tremendous hardship -- you aren't going to have to rip out all the existing prepare() implementations and rewrite them, because they don't exist yet!

True. You cannot request firmware in the current suspend() call either. Rafael's code is a clear improvement over the existing code. Removal of the freezer will need a lot of rewriting in any case.

Regards
Oliver

#39 lore raw

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

In reply to Alan Stern

Am Montag, 14. April 2008 16:49:26 schrieb Alan Stern:

Quoted 6 lines

Now, I don't see what the big deal is here.  We all agree that it would be nice and appropriate if drivers could do things like request_firmware() during prepare().  But for the moment they can't. It's not like this is some tremendous hardship -- you aren't going to have to rip out all the existing prepare() implementations and rewrite them, because they don't exist yet!

True. You cannot request firmware in the current suspend() call either. Rafael's code is a clear improvement over the existing code. Removal of the freezer will need a lot of rewriting in any case.

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

#40 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

I believe the use of prepare for things like request_firmware etc... is worth the effort of fixing the known breakage of not having the freezer while preventing insertion of new devices (mostly USB).

I used USB as an example simply because that's what I'm familiar with. Don't be so quick to assume the rest of the kernel is trouble-free.

Quoted 3 lines

In fact, it
won't be such a big issue as the core should/will return an error from attempting to add the device in that case.

But it _would_ be a regression -- and everyone knows how much Linus and Andrew dislike regressions. :-)

Now, I don't see what the big deal is here. We all agree that it would be nice and appropriate if drivers could do things like request_firmware() during prepare(). But for the moment they can't. It's not like this is some tremendous hardship -- you aren't going to have to rip out all the existing prepare() implementations and rewrite them, because they don't exist yet!

All it means is that the full conversion to the new interface will be a multi-step process. Right now we add the new callbacks. Later on we make it safe to move the freezer after prepare. Later still we eliminate the freezer altogether from suspend. (Hibernation is a separate matter...)

Alan Stern

#41 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

Quoted 2 lines

I'm opposed to designing something around the freezer since we know it will ultimately go away.

Well, I think the freezer is not anything we can remove overnight. It's there and does something our users rely on, whether we like it or not. That means we have to provide the users with other things to rely on and _then_ remove the freezer, not the other way around. Hence, we need to design around it, otherwise the users will suffer.

Quoted 20 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Quoted 7 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

To avoid breaking things (from the functional point of view) unnecessarily.

In short, I don't really see the difference between moving ->prepare() before the freezer and droppig the freezer, which I'm not going to do right now.

Thanks,
Rafael

#42 lore raw

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

In reply to Benjamin Herrenschmidt

Hi.

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

I'm opposed to designing something around the freezer since we know it will ultimately go away.

I don't think we should be assuming that the freezer will ultimately go away. Aiming for that is one thing, assuming that we know what will happen in the future is another. Frankly, I hope it doesn't go away, because right now it's the only way I can see that we can capture as close as possible to a complete image of memory for hibernation. I know that some people don't care about that option, but others of us find it extremely useful.

Quoted 3 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Having said the above, I also agree with this. I want to see things being done properly too. I believe the freezer still has a place when it comes to providing the environment in which we can capture a consistent image for hibernation, but that shouldn't get in the way of kernel drivers (or even well designed userspace drivers) doing their thing, including reloading firmware post-atomic restore or post-suspend-to-ram.

Quoted 11 lines
Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

Quoted 4 lines

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Not a proper/complete solution to every problem.

Quoted 7 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

1 step for pre-freezing prepare (load firmware you might want to restore later, allocate memory) and 1 step for post-freezing prepare (stop driver discovery)? I'm not sure that this is what Rafael has in mind, though.

Nigel

#43 lore raw

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

Quoted 12 lines · Nigel Cunningham

Hi.

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

Quoted 6 lines
Quoted 2 lines

I'm opposed to designing something around the freezer since we know it will ultimately go away.

I don't think we should be assuming that the freezer will ultimately go away. Aiming for that is one thing, assuming that we know what will happen in the future is another.

I agree.

Quoted 4 lines

Frankly, I hope it doesn't go away, because right now it's the only way I can see that we can capture as close as possible to a complete image of memory for hibernation. I know that some people don't care about that option, but others of us find it extremely useful.

Well, I think there's another way, but that's for a separate discussion. :-)

Quoted 10 lines
Quoted 3 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Having said the above, I also agree with this. I want to see things being done properly too. I believe the freezer still has a place when it comes to providing the environment in which we can capture a consistent image for hibernation, but that shouldn't get in the way of kernel drivers (or even well designed userspace drivers) doing their thing, including reloading firmware post-atomic restore or post-suspend-to-ram.

Unfortunately, if ->prepare() is to be run before the freezer, the writers of the ->prepare() routines will have to make sure they won't block any freezable tasks, so that the freezer doesn't fail. This, in turn, will require them to learn how the freezer works etc., which I'm not quite sure is really necessary.

Quoted 24 lines
Quoted 11 lines
Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

Quoted 4 lines

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Not a proper/complete solution to every problem.

Quoted 6 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Quoted 6 lines
Quoted 1 line

Why do this two steps ? What is the point ?

1 step for pre-freezing prepare (load firmware you might want to restore later, allocate memory) and 1 step for post-freezing prepare (stop driver discovery)? I'm not sure that this is what Rafael has in mind, though.

Yes, sort of.

I think that, as long as there is the freezer, we need two "preparation" steps in general, one to be executed with the user space available and one to be executed after it's been frozen. The difference between them is quite clear to me and trying to forcibly merge them into one routine will eventually lead to problems.

If the freezer is not there, though, we can merge the two just fine. This seems to be a natural way to go to me and that's why I'm trying to use this approach.

Thanks,
Rafael

#44 lore raw

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

In reply to Nigel Cunningham
Quoted 12 lines · Nigel Cunningham

Hi.

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

Quoted 6 lines
Quoted 2 lines

I'm opposed to designing something around the freezer since we know it will ultimately go away.

I don't think we should be assuming that the freezer will ultimately go away. Aiming for that is one thing, assuming that we know what will happen in the future is another.

I agree.

Quoted 4 lines

Frankly, I hope it doesn't go away, because right now it's the only way I can see that we can capture as close as possible to a complete image of memory for hibernation. I know that some people don't care about that option, but others of us find it extremely useful.

Well, I think there's another way, but that's for a separate discussion. :-)

Quoted 10 lines
Quoted 3 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Having said the above, I also agree with this. I want to see things being done properly too. I believe the freezer still has a place when it comes to providing the environment in which we can capture a consistent image for hibernation, but that shouldn't get in the way of kernel drivers (or even well designed userspace drivers) doing their thing, including reloading firmware post-atomic restore or post-suspend-to-ram.

Unfortunately, if ->prepare() is to be run before the freezer, the writers of the ->prepare() routines will have to make sure they won't block any freezable tasks, so that the freezer doesn't fail. This, in turn, will require them to learn how the freezer works etc., which I'm not quite sure is really necessary.

Quoted 24 lines
Quoted 11 lines
Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

Quoted 4 lines

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Not a proper/complete solution to every problem.

Quoted 6 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Quoted 6 lines
Quoted 1 line

Why do this two steps ? What is the point ?

1 step for pre-freezing prepare (load firmware you might want to restore later, allocate memory) and 1 step for post-freezing prepare (stop driver discovery)? I'm not sure that this is what Rafael has in mind, though.

Yes, sort of.

I think that, as long as there is the freezer, we need two "preparation" steps in general, one to be executed with the user space available and one to be executed after it's been frozen. The difference between them is quite clear to me and trying to forcibly merge them into one routine will eventually lead to problems.

If the freezer is not there, though, we can merge the two just fine. This seems to be a natural way to go to me and that's why I'm trying to use this approach.

Thanks,
Rafael

#45 lore raw

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

In reply to Benjamin Herrenschmidt

Hi.

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines · Rafael J. Wysocki

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

I'm opposed to designing something around the freezer since we know it will ultimately go away.

I don't think we should be assuming that the freezer will ultimately go away. Aiming for that is one thing, assuming that we know what will happen in the future is another. Frankly, I hope it doesn't go away, because right now it's the only way I can see that we can capture as close as possible to a complete image of memory for hibernation. I know that some people don't care about that option, but others of us find it extremely useful.

Quoted 3 lines

If things like USB have issues with userland doing nasty things after prepare(), then those things need to be fixed. The freezer will only hide bugs and not even always or properly and not on all archs.

Having said the above, I also agree with this. I want to see things being done properly too. I believe the freezer still has a place when it comes to providing the environment in which we can capture a consistent image for hibernation, but that shouldn't get in the way of kernel drivers (or even well designed userspace drivers) doing their thing, including reloading firmware post-atomic restore or post-suspend-to-ram.

Quoted 11 lines
Quoted 2 lines

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

That's just gratuituous complication imho. We can add callbacks every week and no driver will every find out what to use and when.

prepare() has quite well defined and nice semantics if you ignore your freezer trickery. It matches well with the needs of things like request_firmware or the DRM, and possibly a few others, in addition to matching well the need to block bus discovery.

Quoted 4 lines

If some drivers have issue because of what userland might do after prepare(), then those drivers need to be fixed. We all know the freezer is not a proper solution. It just hides problems and not always correctly.

Not a proper/complete solution to every problem.

Quoted 7 lines
Quoted 5 lines

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Why do this two steps ? What is the point ?

1 step for pre-freezing prepare (load firmware you might want to restore later, allocate memory) and 1 step for post-freezing prepare (stop driver discovery)? I'm not sure that this is what Rafael has in mind, though.

Nigel

#46 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 35 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

Most of the actual suspending of requests queues etc... has to be done in suspend. Nothing changed here. I don't see why it would change. prepare() is a way to preallocate things when needed, cache things when needed, etc... and possibly interact user space. At least that how I see it.

It -is- acceptable to stop servicing user space after prepare() in some well defined cases such as the DRM, as long as in-kernel users aren't affected. But that's not necessarily what I have in mind. In the case us userspace for example, the idea here is to perform the migration of all the dirty data in the VRAM (that will be lost during suspend) out to main memory (or AGP memory). That doesn't mean necessarily that the DRM will stop servicing anything from there, it can still perform things. It might mean that user space would have to disable some accelerations that rely on dirty data in VRAM though until complete() is called.

Quoted 3 lines

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

request_firmware() & caching the resulting firmware so that the driver can resume & start operating right away is an example (think about NFS over wireless here for example, or iSCSI). the DRM example above. In general, any driver that needs to interact with user space, perform large allocations, muck around with the VM, etc...

Quoted 8 lines

prepare() isn't intended to stop operations, but to preload/cache/prepare and have userspace available for drivers where this is needed. In some case, that might need the driver will continue operating in some degraded mode (for example, a multiqueue driver can degrade to a single queue with one pre-allocated request to avoid relying on allocations).

I would expect most simple drivers not to need it of course.

Well, in our discussions with Alan Stern ->prepare() turned out to be necessary for exactly one reason, preventing new children of the device from being registered (by threads concurrent wrt the suspend thread). For this reason, it doesn't really seem a good idea to run it before the freezer (seemingly, it would be difficult to avoid situations in which the freezer would fail as a result of ->prepare()).

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

I have imagined that while we have the freezer, the operations that need to be carried out with the user space available will be done using notifiers and the rest will be done by ->prepare() and ->suspend(). Next, when we finally drop the freezer, it will be possible to move the code from the notifiers into ->prepare() and drop the notifiers altogether.

Since, as you said, there aren't too many drivers that will need anything like that, it seems perfectly doable to me.

Thanks,
Rafael

Quoted 8 lines

Cheers,
Ben.

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#47 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Okay, so we have different opinions. :-)

Quoted 6 lines

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

From my point of view, they are as right as they can be at the moment.

Besides, maintainig a set of patches like this so that it always applies to a tree that's continuously changing under it is far from funny. I'm not going to do it much longer, that's for sure.

Quoted 3 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Well, if we put ->prepare() before the freezer, what can it actually do? Certainly nothing that will block any (user space) task, because the freezer won't work after that. So, all of the significant suspend work, like blocking tasks using the device etc., will have to be done by ->suspend(). Will that be convenient? I'm not sure. I'm not even sure that would be _doable_ at all.

The point of view depends on what you think ->prepare() should be used for and I'm sure you have some specific cases in mind. However, are they generic enough?

Thanks,
Rafael

#48 lore raw

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

In reply to Benjamin Herrenschmidt

Hi Rafael etc.

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

Quoted 8 lines

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Regards,

Nigel

#49 lore raw

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

Quoted 1 line · Nigel Cunningham

Hi Rafael etc.

Hi,

Quoted 19 lines · Benjamin Herrenschmidt
Quoted 18 lines
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Quoted 5 lines
Quoted 1 line

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Sorry, what exactly has been changing too often? Device suspend callbacks?? They haven't changed since pm_message_t was introduced.

Thanks,
Rafael

#50 lore raw

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

Hi.

Quoted 24 lines · Rafael J. Wysocki
Quoted 1 line · Nigel Cunningham

Hi Rafael etc.

Hi,

Quoted 19 lines · Benjamin Herrenschmidt
Quoted 18 lines
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Sorry, what exactly has been changing too often? Device suspend callbacks?? They haven't changed since pm_message_t was introduced.

I'm thinking of driver models calls for both hibernation and suspend to ram, both names and semantics as to what is called when.

Regards,

Nigel

#51 lore raw

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

In reply to Rafael J. Wysocki

Hi.

Quoted 24 lines · Rafael J. Wysocki
Quoted 1 line · Nigel Cunningham

Hi Rafael etc.

Hi,

Quoted 19 lines · Benjamin Herrenschmidt
Quoted 18 lines
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Sorry, what exactly has been changing too often? Device suspend callbacks?? They haven't changed since pm_message_t was introduced.

I'm thinking of driver models calls for both hibernation and suspend to ram, both names and semantics as to what is called when.

Regards,

Nigel

#52 lore raw

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

In reply to Nigel Cunningham
Quoted 1 line · Nigel Cunningham

Hi Rafael etc.

Hi,

Quoted 19 lines · Benjamin Herrenschmidt
Quoted 18 lines
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Quoted 5 lines
Quoted 1 line

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Sorry, what exactly has been changing too often? Device suspend callbacks?? They haven't changed since pm_message_t was introduced.

Thanks,
Rafael

#53 lore raw

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

In reply to Nigel Cunningham
Quoted 9 lines · Nigel Cunningham
Quoted 5 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

In practical terms, it will be easier to keep the freezer where it is for now. This is because prepare() requires drivers to change their behavior; they aren't allowed to register new children any more.

But if userspace isn't frozen then user programs can interact with drivers in a way that does cause new children to be created. For example this happens in USB, where opening an audio device and selecting its bitrate causes a new set of endpoints to be realized, along with their representations in sysfs.

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact with userspace. Yes, this will have to be done eventually in any case, as the freezer goes away -- but it shouldn't have to be done right now.

Alan Stern

#54 lore raw

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

In reply to Nigel Cunningham
Quoted 9 lines · Nigel Cunningham
Quoted 5 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

In practical terms, it will be easier to keep the freezer where it is for now. This is because prepare() requires drivers to change their behavior; they aren't allowed to register new children any more.

But if userspace isn't frozen then user programs can interact with drivers in a way that does cause new children to be created. For example this happens in USB, where opening an audio device and selecting its bitrate causes a new set of endpoints to be realized, along with their representations in sysfs.

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact with userspace. Yes, this will have to be done eventually in any case, as the freezer goes away -- but it shouldn't have to be done right now.

Alan Stern

#55 lore raw

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

Quoted 22 lines · Alan Stern
Quoted 9 lines · Nigel Cunningham
Quoted 5 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

In practical terms, it will be easier to keep the freezer where it is for now. This is because prepare() requires drivers to change their behavior; they aren't allowed to register new children any more.

But if userspace isn't frozen then user programs can interact with drivers in a way that does cause new children to be created. For example this happens in USB, where opening an audio device and selecting its bitrate causes a new set of endpoints to be realized, along with their representations in sysfs.

Quoted 4 lines

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact with userspace. Yes, this will have to be done eventually in any case, as the freezer goes away -- but it shouldn't have to be done right now.

That's exactly my point.

Plus in my opinion, while with ->prepare() after the freezer it's possible to write ->prepare() and ->suspend() that will work just fine when we remove the freezer, with ->prepare() before the freezer it would be hard to do that, unless ->prepare() was trivial.

Thanks,
Rafael

#56 lore raw

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

Quoted 8 lines · Rafael J. Wysocki

Plus in my opinion, while with ->prepare() after the freezer it's possible
to write ->prepare() and ->suspend() that will work just fine when we remove
the freezer, with ->prepare() before the freezer it would be hard to do that,
unless ->prepare() was trivial.

And removing a good half of the usage scenario where prepare is useful..

Ben.

#57 lore raw

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

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

Plus in my opinion, while with ->prepare() after the freezer it's possible
to write ->prepare() and ->suspend() that will work just fine when we remove
the freezer, with ->prepare() before the freezer it would be hard to do that,
unless ->prepare() was trivial.

And removing a good half of the usage scenario where prepare is useful..

Ben.

#58 lore raw

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

In reply to Alan Stern
Quoted 22 lines · Alan Stern
Quoted 9 lines · Nigel Cunningham
Quoted 5 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

In practical terms, it will be easier to keep the freezer where it is for now. This is because prepare() requires drivers to change their behavior; they aren't allowed to register new children any more.

But if userspace isn't frozen then user programs can interact with drivers in a way that does cause new children to be created. For example this happens in USB, where opening an audio device and selecting its bitrate causes a new set of endpoints to be realized, along with their representations in sysfs.

Quoted 4 lines

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact with userspace. Yes, this will have to be done eventually in any case, as the freezer goes away -- but it shouldn't have to be done right now.

That's exactly my point.

Plus in my opinion, while with ->prepare() after the freezer it's possible to write ->prepare() and ->suspend() that will work just fine when we remove the freezer, with ->prepare() before the freezer it would be hard to do that, unless ->prepare() was trivial.

Thanks,
Rafael

#59 lore raw

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

In reply to Alan Stern
Quoted 8 lines · Alan Stern

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact
with userspace. Yes, this will have to be done eventually in any case,
as the freezer goes away -- but it shouldn't have to be done right now.

I disagree. The freezer can already be compiled out and is already not used on some architectures.

Cheers,
Ben.

#60 lore raw

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

In reply to Alan Stern
Quoted 8 lines · Alan Stern

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact
with userspace. Yes, this will have to be done eventually in any case,
as the freezer goes away -- but it shouldn't have to be done right now.

I disagree. The freezer can already be compiled out and is already not used on some architectures.

Cheers,
Ben.

#61 lore raw

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

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 8 lines · Alan Stern

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact
with userspace. Yes, this will have to be done eventually in any case,
as the freezer goes away -- but it shouldn't have to be done right now.

Quoted 2 lines

I disagree. The freezer can already be compiled out and is already not used on some architectures.

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

Thanks,
Rafael

#62 lore raw

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

Quoted 9 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

As far as I'm concerned, it's yet another case of the freezer papering over a problem rather than fixing it properly.

If we're going to introduce new callbacks, we should have the right semantic from day 1 -and- fix those problems, rather than going to the same old recursive nonsensical arguments and do things to paper over problems.

Ben.

#63 lore raw

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

In reply to Rafael J. Wysocki
Quoted 9 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

As far as I'm concerned, it's yet another case of the freezer papering over a problem rather than fixing it properly.

If we're going to introduce new callbacks, we should have the right semantic from day 1 -and- fix those problems, rather than going to the same old recursive nonsensical arguments and do things to paper over problems.

Ben.

#64 lore raw

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

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 6 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Quoted 6 lines
Quoted 3 lines

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

As far as I'm concerned, it's yet another case of the freezer papering over a problem rather than fixing it properly.

Well, this is not a user's point of view.

Quoted 4 lines

If we're going to introduce new callbacks, we should have the right semantic from day 1 -and- fix those problems, rather than going to the same old recursive nonsensical arguments and do things to paper over problems.

Still, we're not supposed to break things, as far as the functionality is concerned, and that's important, because it means we _have_ _to_ make changes in steps.

To be more precise, what you suggest (move ->prepare() before the freezer right now) means a patch with _functional_ changes (it's impossible to register new children of dev after ->prepare(dev) has run which can affect the user space in the window before ->prepare() and the freezer), whereas what I'd like to do is the (present) patch without functional changes.

Thanks,
Rafael

#65 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 6 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Quoted 6 lines
Quoted 3 lines

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

As far as I'm concerned, it's yet another case of the freezer papering over a problem rather than fixing it properly.

Well, this is not a user's point of view.

Quoted 4 lines

If we're going to introduce new callbacks, we should have the right semantic from day 1 -and- fix those problems, rather than going to the same old recursive nonsensical arguments and do things to paper over problems.

Still, we're not supposed to break things, as far as the functionality is concerned, and that's important, because it means we _have_ _to_ make changes in steps.

To be more precise, what you suggest (move ->prepare() before the freezer right now) means a patch with _functional_ changes (it's impossible to register new children of dev after ->prepare(dev) has run which can affect the user space in the window before ->prepare() and the freezer), whereas what I'd like to do is the (present) patch without functional changes.

Thanks,
Rafael

#66 lore raw

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

In reply to Rafael J. Wysocki
Quoted 5 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Note that the above seems to lack any useful information (as usual) such as what block driver is involved etc...

We fixed IDE to be robust vs. pending IOs a while ago. It's possible that libata isn't as solid yet, I don't know.

This needs to be done regardless of feezer vs. not freezer. There are thins in the kernel that can trigger BIOs at any time pretty much regardless of user space being frozen or not, again, it's a case of sticking our head in the sand and hoping the freezer hides all our design bugs.

Ben.

#67 lore raw

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

In reply to Rafael J. Wysocki
Quoted 5 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Note that the above seems to lack any useful information (as usual) such as what block driver is involved etc...

We fixed IDE to be robust vs. pending IOs a while ago. It's possible that libata isn't as solid yet, I don't know.

This needs to be done regardless of feezer vs. not freezer. There are thins in the kernel that can trigger BIOs at any time pretty much regardless of user space being frozen or not, again, it's a case of sticking our head in the sand and hoping the freezer hides all our design bugs.

Ben.

#68 lore raw

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

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Note that the above seems to lack any useful information (as usual) such as what block driver is involved etc...

Quoted 8 lines

We fixed IDE to be robust vs. pending IOs a while ago. It's possible that libata isn't as solid yet, I don't know.

This needs to be done regardless of feezer vs. not freezer. There are thins in the kernel that can trigger BIOs at any time pretty much regardless of user space being frozen or not, again, it's a case of sticking our head in the sand and hoping the freezer hides all our design bugs.

Now, you are talking about a completely different thing I agree with.

I gave this example just to show that some drivers break without the freezer if suspend is carried out under stress, nothing else.

My point is (and has always been) that we can't just drop the freezer right now without causing functional regressions to appear, at least for some users.

If there had not been _any_ other way to do things, we could do that, but IMO there is a way (that I described in the previous message).

Thanks,
Rafael

#69 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

Note that the above seems to lack any useful information (as usual) such as what block driver is involved etc...

Quoted 8 lines

We fixed IDE to be robust vs. pending IOs a while ago. It's possible that libata isn't as solid yet, I don't know.

This needs to be done regardless of feezer vs. not freezer. There are thins in the kernel that can trigger BIOs at any time pretty much regardless of user space being frozen or not, again, it's a case of sticking our head in the sand and hoping the freezer hides all our design bugs.

Now, you are talking about a completely different thing I agree with.

I gave this example just to show that some drivers break without the freezer if suspend is carried out under stress, nothing else.

My point is (and has always been) that we can't just drop the freezer right now without causing functional regressions to appear, at least for some users.

If there had not been _any_ other way to do things, we could do that, but IMO there is a way (that I described in the previous message).

Thanks,
Rafael

#70 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 8 lines · Alan Stern

Thus, in addition to making all the interface changes implied by the new callbacks, drivers would also have to change the way they interact
with userspace. Yes, this will have to be done eventually in any case,
as the freezer goes away -- but it shouldn't have to be done right now.

Quoted 2 lines

I disagree. The freezer can already be compiled out and is already not used on some architectures.

Please have a look at this thread:
http://lkml.org/lkml/2008/3/21/322
(in short, the reporter sees APM suspend breakage under stress, occuring because APM uses our suspending of devices without the freezer).

It mostly appears to work without the freezer, but that's bacuse no one actually does things that might break it. I don't think we can rely on users being so kind to us forever. :-)

Thanks,
Rafael

#71 lore raw

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

In reply to Benjamin Herrenschmidt

Hi Rafael etc.

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

Quoted 8 lines

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

Ben.

I agree. These calls have already been changing far too often in mainline. I know it's all been necessary but please, can we try to make one set of changes and just get it right this time?

Regards,

Nigel

#72 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 2 lines · Benjamin Herrenschmidt

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

There is Rafael's patience to remember... (rev 8?)

Quoted 3 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

But also, not all of that chitchat would naturally be associated with any particular device(s). So it's not clear to me that a prepare() is what should oversee that... or that we've had real discussion (yet) about the requirements there.

Quoted 3 lines · Rafael

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

Neither of those is actually a userspace notification/handshake.

- Dave

#73 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 2 lines · Benjamin Herrenschmidt

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

There is Rafael's patience to remember... (rev 8?)

Quoted 3 lines

The ability for prepare() callbacks to sync with userland, request_firmware, etc... is an important feature that's been needed for some time imho.

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

But also, not all of that chitchat would naturally be associated with any particular device(s). So it's not clear to me that a prepare() is what should oversee that... or that we've had real discussion (yet) about the requirements there.

Quoted 3 lines · Rafael

It looks like you'd like to have a third callback executed before the freezer, but OTOH I don't see the reason not to use a notifier for such things.

Neither of those is actually a userspace notification/handshake.

- Dave

#74 lore raw

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

Quoted 5 lines · David Brownell
Quoted 2 lines · Benjamin Herrenschmidt

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

There is Rafael's patience to remember... (rev 8?)

Yeah. And rev. 1 was posted something like ... a month ago.

#75 lore raw

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

In reply to David Brownell
Quoted 5 lines · David Brownell
Quoted 2 lines · Benjamin Herrenschmidt

I think we should get it right now. There's no hurry in pushing things especially if they aren't quite right.

There is Rafael's patience to remember... (rev 8?)

Yeah. And rev. 1 was posted something like ... a month ago.

#76 lore raw

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

In reply to David Brownell
Quoted 6 lines · David Brownell

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

Pavel's recent work aside, the only way to initiate a system sleep is from userspace. So it seems natural for all application notifications to be made by the initiating program, perhaps via dbus.

Alan Stern

#77 lore raw

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

In reply to David Brownell
Quoted 6 lines · David Brownell

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

Pavel's recent work aside, the only way to initiate a system sleep is from userspace. So it seems natural for all application notifications to be made by the initiating program, perhaps via dbus.

Alan Stern

#78 lore raw

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

Quoted 9 lines · Alan Stern
Quoted 6 lines · David Brownell

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

Quoted 3 lines

Pavel's recent work aside, the only way to initiate a system sleep is from userspace. So it seems natural for all application notifications to be made by the initiating program, perhaps via dbus.

No. Certainly not via dbus.

Ben.

#79 lore raw

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

In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 6 lines · David Brownell

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

Quoted 3 lines

Pavel's recent work aside, the only way to initiate a system sleep is from userspace. So it seems natural for all application notifications to be made by the initiating program, perhaps via dbus.

Actually, my plan is to do without notifications. Userspace should tell kernel "I'm prepared, you can suspend any time now"...

Pavel

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

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

In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 6 lines · David Brownell

I sort of agree. Looking at it from a whole-system perspective, suspending needs to be able to chitchat with userspace ... and I don't think that can be done *before* writing to /sys/power/state in an acceptably generic/portable way. (Briefly, applications need to have clean stopping points and be able to arrange system wakeup. They may well have more work to do than most drivers.)

Quoted 3 lines

Pavel's recent work aside, the only way to initiate a system sleep is from userspace. So it seems natural for all application notifications to be made by the initiating program, perhaps via dbus.

Actually, my plan is to do without notifications. Userspace should tell kernel "I'm prepared, you can suspend any time now"...

Pavel

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

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

'allow load_firmware from prepare that was not allowed before' is not 'major'.

If you feel strongly about that, please prepare patch at the top of Rafael's and we can discuss it.

But it really should be separate patch.
Pavel

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

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

I disagree.

Doing it later would introduce yet another major semantic change.

'allow load_firmware from prepare that was not allowed before' is not 'major'.

If you feel strongly about that, please prepare patch at the top of Rafael's and we can discuss it.

But it really should be separate patch.
Pavel

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

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

Quoted 9 lines · Pavel Machek
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

Quoted 5 lines
Quoted 3 lines

I disagree.

Doing it later would introduce yet another major semantic change.

'allow load_firmware from prepare that was not allowed before' is not 'major'.

Having user space fully operating is major.

Ben.

#84 lore raw

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

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · Pavel Machek
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I disagree.

Doing it later would introduce yet another major semantic change.

'allow load_firmware from prepare that was not allowed before' is not 'major'.

Having user space fully operating is major.

Please tell me what exactly is wrong with doing things that depend on the user space being available from notifiers.

Thanks,
Rafael

#85 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · Pavel Machek
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I disagree.

Doing it later would introduce yet another major semantic change.

'allow load_firmware from prepare that was not allowed before' is not 'major'.

Having user space fully operating is major.

Please tell me what exactly is wrong with doing things that depend on the user space being available from notifiers.

Thanks,
Rafael

#86 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines
Quoted 4 lines

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Can't we run the freezer after prepare() instead ?

Well, I'm not sure and I'm not going to introduce the change right now, after the paches have been included in -mm.

That would require quite some changes in the core code that I'd prefer to avoid for now. We can do something like this in a separate patch series after the present one settles down a bit.

Thanks,
Rafael

#87 lore raw

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

In reply to Benjamin Herrenschmidt
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 10 lines · Rafael J. Wysocki
+ *     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().  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).  [To work around this limitation, drivers may
+ *     register suspend and hibernation notifiers that are executed before the
+ *     freezing of tasks.]
Quoted 5 lines

Can you tell me why you kept that limitation with user space ?

I don't see the point... On the contrary, prepare() is the pefect place to implement handshaking with userspace for drivers that need to do so, such as the DRM.

This _comment_ reflects the current situation, which is that we freeze tasks before a suspend. When it's no longer necessary to do that, I'll be happy to change this comment. For now, however, that's not the case.

Thanks,
Rafael

#88 lore raw

patch pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch added to gregkh-2.6 tree

In reply to Rafael J. Wysocki

This is a note to let you know that I've just added the patch titled

Subject: PM: Introduce new top level suspend and hibernation callbacks

to my gregkh-2.6 tree. Its filename is

pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 15 12:03:22 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:33:01 +0200
Subject: PM: Introduce new top level suspend and hibernation callbacks
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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   |    8 
 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         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 852 insertions(+), 204 deletions(-)
arch/x86/kernel/apm_32.c +4 -4
@@ -1221,9 +1221,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);
 	pm_send_all(PM_RESUME, (void *)0);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
@@ -1250,7 +1250,7 @@ static void standby(void)
 		apm_error("standby", err);
 
 	local_irq_disable();
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
 }
 
@@ -1336,7 +1336,7 @@ static void check_events(void)
 			ignore_bounce = 1;
 			if ((event != APM_NORMAL_RESUME)
 			    || (ignore_normal_resume == 0)) {
-				device_resume();
+				device_resume(PMSG_RESUME);
 				pm_send_all(PM_RESUME, (void *)0);
 				queue_event(event, NULL);
 			}
drivers/base/power/main.c +533 -160

904 lines not on this page · raw message

drivers/base/power/power.h +1 -1
@@ -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
@@ -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) {
include/linux/device.h +9 -0
@@ -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 */
include/linux/pm.h +286 -28

334 lines not on this page · raw message

kernel/power/disk.c +13 -7
@@ -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
@@ -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:

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#89 lore raw

patch pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch added to gregkh-2.6 tree

In reply to Rafael J. Wysocki

This is a note to let you know that I've just added the patch titled

Subject: PM: Introduce new top level suspend and hibernation callbacks

to my gregkh-2.6 tree. Its filename is

pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

From [email protected] Tue Apr 15 12:03:22 2008
From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:33:01 +0200
Subject: PM: Introduce new top level suspend and hibernation callbacks
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

Introduce 'struct pm_ops' and 'struct pm_ext_ops' ('ext' meaning 'extended') representing suspend and hibernation operations for bus types, device classes, device types and device drivers.

Modify the PM core to use 'struct pm_ops' and 'struct pm_ext_ops' objects, if defined, instead of the ->suspend(), ->resume(), ->suspend_late(), and ->resume_early() callbacks (the old callbacks 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   |    8 
 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         |  314 ++++++++++++++++++--
 kernel/power/disk.c        |   20 -
 kernel/power/main.c        |    6 
 8 files changed, 852 insertions(+), 204 deletions(-)
arch/x86/kernel/apm_32.c +4 -4
@@ -1221,9 +1221,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);
 	pm_send_all(PM_RESUME, (void *)0);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
@@ -1250,7 +1250,7 @@ static void standby(void)
 		apm_error("standby", err);
 
 	local_irq_disable();
-	device_power_up();
+	device_power_up(PMSG_RESUME);
 	local_irq_enable();
 }
 
@@ -1336,7 +1336,7 @@ static void check_events(void)
 			ignore_bounce = 1;
 			if ((event != APM_NORMAL_RESUME)
 			    || (ignore_normal_resume == 0)) {
-				device_resume();
+				device_resume(PMSG_RESUME);
 				pm_send_all(PM_RESUME, (void *)0);
 				queue_event(event, NULL);
 			}
drivers/base/power/main.c +533 -160

904 lines not on this page · raw message

drivers/base/power/power.h +1 -1
@@ -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
@@ -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) {
include/linux/device.h +9 -0
@@ -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 */
include/linux/pm.h +286 -28

334 lines not on this page · raw message

kernel/power/disk.c +13 -7
@@ -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
@@ -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:

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch --
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

#90 lore raw

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

#91 lore raw

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

#92 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch added to gregkh-2.6 tree

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for platform bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 15 12:21:10 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:33:49 +0200
Subject: PM: New suspend and hibernation callbacks for platform bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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(-)
drivers/base/platform.c +288 -8
@@ -453,6 +453,8 @@ int platform_driver_register(struct plat
 		drv->driver.suspend = platform_drv_suspend;
 	if (drv->resume)
 		drv->driver.resume = platform_drv_resume;
+	if (drv->pm)
+		drv->driver.pm = &drv->pm->base;
 	return driver_register(&drv->driver);
 }
 EXPORT_SYMBOL_GPL(platform_driver_register);
@@ -560,7 +562,9 @@ static int platform_match(struct device 
 	return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
 }
 
-static int platform_suspend(struct device *dev, pm_message_t mesg)
+#ifdef CONFIG_PM_SLEEP
+
+static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
 {
 	int ret = 0;
 
@@ -570,7 +574,7 @@ static int platform_suspend(struct devic
 	return ret;
 }
 
-static int platform_suspend_late(struct device *dev, pm_message_t mesg)
+static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg)
 {
 	struct platform_driver *drv = to_platform_driver(dev->driver);
 	struct platform_device *pdev;
@@ -583,7 +587,7 @@ static int platform_suspend_late(struct 
 	return ret;
 }
 
-static int platform_resume_early(struct device *dev)
+static int platform_legacy_resume_early(struct device *dev)
 {
 	struct platform_driver *drv = to_platform_driver(dev->driver);
 	struct platform_device *pdev;
@@ -596,7 +600,7 @@ static int platform_resume_early(struct 
 	return ret;
 }
 
-static int platform_resume(struct device *dev)
+static int platform_legacy_resume(struct device *dev)
 {
 	int ret = 0;
 
@@ -606,15 +610,291 @@ static int platform_resume(struct device
 	return ret;
 }
 
+static int platform_pm_prepare(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm && drv->pm->prepare)
+		ret = drv->pm->prepare(dev);
+
+	return ret;
+}
+
+static void platform_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 platform_pm_suspend(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->suspend)
+			ret = drv->pm->suspend(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
+	}
+
+	return ret;
+}
+
+static int platform_pm_suspend_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->suspend_noirq)
+			ret = pdrv->pm->suspend_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND);
+	}
+
+	return ret;
+}
+
+static int platform_pm_resume(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->resume)
+			ret = drv->pm->resume(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_resume_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->resume_noirq)
+			ret = pdrv->pm->resume_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define platform_pm_suspend		NULL
+#define platform_pm_resume		NULL
+#define platform_pm_suspend_noirq	NULL
+#define platform_pm_resume_noirq	NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int platform_pm_freeze(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->freeze)
+			ret = drv->pm->freeze(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_FREEZE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_freeze_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->freeze_noirq)
+			ret = pdrv->pm->freeze_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_FREEZE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_thaw(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw)
+			ret = drv->pm->thaw(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_thaw_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->thaw_noirq)
+			ret = pdrv->pm->thaw_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_poweroff(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff)
+			ret = drv->pm->poweroff(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_HIBERNATE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_poweroff_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->poweroff_noirq)
+			ret = pdrv->pm->poweroff_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_restore(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->restore)
+			ret = drv->pm->restore(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_restore_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->restore_noirq)
+			ret = pdrv->pm->restore_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define platform_pm_freeze		NULL
+#define platform_pm_thaw		NULL
+#define platform_pm_poweroff		NULL
+#define platform_pm_restore		NULL
+#define platform_pm_freeze_noirq	NULL
+#define platform_pm_thaw_noirq		NULL
+#define platform_pm_poweroff_noirq	NULL
+#define platform_pm_restore_noirq	NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+struct pm_ext_ops platform_pm_ops = {
+	.base = {
+		.prepare = platform_pm_prepare,
+		.complete = platform_pm_complete,
+		.suspend = platform_pm_suspend,
+		.resume = platform_pm_resume,
+		.freeze = platform_pm_freeze,
+		.thaw = platform_pm_thaw,
+		.poweroff = platform_pm_poweroff,
+		.restore = platform_pm_restore,
+	},
+	.suspend_noirq = platform_pm_suspend_noirq,
+	.resume_noirq = platform_pm_resume_noirq,
+	.freeze_noirq = platform_pm_freeze_noirq,
+	.thaw_noirq = platform_pm_thaw_noirq,
+	.poweroff_noirq = platform_pm_poweroff_noirq,
+	.restore_noirq = platform_pm_restore_noirq,
+};
+
+#define PLATFORM_PM_OPS_PTR	&platform_pm_ops
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define PLATFORM_PM_OPS_PTR	NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
 struct bus_type platform_bus_type = {
 	.name		= "platform",
 	.dev_attrs	= platform_dev_attrs,
 	.match		= platform_match,
 	.uevent		= platform_uevent,
-	.suspend	= platform_suspend,
-	.suspend_late	= platform_suspend_late,
-	.resume_early	= platform_resume_early,
-	.resume		= platform_resume,
+	.pm		= PLATFORM_PM_OPS_PTR,
 };
 EXPORT_SYMBOL_GPL(platform_bus_type);
 
include/linux/platform_device.h +1 -0
@@ -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;
 };
 

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#93 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch added to gregkh-2.6 tree

In reply to Rafael J. Wysocki

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for platform bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 15 12:21:10 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:33:49 +0200
Subject: PM: New suspend and hibernation callbacks for platform bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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(-)
drivers/base/platform.c +288 -8
@@ -453,6 +453,8 @@ int platform_driver_register(struct plat
 		drv->driver.suspend = platform_drv_suspend;
 	if (drv->resume)
 		drv->driver.resume = platform_drv_resume;
+	if (drv->pm)
+		drv->driver.pm = &drv->pm->base;
 	return driver_register(&drv->driver);
 }
 EXPORT_SYMBOL_GPL(platform_driver_register);
@@ -560,7 +562,9 @@ static int platform_match(struct device 
 	return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
 }
 
-static int platform_suspend(struct device *dev, pm_message_t mesg)
+#ifdef CONFIG_PM_SLEEP
+
+static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
 {
 	int ret = 0;
 
@@ -570,7 +574,7 @@ static int platform_suspend(struct devic
 	return ret;
 }
 
-static int platform_suspend_late(struct device *dev, pm_message_t mesg)
+static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg)
 {
 	struct platform_driver *drv = to_platform_driver(dev->driver);
 	struct platform_device *pdev;
@@ -583,7 +587,7 @@ static int platform_suspend_late(struct 
 	return ret;
 }
 
-static int platform_resume_early(struct device *dev)
+static int platform_legacy_resume_early(struct device *dev)
 {
 	struct platform_driver *drv = to_platform_driver(dev->driver);
 	struct platform_device *pdev;
@@ -596,7 +600,7 @@ static int platform_resume_early(struct 
 	return ret;
 }
 
-static int platform_resume(struct device *dev)
+static int platform_legacy_resume(struct device *dev)
 {
 	int ret = 0;
 
@@ -606,15 +610,291 @@ static int platform_resume(struct device
 	return ret;
 }
 
+static int platform_pm_prepare(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm && drv->pm->prepare)
+		ret = drv->pm->prepare(dev);
+
+	return ret;
+}
+
+static void platform_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 platform_pm_suspend(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->suspend)
+			ret = drv->pm->suspend(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
+	}
+
+	return ret;
+}
+
+static int platform_pm_suspend_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->suspend_noirq)
+			ret = pdrv->pm->suspend_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND);
+	}
+
+	return ret;
+}
+
+static int platform_pm_resume(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->resume)
+			ret = drv->pm->resume(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_resume_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->resume_noirq)
+			ret = pdrv->pm->resume_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define platform_pm_suspend		NULL
+#define platform_pm_resume		NULL
+#define platform_pm_suspend_noirq	NULL
+#define platform_pm_resume_noirq	NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int platform_pm_freeze(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->freeze)
+			ret = drv->pm->freeze(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_FREEZE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_freeze_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->freeze_noirq)
+			ret = pdrv->pm->freeze_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_FREEZE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_thaw(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->thaw)
+			ret = drv->pm->thaw(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_thaw_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->thaw_noirq)
+			ret = pdrv->pm->thaw_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_poweroff(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->poweroff)
+			ret = drv->pm->poweroff(dev);
+	} else {
+		ret = platform_legacy_suspend(dev, PMSG_HIBERNATE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_poweroff_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->poweroff_noirq)
+			ret = pdrv->pm->poweroff_noirq(dev);
+	} else {
+		ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE);
+	}
+
+	return ret;
+}
+
+static int platform_pm_restore(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm) {
+		if (drv->pm->restore)
+			ret = drv->pm->restore(dev);
+	} else {
+		ret = platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int platform_pm_restore_noirq(struct device *dev)
+{
+	struct platform_driver *pdrv;
+	int ret = 0;
+
+	if (!dev->driver)
+		return 0;
+
+	pdrv = to_platform_driver(dev->driver);
+	if (pdrv->pm) {
+		if (pdrv->pm->restore_noirq)
+			ret = pdrv->pm->restore_noirq(dev);
+	} else {
+		ret = platform_legacy_resume_early(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define platform_pm_freeze		NULL
+#define platform_pm_thaw		NULL
+#define platform_pm_poweroff		NULL
+#define platform_pm_restore		NULL
+#define platform_pm_freeze_noirq	NULL
+#define platform_pm_thaw_noirq		NULL
+#define platform_pm_poweroff_noirq	NULL
+#define platform_pm_restore_noirq	NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+struct pm_ext_ops platform_pm_ops = {
+	.base = {
+		.prepare = platform_pm_prepare,
+		.complete = platform_pm_complete,
+		.suspend = platform_pm_suspend,
+		.resume = platform_pm_resume,
+		.freeze = platform_pm_freeze,
+		.thaw = platform_pm_thaw,
+		.poweroff = platform_pm_poweroff,
+		.restore = platform_pm_restore,
+	},
+	.suspend_noirq = platform_pm_suspend_noirq,
+	.resume_noirq = platform_pm_resume_noirq,
+	.freeze_noirq = platform_pm_freeze_noirq,
+	.thaw_noirq = platform_pm_thaw_noirq,
+	.poweroff_noirq = platform_pm_poweroff_noirq,
+	.restore_noirq = platform_pm_restore_noirq,
+};
+
+#define PLATFORM_PM_OPS_PTR	&platform_pm_ops
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define PLATFORM_PM_OPS_PTR	NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
 struct bus_type platform_bus_type = {
 	.name		= "platform",
 	.dev_attrs	= platform_dev_attrs,
 	.match		= platform_match,
 	.uevent		= platform_uevent,
-	.suspend	= platform_suspend,
-	.suspend_late	= platform_suspend_late,
-	.resume_early	= platform_resume_early,
-	.resume		= platform_resume,
+	.pm		= PLATFORM_PM_OPS_PTR,
 };
 EXPORT_SYMBOL_GPL(platform_bus_type);
 
include/linux/platform_device.h +1 -0
@@ -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;
 };
 

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#94 lore raw

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

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 |  372 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 335 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +334 -38
Index: linux-next/drivers/pci/pci-driver.c
===================================================================
@@ -271,7 +271,55 @@ 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 +329,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 +347,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 +356,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 +373,288 @@ 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 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 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 +677,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 +805,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-next/include/linux/pci.h
===================================================================
@@ -388,7 +388,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;
#95 lore raw

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

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 |  372 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 335 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +334 -38
Index: linux-next/drivers/pci/pci-driver.c
===================================================================
@@ -271,7 +271,55 @@ 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 +329,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 +347,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 +356,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 +373,288 @@ 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 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 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 +677,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 +805,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-next/include/linux/pci.h
===================================================================
@@ -388,7 +388,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;
#96 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch added to gregkh-2.6 tree

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for PCI bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 15 12:21:43 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:34:51 +0200
Subject: PM: New suspend and hibernation callbacks for PCI bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

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

---
 drivers/pci/pci-driver.c |  372 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 335 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +334 -38
@@ -271,7 +271,55 @@ 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 +329,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 +347,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 +356,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 +373,288 @@ 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 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 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 +677,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 +805,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
@@ -388,7 +388,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;

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#97 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch added to gregkh-2.6 tree

In reply to Rafael J. Wysocki

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for PCI bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 15 12:21:43 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Sun, 13 Apr 2008 15:34:51 +0200
Subject: PM: New suspend and hibernation callbacks for PCI bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, LKML <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

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

---
 drivers/pci/pci-driver.c |  372 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 335 insertions(+), 39 deletions(-)
drivers/pci/pci-driver.c +334 -38
@@ -271,7 +271,55 @@ 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 +329,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 +347,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 +356,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 +373,288 @@ 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 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 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 +677,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 +805,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
@@ -388,7 +388,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;

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-remove-legacy-pm.patch driver-core/power_state-remove-it-from-driver-core.patch driver-core/pm-handle-device-registrations-during-suspend-resume.patch driver-core/pm-convert-wakeup-flag-accessors-to-inline-functions.patch driver-core/driver-core-call-device_pm_add-after-bus_add_device-in-device_add.patch driver-core/pm-remove-destroy_suspended_device.patch driver-core/pm-fix-misuse-of-wakeup-flag-accessors-in-serial-core.patch driver-core/pm-make-wakeup-flags-available-whenever-config_pm-is-set.patch driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#98 lore raw

Re: PM: New suspend and hibernation callbacks for PCI bus type

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

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

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

Changes in Linus's tree broke merging this one really badly, so much so that I can't see what should be done with a quick scan.

I'll drop this from my tree for now, can you regenerate it?

thanks,

greg k-h

#99 lore raw

Re: PM: New suspend and hibernation callbacks for PCI bus type

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

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

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

Changes in Linus's tree broke merging this one really badly, so much so that I can't see what should be done with a quick scan.

I'll drop this from my tree for now, can you regenerate it?

thanks,

greg k-h

author Acked-by Pavel Machek Acked-by Jesse Barnes
#100 lore raw

Re: PM: New suspend and hibernation callbacks for PCI bus type

Quoted 11 lines · Greg KH
Quoted 9 lines · Rafael J. Wysocki

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

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

Quoted 4 lines

Changes in Linus's tree broke merging this one really badly, so much so that I can't see what should be done with a quick scan.

I'll drop this from my tree for now, can you regenerate it?

I've already had regenerated it. The version below applies to the current -git.

Thanks,
Rafael

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

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

---
 drivers/pci/pci-driver.c |  376 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 337 insertions(+), 41 deletions(-)
drivers/pci/pci-driver.c +336 -40
Index: linux-2.6/drivers/pci/pci-driver.c
===================================================================
@@ -274,7 +274,57 @@ 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);
+	pci_msi_shutdown(pci_dev);
+	pci_msix_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;
@@ -284,18 +334,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;
@@ -308,26 +352,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);
@@ -336,11 +361,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);
@@ -353,17 +378,288 @@ 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);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_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 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 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
@@ -386,6 +682,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);
 
@@ -511,12 +810,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
===================================================================
@@ -388,7 +388,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;
author Acked-by Pavel Machek Acked-by Jesse Barnes
#101 lore raw

Re: PM: New suspend and hibernation callbacks for PCI bus type

In reply to Greg KH
Quoted 11 lines · Greg KH
Quoted 9 lines · Rafael J. Wysocki

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

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

Quoted 4 lines

Changes in Linus's tree broke merging this one really badly, so much so that I can't see what should be done with a quick scan.

I'll drop this from my tree for now, can you regenerate it?

I've already had regenerated it. The version below applies to the current -git.

Thanks,
Rafael

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

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

---
 drivers/pci/pci-driver.c |  376 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 337 insertions(+), 41 deletions(-)
drivers/pci/pci-driver.c +336 -40
Index: linux-2.6/drivers/pci/pci-driver.c
===================================================================
@@ -274,7 +274,57 @@ 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);
+	pci_msi_shutdown(pci_dev);
+	pci_msix_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;
@@ -284,18 +334,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;
@@ -308,26 +352,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);
@@ -336,11 +361,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);
@@ -353,17 +378,288 @@ 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);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_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 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 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
@@ -386,6 +682,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);
 
@@ -511,12 +810,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
===================================================================
@@ -388,7 +388,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;
#102 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch added to gregkh-2.6 tree

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for PCI bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Wed Apr 30 05:09:52 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Wed, 30 Apr 2008 14:09:24 +0200
Subject: PM: New suspend and hibernation callbacks for PCI bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

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

---
 drivers/pci/pci-driver.c |  376 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 337 insertions(+), 41 deletions(-)
drivers/pci/pci-driver.c +336 -40
@@ -274,7 +274,57 @@ 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);
+	pci_msi_shutdown(pci_dev);
+	pci_msix_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;
@@ -284,18 +334,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;
@@ -308,26 +352,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);
@@ -336,11 +361,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);
@@ -353,17 +378,288 @@ 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);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_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 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 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
@@ -386,6 +682,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);
 
@@ -511,12 +810,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
@@ -389,7 +389,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;

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#103 lore raw

patch pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch added to gregkh-2.6 tree

In reply to Rafael J. Wysocki

This is a note to let you know that I've just added the patch titled

Subject: PM: New suspend and hibernation callbacks for PCI bus type

to my gregkh-2.6 tree. Its filename is

pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Wed Apr 30 05:09:52 2008

From: "Rafael J. Wysocki" <[email protected]>
Date: Wed, 30 Apr 2008 14:09:24 +0200
Subject: PM: New suspend and hibernation callbacks for PCI bus type
To: Greg KH <[email protected]>
Cc: pm list <[email protected]>, ACPI Devel Maling List <[email protected]>, Alan Stern <[email protected]>, Len Brown <[email protected]>, Alexey Starikovskiy <[email protected]>, David Brownell <[email protected]>, Pavel Machek <[email protected]>, Benjamin Herrenschmidt <[email protected]>, Oliver Neukum <[email protected]>, Nigel Cunningham <[email protected]>, Jesse Barnes <[email protected]>, Andrew Morton <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline

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

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

---
 drivers/pci/pci-driver.c |  376 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/pci.h      |    2 
 2 files changed, 337 insertions(+), 41 deletions(-)
drivers/pci/pci-driver.c +336 -40
@@ -274,7 +274,57 @@ 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);
+	pci_msi_shutdown(pci_dev);
+	pci_msix_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;
@@ -284,18 +334,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;
@@ -308,26 +352,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);
@@ -336,11 +361,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);
@@ -353,17 +378,288 @@ 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);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_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 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 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
@@ -386,6 +682,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);
 
@@ -511,12 +810,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
@@ -389,7 +389,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;

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/pm-introduce-new-top-level-suspend-and-hibernation-callbacks.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-pci-bus-type.patch driver-core/pm-new-suspend-and-hibernation-callbacks-for-platform-bus-type.patch

#104 lore raw

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

#105 lore raw

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

#106 lore raw

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;
#107 lore raw

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;