Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1673156 > unrolled thread
| Started by | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| First post | 2017-06-23 03:10 +0200 |
| Last post | 2017-06-30 01:10 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RFC 1/2] PM / suspend: Add platform_suspend_target_state() Florian Fainelli <f.fainelli@gmail.com> - 2017-06-23 03:10 +0200
Re: [RFC 1/2] PM / suspend: Add platform_suspend_target_state() "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-06-30 01:10 +0200
| From | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| Date | 2017-06-23 03:10 +0200 |
| Subject | [RFC 1/2] PM / suspend: Add platform_suspend_target_state() |
| Message-ID | <tVlgK-3S1-7@gated-at.bofh.it> |
Add an optional platform_suspend_ops callback: target_state, and a
helper function globally visible to get this called:
platform_suspend_target_state().
This is useful for platform specific drivers that may need to take a
slightly different suspend/resume path based on the system's
suspend/resume state being entered.
Although this callback is optional and documented as such, it requires
a platform_suspend_ops::begin callback to be implemented in order to
provide an accurate suspend/resume state within the driver that
implements this platform_suspend_ops.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
include/linux/suspend.h | 12 ++++++++++++
kernel/power/suspend.c | 15 +++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index d9718378a8be..d998a04a90a2 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -172,6 +172,15 @@ static inline void dpm_save_failed_step(enum suspend_stat_step step)
* Called by the PM core if the suspending of devices fails.
* This callback is optional and should only be implemented by platforms
* which require special recovery actions in that situation.
+ *
+ * @target_state: Returns the suspend state the suspend_ops will be entering.
+ * Called by device drivers that need to know the platform specific suspend
+ * state the system is about to enter.
+ * This callback is optional and should only be implemented by platforms
+ * which require special handling of power management states within
+ * drivers. It does require @begin to be implemented to provide the suspend
+ * state. Return value is platform_suspend_ops specific, and may be a 1:1
+ * mapping to suspend_state_t when relevant.
*/
struct platform_suspend_ops {
int (*valid)(suspend_state_t state);
@@ -184,6 +193,7 @@ struct platform_suspend_ops {
bool (*suspend_again)(void);
void (*end)(void);
void (*recover)(void);
+ int (*target_state)(void);
};
struct platform_freeze_ops {
@@ -200,6 +210,7 @@ struct platform_freeze_ops {
*/
extern void suspend_set_ops(const struct platform_suspend_ops *ops);
extern int suspend_valid_only_mem(suspend_state_t state);
+extern int platform_suspend_target_state(void);
extern unsigned int pm_suspend_global_flags;
@@ -279,6 +290,7 @@ static inline bool pm_resume_via_firmware(void) { return false; }
static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
+static inline int platform_suspend_target_state(void) { return -ENOSYS; }
static inline bool idle_should_freeze(void) { return false; }
static inline void __init pm_states_init(void) {}
static inline void freeze_set_ops(const struct platform_freeze_ops *ops) {}
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 15e6baef5c73..d31fe7a08f4a 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -177,6 +177,21 @@ void suspend_set_ops(const struct platform_suspend_ops *ops)
EXPORT_SYMBOL_GPL(suspend_set_ops);
/**
+ * platform_suspend_target_state - Return the platform specific suspend state.
+ * a begin() callback is necessary in order to fill this information correctly
+ * for callers.
+ */
+int platform_suspend_target_state(void)
+{
+ if (!suspend_ops || !suspend_ops->target_state ||
+ (suspend_ops->target_state && !suspend_ops->begin))
+ return -ENOTSUPP;
+
+ return suspend_ops->target_state();
+}
+EXPORT_SYMBOL_GPL(platform_suspend_target_state);
+
+/**
* suspend_valid_only_mem - Generic memory-only valid callback.
*
* Platform drivers that implement mem suspend only and only need to check for
--
2.9.3
[toc] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rjw@rjwysocki.net> |
|---|---|
| Date | 2017-06-30 01:10 +0200 |
| Message-ID | <tXQJr-5OH-9@gated-at.bofh.it> |
| In reply to | #1673156 |
On Thursday, June 22, 2017 06:08:36 PM Florian Fainelli wrote:
> Add an optional platform_suspend_ops callback: target_state, and a
> helper function globally visible to get this called:
> platform_suspend_target_state().
>
> This is useful for platform specific drivers that may need to take a
> slightly different suspend/resume path based on the system's
> suspend/resume state being entered.
>
> Although this callback is optional and documented as such, it requires
> a platform_suspend_ops::begin callback to be implemented in order to
> provide an accurate suspend/resume state within the driver that
> implements this platform_suspend_ops.
>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
> include/linux/suspend.h | 12 ++++++++++++
> kernel/power/suspend.c | 15 +++++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index d9718378a8be..d998a04a90a2 100644
> --- a/include/linux/suspend.h
> +++ b/include/linux/suspend.h
> @@ -172,6 +172,15 @@ static inline void dpm_save_failed_step(enum suspend_stat_step step)
> * Called by the PM core if the suspending of devices fails.
> * This callback is optional and should only be implemented by platforms
> * which require special recovery actions in that situation.
> + *
> + * @target_state: Returns the suspend state the suspend_ops will be entering.
> + * Called by device drivers that need to know the platform specific suspend
> + * state the system is about to enter.
> + * This callback is optional and should only be implemented by platforms
> + * which require special handling of power management states within
> + * drivers. It does require @begin to be implemented to provide the suspend
> + * state. Return value is platform_suspend_ops specific, and may be a 1:1
> + * mapping to suspend_state_t when relevant.
> */
> struct platform_suspend_ops {
> int (*valid)(suspend_state_t state);
> @@ -184,6 +193,7 @@ struct platform_suspend_ops {
> bool (*suspend_again)(void);
> void (*end)(void);
> void (*recover)(void);
> + int (*target_state)(void);
I would use unsigned int (the sign should not matter).
> };
That's almost what I was thinking about except that the values returned by
->target_state should be unique, so it would be good to do something to
ensure that.
The concern is as follows.
Say you have a driver develped for platform X where ->target_state returns
A for "mem" and B for "standby". Then, the same IP is re-used on platform Y
returning B for "mem" and C for "standby" and now the driver cannot
distinguish between them.
Moreover, even if they both returned A for "mem" there might be differences
in how "mem" was defined by each of them and therefore in what the driver was
expected to do to handle "mem" on X and Y.
Thanks,
Rafael
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web