public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found] <200706242239.05678.rjw@sisk.pl>
@ 2007-06-24 20:40 ` Rafael J. Wysocki
  2007-06-24 20:41 ` [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-24 20:40 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

Some drivers may need to use ACPI to determine the low power states in which
to place their devices, but to provide the drivers with this information the
ACPI core needs to know what sleep state the system is going to enter.
Namely, the device's state should not be too high power for given system sleep
state and, if the device is supposed to be able to wake up the system, its state
should not be too low power for the wake up to be possible).  However,
pm_ops->prepare() is only called after the drivers' .suspend() callbacks have
been executed, so we need an additional means to pass the information of the
target system sleep state to the ACPI core.  For this purpose, we can introduce
an additional member function in 'struct pm_ops'.

Additionally, the at91 platform code incorrectly assumes that pm_ops->prepare()
will be called before devices are suspended and uses it for setting the target
system sleep state, so pm_ops->prepare() should to be replaced with the new
operation, pm_ops->set_target(), for this architecture.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 arch/arm/mach-at91/pm.c   |    4 +-
 drivers/acpi/sleep/main.c |   84 ++++++++++++++++++++++++++++------------------
 include/linux/pm.h        |   53 +++++++++++++++++++----------
 kernel/power/main.c       |    6 ++-
 4 files changed, 95 insertions(+), 52 deletions(-)

Index: linux-2.6.22-rc5/include/linux/pm.h
===================================================================
--- linux-2.6.22-rc5.orig/include/linux/pm.h	2007-06-24 01:41:12.000000000 +0200
+++ linux-2.6.22-rc5/include/linux/pm.h	2007-06-24 20:38:33.000000000 +0200
@@ -110,37 +110,54 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
 
 /**
- * struct pm_ops - Callbacks for managing platform dependent suspend states.
- * @valid: Callback to determine whether the given state can be entered.
- *	Valid states are advertised in /sys/power/state but can still
- *	be rejected by prepare or enter if the conditions aren't right.
- *	There is a %pm_valid_only_mem function available that can be assigned
- *	to this if you only implement mem sleep.
+ * struct pm_ops - Callbacks for managing platform dependent system sleep
+ *	states.
  *
- * @prepare: Prepare the platform for the given suspend state. Can return a
- *	negative error code if necessary.
- *
- * @enter: Enter the given suspend state, must be assigned. Can return a
- *	negative error code if necessary.
- *
- * @finish: Called when the system has left the given state and all devices
- *	are resumed. The return value is ignored.
+ * @valid: Callback to determine if given system sleep state is supported by
+ *	the platform.  Valid (ie. supported) states are advertised in
+ *	/sys/power/state.  Note that it still may be impossible to enter given
+ *	system sleep state if the conditions aren't right.
+ *	There is the %pm_valid_only_mem function available that can be assigned
+ *	to this if the platform only supports mem sleep.
+ *
+ * @set_target: Tell the platform which system sleep state is going to be
+ *	entered.  The information passed to @set_target should be disregarded
+ *	by the platform as soon as @finish() is executed and if	@prepare()
+ *	fails.
+ *	This callback is optional.  However, if it is implemented, the
+ *	argument passed to @prepare(), @enter and @finish() must be ignored.
+ *
+ * @prepare: Prepare the platform for entering the system sleep state indicated
+ *	by @set_target().
+ *	This callback is optional.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter given
+ *	sleep state.
+ *
+ * @enter: Enter the system sleep state indicated by @set_target().
+ *	This callback is mandatory.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter given
+ *	sleep state.
+ *
+ * @finish: Called when the system has just left a sleep state.
+ *	This callback is optional, but should be implemented by platforms that
+ *	implement @prepare().  It is always called after @enter() (even if
+ *	@enter() fails).
  */
 struct pm_ops {
 	int (*valid)(suspend_state_t state);
+	int (*set_target)(suspend_state_t state);
 	int (*prepare)(suspend_state_t state);
 	int (*enter)(suspend_state_t state);
 	int (*finish)(suspend_state_t state);
 };
 
+extern struct pm_ops *pm_ops;
+
 /**
  * pm_set_ops - set platform dependent power management ops
  * @pm_ops: The new power management operations to set.
  */
 extern void pm_set_ops(struct pm_ops *pm_ops);
-extern struct pm_ops *pm_ops;
-extern int pm_suspend(suspend_state_t state);
-
 extern int pm_valid_only_mem(suspend_state_t state);
 
 /**
@@ -161,6 +178,8 @@ extern void arch_suspend_disable_irqs(vo
  */
 extern void arch_suspend_enable_irqs(void);
 
+extern int pm_suspend(suspend_state_t state);
+
 /*
  * Device power management
  */
Index: linux-2.6.22-rc5/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc5.orig/kernel/power/main.c	2007-06-24 01:41:49.000000000 +0200
+++ linux-2.6.22-rc5/kernel/power/main.c	2007-06-24 20:38:30.000000000 +0200
@@ -15,7 +15,6 @@
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/pm.h>
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/resume-trace.h>
@@ -161,6 +160,11 @@ int suspend_devices_and_enter(suspend_st
 	if (!pm_ops)
 		return -ENOSYS;
 
+	if (pm_ops->set_target) {
+		error = pm_ops->set_target(state);
+		if (error)
+			return error;
+	}
 	suspend_console();
 	error = device_suspend(PMSG_SUSPEND);
 	if (error) {
Index: linux-2.6.22-rc5/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc5.orig/drivers/acpi/sleep/main.c	2007-06-24 01:40:38.000000000 +0200
+++ linux-2.6.22-rc5/drivers/acpi/sleep/main.c	2007-06-24 20:38:30.000000000 +0200
@@ -34,34 +34,54 @@ static u32 acpi_suspend_states[] = {
 
 static int init_8259A_after_S1;
 
+extern int acpi_sleep_prepare(u32 acpi_state);
+extern void acpi_power_off(void);
+
+static u32 acpi_target_suspend_state = ACPI_STATE_S0;
+
+/**
+ *	acpi_pm_set_target - Set the target system sleep state to the state
+ *		associated with given @pm_state, if supported.
+ */
+
+static int acpi_pm_set_target(suspend_state_t pm_state)
+{
+	u32 acpi_state = acpi_suspend_states[pm_state];
+	int error = 0;
+
+	if (sleep_states[acpi_state]) {
+		acpi_target_suspend_state = acpi_state;
+	} else {
+		printk(KERN_ERR "ACPI does not support this state: %d\n",
+			pm_state);
+		error = -ENOSYS;
+	}
+	return error;
+}
+
 /**
  *	acpi_pm_prepare - Do preliminary suspend work.
- *	@pm_state:		suspend state we're entering.
+ *	@pm_state: ignored
  *
- *	Make sure we support the state. If we do, and we need it, set the
- *	firmware waking vector and do arch-specific nastiness to get the 
- *	wakeup code to the waking vector. 
+ *	If necessary, set the firmware waking vector and do arch-specific
+ *	nastiness to get the wakeup code to the waking vector.
  */
 
-extern int acpi_sleep_prepare(u32 acpi_state);
-extern void acpi_power_off(void);
-
 static int acpi_pm_prepare(suspend_state_t pm_state)
 {
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	int error = acpi_sleep_prepare(acpi_target_suspend_state);
 
-	if (!sleep_states[acpi_state]) {
-		printk("acpi_pm_prepare does not support %d \n", pm_state);
-		return -EPERM;
-	}
-	return acpi_sleep_prepare(acpi_state);
+	if (error)
+		acpi_target_suspend_state = ACPI_STATE_S0;
+
+	return error;
 }
 
 /**
  *	acpi_pm_enter - Actually enter a sleep state.
- *	@pm_state:		State we're entering.
+ *	@pm_state: ignored
  *
- *	Flush caches and go to sleep. For STR or STD, we have to call 
+ *	Flush caches and go to sleep. For STR or S2, we have to call
  *	arch-specific assembly, which in turn call acpi_enter_sleep_state().
  *	It's unfortunate, but it works. Please fix if you're feeling frisky.
  */
@@ -70,31 +90,32 @@ static int acpi_pm_enter(suspend_state_t
 {
 	acpi_status status = AE_OK;
 	unsigned long flags = 0;
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	u32 acpi_state = acpi_target_suspend_state;
 
 	ACPI_FLUSH_CPU_CACHE();
 
 	/* Do arch specific saving of state. */
-	if (pm_state > PM_SUSPEND_STANDBY) {
+	if (acpi_state == ACPI_STATE_S2 || acpi_state == ACPI_STATE_S3) {
 		int error = acpi_save_state_mem();
-		if (error)
+
+		if (error) {
+			acpi_target_suspend_state = ACPI_STATE_S0;
 			return error;
+		}
 	}
 
 	local_irq_save(flags);
 	acpi_enable_wakeup_device(acpi_state);
-	switch (pm_state) {
-	case PM_SUSPEND_STANDBY:
+	switch (acpi_state) {
+	case ACPI_STATE_S1:
 		barrier();
 		status = acpi_enter_sleep_state(acpi_state);
 		break;
 
-	case PM_SUSPEND_MEM:
+	case ACPI_STATE_S2:
+	case ACPI_STATE_S3:
 		do_suspend_lowlevel();
 		break;
-
-	default:
-		return -EINVAL;
 	}
 
 	/* ACPI 3.0 specs (P62) says that it's the responsabilty
@@ -114,12 +135,8 @@ static int acpi_pm_enter(suspend_state_t
 	local_irq_restore(flags);
 	printk(KERN_DEBUG "Back to C!\n");
 
-	/* restore processor state
-	 * We should only be here if we're coming back from STR or STD.
-	 * And, in the case of the latter, the memory image should have already
-	 * been loaded from disk.
-	 */
-	if (pm_state > PM_SUSPEND_STANDBY)
+	/* restore processor state */
+	if (acpi_state == ACPI_STATE_S2 || acpi_state == ACPI_STATE_S3)
 		acpi_restore_state_mem();
 
 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
@@ -127,7 +144,7 @@ static int acpi_pm_enter(suspend_state_t
 
 /**
  *	acpi_pm_finish - Finish up suspend sequence.
- *	@pm_state:		State we're coming out of.
+ *	@pm_state: ignored
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed). 
@@ -135,7 +152,7 @@ static int acpi_pm_enter(suspend_state_t
 
 static int acpi_pm_finish(suspend_state_t pm_state)
 {
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	u32 acpi_state = acpi_target_suspend_state;
 
 	acpi_leave_sleep_state(acpi_state);
 	acpi_disable_wakeup_device(acpi_state);
@@ -143,6 +160,8 @@ static int acpi_pm_finish(suspend_state_
 	/* reset firmware waking vector */
 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 
+	acpi_target_suspend_state = ACPI_STATE_S0;
+
 	if (init_8259A_after_S1) {
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
@@ -183,6 +202,7 @@ static int acpi_pm_state_valid(suspend_s
 
 static struct pm_ops acpi_pm_ops = {
 	.valid = acpi_pm_state_valid,
+	.set_target = acpi_pm_set_target,
 	.prepare = acpi_pm_prepare,
 	.enter = acpi_pm_enter,
 	.finish = acpi_pm_finish,
Index: linux-2.6.22-rc5/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-at91/pm.c	2007-06-24 20:38:33.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-at91/pm.c	2007-06-24 20:40:20.000000000 +0200
@@ -53,7 +53,7 @@ static suspend_state_t target_state;
 /*
  * Called after processes are frozen, but before we shutdown devices.
  */
-static int at91_pm_prepare(suspend_state_t state)
+static int at91_pm_set_target(suspend_state_t state)
 {
 	target_state = state;
 	return 0;
@@ -201,7 +201,7 @@ error:
 
 static struct pm_ops at91_pm_ops ={
 	.valid		= at91_pm_valid_state,
-	.prepare	= at91_pm_prepare,
+	.set_target	= at91_pm_set_target,
 	.enter		= at91_pm_enter,
 };
 

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h
       [not found] <200706242239.05678.rjw@sisk.pl>
  2007-06-24 20:40 ` [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
@ 2007-06-24 20:41 ` Rafael J. Wysocki
  2007-06-24 20:42 ` [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things Rafael J. Wysocki
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-24 20:41 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

Move the definition of 'struct pm_ops' and related functions from <linux/pm.h>
to <linux/suspend.h> .

There are, at least, the following reasons to do that:
* 'struct pm_ops' is specifically related to suspend and not to the power
  management in general.
* As long as 'struct pm_ops' is defined in <linux/pm.h>, any modification of it
  causes the entire kernel to be recompiled, which is unnecessary and annoying.
* Some suspend-related features are already defined in <linux/suspend.h>, so it
  is logical to move the definition of 'struct pm_ops' into there.
* 'struct hibernation_ops', being the hibernation-related counterpart of
  'struct pm_ops', is defined in <linux/suspend.h> .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 arch/arm/common/sharpsl_pm.c             |    1 
 arch/arm/mach-at91/pm.c                  |    3 
 arch/arm/mach-omap1/pm.c                 |    3 
 arch/arm/mach-omap2/pm.c                 |    3 
 arch/arm/mach-pnx4008/pm.c               |    2 
 arch/blackfin/mach-common/pm.c           |    2 
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    2 
 include/linux/pm.h                       |   78 ------------------------
 include/linux/suspend.h                  |  100 +++++++++++++++++++++++++++----
 9 files changed, 96 insertions(+), 98 deletions(-)

Index: linux-2.6.22-rc5/include/linux/pm.h
===================================================================
--- linux-2.6.22-rc5.orig/include/linux/pm.h	2007-06-24 01:42:02.000000000 +0200
+++ linux-2.6.22-rc5/include/linux/pm.h	2007-06-24 18:50:41.000000000 +0200
@@ -102,84 +102,6 @@ struct pm_dev
 extern void (*pm_idle)(void);
 extern void (*pm_power_off)(void);
 
-typedef int __bitwise suspend_state_t;
-
-#define PM_SUSPEND_ON		((__force suspend_state_t) 0)
-#define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
-#define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
-#define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
-
-/**
- * struct pm_ops - Callbacks for managing platform dependent system sleep
- *	states.
- *
- * @valid: Callback to determine if given system sleep state is supported by
- *	the platform.  Valid (ie. supported) states are advertised in
- *	/sys/power/state.  Note that it still may be impossible to enter given
- *	system sleep state if the conditions aren't right.
- *	There is the %pm_valid_only_mem function available that can be assigned
- *	to this if the platform only supports mem sleep.
- *
- * @set_target: Tell the platform which system sleep state is going to be
- *	entered.  The information passed to @set_target should be disregarded
- *	by the platform as soon as @finish() is executed and if	@prepare()
- *	fails.
- *	This callback is optional.  However, if it is implemented, the
- *	argument passed to @prepare(), @enter and @finish() must be ignored.
- *
- * @prepare: Prepare the platform for entering the system sleep state indicated
- *	by @set_target().
- *	This callback is optional.  It returns 0 on success or a negative
- *	error code otherwise, in which case the system cannot enter given
- *	sleep state.
- *
- * @enter: Enter the system sleep state indicated by @set_target().
- *	This callback is mandatory.  It returns 0 on success or a negative
- *	error code otherwise, in which case the system cannot enter given
- *	sleep state.
- *
- * @finish: Called when the system has just left a sleep state.
- *	This callback is optional, but should be implemented by platforms that
- *	implement @prepare().  It is always called after @enter() (even if
- *	@enter() fails).
- */
-struct pm_ops {
-	int (*valid)(suspend_state_t state);
-	int (*set_target)(suspend_state_t state);
-	int (*prepare)(suspend_state_t state);
-	int (*enter)(suspend_state_t state);
-	int (*finish)(suspend_state_t state);
-};
-
-extern struct pm_ops *pm_ops;
-
-/**
- * pm_set_ops - set platform dependent power management ops
- * @pm_ops: The new power management operations to set.
- */
-extern void pm_set_ops(struct pm_ops *pm_ops);
-extern int pm_valid_only_mem(suspend_state_t state);
-
-/**
- * arch_suspend_disable_irqs - disable IRQs for suspend
- *
- * Disables IRQs (in the default case). This is a weak symbol in the common
- * code and thus allows architectures to override it if more needs to be
- * done. Not called for suspend to disk.
- */
-extern void arch_suspend_disable_irqs(void);
-
-/**
- * arch_suspend_enable_irqs - enable IRQs after suspend
- *
- * Enables IRQs (in the default case). This is a weak symbol in the common
- * code and thus allows architectures to override it if more needs to be
- * done. Not called for suspend to disk.
- */
-extern void arch_suspend_enable_irqs(void);
-
-extern int pm_suspend(suspend_state_t state);
-
 /*
  * Device power management
  */
Index: linux-2.6.22-rc5/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc5.orig/include/linux/suspend.h	2007-06-24 00:18:28.000000000 +0200
+++ linux-2.6.22-rc5/include/linux/suspend.h	2007-06-24 18:51:56.000000000 +0200
@@ -1,5 +1,5 @@
-#ifndef _LINUX_SWSUSP_H
-#define _LINUX_SWSUSP_H
+#ifndef _LINUX_SUSPEND_H
+#define _LINUX_SUSPEND_H
 
 #if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32) || defined(CONFIG_PPC64)
 #include <asm/suspend.h>
@@ -10,6 +10,92 @@
 #include <linux/pm.h>
 #include <linux/mm.h>
 
+#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
+extern int pm_prepare_console(void);
+extern void pm_restore_console(void);
+#else
+static inline int pm_prepare_console(void) { return 0; }
+static inline void pm_restore_console(void) {}
+#endif
+
+typedef int __bitwise suspend_state_t;
+
+#define PM_SUSPEND_ON		((__force suspend_state_t) 0)
+#define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
+#define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
+#define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
+
+/**
+ * struct pm_ops - Callbacks for managing platform dependent system sleep
+ *	states.
+ *
+ * @valid: Callback to determine if given system sleep state is supported by
+ *	the platform.  Valid (ie. supported) states are advertised in
+ *	/sys/power/state.  Note that it still may be impossible to enter given
+ *	system sleep state if the conditions aren't right.
+ *	There is the %pm_valid_only_mem function available that can be assigned
+ *	to this if the platform only supports mem sleep.
+ *
+ * @set_target: Tell the platform which system sleep state is going to be
+ *	entered.  The information passed to @set_target should be disregarded
+ *	by the platform as soon as @finish() is executed and if	@prepare()
+ *	fails.
+ *	This callback is optional.  However, if it is implemented, the
+ *	argument passed to @prepare(), @enter and @finish() must be ignored.
+ *
+ * @prepare: Prepare the platform for entering the system sleep state indicated
+ *	by @set_target().
+ *	This callback is optional.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter given
+ *	sleep state.
+ *
+ * @enter: Enter the system sleep state indicated by @set_target().
+ *	This callback is mandatory.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter given
+ *	sleep state.
+ *
+ * @finish: Called when the system has just left a sleep state.
+ *	This callback is optional, but should be implemented by platforms that
+ *	implement @prepare().  It is always called after @enter() (even if
+ *	@enter() fails).
+ */
+struct pm_ops {
+	int (*valid)(suspend_state_t state);
+	int (*set_target)(suspend_state_t state);
+	int (*prepare)(suspend_state_t state);
+	int (*enter)(suspend_state_t state);
+	int (*finish)(suspend_state_t state);
+};
+
+extern struct pm_ops *pm_ops;
+
+/**
+ * pm_set_ops - set platform dependent power management ops
+ * @pm_ops: The new power management operations to set.
+ */
+extern void pm_set_ops(struct pm_ops *pm_ops);
+extern int pm_valid_only_mem(suspend_state_t state);
+
+/**
+ * arch_suspend_disable_irqs - disable IRQs for suspend
+ *
+ * Disables IRQs (in the default case). This is a weak symbol in the common
+ * code and thus allows architectures to override it if more needs to be
+ * done. Not called for suspend to disk.
+ */
+extern void arch_suspend_disable_irqs(void);
+
+/**
+ * arch_suspend_enable_irqs - enable IRQs after suspend
+ *
+ * Enables IRQs (in the default case). This is a weak symbol in the common
+ * code and thus allows architectures to override it if more needs to be
+ * done. Not called for suspend to disk.
+ */
+extern void arch_suspend_enable_irqs(void);
+
+extern int pm_suspend(suspend_state_t state);
+
 /* struct pbe is used for creating lists of pages that should be restored
  * atomically during the resume from disk, because the page frames they have
  * occupied before the suspend are in use.
@@ -24,14 +110,6 @@ struct pbe {
 extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
-#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
-extern int pm_prepare_console(void);
-extern void pm_restore_console(void);
-#else
-static inline int pm_prepare_console(void) { return 0; }
-static inline void pm_restore_console(void) {}
-#endif
-
 /**
  * struct hibernation_ops - hibernation platform support
  *
@@ -127,4 +205,4 @@ static inline void register_nosave_regio
 }
 #endif
 
-#endif /* _LINUX_SWSUSP_H */
+#endif /* _LINUX_SUSPEND_H */
Index: linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/common/sharpsl_pm.c	2007-06-23 21:22:43.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c	2007-06-24 19:01:36.000000000 +0200
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/leds.h>
 #include <linux/apm-emulation.h>
+#include <linux/suspend.h>
 
 #include <asm/hardware.h>
 #include <asm/mach-types.h>
Index: linux-2.6.22-rc5/arch/arm/mach-pnx4008/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pnx4008/pm.c	2007-06-23 21:22:43.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pnx4008/pm.c	2007-06-24 19:03:33.000000000 +0200
@@ -15,7 +15,7 @@
 #include <linux/rtc.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
 
Index: linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap1/pm.c	2007-06-23 21:22:43.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c	2007-06-24 19:05:17.000000000 +0200
@@ -35,10 +35,9 @@
  * 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap2/pm.c	2007-06-17 12:38:46.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c	2007-06-24 19:06:08.000000000 +0200
@@ -16,10 +16,9 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc5/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-at91/pm.c	2007-06-17 12:38:46.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-at91/pm.c	2007-06-24 19:07:22.000000000 +0200
@@ -10,10 +10,9 @@
  * (at your option) any later version.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/blackfin/mach-common/pm.c	2007-06-17 12:38:46.000000000 +0200
+++ linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c	2007-06-24 19:08:21.000000000 +0200
@@ -32,7 +32,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
 
Index: linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-17 12:38:50.000000000 +0200
+++ linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 19:09:20.000000000 +0200
@@ -1,5 +1,5 @@
 #include <linux/init.h>
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/io.h>
 #include <asm/time.h>
 #include <asm/cacheflush.h>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things
       [not found] <200706242239.05678.rjw@sisk.pl>
  2007-06-24 20:40 ` [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
  2007-06-24 20:41 ` [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
@ 2007-06-24 20:42 ` Rafael J. Wysocki
  2007-06-24 20:44 ` [RFC/RFT][PATCH -mm 4/4] PM: Rework struct platform_suspend_operations Rafael J. Wysocki
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-24 20:42 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

The name of 'struct pm_ops' suggests that it is related to the power management
in general, but in fact it is only related to suspend.  Moreover, its name
should indicate what this structure is used for, so it seems reasonable to
change it to 'struct platform_suspend_operations'.  In that case, the name of
the global variable of this type used by the PM core and the names of related
functions should be changed accordingly.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 Documentation/power/interface.txt        |    2 -
 arch/arm/common/sharpsl_pm.c             |    8 +++----
 arch/arm/mach-at91/pm.c                  |    4 +--
 arch/arm/mach-omap1/pm.c                 |    6 ++---
 arch/arm/mach-omap2/pm.c                 |    6 ++---
 arch/arm/mach-pnx4008/pm.c               |    4 +--
 arch/arm/mach-pxa/pm.c                   |    6 ++---
 arch/arm/mach-sa1100/pm.c                |    6 ++---
 arch/arm/plat-s3c24xx/pm.c               |    6 ++---
 arch/blackfin/mach-common/pm.c           |    4 +--
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    4 +--
 arch/sh/boards/hp6xx/pm.c                |    6 ++---
 drivers/acpi/sleep/main.c                |    6 ++---
 include/linux/suspend.h                  |   20 +++++++++---------
 kernel/power/main.c                      |   34 +++++++++++++++----------------
 15 files changed, 61 insertions(+), 61 deletions(-)

Index: linux-2.6.22-rc5/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc5.orig/include/linux/suspend.h	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/include/linux/suspend.h	2007-06-24 20:45:20.000000000 +0200
@@ -26,15 +26,15 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
 
 /**
- * struct pm_ops - Callbacks for managing platform dependent system sleep
- *	states.
+ * struct platform_suspend_operations - Callbacks for managing platform
+ *	dependent system sleep states.
  *
  * @valid: Callback to determine if given system sleep state is supported by
  *	the platform.  Valid (ie. supported) states are advertised in
  *	/sys/power/state.  Note that it still may be impossible to enter given
  *	system sleep state if the conditions aren't right.
- *	There is the %pm_valid_only_mem function available that can be assigned
- *	to this if the platform only supports mem sleep.
+ *	There is the %suspend_valid_only_mem function available that can be
+ *	assigned to this if the platform only supports mem sleep.
  *
  * @set_target: Tell the platform which system sleep state is going to be
  *	entered.  The information passed to @set_target should be disregarded
@@ -59,7 +59,7 @@ typedef int __bitwise suspend_state_t;
  *	implement @prepare().  It is always called after @enter() (even if
  *	@enter() fails).
  */
-struct pm_ops {
+struct platform_suspend_operations {
 	int (*valid)(suspend_state_t state);
 	int (*set_target)(suspend_state_t state);
 	int (*prepare)(suspend_state_t state);
@@ -67,14 +67,14 @@ struct pm_ops {
 	int (*finish)(suspend_state_t state);
 };
 
-extern struct pm_ops *pm_ops;
+extern struct platform_suspend_operations *suspend_ops;
 
 /**
- * pm_set_ops - set platform dependent power management ops
- * @pm_ops: The new power management operations to set.
+ * suspend_set_ops - set platform dependent suspend operations
+ * @ops: The new suspend operations to set.
  */
-extern void pm_set_ops(struct pm_ops *pm_ops);
-extern int pm_valid_only_mem(suspend_state_t state);
+extern void suspend_set_ops(struct platform_suspend_operations *ops);
+extern int suspend_valid_only_mem(suspend_state_t state);
 
 /**
  * arch_suspend_disable_irqs - disable IRQs for suspend
Index: linux-2.6.22-rc5/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc5.orig/drivers/acpi/sleep/main.c	2007-06-24 20:45:15.000000000 +0200
+++ linux-2.6.22-rc5/drivers/acpi/sleep/main.c	2007-06-24 20:45:20.000000000 +0200
@@ -21,7 +21,7 @@
 
 u8 sleep_states[ACPI_S_STATE_COUNT];
 
-static struct pm_ops acpi_pm_ops;
+static struct platform_suspend_operations acpi_pm_ops;
 
 extern void do_suspend_lowlevel(void);
 
@@ -200,7 +200,7 @@ static int acpi_pm_state_valid(suspend_s
 	}
 }
 
-static struct pm_ops acpi_pm_ops = {
+static struct platform_suspend_operations acpi_pm_ops = {
 	.valid = acpi_pm_state_valid,
 	.set_target = acpi_pm_set_target,
 	.prepare = acpi_pm_prepare,
@@ -303,7 +303,7 @@ int __init acpi_sleep_init(void)
 	}
 	printk(")\n");
 
-	pm_set_ops(&acpi_pm_ops);
+	suspend_set_ops(&acpi_pm_ops);
 
 #ifdef CONFIG_SOFTWARE_SUSPEND
 	if (sleep_states[ACPI_STATE_S4])
Index: linux-2.6.22-rc5/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc5.orig/kernel/power/main.c	2007-06-24 20:45:15.000000000 +0200
+++ linux-2.6.22-rc5/kernel/power/main.c	2007-06-24 20:45:20.000000000 +0200
@@ -33,28 +33,28 @@ DEFINE_MUTEX(pm_mutex);
 unsigned int pm_flags;
 EXPORT_SYMBOL(pm_flags);
 
-struct pm_ops *pm_ops;
+struct platform_suspend_operations *suspend_ops;
 
 /**
- *	pm_set_ops - Set the global power method table. 
+ *	suspend_set_ops - Set the global suspend method table.
  *	@ops:	Pointer to ops structure.
  */
 
-void pm_set_ops(struct pm_ops * ops)
+void suspend_set_ops(struct platform_suspend_operations *ops)
 {
 	mutex_lock(&pm_mutex);
-	pm_ops = ops;
+	suspend_ops = ops;
 	mutex_unlock(&pm_mutex);
 }
 
 /**
- * pm_valid_only_mem - generic memory-only valid callback
+ * suspend_valid_only_mem - generic memory-only valid callback
  *
- * pm_ops drivers that implement mem suspend only and only need
+ * Platform drivers that implement mem suspend only and only need
  * to check for that in their .valid callback can use this instead
  * of rolling their own .valid callback.
  */
-int pm_valid_only_mem(suspend_state_t state)
+int suspend_valid_only_mem(suspend_state_t state)
 {
 	return state == PM_SUSPEND_MEM;
 }
@@ -62,8 +62,8 @@ int pm_valid_only_mem(suspend_state_t st
 
 static inline void pm_finish(suspend_state_t state)
 {
-	if (pm_ops->finish)
-		pm_ops->finish(state);
+	if (suspend_ops->finish)
+		suspend_ops->finish(state);
 }
 
 /**
@@ -77,7 +77,7 @@ static int suspend_prepare(void)
 	int error;
 	unsigned int free_pages;
 
-	if (!pm_ops || !pm_ops->enter)
+	if (!suspend_ops || !suspend_ops->enter)
 		return -EPERM;
 
 	error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
@@ -140,7 +140,7 @@ int suspend_enter(suspend_state_t state)
 		printk(KERN_ERR "Some devices failed to power down\n");
 		goto Done;
 	}
-	error = pm_ops->enter(state);
+	error = suspend_ops->enter(state);
 	device_power_up();
  Done:
 	arch_suspend_enable_irqs();
@@ -157,11 +157,11 @@ int suspend_devices_and_enter(suspend_st
 {
 	int error;
 
-	if (!pm_ops)
+	if (!suspend_ops)
 		return -ENOSYS;
 
-	if (pm_ops->set_target) {
-		error = pm_ops->set_target(state);
+	if (suspend_ops->set_target) {
+		error = suspend_ops->set_target(state);
 		if (error)
 			return error;
 	}
@@ -171,8 +171,8 @@ int suspend_devices_and_enter(suspend_st
 		printk(KERN_ERR "Some devices failed to suspend\n");
 		goto Resume_console;
 	}
-	if (pm_ops->prepare) {
-		error = pm_ops->prepare(state);
+	if (suspend_ops->prepare) {
+		error = suspend_ops->prepare(state);
 		if (error)
 			goto Resume_devices;
 	}
@@ -215,7 +215,7 @@ static inline int valid_state(suspend_st
 	/* All states need lowlevel support and need to be valid
 	 * to the lowlevel implementation, no valid callback
 	 * implies that none are valid. */
-	if (!pm_ops || !pm_ops->valid || !pm_ops->valid(state))
+	if (!suspend_ops || !suspend_ops->valid || !suspend_ops->valid(state))
 		return 0;
 	return 1;
 }
Index: linux-2.6.22-rc5/Documentation/power/interface.txt
===================================================================
--- linux-2.6.22-rc5.orig/Documentation/power/interface.txt	2007-06-24 20:38:30.000000000 +0200
+++ linux-2.6.22-rc5/Documentation/power/interface.txt	2007-06-24 20:45:20.000000000 +0200
@@ -20,7 +20,7 @@ states.
 /sys/power/disk controls the operating mode of the suspend-to-disk
 mechanism. Suspend-to-disk can be handled in several ways. We have a
 few options for putting the system to sleep - using the platform driver
-(e.g. ACPI or other pm_ops), powering off the system or rebooting the
+(e.g. ACPI or other suspend_ops), powering off the system or rebooting the
 system (for testing).
 
 Additionally, /sys/power/disk can be used to turn on one of the two testing
Index: linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/common/sharpsl_pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c	2007-06-24 20:45:20.000000000 +0200
@@ -766,11 +766,11 @@ static void sharpsl_apm_get_power_status
 	info->battery_life = sharpsl_pm.battstat.mainbat_percent;
 }
 
-static struct pm_ops sharpsl_pm_ops = {
+static struct platform_suspend_operations sharpsl_pm_ops = {
 	.prepare	= pxa_pm_prepare,
 	.enter		= corgi_pxa_pm_enter,
 	.finish		= pxa_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init sharpsl_pm_probe(struct platform_device *pdev)
@@ -802,7 +802,7 @@ static int __init sharpsl_pm_probe(struc
 
 	apm_get_power_status = sharpsl_apm_get_power_status;
 
-	pm_set_ops(&sharpsl_pm_ops);
+	suspend_set_ops(&sharpsl_pm_ops);
 
 	mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250));
 
@@ -811,7 +811,7 @@ static int __init sharpsl_pm_probe(struc
 
 static int sharpsl_pm_remove(struct platform_device *pdev)
 {
-	pm_set_ops(NULL);
+	suspend_set_ops(NULL);
 
 	device_remove_file(&pdev->dev, &dev_attr_battery_percentage);
 	device_remove_file(&pdev->dev, &dev_attr_battery_voltage);
Index: linux-2.6.22-rc5/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-at91/pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-at91/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -198,7 +198,7 @@ error:
 }
 
 
-static struct pm_ops at91_pm_ops ={
+static struct platform_suspend_operations at91_pm_ops ={
 	.valid		= at91_pm_valid_state,
 	.set_target	= at91_pm_set_target,
 	.enter		= at91_pm_enter,
@@ -219,7 +219,7 @@ static int __init at91_pm_init(void)
 	/* Disable SDRAM low-power mode.  Cannot be used with self-refresh. */
 	at91_sys_write(AT91_SDRAMC_LPR, 0);
 
-	pm_set_ops(&at91_pm_ops);
+	suspend_set_ops(&at91_pm_ops);
 
 	return 0;
 }
Index: linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap1/pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -687,11 +687,11 @@ static struct irqaction omap_wakeup_irq 
 
 
 
-static struct pm_ops omap_pm_ops ={
+static struct platform_suspend_operations omap_pm_ops ={
 	.prepare	= omap_pm_prepare,
 	.enter		= omap_pm_enter,
 	.finish		= omap_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init omap_pm_init(void)
@@ -748,7 +748,7 @@ static int __init omap_pm_init(void)
 	else if (cpu_is_omap16xx())
 		omap_writel(OMAP1610_IDLECT3_VAL, OMAP1610_IDLECT3);
 
-	pm_set_ops(&omap_pm_ops);
+	suspend_set_ops(&omap_pm_ops);
 
 #if defined(DEBUG) && defined(CONFIG_PROC_FS)
 	omap_pm_init_proc();
Index: linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap2/pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -368,11 +368,11 @@ static int omap2_pm_finish(suspend_state
 	return 0;
 }
 
-static struct pm_ops omap_pm_ops = {
+static struct platform_suspend_operations omap_pm_ops = {
 	.prepare	= omap2_pm_prepare,
 	.enter		= omap2_pm_enter,
 	.finish		= omap2_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 int __init omap2_pm_init(void)
@@ -396,7 +396,7 @@ int __init omap2_pm_init(void)
 	omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend,
 					    omap24xx_cpu_suspend_sz);
 
-	pm_set_ops(&omap_pm_ops);
+	suspend_set_ops(&omap_pm_ops);
 	pm_idle = omap2_pm_idle;
 
 	pmdomain_init();
Index: linux-2.6.22-rc5/arch/arm/mach-pnx4008/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pnx4008/pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pnx4008/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -117,7 +117,7 @@ static int pnx4008_pm_valid(suspend_stat
 	       (state == PM_SUSPEND_MEM);
 }
 
-static struct pm_ops pnx4008_pm_ops = {
+static struct platform_suspend_operations pnx4008_pm_ops = {
 	.enter = pnx4008_pm_enter,
 	.valid = pnx4008_pm_valid,
 };
@@ -146,7 +146,7 @@ static int __init pnx4008_pm_init(void)
 		return -ENOMEM;
 	}
 
-	pm_set_ops(&pnx4008_pm_ops);
+	suspend_set_ops(&pnx4008_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc5/arch/arm/mach-pxa/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pxa/pm.c	2007-06-24 20:38:33.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pxa/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -223,16 +223,16 @@ int pxa_pm_finish(suspend_state_t state)
 
 EXPORT_SYMBOL_GPL(pxa_pm_finish);
 
-static struct pm_ops pxa_pm_ops = {
+static struct platform_suspend_operations pxa_pm_ops = {
 	.prepare	= pxa_pm_prepare,
 	.enter		= pxa_pm_enter,
 	.finish		= pxa_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init pxa_pm_init(void)
 {
-	pm_set_ops(&pxa_pm_ops);
+	suspend_set_ops(&pxa_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc5/arch/arm/mach-sa1100/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-sa1100/pm.c	2007-06-24 20:38:33.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-sa1100/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -131,14 +131,14 @@ unsigned long sleep_phys_sp(void *sp)
 	return virt_to_phys(sp);
 }
 
-static struct pm_ops sa11x0_pm_ops = {
+static struct platform_suspend_operations sa11x0_pm_ops = {
 	.enter		= sa11x0_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init sa11x0_pm_init(void)
 {
-	pm_set_ops(&sa11x0_pm_ops);
+	suspend_set_ops(&sa11x0_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc5/arch/arm/plat-s3c24xx/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/plat-s3c24xx/pm.c	2007-06-24 20:38:33.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/plat-s3c24xx/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -612,9 +612,9 @@ static int s3c2410_pm_enter(suspend_stat
 	return 0;
 }
 
-static struct pm_ops s3c2410_pm_ops = {
+static struct platform_suspend_operations s3c2410_pm_ops = {
 	.enter		= s3c2410_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 /* s3c2410_pm_init
@@ -628,6 +628,6 @@ int __init s3c2410_pm_init(void)
 {
 	printk("S3C2410 Power Management, (c) 2004 Simtec Electronics\n");
 
-	pm_set_ops(&s3c2410_pm_ops);
+	suspend_set_ops(&s3c2410_pm_ops);
 	return 0;
 }
Index: linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/blackfin/mach-common/pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -158,7 +158,7 @@ static int bfin_pm_finish(suspend_state_
 	return 0;
 }
 
-struct pm_ops bfin_pm_ops = {
+struct platform_suspend_operations bfin_pm_ops = {
 	.prepare = bfin_pm_prepare,
 	.enter = bfin_pm_enter,
 	.finish = bfin_pm_finish,
@@ -166,7 +166,7 @@ struct pm_ops bfin_pm_ops = {
 
 static int __init bfin_pm_init(void)
 {
-	pm_set_ops(&bfin_pm_ops);
+	suspend_set_ops(&bfin_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 20:45:16.000000000 +0200
+++ linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -177,7 +177,7 @@ int mpc52xx_pm_finish(suspend_state_t st
 	return 0;
 }
 
-static struct pm_ops mpc52xx_pm_ops = {
+static struct platform_suspend_operations mpc52xx_pm_ops = {
 	.valid		= mpc52xx_pm_valid,
 	.prepare	= mpc52xx_pm_prepare,
 	.enter		= mpc52xx_pm_enter,
@@ -186,6 +186,6 @@ static struct pm_ops mpc52xx_pm_ops = {
 
 int __init mpc52xx_pm_init(void)
 {
-	pm_set_ops(&mpc52xx_pm_ops);
+	suspend_set_ops(&mpc52xx_pm_ops);
 	return 0;
 }
Index: linux-2.6.22-rc5/arch/sh/boards/hp6xx/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/sh/boards/hp6xx/pm.c	2007-06-24 20:38:33.000000000 +0200
+++ linux-2.6.22-rc5/arch/sh/boards/hp6xx/pm.c	2007-06-24 20:45:21.000000000 +0200
@@ -67,14 +67,14 @@ static int hp6x0_pm_enter(suspend_state_
 	return 0;
 }
 
-static struct pm_ops hp6x0_pm_ops = {
+static struct platform_suspend_operations hp6x0_pm_ops = {
 	.enter		= hp6x0_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init hp6x0_pm_init(void)
 {
-	pm_set_ops(&hp6x0_pm_ops);
+	suspend_set_ops(&hp6x0_pm_ops);
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 4/4] PM: Rework struct platform_suspend_operations
       [not found] <200706242239.05678.rjw@sisk.pl>
                   ` (2 preceding siblings ...)
  2007-06-24 20:42 ` [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things Rafael J. Wysocki
@ 2007-06-24 20:44 ` Rafael J. Wysocki
       [not found] ` <200706242242.47573.rjw@sisk.pl>
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-24 20:44 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

There is no reason why the .prepare() and .finish() methods in 'struct
platform_suspend_operations' should take any arguments, since architectures
don't use these methods' argument in any practically meaningful way (ie. either
the target system sleep state is conveyed to the platform by .set_target(), or
there is only one suspend state supported and it is indicated to the PM core by
.valid(), or .prepare() and .finish() aren't defined at all).  There also is
no reason why .finish() should return any result.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 arch/arm/common/sharpsl_pm.c             |    2 -
 arch/arm/mach-omap1/pm.c                 |   20 +-----------
 arch/arm/mach-omap2/pm.c                 |   21 +------------
 arch/arm/mach-pxa/pm.c                   |   24 ---------------
 arch/arm/mach-pxa/pxa25x.c               |   12 -------
 arch/arm/mach-pxa/pxa27x.c               |   11 ------
 arch/blackfin/mach-common/pm.c           |   49 +++----------------------------
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    8 +----
 drivers/acpi/sleep/main.c                |    7 +---
 include/asm-arm/arch-pxa/pm.h            |    2 -
 include/linux/suspend.h                  |   19 ++++++------
 kernel/power/main.c                      |   12 +------
 12 files changed, 30 insertions(+), 157 deletions(-)

Index: linux-2.6.22-rc5/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc5.orig/include/linux/suspend.h	2007-06-24 20:45:20.000000000 +0200
+++ linux-2.6.22-rc5/include/linux/suspend.h	2007-06-24 20:48:56.000000000 +0200
@@ -40,8 +40,9 @@ typedef int __bitwise suspend_state_t;
  *	entered.  The information passed to @set_target should be disregarded
  *	by the platform as soon as @finish() is executed and if	@prepare()
  *	fails.
- *	This callback is optional.  However, if it is implemented, the
- *	argument passed to @prepare(), @enter and @finish() must be ignored.
+ *	This callback is optional, but it must be implemented if @prepare() and
+ *	@finish() are.  Moreover, if it is implemented, the argument passed to
+ *	@enter() is meaningless and therefore must be ignored.
  *
  * @prepare: Prepare the platform for entering the system sleep state indicated
  *	by @set_target().
@@ -49,22 +50,24 @@ typedef int __bitwise suspend_state_t;
  *	error code otherwise, in which case the system cannot enter given
  *	sleep state.
  *
- * @enter: Enter the system sleep state indicated by @set_target().
+ * @enter: Enter the system sleep state indicated by @set_target() or given as
+ *	the argument if @set_target() is not implemented.
  *	This callback is mandatory.  It returns 0 on success or a negative
  *	error code otherwise, in which case the system cannot enter given
- *	sleep state.
+ *	sleep state.  If @set_target() is called prior to it, the argument is
+ *	meaningless and must be ignored.
  *
  * @finish: Called when the system has just left a sleep state.
  *	This callback is optional, but should be implemented by platforms that
- *	implement @prepare().  It is always called after @enter() (even if
- *	@enter() fails).
+ *	implement @prepare().  If implemented, it is always called after
+ *	@enter() (even if @enter() fails).
  */
 struct platform_suspend_operations {
 	int (*valid)(suspend_state_t state);
 	int (*set_target)(suspend_state_t state);
-	int (*prepare)(suspend_state_t state);
+	int (*prepare)(void);
 	int (*enter)(suspend_state_t state);
-	int (*finish)(suspend_state_t state);
+	void (*finish)(void);
 };
 
 extern struct platform_suspend_operations *suspend_ops;
Index: linux-2.6.22-rc5/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc5.orig/kernel/power/main.c	2007-06-24 20:45:20.000000000 +0200
+++ linux-2.6.22-rc5/kernel/power/main.c	2007-06-24 20:45:26.000000000 +0200
@@ -59,13 +59,6 @@ int suspend_valid_only_mem(suspend_state
 	return state == PM_SUSPEND_MEM;
 }
 
-
-static inline void pm_finish(suspend_state_t state)
-{
-	if (suspend_ops->finish)
-		suspend_ops->finish(state);
-}
-
 /**
  *	suspend_prepare - Do prep work before entering low-power state.
  *
@@ -172,7 +165,7 @@ int suspend_devices_and_enter(suspend_st
 		goto Resume_console;
 	}
 	if (suspend_ops->prepare) {
-		error = suspend_ops->prepare(state);
+		error = suspend_ops->prepare();
 		if (error)
 			goto Resume_devices;
 	}
@@ -181,7 +174,8 @@ int suspend_devices_and_enter(suspend_st
 		suspend_enter(state);
 
 	enable_nonboot_cpus();
-	pm_finish(state);
+	if (suspend_ops->finish)
+		suspend_ops->finish();
  Resume_devices:
 	device_resume();
  Resume_console:
Index: linux-2.6.22-rc5/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc5.orig/drivers/acpi/sleep/main.c	2007-06-24 20:45:20.000000000 +0200
+++ linux-2.6.22-rc5/drivers/acpi/sleep/main.c	2007-06-24 20:49:21.000000000 +0200
@@ -61,13 +61,12 @@ static int acpi_pm_set_target(suspend_st
 
 /**
  *	acpi_pm_prepare - Do preliminary suspend work.
- *	@pm_state: ignored
  *
  *	If necessary, set the firmware waking vector and do arch-specific
  *	nastiness to get the wakeup code to the waking vector.
  */
 
-static int acpi_pm_prepare(suspend_state_t pm_state)
+static int acpi_pm_prepare(void)
 {
 	int error = acpi_sleep_prepare(acpi_target_suspend_state);
 
@@ -144,13 +143,12 @@ static int acpi_pm_enter(suspend_state_t
 
 /**
  *	acpi_pm_finish - Finish up suspend sequence.
- *	@pm_state: ignored
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed). 
  */
 
-static int acpi_pm_finish(suspend_state_t pm_state)
+static void acpi_pm_finish(void)
 {
 	u32 acpi_state = acpi_target_suspend_state;
 
@@ -166,7 +164,6 @@ static int acpi_pm_finish(suspend_state_
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
 	}
-	return 0;
 }
 
 int acpi_suspend(u32 acpi_state)
Index: linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/common/sharpsl_pm.c	2007-06-24 20:45:20.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/common/sharpsl_pm.c	2007-06-24 20:45:26.000000000 +0200
@@ -767,9 +767,7 @@ static void sharpsl_apm_get_power_status
 }
 
 static struct platform_suspend_operations sharpsl_pm_ops = {
-	.prepare	= pxa_pm_prepare,
 	.enter		= corgi_pxa_pm_enter,
-	.finish		= pxa_pm_finish,
 	.valid		= suspend_valid_only_mem,
 };
 
Index: linux-2.6.22-rc5/arch/arm/mach-pxa/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pxa/pm.c	2007-06-24 20:45:21.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pxa/pm.c	2007-06-24 20:45:26.000000000 +0200
@@ -201,32 +201,8 @@ unsigned long sleep_phys_sp(void *sp)
 	return virt_to_phys(sp);
 }
 
-/*
- * Called after processes are frozen, but before we shut down devices.
- */
-int pxa_pm_prepare(suspend_state_t state)
-{
-	extern int pxa_cpu_pm_prepare(suspend_state_t state);
-
-	return pxa_cpu_pm_prepare(state);
-}
-
-EXPORT_SYMBOL_GPL(pxa_pm_prepare);
-
-/*
- * Called after devices are re-setup, but before processes are thawed.
- */
-int pxa_pm_finish(suspend_state_t state)
-{
-	return 0;
-}
-
-EXPORT_SYMBOL_GPL(pxa_pm_finish);
-
 static struct platform_suspend_operations pxa_pm_ops = {
-	.prepare	= pxa_pm_prepare,
 	.enter		= pxa_pm_enter,
-	.finish		= pxa_pm_finish,
 	.valid		= suspend_valid_only_mem,
 };
 
Index: linux-2.6.22-rc5/arch/arm/mach-pxa/pxa25x.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pxa/pxa25x.c	2007-06-24 20:38:28.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pxa/pxa25x.c	2007-06-24 20:45:26.000000000 +0200
@@ -105,18 +105,6 @@ EXPORT_SYMBOL(get_lcdclk_frequency_10khz
 
 #ifdef CONFIG_PM
 
-int pxa_cpu_pm_prepare(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_MEM:
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 void pxa_cpu_pm_enter(suspend_state_t state)
 {
 	extern void pxa_cpu_suspend(unsigned int);
Index: linux-2.6.22-rc5/arch/arm/mach-pxa/pxa27x.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-pxa/pxa27x.c	2007-06-24 20:38:28.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-pxa/pxa27x.c	2007-06-24 20:45:26.000000000 +0200
@@ -122,17 +122,6 @@ EXPORT_SYMBOL(get_lcdclk_frequency_10khz
 
 #ifdef CONFIG_PM
 
-int pxa_cpu_pm_prepare(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_MEM:
-	case PM_SUSPEND_STANDBY:
-		return 0;
-	default:
-		return -EINVAL;
-	}
-}
-
 void pxa_cpu_pm_enter(suspend_state_t state)
 {
 	extern void pxa_cpu_standby(void);
Index: linux-2.6.22-rc5/include/asm-arm/arch-pxa/pm.h
===================================================================
--- linux-2.6.22-rc5.orig/include/asm-arm/arch-pxa/pm.h	2007-06-24 20:38:28.000000000 +0200
+++ linux-2.6.22-rc5/include/asm-arm/arch-pxa/pm.h	2007-06-24 20:45:26.000000000 +0200
@@ -7,6 +7,4 @@
  *
  */
 
-extern int pxa_pm_prepare(suspend_state_t state);
 extern int pxa_pm_enter(suspend_state_t state);
-extern int pxa_pm_finish(suspend_state_t state);
Index: linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap1/pm.c	2007-06-24 20:45:21.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap1/pm.c	2007-06-24 20:48:48.000000000 +0200
@@ -613,27 +613,15 @@ static void (*saved_idle)(void) = NULL;
 
 /*
  *	omap_pm_prepare - Do preliminary suspend work.
- *	@state:		suspend state we're entering.
  *
  */
-static int omap_pm_prepare(suspend_state_t state)
+static int omap_pm_prepare(void)
 {
-	int error = 0;
-
 	/* We cannot sleep in idle until we have resumed */
 	saved_idle = pm_idle;
 	pm_idle = NULL;
 
-	switch (state)
-	{
-	case PM_SUSPEND_STANDBY:
-	case PM_SUSPEND_MEM:
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return 0;
 }
 
 
@@ -661,16 +649,14 @@ static int omap_pm_enter(suspend_state_t
 
 /**
  *	omap_pm_finish - Finish up suspend sequence.
- *	@state:		State we're coming out of.
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed).
  */
 
-static int omap_pm_finish(suspend_state_t state)
+static void omap_pm_finish(void)
 {
 	pm_idle = saved_idle;
-	return 0;
 }
 
 
Index: linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/arm/mach-omap2/pm.c	2007-06-24 20:45:21.000000000 +0200
+++ linux-2.6.22-rc5/arch/arm/mach-omap2/pm.c	2007-06-24 20:53:15.000000000 +0200
@@ -72,26 +72,10 @@ void omap2_pm_idle(void)
 
 static int omap2_pm_prepare(suspend_state_t state)
 {
-	int error = 0;
-
 	/* We cannot sleep in idle until we have resumed */
 	saved_idle = pm_idle;
 	pm_idle = NULL;
-
-	switch (state)
-	{
-	case PM_SUSPEND_STANDBY:
-	case PM_SUSPEND_MEM:
-		break;
-
-	case PM_SUSPEND_DISK:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return 0;
 }
 
 #define INT0_WAKE_MASK	(OMAP_IRQ_BIT(INT_24XX_GPIO_BANK1) |	\
@@ -362,10 +346,9 @@ static int omap2_pm_enter(suspend_state_
 	return ret;
 }
 
-static int omap2_pm_finish(suspend_state_t state)
+static void omap2_pm_finish(suspend_state_t state)
 {
 	pm_idle = saved_idle;
-	return 0;
 }
 
 static struct platform_suspend_operations omap_pm_ops = {
Index: linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/blackfin/mach-common/pm.c	2007-06-24 20:45:21.000000000 +0200
+++ linux-2.6.22-rc5/arch/blackfin/mach-common/pm.c	2007-06-24 21:00:17.000000000 +0200
@@ -89,28 +89,15 @@ void bfin_pm_suspend_standby_enter(void)
 #endif				/* CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR */
 }
 
-
 /*
- *	bfin_pm_prepare - Do preliminary suspend work.
- *	@state:		suspend state we're entering.
+ *	bfin_pm_valid - Tell the PM core that we only support the standby sleep
+ *			state
+ *	@state:		suspend state we're checking.
  *
  */
-static int bfin_pm_prepare(suspend_state_t state)
+static int bfin_pm_valid(suspend_state_t state)
 {
-	int error = 0;
-
-	switch (state) {
-	case PM_SUSPEND_STANDBY:
-		break;
-
-	case PM_SUSPEND_MEM:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return (state == PM_SUSPEND_STANDBY);
 }
 
 /*
@@ -135,33 +122,9 @@ static int bfin_pm_enter(suspend_state_t
 	return 0;
 }
 
-/*
- *	bfin_pm_finish - Finish up suspend sequence.
- *	@state:		State we're coming out of.
- *
- *	This is called after we wake back up (or if entering the sleep state
- *	failed).
- */
-static int bfin_pm_finish(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_STANDBY:
-		break;
-
-	case PM_SUSPEND_MEM:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 struct platform_suspend_operations bfin_pm_ops = {
-	.prepare = bfin_pm_prepare,
+	.valid = bfin_pm_valid,
 	.enter = bfin_pm_enter,
-	.finish = bfin_pm_finish,
 };
 
 static int __init bfin_pm_init(void)
Index: linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc5.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 20:45:21.000000000 +0200
+++ linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 21:07:41.000000000 +0200
@@ -25,6 +25,7 @@ static void *sram;
 static int sram_size;
 
 struct mpc52xx_suspend mpc52xx_suspend;
+static suspend_state_t mpc52xx_pm_target_state;
 
 static int mpc52xx_pm_valid(suspend_state_t state)
 {
@@ -57,11 +58,8 @@ int mpc52xx_set_wakeup_gpio(u8 pin, u8 l
 	return 0;
 }
 
-int mpc52xx_pm_prepare(suspend_state_t state)
+static int mpc52xx_pm_prepare(void)
 {
-	if (state != PM_SUSPEND_STANDBY)
-		return -EINVAL;
-
 	/* map the whole register space */
 	mbar = mpc52xx_find_and_map("mpc5200");
 	if (!mbar) {
@@ -166,7 +164,7 @@ int mpc52xx_pm_enter(suspend_state_t sta
 	return 0;
 }
 
-int mpc52xx_pm_finish(suspend_state_t state)
+static void mpc52xx_pm_finish(void)
 {
 	/* call board resume code */
 	if (mpc52xx_suspend.board_resume_finish)

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found] ` <200706242240.40476.rjw@sisk.pl>
@ 2007-06-25  2:11   ` David Brownell
  2007-06-25 21:28   ` Johannes Berg
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 32+ messages in thread
From: David Brownell @ 2007-06-25  2:11 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, linux acpi, Pavel Machek, pm list, Johannes Berg

On Sunday 24 June 2007, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> Some drivers may need to use ACPI to determine the low power states in which
> to place their devices, but to provide the drivers with this information the
> ACPI core needs to know what sleep state the system is going to enter.

It also needs to export that to things like the ACPI-to-PCI glue
code.  So it would be good if you defined the missing routine now,
saving the effort of patching it in later:

	int acpi_get_target_sleep_state(void);

It doesn't need EXPORT_SYMBOL().


> Namely, the device's state should not be too high power for given system sleep
> state and, if the device is supposed to be able to wake up the system, its state
> should not be too low power for the wake up to be possible).  However,
> pm_ops->prepare() is only called after the drivers' .suspend() callbacks have
> been executed, 

That's a critical point that should show up in your doc updates.


> so we need an additional means to pass the information of the 
> target system sleep state to the ACPI core.  For this purpose, we can introduce
> an additional member function in 'struct pm_ops'.
> 
> Additionally, the at91 platform code incorrectly assumes that pm_ops->prepare()
> will be called before devices are suspended and uses it for setting the target
> system sleep state, so pm_ops->prepare() should to be replaced with the new
> operation, pm_ops->set_target(), for this architecture.

That was originally correct ... but as you pointed out, the
semantics there changed in RC5.

Which means this patch is a *BUGFIX*, preventing what would
otherwise be a regression in 2.6.22 ... and so it should
be merged for RC6 or so.


Another way to describe the changes is that set_target() now
does what prepare() used to do, while prepare() serves a
new role.  A role which still needs to be well-described in
the documentation you provided, by the way... it seems to
do whatever needs to be done after devices suspend but
before nonboot CPUs are disabled.

- Dave

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things
       [not found] ` <200706242242.47573.rjw@sisk.pl>
@ 2007-06-25  4:12   ` David Brownell
  2007-06-25 19:34   ` Pavel Machek
  1 sibling, 0 replies; 32+ messages in thread
From: David Brownell @ 2007-06-25  4:12 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, linux acpi, Pavel Machek, pm list, Johannes Berg

On Sunday 24 June 2007, Rafael J. Wysocki wrote:

>  arch/arm/common/sharpsl_pm.c             |    8 +++----
>  arch/arm/mach-at91/pm.c                  |    4 +--
>  arch/arm/mach-omap1/pm.c                 |    6 ++---
>  arch/arm/mach-omap2/pm.c                 |    6 ++---
>  arch/arm/mach-pnx4008/pm.c               |    4 +--
>  arch/arm/mach-pxa/pm.c                   |    6 ++---
>  arch/arm/mach-sa1100/pm.c                |    6 ++---
>  arch/arm/plat-s3c24xx/pm.c               |    6 ++---
>  arch/blackfin/mach-common/pm.c           |    4 +--
>  arch/powerpc/platforms/52xx/mpc52xx_pm.c |    4 +--
>  arch/sh/boards/hp6xx/pm.c                |    6 ++---
>  drivers/acpi/sleep/main.c                |    6 ++---

It's interesting that so few systems support suspend states,
and thus need to change for this patch ... 


- Dave

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h
       [not found] ` <200706242241.39283.rjw@sisk.pl>
@ 2007-06-25 19:33   ` Pavel Machek
  0 siblings, 0 replies; 32+ messages in thread
From: Pavel Machek @ 2007-06-25 19:33 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, pm list, Johannes Berg

On Sun 2007-06-24 22:41:38, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> Move the definition of 'struct pm_ops' and related functions from <linux/pm.h>
> to <linux/suspend.h> .
> 
> There are, at least, the following reasons to do that:
> * 'struct pm_ops' is specifically related to suspend and not to the power
>   management in general.
> * As long as 'struct pm_ops' is defined in <linux/pm.h>, any modification of it
>   causes the entire kernel to be recompiled, which is unnecessary and annoying.
> * Some suspend-related features are already defined in <linux/suspend.h>, so it
>   is logical to move the definition of 'struct pm_ops' into there.
> * 'struct hibernation_ops', being the hibernation-related counterpart of
>   'struct pm_ops', is defined in <linux/suspend.h> .
> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

ACK.
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things
       [not found] ` <200706242242.47573.rjw@sisk.pl>
  2007-06-25  4:12   ` [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things David Brownell
@ 2007-06-25 19:34   ` Pavel Machek
  1 sibling, 0 replies; 32+ messages in thread
From: Pavel Machek @ 2007-06-25 19:34 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, pm list, Johannes Berg

On Sun 2007-06-24 22:42:46, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> The name of 'struct pm_ops' suggests that it is related to the power management
> in general, but in fact it is only related to suspend.  Moreover, its name
> should indicate what this structure is used for, so it seems reasonable to
> change it to 'struct platform_suspend_operations'.  In that case, the name of
> the global variable of this type used by the PM core and the names of related
> functions should be changed accordingly.
> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

ACK.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found] ` <200706242240.40476.rjw@sisk.pl>
  2007-06-25  2:11   ` [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops David Brownell
@ 2007-06-25 21:28   ` Johannes Berg
       [not found]   ` <200706241911.18201.david-b@pacbell.net>
       [not found]   ` <1182806886.6644.4.camel@johannes.berg>
  3 siblings, 0 replies; 32+ messages in thread
From: Johannes Berg @ 2007-06-25 21:28 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, Pavel Machek, pm list


[-- Attachment #1.1: Type: text/plain, Size: 751 bytes --]

On Sun, 2007-06-24 at 22:40 +0200, Rafael J. Wysocki wrote:

> + * @set_target: Tell the platform which system sleep state is going to be
> + *	entered.  The information passed to @set_target should be disregarded
> + *	by the platform as soon as @finish() is executed and if	@prepare()
> + *	fails.
> + *	This callback is optional.  However, if it is implemented, the
> + *	argument passed to @prepare(), @enter and @finish() must be ignored.

I don't understand the point in mandating that then the argument to
enter() is to be ignored, why bother? It doesn't look as though we can
possibly do anything with the semantics here that would mean the state
set by set_target is different to the state passed to enter(), can we?

johannes

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 4/4] PM: Rework struct platform_suspend_operations
       [not found] ` <200706242244.51335.rjw@sisk.pl>
@ 2007-06-25 21:30   ` Johannes Berg
  0 siblings, 0 replies; 32+ messages in thread
From: Johannes Berg @ 2007-06-25 21:30 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, Pavel Machek, pm list


[-- Attachment #1.1: Type: text/plain, Size: 1180 bytes --]

On Sun, 2007-06-24 at 22:44 +0200, Rafael J. Wysocki wrote:

> There is no reason why the .prepare() and .finish() methods in 'struct
> platform_suspend_operations' should take any arguments, since architectures
> don't use these methods' argument in any practically meaningful way (ie. either
> the target system sleep state is conveyed to the platform by .set_target(), or
> there is only one suspend state supported and it is indicated to the PM core by
> .valid(), or .prepare() and .finish() aren't defined at all).  There also is
> no reason why .finish() should return any result.

Nice cleanups, I'd wanted to do them when I was doing all that pm_ops
stuff but then didn't get around. Good stuff.
 
> --- linux-2.6.22-rc5.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 20:45:21.000000000 +0200
> +++ linux-2.6.22-rc5/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-24 21:07:41.000000000 +0200

> -int mpc52xx_pm_prepare(suspend_state_t state)
> +static int mpc52xx_pm_prepare(void)
>  {
> -	if (state != PM_SUSPEND_STANDBY)
> -		return -EINVAL;
> -

Hm. I thought I'd told them to leave that out before it went in. Oh
well.

johannes

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found]   ` <200706241911.18201.david-b@pacbell.net>
@ 2007-06-25 22:06     ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:06 UTC (permalink / raw)
  To: David Brownell
  Cc: Len Brown, linux acpi, Pavel Machek, pm list, Johannes Berg

On Monday, 25 June 2007 04:11, David Brownell wrote:
> On Sunday 24 June 2007, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rjw@sisk.pl>
> > 
> > Some drivers may need to use ACPI to determine the low power states in which
> > to place their devices, but to provide the drivers with this information the
> > ACPI core needs to know what sleep state the system is going to enter.
> 
> It also needs to export that to things like the ACPI-to-PCI glue
> code.  So it would be good if you defined the missing routine now,
> saving the effort of patching it in later:
> 
> 	int acpi_get_target_sleep_state(void);
> 
> It doesn't need EXPORT_SYMBOL().

I'd rather like to add this as a separate patch in the same series.  Will do.

> > Namely, the device's state should not be too high power for given system sleep
> > state and, if the device is supposed to be able to wake up the system, its state
> > should not be too low power for the wake up to be possible).  However,
> > pm_ops->prepare() is only called after the drivers' .suspend() callbacks have
> > been executed, 
> 
> That's a critical point that should show up in your doc updates.

Yes, will add that.

> > so we need an additional means to pass the information of the 
> > target system sleep state to the ACPI core.  For this purpose, we can introduce
> > an additional member function in 'struct pm_ops'.
> > 
> > Additionally, the at91 platform code incorrectly assumes that pm_ops->prepare()
> > will be called before devices are suspended and uses it for setting the target
> > system sleep state, so pm_ops->prepare() should to be replaced with the new
> > operation, pm_ops->set_target(), for this architecture.
> 
> That was originally correct ... but as you pointed out, the
> semantics there changed in RC5.
> 
> Which means this patch is a *BUGFIX*, preventing what would
> otherwise be a regression in 2.6.22 ... and so it should
> be merged for RC6 or so.

In that case I'd separate the addition of set_target() and the at91 from
the rest of the series and push it to Andrew ASAP (there's a little time left
before 2.6.22, it seems).

> Another way to describe the changes is that set_target() now
> does what prepare() used to do, while prepare() serves a
> new role.  A role which still needs to be well-described in
> the documentation you provided, by the way... it seems to
> do whatever needs to be done after devices suspend but
> before nonboot CPUs are disabled.

Yes, exactly.

I have the updated series of patches almost ready.  I'll send it in a new
thread in a while.

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 0/8] PM: Rework struct pm_ops and related things (take 2)
       [not found] <200706242239.05678.rjw@sisk.pl>
                   ` (7 preceding siblings ...)
       [not found] ` <200706242244.51335.rjw@sisk.pl>
@ 2007-06-25 22:39 ` Rafael J. Wysocki
       [not found] ` <200706260039.17530.rjw@sisk.pl>
  9 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:39 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

Hi,

This is the second version of the patch series to rework pm_ops in order to
introduce the set_target() method etc.  This time I've takes some Dave's
comments into consideration and I've realized that a method similar to
set_target() is also needed for hibernation, so I've reworked that too, a bit.

The following series of patches:
* introduces the .set_target() method in 'struct pm_ops' so that the platform
  code knows in advance what sleep state the system is going to enter (this
  is urgently needed by at91 and should go into 2.6.22 as a bugfix)
* makes ACPI use .set_target()
* adds an ACPI helper function for the devices to determine the power state
  to put the device into
* moves the definition of 'struct pm_ops' to <include/suspend.h>
* changes the name of 'struct pm_ops' to 'struct platform_suspend_operations'
  and modifies the names of some related functions and global variables
  accordingly
* modifies 'struct platform_suspend_operations' so that .prepare() and
  .finish() don't take arguments (.enter() still takes the state argument, 
  because some platforms don't need to implement the other callbacks)
* reworks 'struct hibernation_ops' to add the new method analogous to
  .set_target()
* renames 'struct hibernation_ops' to 'struct hibernation_platform_operations'
  (in analogy with 'struct platform_suspend_operations')
The details are in the changelogs.

The series have been compilation-tested on x86_64 and I'm going to compile
it for all of the affected platforms.

Comments welcome.

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops
       [not found] ` <200706260039.17530.rjw@sisk.pl>
@ 2007-06-25 22:41   ` Rafael J. Wysocki
  2007-06-25 22:43   ` [RFC/RFT][PATCH -mm 2/8] ACPI: Implement the set_target() callback from pm_ops Rafael J. Wysocki
                     ` (10 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:41 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

The at91 platform code incorrectly assumes that pm_ops->prepare() will be called
before devices are suspended and uses it to make the PM core set the target
system sleep state used by the platform when suspending devices.  Thus, at91
needs a new member function in 'struct pm_ops' that will be used by the PM core
to convey the target system sleep state to the platform code before devices are
suspended.

Moreover, in the future some drivers may need to use ACPI to determine the low
power states in which to place their devices, but to provide the drivers with
this information the ACPI core needs to know what sleep state the system is
going to enter.  Namely, the device's state should not be too high power for
given system sleep state and, if the device is supposed to be able to wake up
the system, its state should not be too low power for the wake up to be
possible).  However, pm_ops->prepare() is only called after the drivers'
.suspend() callbacks have been executed, so we need an additional means to
convey the target system sleep state to the ACPI core.  The new member function
in 'struct pm_ops', set_target(), can be used for this purpose.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 arch/arm/mach-at91/pm.c |    4 +-
 include/linux/pm.h      |   66 +++++++++++++++++++++++++++++++++++-------------
 kernel/power/main.c     |    6 +++-
 3 files changed, 56 insertions(+), 20 deletions(-)

Index: linux-2.6.22-rc6/include/linux/pm.h
===================================================================
--- linux-2.6.22-rc6.orig/include/linux/pm.h	2007-06-25 21:09:18.000000000 +0200
+++ linux-2.6.22-rc6/include/linux/pm.h	2007-06-25 21:09:30.000000000 +0200
@@ -110,37 +110,67 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
 
 /**
- * struct pm_ops - Callbacks for managing platform dependent suspend states.
- * @valid: Callback to determine whether the given state can be entered.
- *	Valid states are advertised in /sys/power/state but can still
- *	be rejected by prepare or enter if the conditions aren't right.
- *	There is a %pm_valid_only_mem function available that can be assigned
- *	to this if you only implement mem sleep.
+ * struct pm_ops - Callbacks for managing platform dependent system sleep
+ *	states.
  *
- * @prepare: Prepare the platform for the given suspend state. Can return a
- *	negative error code if necessary.
- *
- * @enter: Enter the given suspend state, must be assigned. Can return a
- *	negative error code if necessary.
- *
- * @finish: Called when the system has left the given state and all devices
- *	are resumed. The return value is ignored.
+ * @valid: Callback to determine if given system sleep state is supported by
+ *	the platform.
+ *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
+ *	that it still may be impossible to enter given system sleep state if the
+ *	conditions aren't right.
+ *	There is the %pm_valid_only_mem function available that can be assigned
+ *	to this if the platform only supports mem sleep.
+ *
+ * @set_target: Tell the platform which system sleep state is going to be
+ *	entered.
+ *	@set_target() is executed right prior to suspending devices.  The
+ *	information conveyed to the platform code by @set_target() should be
+ *	disregarded by the platform as soon as @finish() is executed and if
+ *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
+ *	@prepare(), @enter() and @finish() will not be called by the PM core.
+ *	This callback is optional.  However, if it is implemented, the argument
+ *	passed to @prepare(), @enter() and @finish() is meaningless and should
+ *	be ignored.
+ *
+ * @prepare: Prepare the platform for entering the system sleep state indicated
+ *	by @set_target() or represented by the argument if @set_target() is not
+ *	implemented.
+ *	@prepare() is called right after devices have been suspended (ie. the
+ *	appropriate .suspend() method has been executed for each device) and
+ *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
+ *	This callback is optional.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter the desired
+ *	sleep state (@enter() and @finish() will not be called in that case).
+ *
+ * @enter: Enter the system sleep state indicated by @set_target() or
+ *	represented by the argument if @set_target() is not implemented.
+ *	This callback is mandatory.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter the desired
+ *	sleep state.
+ *
+ * @finish: Called when the system has just left a sleep state, right after
+ *	the nonboot CPUs have been enabled and before devices are resumed (it is
+ *	executed with IRQs enabled).  If @set_target() is not implemented, the
+ *	argument represents the sleep state being left.
+ *	This callback is optional, but should be implemented by the platforms
+ *	that implement @prepare().  If implemented, it is always called after
+ *	@enter() (even if @enter() fails).
  */
 struct pm_ops {
 	int (*valid)(suspend_state_t state);
+	int (*set_target)(suspend_state_t state);
 	int (*prepare)(suspend_state_t state);
 	int (*enter)(suspend_state_t state);
 	int (*finish)(suspend_state_t state);
 };
 
+extern struct pm_ops *pm_ops;
+
 /**
  * pm_set_ops - set platform dependent power management ops
  * @pm_ops: The new power management operations to set.
  */
 extern void pm_set_ops(struct pm_ops *pm_ops);
-extern struct pm_ops *pm_ops;
-extern int pm_suspend(suspend_state_t state);
-
 extern int pm_valid_only_mem(suspend_state_t state);
 
 /**
@@ -161,6 +191,8 @@ extern void arch_suspend_disable_irqs(vo
  */
 extern void arch_suspend_enable_irqs(void);
 
+extern int pm_suspend(suspend_state_t state);
+
 /*
  * Device power management
  */
Index: linux-2.6.22-rc6/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc6.orig/kernel/power/main.c	2007-06-25 21:09:18.000000000 +0200
+++ linux-2.6.22-rc6/kernel/power/main.c	2007-06-25 21:09:30.000000000 +0200
@@ -15,7 +15,6 @@
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/pm.h>
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/resume-trace.h>
@@ -161,6 +160,11 @@ int suspend_devices_and_enter(suspend_st
 	if (!pm_ops)
 		return -ENOSYS;
 
+	if (pm_ops->set_target) {
+		error = pm_ops->set_target(state);
+		if (error)
+			return error;
+	}
 	suspend_console();
 	error = device_suspend(PMSG_SUSPEND);
 	if (error) {
Index: linux-2.6.22-rc6/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-at91/pm.c	2007-06-25 21:09:18.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-at91/pm.c	2007-06-25 21:09:30.000000000 +0200
@@ -53,7 +53,7 @@ static suspend_state_t target_state;
 /*
  * Called after processes are frozen, but before we shutdown devices.
  */
-static int at91_pm_prepare(suspend_state_t state)
+static int at91_pm_set_target(suspend_state_t state)
 {
 	target_state = state;
 	return 0;
@@ -201,7 +201,7 @@ error:
 
 static struct pm_ops at91_pm_ops ={
 	.valid		= at91_pm_valid_state,
-	.prepare	= at91_pm_prepare,
+	.set_target	= at91_pm_set_target,
 	.enter		= at91_pm_enter,
 };
 

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 2/8] ACPI: Implement the set_target() callback from pm_ops
       [not found] ` <200706260039.17530.rjw@sisk.pl>
  2007-06-25 22:41   ` [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
@ 2007-06-25 22:43   ` Rafael J. Wysocki
  2007-06-25 22:45   ` [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine Rafael J. Wysocki
                     ` (9 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:43 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

In the future some drivers may need to use ACPI to determine the low power
states in which to place their devices, but to provide the drivers with this
information the ACPI core needs to know what sleep state the system is going to
enter.  Namely, the device's state should not be too high power for given system
sleep state and, if the device is supposed to be able to wake up the system, its
state should not be too low power for the wake up to be possible).  For this
purpose, the ACPI core needs to implement the set_target() method from 'struct
pm_ops' and store the target system sleep state passed by the PM core in a
variable.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/sleep/main.c |   84 ++++++++++++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 32 deletions(-)

Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 21:09:18.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 21:34:46.000000000 +0200
@@ -34,34 +34,54 @@ static u32 acpi_suspend_states[] = {
 
 static int init_8259A_after_S1;
 
+extern int acpi_sleep_prepare(u32 acpi_state);
+extern void acpi_power_off(void);
+
+static u32 acpi_target_sleep_state = ACPI_STATE_S0;
+
+/**
+ *	acpi_pm_set_target - Set the target system sleep state to the state
+ *		associated with given @pm_state, if supported.
+ */
+
+static int acpi_pm_set_target(suspend_state_t pm_state)
+{
+	u32 acpi_state = acpi_suspend_states[pm_state];
+	int error = 0;
+
+	if (sleep_states[acpi_state]) {
+		acpi_target_sleep_state = acpi_state;
+	} else {
+		printk(KERN_ERR "ACPI does not support this state: %d\n",
+			pm_state);
+		error = -ENOSYS;
+	}
+	return error;
+}
+
 /**
  *	acpi_pm_prepare - Do preliminary suspend work.
- *	@pm_state:		suspend state we're entering.
+ *	@pm_state: ignored
  *
- *	Make sure we support the state. If we do, and we need it, set the
- *	firmware waking vector and do arch-specific nastiness to get the 
- *	wakeup code to the waking vector. 
+ *	If necessary, set the firmware waking vector and do arch-specific
+ *	nastiness to get the wakeup code to the waking vector.
  */
 
-extern int acpi_sleep_prepare(u32 acpi_state);
-extern void acpi_power_off(void);
-
 static int acpi_pm_prepare(suspend_state_t pm_state)
 {
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	int error = acpi_sleep_prepare(acpi_target_sleep_state);
 
-	if (!sleep_states[acpi_state]) {
-		printk("acpi_pm_prepare does not support %d \n", pm_state);
-		return -EPERM;
-	}
-	return acpi_sleep_prepare(acpi_state);
+	if (error)
+		acpi_target_sleep_state = ACPI_STATE_S0;
+
+	return error;
 }
 
 /**
  *	acpi_pm_enter - Actually enter a sleep state.
- *	@pm_state:		State we're entering.
+ *	@pm_state: ignored
  *
- *	Flush caches and go to sleep. For STR or STD, we have to call 
+ *	Flush caches and go to sleep. For STR or S2, we have to call
  *	arch-specific assembly, which in turn call acpi_enter_sleep_state().
  *	It's unfortunate, but it works. Please fix if you're feeling frisky.
  */
@@ -70,31 +90,32 @@ static int acpi_pm_enter(suspend_state_t
 {
 	acpi_status status = AE_OK;
 	unsigned long flags = 0;
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	u32 acpi_state = acpi_target_sleep_state;
 
 	ACPI_FLUSH_CPU_CACHE();
 
 	/* Do arch specific saving of state. */
-	if (pm_state > PM_SUSPEND_STANDBY) {
+	if (acpi_state == ACPI_STATE_S2 || acpi_state == ACPI_STATE_S3) {
 		int error = acpi_save_state_mem();
-		if (error)
+
+		if (error) {
+			acpi_target_sleep_state = ACPI_STATE_S0;
 			return error;
+		}
 	}
 
 	local_irq_save(flags);
 	acpi_enable_wakeup_device(acpi_state);
-	switch (pm_state) {
-	case PM_SUSPEND_STANDBY:
+	switch (acpi_state) {
+	case ACPI_STATE_S1:
 		barrier();
 		status = acpi_enter_sleep_state(acpi_state);
 		break;
 
-	case PM_SUSPEND_MEM:
+	case ACPI_STATE_S2:
+	case ACPI_STATE_S3:
 		do_suspend_lowlevel();
 		break;
-
-	default:
-		return -EINVAL;
 	}
 
 	/* ACPI 3.0 specs (P62) says that it's the responsabilty
@@ -114,12 +135,8 @@ static int acpi_pm_enter(suspend_state_t
 	local_irq_restore(flags);
 	printk(KERN_DEBUG "Back to C!\n");
 
-	/* restore processor state
-	 * We should only be here if we're coming back from STR or STD.
-	 * And, in the case of the latter, the memory image should have already
-	 * been loaded from disk.
-	 */
-	if (pm_state > PM_SUSPEND_STANDBY)
+	/* restore processor state */
+	if (acpi_state == ACPI_STATE_S2 || acpi_state == ACPI_STATE_S3)
 		acpi_restore_state_mem();
 
 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
@@ -127,7 +144,7 @@ static int acpi_pm_enter(suspend_state_t
 
 /**
  *	acpi_pm_finish - Finish up suspend sequence.
- *	@pm_state:		State we're coming out of.
+ *	@pm_state: ignored
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed). 
@@ -135,7 +152,7 @@ static int acpi_pm_enter(suspend_state_t
 
 static int acpi_pm_finish(suspend_state_t pm_state)
 {
-	u32 acpi_state = acpi_suspend_states[pm_state];
+	u32 acpi_state = acpi_target_sleep_state;
 
 	acpi_leave_sleep_state(acpi_state);
 	acpi_disable_wakeup_device(acpi_state);
@@ -143,6 +160,8 @@ static int acpi_pm_finish(suspend_state_
 	/* reset firmware waking vector */
 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 
+	acpi_target_sleep_state = ACPI_STATE_S0;
+
 	if (init_8259A_after_S1) {
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
@@ -183,6 +202,7 @@ static int acpi_pm_state_valid(suspend_s
 
 static struct pm_ops acpi_pm_ops = {
 	.valid = acpi_pm_state_valid,
+	.set_target = acpi_pm_set_target,
 	.prepare = acpi_pm_prepare,
 	.enter = acpi_pm_enter,
 	.finish = acpi_pm_finish,

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine
       [not found] ` <200706260039.17530.rjw@sisk.pl>
  2007-06-25 22:41   ` [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
  2007-06-25 22:43   ` [RFC/RFT][PATCH -mm 2/8] ACPI: Implement the set_target() callback from pm_ops Rafael J. Wysocki
@ 2007-06-25 22:45   ` Rafael J. Wysocki
  2007-06-25 22:47   ` [RFC/RFT][PATCH -mm 4/8] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:45 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Shaohua Li <shaohua.li@intel.com>, Rafael J. Wysocki <rjw@sisk.pl>

Based on the David Brownell's patch at
http://marc.info/?l=linux-acpi&m=117873972806360&w=2

Add a helper routine returning the lowest power (highest number) ACPI device
power state that given device can be in while the system is in the sleep state
indicated by acpi_target_sleep_state .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/sleep/main.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h   |    2 +
 2 files changed, 57 insertions(+)

Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 21:34:46.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 21:58:30.000000000 +0200
@@ -262,6 +262,61 @@ static struct hibernation_ops acpi_hiber
 };
 #endif				/* CONFIG_SOFTWARE_SUSPEND */
 
+/**
+ *	acpi_pm_device_sleep_state - return the lowest power (highest number)
+ *				     ACPI device power state given device can be
+ *				     in while the system is in the sleep state
+ *				     indicated by %acpi_target_sleep_state
+ *	@handle: Represents the device the state is evaluated for
+ */
+
+int acpi_pm_device_sleep_state(acpi_handle handle)
+{
+	char acpi_method[] = "_SxD";
+	unsigned long d_min, d_max;
+	struct acpi_device *dev;
+
+	if (acpi_bus_get_device(handle, &dev)) {
+		printk(KERN_ERR "ACPI handle has no context!\n");
+		return ACPI_STATE_D3;
+	}
+	acpi_method[2] = '0' + acpi_target_sleep_state;
+	/*
+	 * If the sleep state is S0, we will return D3, but if the device has
+	 * _S0W, we will use the value from _S0W
+	 */
+	d_min = ACPI_STATE_D3;
+	d_max = ACPI_STATE_D3;
+
+	/*
+	 * If present, _SxD methods give the minimum D-state we may use
+	 * for each S-state ... with lowest latency state switching.
+	 *
+	 * We rely on acpi_evaluate_integer() not clobbering the integer
+	 * provided -- that's our fault recovery, we ignore retval.
+	 */
+	if (acpi_target_sleep_state > ACPI_STATE_S0)
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
+
+	/*
+	 * If _PRW says we can wake from the upcoming system state, the _SxD
+	 * value can wake ... and we'll assume a wakeup-aware driver.  If _SxW
+	 * methods exist (ACPI 3.x), they give the lowest power D-state that
+	 * can also wake the system.  _S0W can be valid.
+	 */
+	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
+	    (dev->wakeup.state.enabled &&
+	     dev->wakeup.sleep_state <= acpi_target_sleep_state)) {
+		acpi_method[3] = 'W';
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
+	}
+	/*
+	 * Choose a state within d_min to d_max, we just choose the max
+	 * (ie. lower power)
+	 */
+	return d_max > d_min ? d_max : d_min;
+}
+
 /*
  * Toshiba fails to preserve interrupts over S1, reinitialization
  * of 8259 is needed after S1 resume.
Index: linux-2.6.22-rc6/include/acpi/acpi_bus.h
===================================================================
--- linux-2.6.22-rc6.orig/include/acpi/acpi_bus.h	2007-06-25 21:34:04.000000000 +0200
+++ linux-2.6.22-rc6/include/acpi/acpi_bus.h	2007-06-25 21:53:19.000000000 +0200
@@ -364,6 +364,8 @@ acpi_handle acpi_get_child(acpi_handle, 
 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
 #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
 
+int acpi_pm_device_sleep_state(acpi_handle handle);
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 4/8] PM: Move definition of struct pm_ops to suspend.h
       [not found] ` <200706260039.17530.rjw@sisk.pl>
                     ` (2 preceding siblings ...)
  2007-06-25 22:45   ` [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine Rafael J. Wysocki
@ 2007-06-25 22:47   ` Rafael J. Wysocki
  2007-06-25 22:48   ` [RFC/RFT][PATCH -mm 5/8] PM: Rename struct pm_ops and related things Rafael J. Wysocki
                     ` (7 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:47 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

Move the definition of 'struct pm_ops' and related functions from <linux/pm.h>
to <linux/suspend.h> .

There are, at least, the following reasons to do that:
* 'struct pm_ops' is specifically related to suspend and not to the power
  management in general.
* As long as 'struct pm_ops' is defined in <linux/pm.h>, any modification of it
  causes the entire kernel to be recompiled, which is unnecessary and annoying.
* Some suspend-related features are already defined in <linux/suspend.h>, so it
  is logical to move the definition of 'struct pm_ops' into there.
* 'struct hibernation_ops', being the hibernation-related counterpart of
  'struct pm_ops', is defined in <linux/suspend.h> .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 arch/arm/common/sharpsl_pm.c             |    1 
 arch/arm/mach-at91/pm.c                  |    3 
 arch/arm/mach-omap1/pm.c                 |    3 
 arch/arm/mach-omap2/pm.c                 |    3 
 arch/arm/mach-pnx4008/pm.c               |    2 
 arch/blackfin/mach-common/pm.c           |    2 
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    2 
 include/linux/pm.h                       |   91 ------------------------
 include/linux/suspend.h                  |  113 +++++++++++++++++++++++++++----
 9 files changed, 109 insertions(+), 111 deletions(-)

Index: linux-2.6.22-rc4-mm2/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc4-mm2.orig/include/linux/suspend.h
+++ linux-2.6.22-rc4-mm2/include/linux/suspend.h
@@ -1,5 +1,5 @@
-#ifndef _LINUX_SWSUSP_H
-#define _LINUX_SWSUSP_H
+#ifndef _LINUX_SUSPEND_H
+#define _LINUX_SUSPEND_H
 
 #if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32) || defined(CONFIG_PPC64)
 #include <asm/suspend.h>
@@ -10,6 +10,105 @@
 #include <linux/pm.h>
 #include <linux/mm.h>
 
+#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
+extern int pm_prepare_console(void);
+extern void pm_restore_console(void);
+#else
+static inline int pm_prepare_console(void) { return 0; }
+static inline void pm_restore_console(void) {}
+#endif
+
+typedef int __bitwise suspend_state_t;
+
+#define PM_SUSPEND_ON		((__force suspend_state_t) 0)
+#define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
+#define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
+#define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
+
+/**
+ * struct pm_ops - Callbacks for managing platform dependent system sleep
+ *	states.
+ *
+ * @valid: Callback to determine if given system sleep state is supported by
+ *	the platform.
+ *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
+ *	that it still may be impossible to enter given system sleep state if the
+ *	conditions aren't right.
+ *	There is the %pm_valid_only_mem function available that can be assigned
+ *	to this if the platform only supports mem sleep.
+ *
+ * @set_target: Tell the platform which system sleep state is going to be
+ *	entered.
+ *	@set_target() is executed right prior to suspending devices.  The
+ *	information conveyed to the platform code by @set_target() should be
+ *	disregarded by the platform as soon as @finish() is executed and if
+ *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
+ *	@prepare(), @enter() and @finish() will not be called by the PM core.
+ *	This callback is optional.  However, if it is implemented, the argument
+ *	passed to @prepare(), @enter() and @finish() is meaningless and should
+ *	be ignored.
+ *
+ * @prepare: Prepare the platform for entering the system sleep state indicated
+ *	by @set_target() or represented by the argument if @set_target() is not
+ *	implemented.
+ *	@prepare() is called right after devices have been suspended (ie. the
+ *	appropriate .suspend() method has been executed for each device) and
+ *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
+ *	This callback is optional.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter the desired
+ *	sleep state (@enter() and @finish() will not be called in that case).
+ *
+ * @enter: Enter the system sleep state indicated by @set_target() or
+ *	represented by the argument if @set_target() is not implemented.
+ *	This callback is mandatory.  It returns 0 on success or a negative
+ *	error code otherwise, in which case the system cannot enter the desired
+ *	sleep state.
+ *
+ * @finish: Called when the system has just left a sleep state, right after
+ *	the nonboot CPUs have been enabled and before devices are resumed (it is
+ *	executed with IRQs enabled).  If @set_target() is not implemented, the
+ *	argument represents the sleep state being left.
+ *	This callback is optional, but should be implemented by the platforms
+ *	that implement @prepare().  If implemented, it is always called after
+ *	@enter() (even if @enter() fails).
+ */
+struct pm_ops {
+	int (*valid)(suspend_state_t state);
+	int (*set_target)(suspend_state_t state);
+	int (*prepare)(suspend_state_t state);
+	int (*enter)(suspend_state_t state);
+	int (*finish)(suspend_state_t state);
+};
+
+extern struct pm_ops *pm_ops;
+
+/**
+ * pm_set_ops - set platform dependent power management ops
+ * @pm_ops: The new power management operations to set.
+ */
+extern void pm_set_ops(struct pm_ops *pm_ops);
+extern int pm_valid_only_mem(suspend_state_t state);
+
+/**
+ * arch_suspend_disable_irqs - disable IRQs for suspend
+ *
+ * Disables IRQs (in the default case). This is a weak symbol in the common
+ * code and thus allows architectures to override it if more needs to be
+ * done. Not called for suspend to disk.
+ */
+extern void arch_suspend_disable_irqs(void);
+
+/**
+ * arch_suspend_enable_irqs - enable IRQs after suspend
+ *
+ * Enables IRQs (in the default case). This is a weak symbol in the common
+ * code and thus allows architectures to override it if more needs to be
+ * done. Not called for suspend to disk.
+ */
+extern void arch_suspend_enable_irqs(void);
+
+extern int pm_suspend(suspend_state_t state);
+
 /* struct pbe is used for creating lists of pages that should be restored
  * atomically during the resume from disk, because the page frames they have
  * occupied before the suspend are in use.
@@ -24,14 +123,6 @@ struct pbe {
 extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
-#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
-extern int pm_prepare_console(void);
-extern void pm_restore_console(void);
-#else
-static inline int pm_prepare_console(void) { return 0; }
-static inline void pm_restore_console(void) {}
-#endif
-
 /**
  * struct hibernation_ops - hibernation platform support
  *
@@ -127,4 +218,4 @@ static inline void register_nosave_regio
 }
 #endif
 
-#endif /* _LINUX_SWSUSP_H */
+#endif /* _LINUX_SUSPEND_H */
Index: linux-2.6.22-rc4-mm2/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/arm/common/sharpsl_pm.c
+++ linux-2.6.22-rc4-mm2/arch/arm/common/sharpsl_pm.c
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/leds.h>
 #include <linux/apm-emulation.h>
+#include <linux/suspend.h>
 
 #include <asm/hardware.h>
 #include <asm/mach-types.h>
Index: linux-2.6.22-rc4-mm2/arch/arm/mach-pnx4008/pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/arm/mach-pnx4008/pm.c
+++ linux-2.6.22-rc4-mm2/arch/arm/mach-pnx4008/pm.c
@@ -15,7 +15,7 @@
 #include <linux/rtc.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
 
Index: linux-2.6.22-rc4-mm2/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/arm/mach-omap1/pm.c
+++ linux-2.6.22-rc4-mm2/arch/arm/mach-omap1/pm.c
@@ -35,10 +35,9 @@
  * 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc4-mm2/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/arm/mach-omap2/pm.c
+++ linux-2.6.22-rc4-mm2/arch/arm/mach-omap2/pm.c
@@ -16,10 +16,9 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc4-mm2/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/arm/mach-at91/pm.c
+++ linux-2.6.22-rc4-mm2/arch/arm/mach-at91/pm.c
@@ -10,10 +10,9 @@
  * (at your option) any later version.
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
-#include <linux/pm.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
Index: linux-2.6.22-rc4-mm2/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/blackfin/mach-common/pm.c
+++ linux-2.6.22-rc4-mm2/arch/blackfin/mach-common/pm.c
@@ -32,7 +32,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/sched.h>
 #include <linux/proc_fs.h>
 
Index: linux-2.6.22-rc4-mm2/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c
+++ linux-2.6.22-rc4-mm2/arch/powerpc/platforms/52xx/mpc52xx_pm.c
@@ -1,5 +1,5 @@
 #include <linux/init.h>
-#include <linux/pm.h>
+#include <linux/suspend.h>
 #include <linux/io.h>
 #include <asm/time.h>
 #include <asm/cacheflush.h>
Index: linux-2.6.22-rc4-mm2/include/linux/pm.h
===================================================================
--- linux-2.6.22-rc4-mm2.orig/include/linux/pm.h
+++ linux-2.6.22-rc4-mm2/include/linux/pm.h
@@ -102,97 +102,6 @@ struct pm_dev
 extern void (*pm_idle)(void);
 extern void (*pm_power_off)(void);
 
-typedef int __bitwise suspend_state_t;
-
-#define PM_SUSPEND_ON		((__force suspend_state_t) 0)
-#define PM_SUSPEND_STANDBY	((__force suspend_state_t) 1)
-#define PM_SUSPEND_MEM		((__force suspend_state_t) 3)
-#define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
-
-/**
- * struct pm_ops - Callbacks for managing platform dependent system sleep
- *	states.
- *
- * @valid: Callback to determine if given system sleep state is supported by
- *	the platform.
- *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
- *	that it still may be impossible to enter given system sleep state if the
- *	conditions aren't right.
- *	There is the %pm_valid_only_mem function available that can be assigned
- *	to this if the platform only supports mem sleep.
- *
- * @set_target: Tell the platform which system sleep state is going to be
- *	entered.
- *	@set_target() is executed right prior to suspending devices.  The
- *	information conveyed to the platform code by @set_target() should be
- *	disregarded by the platform as soon as @finish() is executed and if
- *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
- *	@prepare(), @enter() and @finish() will not be called by the PM core.
- *	This callback is optional.  However, if it is implemented, the argument
- *	passed to @prepare(), @enter() and @finish() is meaningless and should
- *	be ignored.
- *
- * @prepare: Prepare the platform for entering the system sleep state indicated
- *	by @set_target() or represented by the argument if @set_target() is not
- *	implemented.
- *	@prepare() is called right after devices have been suspended (ie. the
- *	appropriate .suspend() method has been executed for each device) and
- *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
- *	This callback is optional.  It returns 0 on success or a negative
- *	error code otherwise, in which case the system cannot enter the desired
- *	sleep state (@enter() and @finish() will not be called in that case).
- *
- * @enter: Enter the system sleep state indicated by @set_target() or
- *	represented by the argument if @set_target() is not implemented.
- *	This callback is mandatory.  It returns 0 on success or a negative
- *	error code otherwise, in which case the system cannot enter the desired
- *	sleep state.
- *
- * @finish: Called when the system has just left a sleep state, right after
- *	the nonboot CPUs have been enabled and before devices are resumed (it is
- *	executed with IRQs enabled).  If @set_target() is not implemented, the
- *	argument represents the sleep state being left.
- *	This callback is optional, but should be implemented by the platforms
- *	that implement @prepare().  If implemented, it is always called after
- *	@enter() (even if @enter() fails).
- */
-struct pm_ops {
-	int (*valid)(suspend_state_t state);
-	int (*set_target)(suspend_state_t state);
-	int (*prepare)(suspend_state_t state);
-	int (*enter)(suspend_state_t state);
-	int (*finish)(suspend_state_t state);
-};
-
-extern struct pm_ops *pm_ops;
-
-/**
- * pm_set_ops - set platform dependent power management ops
- * @pm_ops: The new power management operations to set.
- */
-extern void pm_set_ops(struct pm_ops *pm_ops);
-extern int pm_valid_only_mem(suspend_state_t state);
-
-/**
- * arch_suspend_disable_irqs - disable IRQs for suspend
- *
- * Disables IRQs (in the default case). This is a weak symbol in the common
- * code and thus allows architectures to override it if more needs to be
- * done. Not called for suspend to disk.
- */
-extern void arch_suspend_disable_irqs(void);
-
-/**
- * arch_suspend_enable_irqs - enable IRQs after suspend
- *
- * Enables IRQs (in the default case). This is a weak symbol in the common
- * code and thus allows architectures to override it if more needs to be
- * done. Not called for suspend to disk.
- */
-extern void arch_suspend_enable_irqs(void);
-
-extern int pm_suspend(suspend_state_t state);
-
 /*
  * Device power management
  */

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 5/8] PM: Rename struct pm_ops and related things
       [not found] ` <200706260039.17530.rjw@sisk.pl>
                     ` (3 preceding siblings ...)
  2007-06-25 22:47   ` [RFC/RFT][PATCH -mm 4/8] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
@ 2007-06-25 22:48   ` Rafael J. Wysocki
  2007-06-25 22:49   ` [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations Rafael J. Wysocki
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:48 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

The name of 'struct pm_ops' suggests that it is related to the power management
in general, but in fact it is only related to suspend.  Moreover, its name
should indicate what this structure is used for, so it seems reasonable to
change it to 'struct platform_suspend_operations'.  In that case, the name of
the global variable of this type used by the PM core and the names of related
functions should be changed accordingly.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 Documentation/power/interface.txt        |    2 -
 arch/arm/common/sharpsl_pm.c             |    8 +++----
 arch/arm/mach-at91/pm.c                  |    4 +--
 arch/arm/mach-omap1/pm.c                 |    6 ++---
 arch/arm/mach-omap2/pm.c                 |    6 ++---
 arch/arm/mach-pnx4008/pm.c               |    4 +--
 arch/arm/mach-pxa/pm.c                   |    6 ++---
 arch/arm/mach-sa1100/pm.c                |    6 ++---
 arch/arm/plat-s3c24xx/pm.c               |    6 ++---
 arch/blackfin/mach-common/pm.c           |    4 +--
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    4 +--
 arch/sh/boards/hp6xx/pm.c                |    6 ++---
 drivers/acpi/sleep/main.c                |    6 ++---
 include/linux/suspend.h                  |   20 +++++++++---------
 kernel/power/main.c                      |   34 +++++++++++++++----------------
 15 files changed, 61 insertions(+), 61 deletions(-)

Index: linux-2.6.22-rc6/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc6.orig/include/linux/suspend.h	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/include/linux/suspend.h	2007-06-25 21:53:51.000000000 +0200
@@ -26,16 +26,16 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
 
 /**
- * struct pm_ops - Callbacks for managing platform dependent system sleep
- *	states.
+ * struct platform_suspend_operations - Callbacks for managing platform
+ *	dependent system sleep states.
  *
  * @valid: Callback to determine if given system sleep state is supported by
  *	the platform.
  *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
  *	that it still may be impossible to enter given system sleep state if the
  *	conditions aren't right.
- *	There is the %pm_valid_only_mem function available that can be assigned
- *	to this if the platform only supports mem sleep.
+ *	There is the %suspend_valid_only_mem function available that can be
+ *	assigned to this if the platform only supports mem sleep.
  *
  * @set_target: Tell the platform which system sleep state is going to be
  *	entered.
@@ -72,7 +72,7 @@ typedef int __bitwise suspend_state_t;
  *	that implement @prepare().  If implemented, it is always called after
  *	@enter() (even if @enter() fails).
  */
-struct pm_ops {
+struct platform_suspend_operations {
 	int (*valid)(suspend_state_t state);
 	int (*set_target)(suspend_state_t state);
 	int (*prepare)(suspend_state_t state);
@@ -80,14 +80,14 @@ struct pm_ops {
 	int (*finish)(suspend_state_t state);
 };
 
-extern struct pm_ops *pm_ops;
+extern struct platform_suspend_operations *suspend_ops;
 
 /**
- * pm_set_ops - set platform dependent power management ops
- * @pm_ops: The new power management operations to set.
+ * suspend_set_ops - set platform dependent suspend operations
+ * @ops: The new suspend operations to set.
  */
-extern void pm_set_ops(struct pm_ops *pm_ops);
-extern int pm_valid_only_mem(suspend_state_t state);
+extern void suspend_set_ops(struct platform_suspend_operations *ops);
+extern int suspend_valid_only_mem(suspend_state_t state);
 
 /**
  * arch_suspend_disable_irqs - disable IRQs for suspend
Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 21:53:51.000000000 +0200
@@ -21,7 +21,7 @@
 
 u8 sleep_states[ACPI_S_STATE_COUNT];
 
-static struct pm_ops acpi_pm_ops;
+static struct platform_suspend_operations acpi_pm_ops;
 
 extern void do_suspend_lowlevel(void);
 
@@ -200,7 +200,7 @@ static int acpi_pm_state_valid(suspend_s
 	}
 }
 
-static struct pm_ops acpi_pm_ops = {
+static struct platform_suspend_operations acpi_pm_ops = {
 	.valid = acpi_pm_state_valid,
 	.set_target = acpi_pm_set_target,
 	.prepare = acpi_pm_prepare,
@@ -358,7 +358,7 @@ int __init acpi_sleep_init(void)
 	}
 	printk(")\n");
 
-	pm_set_ops(&acpi_pm_ops);
+	suspend_set_ops(&acpi_pm_ops);
 
 #ifdef CONFIG_SOFTWARE_SUSPEND
 	if (sleep_states[ACPI_STATE_S4])
Index: linux-2.6.22-rc6/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc6.orig/kernel/power/main.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/kernel/power/main.c	2007-06-25 21:53:51.000000000 +0200
@@ -33,28 +33,28 @@ DEFINE_MUTEX(pm_mutex);
 unsigned int pm_flags;
 EXPORT_SYMBOL(pm_flags);
 
-struct pm_ops *pm_ops;
+struct platform_suspend_operations *suspend_ops;
 
 /**
- *	pm_set_ops - Set the global power method table. 
+ *	suspend_set_ops - Set the global suspend method table.
  *	@ops:	Pointer to ops structure.
  */
 
-void pm_set_ops(struct pm_ops * ops)
+void suspend_set_ops(struct platform_suspend_operations *ops)
 {
 	mutex_lock(&pm_mutex);
-	pm_ops = ops;
+	suspend_ops = ops;
 	mutex_unlock(&pm_mutex);
 }
 
 /**
- * pm_valid_only_mem - generic memory-only valid callback
+ * suspend_valid_only_mem - generic memory-only valid callback
  *
- * pm_ops drivers that implement mem suspend only and only need
+ * Platform drivers that implement mem suspend only and only need
  * to check for that in their .valid callback can use this instead
  * of rolling their own .valid callback.
  */
-int pm_valid_only_mem(suspend_state_t state)
+int suspend_valid_only_mem(suspend_state_t state)
 {
 	return state == PM_SUSPEND_MEM;
 }
@@ -62,8 +62,8 @@ int pm_valid_only_mem(suspend_state_t st
 
 static inline void pm_finish(suspend_state_t state)
 {
-	if (pm_ops->finish)
-		pm_ops->finish(state);
+	if (suspend_ops->finish)
+		suspend_ops->finish(state);
 }
 
 /**
@@ -77,7 +77,7 @@ static int suspend_prepare(void)
 	int error;
 	unsigned int free_pages;
 
-	if (!pm_ops || !pm_ops->enter)
+	if (!suspend_ops || !suspend_ops->enter)
 		return -EPERM;
 
 	error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
@@ -140,7 +140,7 @@ int suspend_enter(suspend_state_t state)
 		printk(KERN_ERR "Some devices failed to power down\n");
 		goto Done;
 	}
-	error = pm_ops->enter(state);
+	error = suspend_ops->enter(state);
 	device_power_up();
  Done:
 	arch_suspend_enable_irqs();
@@ -157,11 +157,11 @@ int suspend_devices_and_enter(suspend_st
 {
 	int error;
 
-	if (!pm_ops)
+	if (!suspend_ops)
 		return -ENOSYS;
 
-	if (pm_ops->set_target) {
-		error = pm_ops->set_target(state);
+	if (suspend_ops->set_target) {
+		error = suspend_ops->set_target(state);
 		if (error)
 			return error;
 	}
@@ -171,8 +171,8 @@ int suspend_devices_and_enter(suspend_st
 		printk(KERN_ERR "Some devices failed to suspend\n");
 		goto Resume_console;
 	}
-	if (pm_ops->prepare) {
-		error = pm_ops->prepare(state);
+	if (suspend_ops->prepare) {
+		error = suspend_ops->prepare(state);
 		if (error)
 			goto Resume_devices;
 	}
@@ -215,7 +215,7 @@ static inline int valid_state(suspend_st
 	/* All states need lowlevel support and need to be valid
 	 * to the lowlevel implementation, no valid callback
 	 * implies that none are valid. */
-	if (!pm_ops || !pm_ops->valid || !pm_ops->valid(state))
+	if (!suspend_ops || !suspend_ops->valid || !suspend_ops->valid(state))
 		return 0;
 	return 1;
 }
Index: linux-2.6.22-rc6/Documentation/power/interface.txt
===================================================================
--- linux-2.6.22-rc6.orig/Documentation/power/interface.txt	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/Documentation/power/interface.txt	2007-06-25 21:53:51.000000000 +0200
@@ -20,7 +20,7 @@ states.
 /sys/power/disk controls the operating mode of the suspend-to-disk
 mechanism. Suspend-to-disk can be handled in several ways. We have a
 few options for putting the system to sleep - using the platform driver
-(e.g. ACPI or other pm_ops), powering off the system or rebooting the
+(e.g. ACPI or other suspend_ops), powering off the system or rebooting the
 system (for testing).
 
 Additionally, /sys/power/disk can be used to turn on one of the two testing
Index: linux-2.6.22-rc6/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/common/sharpsl_pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/common/sharpsl_pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -766,11 +766,11 @@ static void sharpsl_apm_get_power_status
 	info->battery_life = sharpsl_pm.battstat.mainbat_percent;
 }
 
-static struct pm_ops sharpsl_pm_ops = {
+static struct platform_suspend_operations sharpsl_pm_ops = {
 	.prepare	= pxa_pm_prepare,
 	.enter		= corgi_pxa_pm_enter,
 	.finish		= pxa_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init sharpsl_pm_probe(struct platform_device *pdev)
@@ -802,7 +802,7 @@ static int __init sharpsl_pm_probe(struc
 
 	apm_get_power_status = sharpsl_apm_get_power_status;
 
-	pm_set_ops(&sharpsl_pm_ops);
+	suspend_set_ops(&sharpsl_pm_ops);
 
 	mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250));
 
@@ -811,7 +811,7 @@ static int __init sharpsl_pm_probe(struc
 
 static int sharpsl_pm_remove(struct platform_device *pdev)
 {
-	pm_set_ops(NULL);
+	suspend_set_ops(NULL);
 
 	device_remove_file(&pdev->dev, &dev_attr_battery_percentage);
 	device_remove_file(&pdev->dev, &dev_attr_battery_voltage);
Index: linux-2.6.22-rc6/arch/arm/mach-at91/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-at91/pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-at91/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -198,7 +198,7 @@ error:
 }
 
 
-static struct pm_ops at91_pm_ops ={
+static struct platform_suspend_operations at91_pm_ops ={
 	.valid		= at91_pm_valid_state,
 	.set_target	= at91_pm_set_target,
 	.enter		= at91_pm_enter,
@@ -219,7 +219,7 @@ static int __init at91_pm_init(void)
 	/* Disable SDRAM low-power mode.  Cannot be used with self-refresh. */
 	at91_sys_write(AT91_SDRAMC_LPR, 0);
 
-	pm_set_ops(&at91_pm_ops);
+	suspend_set_ops(&at91_pm_ops);
 
 	return 0;
 }
Index: linux-2.6.22-rc6/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-omap1/pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-omap1/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -687,11 +687,11 @@ static struct irqaction omap_wakeup_irq 
 
 
 
-static struct pm_ops omap_pm_ops ={
+static struct platform_suspend_operations omap_pm_ops ={
 	.prepare	= omap_pm_prepare,
 	.enter		= omap_pm_enter,
 	.finish		= omap_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init omap_pm_init(void)
@@ -748,7 +748,7 @@ static int __init omap_pm_init(void)
 	else if (cpu_is_omap16xx())
 		omap_writel(OMAP1610_IDLECT3_VAL, OMAP1610_IDLECT3);
 
-	pm_set_ops(&omap_pm_ops);
+	suspend_set_ops(&omap_pm_ops);
 
 #if defined(DEBUG) && defined(CONFIG_PROC_FS)
 	omap_pm_init_proc();
Index: linux-2.6.22-rc6/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-omap2/pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-omap2/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -368,11 +368,11 @@ static int omap2_pm_finish(suspend_state
 	return 0;
 }
 
-static struct pm_ops omap_pm_ops = {
+static struct platform_suspend_operations omap_pm_ops = {
 	.prepare	= omap2_pm_prepare,
 	.enter		= omap2_pm_enter,
 	.finish		= omap2_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 int __init omap2_pm_init(void)
@@ -396,7 +396,7 @@ int __init omap2_pm_init(void)
 	omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend,
 					    omap24xx_cpu_suspend_sz);
 
-	pm_set_ops(&omap_pm_ops);
+	suspend_set_ops(&omap_pm_ops);
 	pm_idle = omap2_pm_idle;
 
 	pmdomain_init();
Index: linux-2.6.22-rc6/arch/arm/mach-pnx4008/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-pnx4008/pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-pnx4008/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -117,7 +117,7 @@ static int pnx4008_pm_valid(suspend_stat
 	       (state == PM_SUSPEND_MEM);
 }
 
-static struct pm_ops pnx4008_pm_ops = {
+static struct platform_suspend_operations pnx4008_pm_ops = {
 	.enter = pnx4008_pm_enter,
 	.valid = pnx4008_pm_valid,
 };
@@ -146,7 +146,7 @@ static int __init pnx4008_pm_init(void)
 		return -ENOMEM;
 	}
 
-	pm_set_ops(&pnx4008_pm_ops);
+	suspend_set_ops(&pnx4008_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc6/arch/arm/mach-pxa/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-pxa/pm.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-pxa/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -223,16 +223,16 @@ int pxa_pm_finish(suspend_state_t state)
 
 EXPORT_SYMBOL_GPL(pxa_pm_finish);
 
-static struct pm_ops pxa_pm_ops = {
+static struct platform_suspend_operations pxa_pm_ops = {
 	.prepare	= pxa_pm_prepare,
 	.enter		= pxa_pm_enter,
 	.finish		= pxa_pm_finish,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init pxa_pm_init(void)
 {
-	pm_set_ops(&pxa_pm_ops);
+	suspend_set_ops(&pxa_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc6/arch/arm/mach-sa1100/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-sa1100/pm.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-sa1100/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -131,14 +131,14 @@ unsigned long sleep_phys_sp(void *sp)
 	return virt_to_phys(sp);
 }
 
-static struct pm_ops sa11x0_pm_ops = {
+static struct platform_suspend_operations sa11x0_pm_ops = {
 	.enter		= sa11x0_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init sa11x0_pm_init(void)
 {
-	pm_set_ops(&sa11x0_pm_ops);
+	suspend_set_ops(&sa11x0_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc6/arch/arm/plat-s3c24xx/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/plat-s3c24xx/pm.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/plat-s3c24xx/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -612,9 +612,9 @@ static int s3c2410_pm_enter(suspend_stat
 	return 0;
 }
 
-static struct pm_ops s3c2410_pm_ops = {
+static struct platform_suspend_operations s3c2410_pm_ops = {
 	.enter		= s3c2410_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 /* s3c2410_pm_init
@@ -628,6 +628,6 @@ int __init s3c2410_pm_init(void)
 {
 	printk("S3C2410 Power Management, (c) 2004 Simtec Electronics\n");
 
-	pm_set_ops(&s3c2410_pm_ops);
+	suspend_set_ops(&s3c2410_pm_ops);
 	return 0;
 }
Index: linux-2.6.22-rc6/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/blackfin/mach-common/pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/blackfin/mach-common/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -158,7 +158,7 @@ static int bfin_pm_finish(suspend_state_
 	return 0;
 }
 
-struct pm_ops bfin_pm_ops = {
+struct platform_suspend_operations bfin_pm_ops = {
 	.prepare = bfin_pm_prepare,
 	.enter = bfin_pm_enter,
 	.finish = bfin_pm_finish,
@@ -166,7 +166,7 @@ struct pm_ops bfin_pm_ops = {
 
 static int __init bfin_pm_init(void)
 {
-	pm_set_ops(&bfin_pm_ops);
+	suspend_set_ops(&bfin_pm_ops);
 	return 0;
 }
 
Index: linux-2.6.22-rc6/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-25 21:53:50.000000000 +0200
+++ linux-2.6.22-rc6/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -177,7 +177,7 @@ int mpc52xx_pm_finish(suspend_state_t st
 	return 0;
 }
 
-static struct pm_ops mpc52xx_pm_ops = {
+static struct platform_suspend_operations mpc52xx_pm_ops = {
 	.valid		= mpc52xx_pm_valid,
 	.prepare	= mpc52xx_pm_prepare,
 	.enter		= mpc52xx_pm_enter,
@@ -186,6 +186,6 @@ static struct pm_ops mpc52xx_pm_ops = {
 
 int __init mpc52xx_pm_init(void)
 {
-	pm_set_ops(&mpc52xx_pm_ops);
+	suspend_set_ops(&mpc52xx_pm_ops);
 	return 0;
 }
Index: linux-2.6.22-rc6/arch/sh/boards/hp6xx/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/sh/boards/hp6xx/pm.c	2007-06-25 21:53:44.000000000 +0200
+++ linux-2.6.22-rc6/arch/sh/boards/hp6xx/pm.c	2007-06-25 21:53:51.000000000 +0200
@@ -67,14 +67,14 @@ static int hp6x0_pm_enter(suspend_state_
 	return 0;
 }
 
-static struct pm_ops hp6x0_pm_ops = {
+static struct platform_suspend_operations hp6x0_pm_ops = {
 	.enter		= hp6x0_pm_enter,
-	.valid		= pm_valid_only_mem,
+	.valid		= suspend_valid_only_mem,
 };
 
 static int __init hp6x0_pm_init(void)
 {
-	pm_set_ops(&hp6x0_pm_ops);
+	suspend_set_ops(&hp6x0_pm_ops);
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations
       [not found] ` <200706260039.17530.rjw@sisk.pl>
                     ` (4 preceding siblings ...)
  2007-06-25 22:48   ` [RFC/RFT][PATCH -mm 5/8] PM: Rename struct pm_ops and related things Rafael J. Wysocki
@ 2007-06-25 22:49   ` Rafael J. Wysocki
  2007-06-25 22:51   ` [RFC/RFT][PATCH -mm 7/8] PM: Rework struct hibernation_ops Rafael J. Wysocki
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:49 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

There is no reason why the .prepare() and .finish() methods in 'struct
platform_suspend_operations' should take any arguments, since architectures
don't use these methods' argument in any practically meaningful way (ie. either
the target system sleep state is conveyed to the platform by .set_target(), or
there is only one suspend state supported and it is indicated to the PM core by
.valid(), or .prepare() and .finish() aren't defined at all).  There also is
no reason why .finish() should return any result.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 arch/arm/common/sharpsl_pm.c             |    2 -
 arch/arm/mach-omap1/pm.c                 |   20 +-----------
 arch/arm/mach-omap2/pm.c                 |   21 +------------
 arch/arm/mach-pxa/pm.c                   |   24 ---------------
 arch/arm/mach-pxa/pxa25x.c               |   12 -------
 arch/arm/mach-pxa/pxa27x.c               |   11 ------
 arch/blackfin/mach-common/pm.c           |   49 +++----------------------------
 arch/powerpc/platforms/52xx/mpc52xx_pm.c |    8 +----
 drivers/acpi/sleep/main.c                |    7 +---
 include/asm-arm/arch-pxa/pm.h            |    2 -
 include/linux/suspend.h                  |   13 +++-----
 kernel/power/main.c                      |   12 +------
 12 files changed, 24 insertions(+), 157 deletions(-)

Index: linux-2.6.22-rc6/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc6.orig/include/linux/suspend.h	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/include/linux/suspend.h	2007-06-25 21:58:38.000000000 +0200
@@ -45,12 +45,10 @@ typedef int __bitwise suspend_state_t;
  *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
  *	@prepare(), @enter() and @finish() will not be called by the PM core.
  *	This callback is optional.  However, if it is implemented, the argument
- *	passed to @prepare(), @enter() and @finish() is meaningless and should
- *	be ignored.
+ *	passed to @enter() is meaningless and should be ignored.
  *
  * @prepare: Prepare the platform for entering the system sleep state indicated
- *	by @set_target() or represented by the argument if @set_target() is not
- *	implemented.
+ *	by @set_target().
  *	@prepare() is called right after devices have been suspended (ie. the
  *	appropriate .suspend() method has been executed for each device) and
  *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
@@ -66,8 +64,7 @@ typedef int __bitwise suspend_state_t;
  *
  * @finish: Called when the system has just left a sleep state, right after
  *	the nonboot CPUs have been enabled and before devices are resumed (it is
- *	executed with IRQs enabled).  If @set_target() is not implemented, the
- *	argument represents the sleep state being left.
+ *	executed with IRQs enabled).
  *	This callback is optional, but should be implemented by the platforms
  *	that implement @prepare().  If implemented, it is always called after
  *	@enter() (even if @enter() fails).
@@ -75,9 +72,9 @@ typedef int __bitwise suspend_state_t;
 struct platform_suspend_operations {
 	int (*valid)(suspend_state_t state);
 	int (*set_target)(suspend_state_t state);
-	int (*prepare)(suspend_state_t state);
+	int (*prepare)(void);
 	int (*enter)(suspend_state_t state);
-	int (*finish)(suspend_state_t state);
+	void (*finish)(void);
 };
 
 extern struct platform_suspend_operations *suspend_ops;
Index: linux-2.6.22-rc6/kernel/power/main.c
===================================================================
--- linux-2.6.22-rc6.orig/kernel/power/main.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/kernel/power/main.c	2007-06-25 21:58:38.000000000 +0200
@@ -59,13 +59,6 @@ int suspend_valid_only_mem(suspend_state
 	return state == PM_SUSPEND_MEM;
 }
 
-
-static inline void pm_finish(suspend_state_t state)
-{
-	if (suspend_ops->finish)
-		suspend_ops->finish(state);
-}
-
 /**
  *	suspend_prepare - Do prep work before entering low-power state.
  *
@@ -172,7 +165,7 @@ int suspend_devices_and_enter(suspend_st
 		goto Resume_console;
 	}
 	if (suspend_ops->prepare) {
-		error = suspend_ops->prepare(state);
+		error = suspend_ops->prepare();
 		if (error)
 			goto Resume_devices;
 	}
@@ -181,7 +174,8 @@ int suspend_devices_and_enter(suspend_st
 		suspend_enter(state);
 
 	enable_nonboot_cpus();
-	pm_finish(state);
+	if (suspend_ops->finish)
+		suspend_ops->finish();
  Resume_devices:
 	device_resume();
  Resume_console:
Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 21:58:38.000000000 +0200
@@ -61,13 +61,12 @@ static int acpi_pm_set_target(suspend_st
 
 /**
  *	acpi_pm_prepare - Do preliminary suspend work.
- *	@pm_state: ignored
  *
  *	If necessary, set the firmware waking vector and do arch-specific
  *	nastiness to get the wakeup code to the waking vector.
  */
 
-static int acpi_pm_prepare(suspend_state_t pm_state)
+static int acpi_pm_prepare(void)
 {
 	int error = acpi_sleep_prepare(acpi_target_sleep_state);
 
@@ -144,13 +143,12 @@ static int acpi_pm_enter(suspend_state_t
 
 /**
  *	acpi_pm_finish - Finish up suspend sequence.
- *	@pm_state: ignored
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed). 
  */
 
-static int acpi_pm_finish(suspend_state_t pm_state)
+static void acpi_pm_finish(void)
 {
 	u32 acpi_state = acpi_target_sleep_state;
 
@@ -166,7 +164,6 @@ static int acpi_pm_finish(suspend_state_
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
 	}
-	return 0;
 }
 
 int acpi_suspend(u32 acpi_state)
Index: linux-2.6.22-rc6/arch/arm/common/sharpsl_pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/common/sharpsl_pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/common/sharpsl_pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -767,9 +767,7 @@ static void sharpsl_apm_get_power_status
 }
 
 static struct platform_suspend_operations sharpsl_pm_ops = {
-	.prepare	= pxa_pm_prepare,
 	.enter		= corgi_pxa_pm_enter,
-	.finish		= pxa_pm_finish,
 	.valid		= suspend_valid_only_mem,
 };
 
Index: linux-2.6.22-rc6/arch/arm/mach-pxa/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-pxa/pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-pxa/pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -201,32 +201,8 @@ unsigned long sleep_phys_sp(void *sp)
 	return virt_to_phys(sp);
 }
 
-/*
- * Called after processes are frozen, but before we shut down devices.
- */
-int pxa_pm_prepare(suspend_state_t state)
-{
-	extern int pxa_cpu_pm_prepare(suspend_state_t state);
-
-	return pxa_cpu_pm_prepare(state);
-}
-
-EXPORT_SYMBOL_GPL(pxa_pm_prepare);
-
-/*
- * Called after devices are re-setup, but before processes are thawed.
- */
-int pxa_pm_finish(suspend_state_t state)
-{
-	return 0;
-}
-
-EXPORT_SYMBOL_GPL(pxa_pm_finish);
-
 static struct platform_suspend_operations pxa_pm_ops = {
-	.prepare	= pxa_pm_prepare,
 	.enter		= pxa_pm_enter,
-	.finish		= pxa_pm_finish,
 	.valid		= suspend_valid_only_mem,
 };
 
Index: linux-2.6.22-rc6/arch/arm/mach-pxa/pxa25x.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-pxa/pxa25x.c	2007-06-25 21:58:20.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-pxa/pxa25x.c	2007-06-25 21:58:38.000000000 +0200
@@ -105,18 +105,6 @@ EXPORT_SYMBOL(get_lcdclk_frequency_10khz
 
 #ifdef CONFIG_PM
 
-int pxa_cpu_pm_prepare(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_MEM:
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 void pxa_cpu_pm_enter(suspend_state_t state)
 {
 	extern void pxa_cpu_suspend(unsigned int);
Index: linux-2.6.22-rc6/arch/arm/mach-pxa/pxa27x.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-pxa/pxa27x.c	2007-06-25 21:58:20.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-pxa/pxa27x.c	2007-06-25 21:58:38.000000000 +0200
@@ -122,17 +122,6 @@ EXPORT_SYMBOL(get_lcdclk_frequency_10khz
 
 #ifdef CONFIG_PM
 
-int pxa_cpu_pm_prepare(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_MEM:
-	case PM_SUSPEND_STANDBY:
-		return 0;
-	default:
-		return -EINVAL;
-	}
-}
-
 void pxa_cpu_pm_enter(suspend_state_t state)
 {
 	extern void pxa_cpu_standby(void);
Index: linux-2.6.22-rc6/include/asm-arm/arch-pxa/pm.h
===================================================================
--- linux-2.6.22-rc6.orig/include/asm-arm/arch-pxa/pm.h	2007-06-25 21:58:20.000000000 +0200
+++ linux-2.6.22-rc6/include/asm-arm/arch-pxa/pm.h	2007-06-25 21:58:38.000000000 +0200
@@ -7,6 +7,4 @@
  *
  */
 
-extern int pxa_pm_prepare(suspend_state_t state);
 extern int pxa_pm_enter(suspend_state_t state);
-extern int pxa_pm_finish(suspend_state_t state);
Index: linux-2.6.22-rc6/arch/arm/mach-omap1/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-omap1/pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-omap1/pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -613,27 +613,15 @@ static void (*saved_idle)(void) = NULL;
 
 /*
  *	omap_pm_prepare - Do preliminary suspend work.
- *	@state:		suspend state we're entering.
  *
  */
-static int omap_pm_prepare(suspend_state_t state)
+static int omap_pm_prepare(void)
 {
-	int error = 0;
-
 	/* We cannot sleep in idle until we have resumed */
 	saved_idle = pm_idle;
 	pm_idle = NULL;
 
-	switch (state)
-	{
-	case PM_SUSPEND_STANDBY:
-	case PM_SUSPEND_MEM:
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return 0;
 }
 
 
@@ -661,16 +649,14 @@ static int omap_pm_enter(suspend_state_t
 
 /**
  *	omap_pm_finish - Finish up suspend sequence.
- *	@state:		State we're coming out of.
  *
  *	This is called after we wake back up (or if entering the sleep state
  *	failed).
  */
 
-static int omap_pm_finish(suspend_state_t state)
+static void omap_pm_finish(void)
 {
 	pm_idle = saved_idle;
-	return 0;
 }
 
 
Index: linux-2.6.22-rc6/arch/arm/mach-omap2/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/arm/mach-omap2/pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/arm/mach-omap2/pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -72,26 +72,10 @@ void omap2_pm_idle(void)
 
 static int omap2_pm_prepare(suspend_state_t state)
 {
-	int error = 0;
-
 	/* We cannot sleep in idle until we have resumed */
 	saved_idle = pm_idle;
 	pm_idle = NULL;
-
-	switch (state)
-	{
-	case PM_SUSPEND_STANDBY:
-	case PM_SUSPEND_MEM:
-		break;
-
-	case PM_SUSPEND_DISK:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return 0;
 }
 
 #define INT0_WAKE_MASK	(OMAP_IRQ_BIT(INT_24XX_GPIO_BANK1) |	\
@@ -362,10 +346,9 @@ static int omap2_pm_enter(suspend_state_
 	return ret;
 }
 
-static int omap2_pm_finish(suspend_state_t state)
+static void omap2_pm_finish(suspend_state_t state)
 {
 	pm_idle = saved_idle;
-	return 0;
 }
 
 static struct platform_suspend_operations omap_pm_ops = {
Index: linux-2.6.22-rc6/arch/blackfin/mach-common/pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/blackfin/mach-common/pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/blackfin/mach-common/pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -89,28 +89,15 @@ void bfin_pm_suspend_standby_enter(void)
 #endif				/* CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR */
 }
 
-
 /*
- *	bfin_pm_prepare - Do preliminary suspend work.
- *	@state:		suspend state we're entering.
+ *	bfin_pm_valid - Tell the PM core that we only support the standby sleep
+ *			state
+ *	@state:		suspend state we're checking.
  *
  */
-static int bfin_pm_prepare(suspend_state_t state)
+static int bfin_pm_valid(suspend_state_t state)
 {
-	int error = 0;
-
-	switch (state) {
-	case PM_SUSPEND_STANDBY:
-		break;
-
-	case PM_SUSPEND_MEM:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return error;
+	return (state == PM_SUSPEND_STANDBY);
 }
 
 /*
@@ -135,33 +122,9 @@ static int bfin_pm_enter(suspend_state_t
 	return 0;
 }
 
-/*
- *	bfin_pm_finish - Finish up suspend sequence.
- *	@state:		State we're coming out of.
- *
- *	This is called after we wake back up (or if entering the sleep state
- *	failed).
- */
-static int bfin_pm_finish(suspend_state_t state)
-{
-	switch (state) {
-	case PM_SUSPEND_STANDBY:
-		break;
-
-	case PM_SUSPEND_MEM:
-		return -ENOTSUPP;
-
-	default:
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 struct platform_suspend_operations bfin_pm_ops = {
-	.prepare = bfin_pm_prepare,
+	.valid = bfin_pm_valid,
 	.enter = bfin_pm_enter,
-	.finish = bfin_pm_finish,
 };
 
 static int __init bfin_pm_init(void)
Index: linux-2.6.22-rc6/arch/powerpc/platforms/52xx/mpc52xx_pm.c
===================================================================
--- linux-2.6.22-rc6.orig/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-25 21:58:38.000000000 +0200
+++ linux-2.6.22-rc6/arch/powerpc/platforms/52xx/mpc52xx_pm.c	2007-06-25 21:58:38.000000000 +0200
@@ -25,6 +25,7 @@ static void *sram;
 static int sram_size;
 
 struct mpc52xx_suspend mpc52xx_suspend;
+static suspend_state_t mpc52xx_pm_target_state;
 
 static int mpc52xx_pm_valid(suspend_state_t state)
 {
@@ -57,11 +58,8 @@ int mpc52xx_set_wakeup_gpio(u8 pin, u8 l
 	return 0;
 }
 
-int mpc52xx_pm_prepare(suspend_state_t state)
+static int mpc52xx_pm_prepare(void)
 {
-	if (state != PM_SUSPEND_STANDBY)
-		return -EINVAL;
-
 	/* map the whole register space */
 	mbar = mpc52xx_find_and_map("mpc5200");
 	if (!mbar) {
@@ -166,7 +164,7 @@ int mpc52xx_pm_enter(suspend_state_t sta
 	return 0;
 }
 
-int mpc52xx_pm_finish(suspend_state_t state)
+static void mpc52xx_pm_finish(void)
 {
 	/* call board resume code */
 	if (mpc52xx_suspend.board_resume_finish)

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 7/8] PM: Rework struct hibernation_ops
       [not found] ` <200706260039.17530.rjw@sisk.pl>
                     ` (5 preceding siblings ...)
  2007-06-25 22:49   ` [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations Rafael J. Wysocki
@ 2007-06-25 22:51   ` Rafael J. Wysocki
  2007-06-25 22:52   ` [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations Rafael J. Wysocki
                     ` (4 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:51 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

During hibernation we also need to tell the ACPI core that we're going to put
the system into the S4 sleep state.  For this reason, an additional method
in 'struct hibernation_ops' is needed, playing the role of set_target() in
'struct platform_suspend_operations'.  Moreover, the role of the .prepare()
method is now different, so it's better to introduce another method, that in
general may be different from .prepare(), that will be used to prepare the
platform for creating the hibernation image (.prepare() is used anyway to
notify the platform that we're going to enter the low power state after the
image has been saved).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/sleep/main.c |   12 +++++++++++-
 include/linux/suspend.h   |   38 ++++++++++++++++++++++++++++++++------
 kernel/power/disk.c       |   27 +++++++++++++++++++++------
 3 files changed, 64 insertions(+), 13 deletions(-)

Index: linux-2.6.22-rc6/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc6.orig/include/linux/suspend.h	2007-06-25 22:53:16.000000000 +0200
+++ linux-2.6.22-rc6/include/linux/suspend.h	2007-06-25 22:58:00.000000000 +0200
@@ -128,16 +128,42 @@ extern void mark_free_pages(struct zone 
  *
  * All three methods must be assigned.
  *
- * @prepare: prepare system for hibernation
- * @enter: shut down system after state has been saved to disk
- * @finish: finish/clean up after state has been reloaded
- * @pre_restore: prepare system for the restoration from a hibernation image
- * @restore_cleanup: clean up after a failing image restoration
+ * @start: Tell the platform driver that we're starting hibernation.
+ *	Called right after shrinking memory and before freezing devices.
+ *
+ * @pre_snapshot: Prepare the platform for creating the hibernation image.
+ *	Called right after devices have been frozen and before the nonboot
+ *	CPUs are disabled (runs with IRQs on).
+ *
+ * @finish: Restore the previous state of the platform after the hibernation
+ *	image has been created *or* put the platform into the normal operation
+ *	mode after the hibernation (the same method is executed in both cases).
+ *	Called right after the nonboot CPUs have been enabled and before
+ *	thawing devices (runs with IRQs on).
+ *
+ * @prepare: Prepare the platform for entering the low power state.
+ *	Called right after the hibernation image has been saved and before
+ *	devices are prepared for entering the low power state.
+ *
+ * @enter: Put the system into the low power state after the hibernation image
+ *	has been saved to disk.
+ *	Called after the nonboot CPUs have been disabled and all of the low
+ *	level devices have been shut down (runs with IRQs off).
+ *
+ * @pre_restore: Prepare system for the restoration from a hibernation image.
+ *	Called right after devices have been frozen and before the nonboot
+ *	CPUs are disabled (runs with IRQs on).
+ *
+ * @restore_cleanup: Clean up after a failing image restoration.
+ *	Called right after the nonboot CPUs have been enabled and before
+ *	thawing devices (runs with IRQs on).
  */
 struct hibernation_ops {
+	int (*start)(void);
+	int (*pre_snapshot)(void);
+	void (*finish)(void);
 	int (*prepare)(void);
 	int (*enter)(void);
-	void (*finish)(void);
 	int (*pre_restore)(void);
 	void (*restore_cleanup)(void);
 };
Index: linux-2.6.22-rc6/kernel/power/disk.c
===================================================================
--- linux-2.6.22-rc6.orig/kernel/power/disk.c	2007-06-25 22:53:16.000000000 +0200
+++ linux-2.6.22-rc6/kernel/power/disk.c	2007-06-25 22:59:28.000000000 +0200
@@ -54,8 +54,9 @@ struct hibernation_ops *hibernation_ops;
 
 void hibernation_set_ops(struct hibernation_ops *ops)
 {
-	if (ops && !(ops->prepare && ops->enter && ops->finish
-	    && ops->pre_restore && ops->restore_cleanup)) {
+	if (ops && !(ops->start && ops->pre_snapshot && ops->finish
+	    && ops->prepare && ops->enter && ops->pre_restore
+	    && ops->restore_cleanup)) {
 		WARN_ON(1);
 		return;
 	}
@@ -69,16 +70,26 @@ void hibernation_set_ops(struct hibernat
 	mutex_unlock(&pm_mutex);
 }
 
+/**
+ *	platform_start - tell the platform driver that we're starting
+ *	hibernation
+ */
+
+static int platform_start(int platform_mode)
+{
+	return (platform_mode && hibernation_ops) ?
+		hibernation_ops->start() : 0;
+}
 
 /**
- *	platform_prepare - prepare the machine for hibernation using the
+ *	platform_pre_snapshot - prepare the machine for hibernation using the
  *	platform driver if so configured and return an error code if it fails
  */
 
-static int platform_prepare(int platform_mode)
+static int platform_pre_snapshot(int platform_mode)
 {
 	return (platform_mode && hibernation_ops) ?
-		hibernation_ops->prepare() : 0;
+		hibernation_ops->pre_snapshot() : 0;
 }
 
 /**
@@ -135,12 +146,16 @@ int hibernation_snapshot(int platform_mo
 	if (error)
 		return error;
 
+	error = platform_start(platform_mode);
+	if (error)
+		return error;
+
 	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
 	if (error)
 		goto Resume_console;
 
-	error = platform_prepare(platform_mode);
+	error = platform_pre_snapshot(platform_mode);
 	if (error)
 		goto Resume_devices;
 
Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 22:53:16.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 22:58:53.000000000 +0200
@@ -206,6 +206,12 @@ static struct platform_suspend_operation
 };
 
 #ifdef CONFIG_SOFTWARE_SUSPEND
+static int acpi_hibernation_start(void)
+{
+	acpi_target_sleep_state = ACPI_STATE_S4;
+	return 0;
+}
+
 static int acpi_hibernation_prepare(void)
 {
 	return acpi_sleep_prepare(ACPI_STATE_S4);
@@ -234,6 +240,8 @@ static void acpi_hibernation_finish(void
 
 	/* reset firmware waking vector */
 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
+
+	acpi_target_sleep_state = ACPI_STATE_S0;
 }
 
 static int acpi_hibernation_pre_restore(void)
@@ -251,9 +259,11 @@ static void acpi_hibernation_restore_cle
 }
 
 static struct hibernation_ops acpi_hibernation_ops = {
+	.start = acpi_hibernation_start,
+	.pre_snapshot = acpi_hibernation_prepare,
+	.finish = acpi_hibernation_finish,
 	.prepare = acpi_hibernation_prepare,
 	.enter = acpi_hibernation_enter,
-	.finish = acpi_hibernation_finish,
 	.pre_restore = acpi_hibernation_pre_restore,
 	.restore_cleanup = acpi_hibernation_restore_cleanup,
 };

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations
       [not found] ` <200706260039.17530.rjw@sisk.pl>
                     ` (6 preceding siblings ...)
  2007-06-25 22:51   ` [RFC/RFT][PATCH -mm 7/8] PM: Rework struct hibernation_ops Rafael J. Wysocki
@ 2007-06-25 22:52   ` Rafael J. Wysocki
       [not found]   ` <200706260049.40457.rjw@sisk.pl>
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-25 22:52 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

From: Rafael J. Wysocki <rjw@sisk.pl>

Rename 'struct hibernation_ops' to 'struct platform_hibernation_operations' in
analogy with 'struct platform_suspend_operations'.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/sleep/main.c |    2 +-
 include/linux/suspend.h   |    9 +++++----
 kernel/power/disk.c       |    4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c	2007-06-25 22:58:53.000000000 +0200
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c	2007-06-25 23:08:48.000000000 +0200
@@ -258,7 +258,7 @@ static void acpi_hibernation_restore_cle
 	acpi_hw_enable_all_runtime_gpes();
 }
 
-static struct hibernation_ops acpi_hibernation_ops = {
+static struct platform_hibernation_operations acpi_hibernation_ops = {
 	.start = acpi_hibernation_start,
 	.pre_snapshot = acpi_hibernation_prepare,
 	.finish = acpi_hibernation_finish,
Index: linux-2.6.22-rc6/include/linux/suspend.h
===================================================================
--- linux-2.6.22-rc6.orig/include/linux/suspend.h	2007-06-25 22:58:00.000000000 +0200
+++ linux-2.6.22-rc6/include/linux/suspend.h	2007-06-25 23:07:21.000000000 +0200
@@ -121,7 +121,7 @@ extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
 /**
- * struct hibernation_ops - hibernation platform support
+ * struct platform_hibernation_operations - hibernation platform support
  *
  * The methods in this structure allow a platform to override the default
  * mechanism of shutting down the machine during a hibernation transition.
@@ -158,7 +158,7 @@ extern void mark_free_pages(struct zone 
  *	Called right after the nonboot CPUs have been enabled and before
  *	thawing devices (runs with IRQs on).
  */
-struct hibernation_ops {
+struct platform_hibernation_operations {
 	int (*start)(void);
 	int (*pre_snapshot)(void);
 	void (*finish)(void);
@@ -185,14 +185,15 @@ extern void swsusp_set_page_free(struct 
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
 
-extern void hibernation_set_ops(struct hibernation_ops *ops);
+extern void hibernation_set_ops(struct platform_hibernation_operations *ops);
 extern int hibernate(void);
 #else /* CONFIG_SOFTWARE_SUSPEND */
 static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
 static inline void swsusp_set_page_free(struct page *p) {}
 static inline void swsusp_unset_page_free(struct page *p) {}
 
-static inline void hibernation_set_ops(struct hibernation_ops *ops) {}
+static inline void
+hibernation_set_ops(struct platform_hibernation_operations *ops) {}
 static inline int hibernate(void) { return -ENOSYS; }
 #endif /* CONFIG_SOFTWARE_SUSPEND */
 
Index: linux-2.6.22-rc6/kernel/power/disk.c
===================================================================
--- linux-2.6.22-rc6.orig/kernel/power/disk.c	2007-06-25 22:59:28.000000000 +0200
+++ linux-2.6.22-rc6/kernel/power/disk.c	2007-06-25 23:08:36.000000000 +0200
@@ -45,14 +45,14 @@ enum {
 
 static int hibernation_mode = HIBERNATION_SHUTDOWN;
 
-struct hibernation_ops *hibernation_ops;
+struct platform_hibernation_operations *hibernation_ops;
 
 /**
  * hibernation_set_ops - set the global hibernate operations
  * @ops: the hibernation operations to use in subsequent hibernation transitions
  */
 
-void hibernation_set_ops(struct hibernation_ops *ops)
+void hibernation_set_ops(struct platform_hibernation_operations *ops)
 {
 	if (ops && !(ops->start && ops->pre_snapshot && ops->finish
 	    && ops->prepare && ops->enter && ops->pre_restore

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations
       [not found]   ` <200706260049.40457.rjw@sisk.pl>
@ 2007-06-26  8:52     ` Pavel Machek
  0 siblings, 0 replies; 32+ messages in thread
From: Pavel Machek @ 2007-06-26  8:52 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, pm list, Johannes Berg

Hi!

> There is no reason why the .prepare() and .finish() methods in 'struct
> platform_suspend_operations' should take any arguments, since architectures
> don't use these methods' argument in any practically meaningful way (ie. either
> the target system sleep state is conveyed to the platform by .set_target(), or
> there is only one suspend state supported and it is indicated to the PM core by
> .valid(), or .prepare() and .finish() aren't defined at all).  There also is
> no reason why .finish() should return any result.
> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

ACK. (Maybe you should not in changelog that this changes absolutely
no behaviour; it is not immediately obvious).

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations
       [not found]   ` <200706260052.28206.rjw@sisk.pl>
@ 2007-06-26  8:54     ` Pavel Machek
  2007-06-27 15:19       ` Rafael J. Wysocki
  0 siblings, 1 reply; 32+ messages in thread
From: Pavel Machek @ 2007-06-26  8:54 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, linux acpi, pm list, Johannes Berg

Hi!

> Rename 'struct hibernation_ops' to 'struct platform_hibernation_operations' in
> analogy with 'struct platform_suspend_operations'.

Can I NAK it because it gets too long? platform_hibernation_ops /
platform_suspend_ops is long but maybe acceptable, 'struct
platform_hibernation_operations' is too long.
							Pavel

> @@ -185,14 +185,15 @@ extern void swsusp_set_page_free(struct 
>  extern void swsusp_unset_page_free(struct page *);
>  extern unsigned long get_safe_page(gfp_t gfp_mask);
>  
> -extern void hibernation_set_ops(struct hibernation_ops *ops);
> +extern void hibernation_set_ops(struct platform_hibernation_operations *ops);
>  extern int hibernate(void);
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found]   ` <1182806886.6644.4.camel@johannes.berg>
@ 2007-06-26  8:55     ` Pavel Machek
  2007-06-26  9:41     ` Rafael J. Wysocki
       [not found]     ` <200706261141.35071.rjw@sisk.pl>
  2 siblings, 0 replies; 32+ messages in thread
From: Pavel Machek @ 2007-06-26  8:55 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Len Brown, linux acpi, pm list

On Mon 2007-06-25 23:28:06, Johannes Berg wrote:
> On Sun, 2007-06-24 at 22:40 +0200, Rafael J. Wysocki wrote:
> 
> > + * @set_target: Tell the platform which system sleep state is going to be
> > + *	entered.  The information passed to @set_target should be disregarded
> > + *	by the platform as soon as @finish() is executed and if	@prepare()
> > + *	fails.
> > + *	This callback is optional.  However, if it is implemented, the
> > + *	argument passed to @prepare(), @enter and @finish() must be ignored.
> 
> I don't understand the point in mandating that then the argument to
> enter() is to be ignored, why bother? It doesn't look as though we can
> possibly do anything with the semantics here that would mean the state
> set by set_target is different to the state passed to enter(), can we?

That's what 4/4 does, AFAICT.



-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found]   ` <1182806886.6644.4.camel@johannes.berg>
  2007-06-26  8:55     ` Pavel Machek
@ 2007-06-26  9:41     ` Rafael J. Wysocki
       [not found]     ` <200706261141.35071.rjw@sisk.pl>
  2 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-26  9:41 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Len Brown, linux acpi, Pavel Machek, pm list

On Monday, 25 June 2007 23:28, Johannes Berg wrote:
> On Sun, 2007-06-24 at 22:40 +0200, Rafael J. Wysocki wrote:
> 
> > + * @set_target: Tell the platform which system sleep state is going to be
> > + *	entered.  The information passed to @set_target should be disregarded
> > + *	by the platform as soon as @finish() is executed and if	@prepare()
> > + *	fails.
> > + *	This callback is optional.  However, if it is implemented, the
> > + *	argument passed to @prepare(), @enter and @finish() must be ignored.
> 
> I don't understand the point in mandating that then the argument to
> enter() is to be ignored, why bother? It doesn't look as though we can
> possibly do anything with the semantics here that would mean the state
> set by set_target is different to the state passed to enter(), can we?

In principle we can't, but I think that it should be "either, or".  Either the
platform implements set_target() and uses the value provided by it, or it
uses the argument passed to the other functions.

Alternatively, I could write that the argument passed to .enter() etc. is
guaranteed to be the same as the one passed to .set_target(), but I didn't want
to say that. :-)

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine (updated)
       [not found]   ` <200706260045.51039.rjw@sisk.pl>
@ 2007-06-26 10:00     ` Rafael J. Wysocki
       [not found]     ` <200706261200.29421.rjw@sisk.pl>
  1 sibling, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-26 10:00 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

[The previous version wouldn't work correctly.]
---
From: Shaohua Li <shaohua.li@intel.com>, Rafael J. Wysocki <rjw@sisk.pl>

Based on the David Brownell's patch at
http://marc.info/?l=linux-acpi&m=117873972806360&w=2

Add a helper routine returning the lowest power (highest number) ACPI device
power state that given device can be in while the system is in the sleep state
indicated by acpi_target_sleep_state .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/sleep/main.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h   |    2 +
 2 files changed, 53 insertions(+)

Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c
@@ -262,6 +262,57 @@ static struct hibernation_ops acpi_hiber
 };
 #endif				/* CONFIG_SOFTWARE_SUSPEND */
 
+/**
+ *	acpi_pm_device_sleep_state - return the lowest power (highest number)
+ *				     ACPI device power state given device can be
+ *				     in while the system is in the sleep state
+ *				     indicated by %acpi_target_sleep_state
+ *	@handle: Represents the device the state is evaluated for
+ */
+
+int acpi_pm_device_sleep_state(acpi_handle handle)
+{
+	char acpi_method[] = "_SxD";
+	unsigned long d_min, d_max;
+	struct acpi_device *dev;
+
+	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev)))
+		printk(KERN_ERR "ACPI handle has no context!\n");
+		return -ENODEV;
+	}
+	acpi_method[2] = '0' + acpi_target_sleep_state;
+	/*
+	 * If the sleep state is S0, we will return D3, but if the device has
+	 * _S0W, we will use the value from _S0W
+	 */
+	d_min = ACPI_STATE_D3;
+	d_max = ACPI_STATE_D3;
+	/*
+	 * If present, _SxD methods give the minimum D-state we may use
+	 * for each S-state ... with lowest latency state switching.
+	 *
+	 * We rely on acpi_evaluate_integer() not clobbering the integer
+	 * provided -- that's our fault recovery, we ignore retval.
+	 */
+	if (acpi_target_sleep_state > ACPI_STATE_S0)
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
+
+	/*
+	 * If _PRW says we can wake from the upcoming system state, the _SxD
+	 * value can wake ... and we'll assume a wakeup-aware driver.  If _SxW
+	 * methods exist (ACPI 3.x), they give the lowest power D-state that
+	 * can also wake the system.  _S0W can be valid.
+	 */
+	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
+	    (dev->wakeup.state.enabled &&
+	     dev->wakeup.sleep_state <= acpi_target_sleep_state)) {
+		d_max = d_min;
+		acpi_method[3] = 'W';
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
+	}
+	return d_max;
+}
+
 /*
  * Toshiba fails to preserve interrupts over S1, reinitialization
  * of 8259 is needed after S1 resume.
Index: linux-2.6.22-rc6/include/acpi/acpi_bus.h
===================================================================
--- linux-2.6.22-rc6.orig/include/acpi/acpi_bus.h
+++ linux-2.6.22-rc6/include/acpi/acpi_bus.h
@@ -364,6 +364,8 @@ acpi_handle acpi_get_child(acpi_handle, 
 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
 #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
 
+int acpi_pm_device_sleep_state(acpi_handle handle);
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine (updated 2x)
       [not found]     ` <200706261200.29421.rjw@sisk.pl>
@ 2007-06-26 10:34       ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-26 10:34 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

[The previous version didn't compile.  Sorry for the mess.]
---
From: Shaohua Li <shaohua.li@intel.com>, Rafael J. Wysocki <rjw@sisk.pl>

Based on David Brownell's patch at
http://marc.info/?l=linux-acpi&m=117873972806360&w=2

Add a helper routine returning the lowest power (highest number) ACPI device
power state that given device can be in while the system is in the sleep state
indicated by acpi_target_sleep_state .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

 drivers/acpi/sleep/main.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h   |    2 +
 2 files changed, 53 insertions(+)

Index: linux-2.6.22-rc6/drivers/acpi/sleep/main.c
===================================================================
--- linux-2.6.22-rc6.orig/drivers/acpi/sleep/main.c
+++ linux-2.6.22-rc6/drivers/acpi/sleep/main.c
@@ -262,6 +262,57 @@ static struct hibernation_ops acpi_hiber
 };
 #endif				/* CONFIG_SOFTWARE_SUSPEND */
 
+/**
+ *	acpi_pm_device_sleep_state - return the lowest power (highest number)
+ *				     ACPI device power state given device can be
+ *				     in while the system is in the sleep state
+ *				     indicated by %acpi_target_sleep_state
+ *	@handle: Represents the device the state is evaluated for
+ */
+
+int acpi_pm_device_sleep_state(acpi_handle handle)
+{
+	char acpi_method[] = "_SxD";
+	unsigned long d_min, d_max;
+	struct acpi_device *dev;
+
+	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
+		printk(KERN_ERR "ACPI handle has no context!\n");
+		return -ENODEV;
+	}
+	acpi_method[2] = '0' + acpi_target_sleep_state;
+	/*
+	 * If the sleep state is S0, we will return D3, but if the device has
+	 * _S0W, we will use the value from _S0W
+	 */
+	d_min = ACPI_STATE_D3;
+	d_max = ACPI_STATE_D3;
+	/*
+	 * If present, _SxD methods give the minimum D-state we may use
+	 * for each S-state ... with lowest latency state switching.
+	 *
+	 * We rely on acpi_evaluate_integer() not clobbering the integer
+	 * provided -- that's our fault recovery, we ignore retval.
+	 */
+	if (acpi_target_sleep_state > ACPI_STATE_S0)
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
+
+	/*
+	 * If _PRW says we can wake from the upcoming system state, the _SxD
+	 * value can wake ... and we'll assume a wakeup-aware driver.  If _SxW
+	 * methods exist (ACPI 3.x), they give the lowest power D-state that
+	 * can also wake the system.  _S0W can be valid.
+	 */
+	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
+	    (dev->wakeup.state.enabled &&
+	     dev->wakeup.sleep_state <= acpi_target_sleep_state)) {
+		d_max = d_min;
+		acpi_method[3] = 'W';
+		acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
+	}
+	return d_max;
+}
+
 /*
  * Toshiba fails to preserve interrupts over S1, reinitialization
  * of 8259 is needed after S1 resume.
Index: linux-2.6.22-rc6/include/acpi/acpi_bus.h
===================================================================
--- linux-2.6.22-rc6.orig/include/acpi/acpi_bus.h
+++ linux-2.6.22-rc6/include/acpi/acpi_bus.h
@@ -364,6 +364,8 @@ acpi_handle acpi_get_child(acpi_handle, 
 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
 #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
 
+int acpi_pm_device_sleep_state(acpi_handle handle);
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found]     ` <200706261141.35071.rjw@sisk.pl>
@ 2007-06-26 17:19       ` David Brownell
       [not found]       ` <200706261019.59712.david-b@pacbell.net>
  1 sibling, 0 replies; 32+ messages in thread
From: David Brownell @ 2007-06-26 17:19 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg, pm list

On Tuesday 26 June 2007, Rafael J. Wysocki wrote:

> Alternatively, I could write that the argument passed to .enter() etc. is
> guaranteed to be the same as the one passed to .set_target(), but I didn't want
> to say that. :-)

Why not?  So long as enter() takes an argument, that seems
to me exactly what it should guarantee.  Although that 
argument should vanish; any platform that differentiates
what it does based on that parameter can just be required
to provide a set_target() method.

- Dave

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops
       [not found]       ` <200706261019.59712.david-b@pacbell.net>
@ 2007-06-26 20:14         ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-26 20:14 UTC (permalink / raw)
  To: David Brownell
  Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg, pm list

On Tuesday, 26 June 2007 19:19, David Brownell wrote:
> On Tuesday 26 June 2007, Rafael J. Wysocki wrote:
> 
> > Alternatively, I could write that the argument passed to .enter() etc. is
> > guaranteed to be the same as the one passed to .set_target(), but I didn't want
> > to say that. :-)
> 
> Why not?  So long as enter() takes an argument, that seems
> to me exactly what it should guarantee.

Okay, I can change the wording, although reluctantly.  [Please have a look at
[PATCH 1/8] in the updated series, the comment is a bit different in there,
with "should" instead of "must" which I think is correct.] 

> Although that argument should vanish; any platform that differentiates
> what it does based on that parameter can just be required
> to provide a set_target() method.

Well, I'd like to leave the option for defining only .enter(), without the
other callbacks (some platforms do it and I don't see why we should force
them to complicate things).

In fact, what I wanted the comment to _mean_ after applying the entire patchset
is that either you can define .set_target(), in which case you should use what
it gives you and not anything else, or you can define only .enter(), in which
case its argument represents the target state.

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations
  2007-06-26  8:54     ` [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations Pavel Machek
@ 2007-06-27 15:19       ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-27 15:19 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Len Brown, linux acpi, pm list, Johannes Berg

On Tuesday, 26 June 2007 10:54, Pavel Machek wrote:
> Hi!
> 
> > Rename 'struct hibernation_ops' to 'struct platform_hibernation_operations' in
> > analogy with 'struct platform_suspend_operations'.
> 
> Can I NAK it because it gets too long? platform_hibernation_ops /
> platform_suspend_ops is long but maybe acceptable, 'struct
> platform_hibernation_operations' is too long.

Okay, I can change both to platform_suspend_ops and platform_hibernation_ops
(should be mutually consistent IMO).

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops
       [not found]   ` <200706260041.20561.rjw@sisk.pl>
@ 2007-06-27 20:27     ` Rafael J. Wysocki
  2007-06-27 20:41     ` David Brownell
       [not found]     ` <200706271341.53599.david-b@pacbell.net>
  2 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-27 20:27 UTC (permalink / raw)
  To: pm list; +Cc: Len Brown, linux acpi, Pavel Machek, Johannes Berg

On Tuesday, 26 June 2007 00:41, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> The at91 platform code incorrectly assumes that pm_ops->prepare() will be called
> before devices are suspended and uses it to make the PM core set the target
> system sleep state used by the platform when suspending devices.  Thus, at91
> needs a new member function in 'struct pm_ops' that will be used by the PM core
> to convey the target system sleep state to the platform code before devices are
> suspended.
> 
> Moreover, in the future some drivers may need to use ACPI to determine the low
> power states in which to place their devices, but to provide the drivers with
> this information the ACPI core needs to know what sleep state the system is
> going to enter.  Namely, the device's state should not be too high power for
> given system sleep state and, if the device is supposed to be able to wake up
> the system, its state should not be too low power for the wake up to be
> possible).  However, pm_ops->prepare() is only called after the drivers'
> .suspend() callbacks have been executed, so we need an additional means to
> convey the target system sleep state to the ACPI core.  The new member function
> in 'struct pm_ops', set_target(), can be used for this purpose.

If there are no objections to this patch, I'd like to push it for merging into
2.6.22, because at91 suspend will be broken without it.

Greetings,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops
       [not found]   ` <200706260041.20561.rjw@sisk.pl>
  2007-06-27 20:27     ` [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
@ 2007-06-27 20:41     ` David Brownell
       [not found]     ` <200706271341.53599.david-b@pacbell.net>
  2 siblings, 0 replies; 32+ messages in thread
From: David Brownell @ 2007-06-27 20:41 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, linux acpi, Pavel Machek, Andrew Victor, pm list,
	Johannes Berg

On Monday 25 June 2007, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> The at91 platform code incorrectly assumes that pm_ops->prepare() will be called

Make that "code assumes that ... but that requirement was broken
by a patch merged in RC5 to make ACPI behave better."  That is,
the problem is not that the AT91 code was doing anything wrong,
it's that the API definition changed (incompatibly!) in RC5.

> before devices are suspended and uses it to make the PM core set the target
> system sleep state used by the platform when suspending devices.  Thus, at91
> needs a new member function in 'struct pm_ops' that will be used by the PM core
> to convey the target system sleep state to the platform code before devices are
> suspended.
> 
> Moreover, in the future some drivers may need to use ACPI to determine the low
> power states in which to place their devices, but to provide the drivers with
> this information the ACPI core needs to know what sleep state the system is
> going to enter.  Namely, the device's state should not be too high power for
> given system sleep state and, if the device is supposed to be able to wake up
> the system, its state should not be too low power for the wake up to be
> possible).  However, pm_ops->prepare() is only called after the drivers'
> .suspend() callbacks have been executed, so we need an additional means to
> convey the target system sleep state to the ACPI core.  The new member function
> in 'struct pm_ops', set_target(), can be used for this purpose.

That's all extremely verbose:  (a) prepare() used to be called
early, so a platform knew the target state while devices were
being suspended; (b) that changed in RC5; (c) we still need a
call delivering the original semantics, since (c1) AT91 depends
on it now and (c2) ACPI should be depending on it, and this change
broke a patch fixing that; ... so (d) here's a patch adding a new
function that can do what prepare() used to do.


> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Acked-by: David Brownell <dbrownell@users.sourceforge.net>

> ---
>  arch/arm/mach-at91/pm.c |    4 +-
>  include/linux/pm.h      |   66 +++++++++++++++++++++++++++++++++++-------------
>  kernel/power/main.c     |    6 +++-
>  3 files changed, 56 insertions(+), 20 deletions(-)
> 
> Index: linux-2.6.22-rc6/include/linux/pm.h
> ===================================================================
> --- linux-2.6.22-rc6.orig/include/linux/pm.h	2007-06-25 21:09:18.000000000 +0200
> +++ linux-2.6.22-rc6/include/linux/pm.h	2007-06-25 21:09:30.000000000 +0200
> @@ -110,37 +110,67 @@ typedef int __bitwise suspend_state_t;
>  #define PM_SUSPEND_MAX		((__force suspend_state_t) 4)
>  
>  /**
> - * struct pm_ops - Callbacks for managing platform dependent suspend states.
> - * @valid: Callback to determine whether the given state can be entered.
> - *	Valid states are advertised in /sys/power/state but can still
> - *	be rejected by prepare or enter if the conditions aren't right.
> - *	There is a %pm_valid_only_mem function available that can be assigned
> - *	to this if you only implement mem sleep.
> + * struct pm_ops - Callbacks for managing platform dependent system sleep
> + *	states.
>   *
> - * @prepare: Prepare the platform for the given suspend state. Can return a
> - *	negative error code if necessary.
> - *
> - * @enter: Enter the given suspend state, must be assigned. Can return a
> - *	negative error code if necessary.
> - *
> - * @finish: Called when the system has left the given state and all devices
> - *	are resumed. The return value is ignored.
> + * @valid: Callback to determine if given system sleep state is supported by
> + *	the platform.
> + *	Valid (ie. supported) states are advertised in /sys/power/state.  Note
> + *	that it still may be impossible to enter given system sleep state if the
> + *	conditions aren't right.
> + *	There is the %pm_valid_only_mem function available that can be assigned
> + *	to this if the platform only supports mem sleep.
> + *
> + * @set_target: Tell the platform which system sleep state is going to be
> + *	entered.
> + *	@set_target() is executed right prior to suspending devices.  The
> + *	information conveyed to the platform code by @set_target() should be
> + *	disregarded by the platform as soon as @finish() is executed and if
> + *	@prepare() fails.  If @set_target() fails (ie. returns nonzero),
> + *	@prepare(), @enter() and @finish() will not be called by the PM core.
> + *	This callback is optional.  However, if it is implemented, the argument
> + *	passed to @prepare(), @enter() and @finish() is meaningless and should
> + *	be ignored.
> + *
> + * @prepare: Prepare the platform for entering the system sleep state indicated
> + *	by @set_target() or represented by the argument if @set_target() is not
> + *	implemented.
> + *	@prepare() is called right after devices have been suspended (ie. the
> + *	appropriate .suspend() method has been executed for each device) and
> + *	before the nonboot CPUs are disabled (it is executed with IRQs enabled).
> + *	This callback is optional.  It returns 0 on success or a negative
> + *	error code otherwise, in which case the system cannot enter the desired
> + *	sleep state (@enter() and @finish() will not be called in that case).
> + *
> + * @enter: Enter the system sleep state indicated by @set_target() or
> + *	represented by the argument if @set_target() is not implemented.
> + *	This callback is mandatory.  It returns 0 on success or a negative
> + *	error code otherwise, in which case the system cannot enter the desired
> + *	sleep state.
> + *
> + * @finish: Called when the system has just left a sleep state, right after
> + *	the nonboot CPUs have been enabled and before devices are resumed (it is
> + *	executed with IRQs enabled).  If @set_target() is not implemented, the
> + *	argument represents the sleep state being left.
> + *	This callback is optional, but should be implemented by the platforms
> + *	that implement @prepare().  If implemented, it is always called after
> + *	@enter() (even if @enter() fails).
>   */
>  struct pm_ops {
>  	int (*valid)(suspend_state_t state);
> +	int (*set_target)(suspend_state_t state);
>  	int (*prepare)(suspend_state_t state);
>  	int (*enter)(suspend_state_t state);
>  	int (*finish)(suspend_state_t state);
>  };
>  
> +extern struct pm_ops *pm_ops;
> +
>  /**
>   * pm_set_ops - set platform dependent power management ops
>   * @pm_ops: The new power management operations to set.
>   */
>  extern void pm_set_ops(struct pm_ops *pm_ops);
> -extern struct pm_ops *pm_ops;
> -extern int pm_suspend(suspend_state_t state);
> -
>  extern int pm_valid_only_mem(suspend_state_t state);
>  
>  /**
> @@ -161,6 +191,8 @@ extern void arch_suspend_disable_irqs(vo
>   */
>  extern void arch_suspend_enable_irqs(void);
>  
> +extern int pm_suspend(suspend_state_t state);
> +
>  /*
>   * Device power management
>   */
> Index: linux-2.6.22-rc6/kernel/power/main.c
> ===================================================================
> --- linux-2.6.22-rc6.orig/kernel/power/main.c	2007-06-25 21:09:18.000000000 +0200
> +++ linux-2.6.22-rc6/kernel/power/main.c	2007-06-25 21:09:30.000000000 +0200
> @@ -15,7 +15,6 @@
>  #include <linux/delay.h>
>  #include <linux/errno.h>
>  #include <linux/init.h>
> -#include <linux/pm.h>
>  #include <linux/console.h>
>  #include <linux/cpu.h>
>  #include <linux/resume-trace.h>
> @@ -161,6 +160,11 @@ int suspend_devices_and_enter(suspend_st
>  	if (!pm_ops)
>  		return -ENOSYS;
>  
> +	if (pm_ops->set_target) {
> +		error = pm_ops->set_target(state);
> +		if (error)
> +			return error;
> +	}
>  	suspend_console();
>  	error = device_suspend(PMSG_SUSPEND);
>  	if (error) {
> Index: linux-2.6.22-rc6/arch/arm/mach-at91/pm.c
> ===================================================================
> --- linux-2.6.22-rc6.orig/arch/arm/mach-at91/pm.c	2007-06-25 21:09:18.000000000 +0200
> +++ linux-2.6.22-rc6/arch/arm/mach-at91/pm.c	2007-06-25 21:09:30.000000000 +0200
> @@ -53,7 +53,7 @@ static suspend_state_t target_state;
>  /*
>   * Called after processes are frozen, but before we shutdown devices.
>   */
> -static int at91_pm_prepare(suspend_state_t state)
> +static int at91_pm_set_target(suspend_state_t state)
>  {
>  	target_state = state;
>  	return 0;
> @@ -201,7 +201,7 @@ error:
>  
>  static struct pm_ops at91_pm_ops ={
>  	.valid		= at91_pm_valid_state,
> -	.prepare	= at91_pm_prepare,
> +	.set_target	= at91_pm_set_target,
>  	.enter		= at91_pm_enter,
>  };
>  
> 

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops
       [not found]     ` <200706271341.53599.david-b@pacbell.net>
@ 2007-06-27 20:55       ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2007-06-27 20:55 UTC (permalink / raw)
  To: David Brownell
  Cc: Len Brown, linux acpi, Pavel Machek, Andrew Victor, pm list,
	Johannes Berg

On Wednesday, 27 June 2007 22:41, David Brownell wrote:
> On Monday 25 June 2007, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rjw@sisk.pl>
> > 
> > The at91 platform code incorrectly assumes that pm_ops->prepare() will be called
> 
> Make that "code assumes that ... but that requirement was broken
> by a patch merged in RC5 to make ACPI behave better."  That is,
> the problem is not that the AT91 code was doing anything wrong,
> it's that the API definition changed (incompatibly!) in RC5.
> 
> > before devices are suspended and uses it to make the PM core set the target
> > system sleep state used by the platform when suspending devices.  Thus, at91
> > needs a new member function in 'struct pm_ops' that will be used by the PM core
> > to convey the target system sleep state to the platform code before devices are
> > suspended.
> > 
> > Moreover, in the future some drivers may need to use ACPI to determine the low
> > power states in which to place their devices, but to provide the drivers with
> > this information the ACPI core needs to know what sleep state the system is
> > going to enter.  Namely, the device's state should not be too high power for
> > given system sleep state and, if the device is supposed to be able to wake up
> > the system, its state should not be too low power for the wake up to be
> > possible).  However, pm_ops->prepare() is only called after the drivers'
> > .suspend() callbacks have been executed, so we need an additional means to
> > convey the target system sleep state to the ACPI core.  The new member function
> > in 'struct pm_ops', set_target(), can be used for this purpose.
> 
> That's all extremely verbose:  (a) prepare() used to be called
> early, so a platform knew the target state while devices were
> being suspended; (b) that changed in RC5; (c) we still need a
> call delivering the original semantics, since (c1) AT91 depends
> on it now and (c2) ACPI should be depending on it, and this change
> broke a patch fixing that; ... so (d) here's a patch adding a new
> function that can do what prepare() used to do.

OK, I'll modify the changelog.

> > 
> > Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
> 
> Acked-by: David Brownell <dbrownell@users.sourceforge.net>

Thanks,
Rafael


-- 
"Premature optimization is the root of all evil." - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2007-06-27 20:55 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200706242239.05678.rjw@sisk.pl>
2007-06-24 20:40 ` [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
2007-06-24 20:41 ` [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
2007-06-24 20:42 ` [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things Rafael J. Wysocki
2007-06-24 20:44 ` [RFC/RFT][PATCH -mm 4/4] PM: Rework struct platform_suspend_operations Rafael J. Wysocki
     [not found] ` <200706242242.47573.rjw@sisk.pl>
2007-06-25  4:12   ` [RFC/RFT][PATCH -mm 3/4] PM: Rename struct pm_ops and related things David Brownell
2007-06-25 19:34   ` Pavel Machek
     [not found] ` <200706242241.39283.rjw@sisk.pl>
2007-06-25 19:33   ` [RFC/RFT][PATCH -mm 2/4] PM: Move definition of struct pm_ops to suspend.h Pavel Machek
     [not found] ` <200706242240.40476.rjw@sisk.pl>
2007-06-25  2:11   ` [RFC/RFT][PATCH -mm 1/4] PM: Introduce set_target method in pm_ops David Brownell
2007-06-25 21:28   ` Johannes Berg
     [not found]   ` <200706241911.18201.david-b@pacbell.net>
2007-06-25 22:06     ` Rafael J. Wysocki
     [not found]   ` <1182806886.6644.4.camel@johannes.berg>
2007-06-26  8:55     ` Pavel Machek
2007-06-26  9:41     ` Rafael J. Wysocki
     [not found]     ` <200706261141.35071.rjw@sisk.pl>
2007-06-26 17:19       ` David Brownell
     [not found]       ` <200706261019.59712.david-b@pacbell.net>
2007-06-26 20:14         ` Rafael J. Wysocki
     [not found] ` <200706242244.51335.rjw@sisk.pl>
2007-06-25 21:30   ` [RFC/RFT][PATCH -mm 4/4] PM: Rework struct platform_suspend_operations Johannes Berg
2007-06-25 22:39 ` [RFC/RFT][PATCH -mm 0/8] PM: Rework struct pm_ops and related things (take 2) Rafael J. Wysocki
     [not found] ` <200706260039.17530.rjw@sisk.pl>
2007-06-25 22:41   ` [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
2007-06-25 22:43   ` [RFC/RFT][PATCH -mm 2/8] ACPI: Implement the set_target() callback from pm_ops Rafael J. Wysocki
2007-06-25 22:45   ` [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine Rafael J. Wysocki
2007-06-25 22:47   ` [RFC/RFT][PATCH -mm 4/8] PM: Move definition of struct pm_ops to suspend.h Rafael J. Wysocki
2007-06-25 22:48   ` [RFC/RFT][PATCH -mm 5/8] PM: Rename struct pm_ops and related things Rafael J. Wysocki
2007-06-25 22:49   ` [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations Rafael J. Wysocki
2007-06-25 22:51   ` [RFC/RFT][PATCH -mm 7/8] PM: Rework struct hibernation_ops Rafael J. Wysocki
2007-06-25 22:52   ` [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations Rafael J. Wysocki
     [not found]   ` <200706260049.40457.rjw@sisk.pl>
2007-06-26  8:52     ` [RFC/RFT][PATCH -mm 6/8] PM: Rework struct platform_suspend_operations Pavel Machek
     [not found]   ` <200706260052.28206.rjw@sisk.pl>
2007-06-26  8:54     ` [RFC/RFT][PATCH -mm 8/8] PM: Rename hibernation_ops to platform_hibernation_operations Pavel Machek
2007-06-27 15:19       ` Rafael J. Wysocki
     [not found]   ` <200706260045.51039.rjw@sisk.pl>
2007-06-26 10:00     ` [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine (updated) Rafael J. Wysocki
     [not found]     ` <200706261200.29421.rjw@sisk.pl>
2007-06-26 10:34       ` [RFC/RFT][PATCH -mm 3/8] ACPI: Add acpi_pm_device_sleep_state helper routine (updated 2x) Rafael J. Wysocki
     [not found]   ` <200706260041.20561.rjw@sisk.pl>
2007-06-27 20:27     ` [RFC/RFT][PATCH -mm 1/8][bugfix] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
2007-06-27 20:41     ` David Brownell
     [not found]     ` <200706271341.53599.david-b@pacbell.net>
2007-06-27 20:55       ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox