All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	linux-pm <linux-pm@vger.kernel.org>,
	Thibaud Cornic <thibaud_cornic@sigmadesigns.com>,
	JB <jb_lescher@sigmadesigns.com>, Mason <slash.tmp@free.fr>,
	Kevin Hilman <khilman@kernel.org>, Pavel Machek <pavel@ucw.cz>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFC 1/2] PM / suspend: Add platform_suspend_target_state()
Date: Sat, 15 Jul 2017 00:16:16 +0200	[thread overview]
Message-ID: <2497538.J9F6XFeBfd@aspire.rjw.lan> (raw)
In-Reply-To: <85441336-8d89-f7aa-4fbe-a4edaf478649@gmail.com>

On Wednesday, July 12, 2017 11:08:19 AM Florian Fainelli wrote:
> On 06/29/2017 04:00 PM, Rafael J. Wysocki wrote:
> > 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.
> 
> That makes sense, would you need the core implementation in
> platform_suspend_target_state() to range check what
> suspend_ops->target_state() returns against a set of reserved value say,
> checking from 0 up to ACPI_S_STATE_COUNT or is there another range you
> would like to see being used?

I had an idea of using an enum type encompassing all of the power states
defined for various platforms and serving both as a registry (to ensure the
uniqueness of the values assigned to the states) and a common ground
between platforms and drivers.

Something like:

enum platform_target_state {
	PLATFORM_STATE_UNKNOWN = -1,
	PLATFORM_STATE_WORKING = 0,
	PLATFORM_STATE_ACPI_S1,
	PLATFORM_STATE_ACPI_S2,
	PLATFORM_STATE_ACPI_S3,
	PLATFORM_STATE_MY_BOARD_1_GATE_CLOCKS,
	PLATFORM_STATE_MY_BOARD_1_GATE_POWER,
	PLATFORM_STATE_ANOTHER_BOARD_DO_CRAZY_STUFF,
	...
};

and define ->target_state to return a value of this type.

Then, if a driver sees one of these and recognizes that value, it should
know exactly what to do.

Thanks,
Rafael

WARNING: multiple messages have this Message-ID (diff)
From: rjw@rjwysocki.net (Rafael J. Wysocki)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 1/2] PM / suspend: Add platform_suspend_target_state()
Date: Sat, 15 Jul 2017 00:16:16 +0200	[thread overview]
Message-ID: <2497538.J9F6XFeBfd@aspire.rjw.lan> (raw)
In-Reply-To: <85441336-8d89-f7aa-4fbe-a4edaf478649@gmail.com>

On Wednesday, July 12, 2017 11:08:19 AM Florian Fainelli wrote:
> On 06/29/2017 04:00 PM, Rafael J. Wysocki wrote:
> > 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.
> 
> That makes sense, would you need the core implementation in
> platform_suspend_target_state() to range check what
> suspend_ops->target_state() returns against a set of reserved value say,
> checking from 0 up to ACPI_S_STATE_COUNT or is there another range you
> would like to see being used?

I had an idea of using an enum type encompassing all of the power states
defined for various platforms and serving both as a registry (to ensure the
uniqueness of the values assigned to the states) and a common ground
between platforms and drivers.

Something like:

enum platform_target_state {
	PLATFORM_STATE_UNKNOWN = -1,
	PLATFORM_STATE_WORKING = 0,
	PLATFORM_STATE_ACPI_S1,
	PLATFORM_STATE_ACPI_S2,
	PLATFORM_STATE_ACPI_S3,
	PLATFORM_STATE_MY_BOARD_1_GATE_CLOCKS,
	PLATFORM_STATE_MY_BOARD_1_GATE_POWER,
	PLATFORM_STATE_ANOTHER_BOARD_DO_CRAZY_STUFF,
	...
};

and define ->target_state to return a value of this type.

Then, if a driver sees one of these and recognizes that value, it should
know exactly what to do.

Thanks,
Rafael

  reply	other threads:[~2017-07-14 22:24 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-09 15:20 Drivers taking different actions depending on sleep state Mason
2017-06-09 15:20 ` Mason
2017-06-09 16:27 ` Mason
2017-06-09 16:27   ` Mason
2017-06-09 21:30   ` Pavel Machek
2017-06-09 21:30     ` Pavel Machek
2017-06-10  9:16     ` Mason
2017-06-10  9:16       ` Mason
2017-06-09 22:05 ` Florian Fainelli
2017-06-09 22:05   ` Florian Fainelli
2017-06-09 22:53 ` Rafael J. Wysocki
2017-06-09 22:53   ` Rafael J. Wysocki
2017-06-21 21:16   ` Florian Fainelli
2017-06-21 21:16     ` Florian Fainelli
2017-06-21 21:59     ` Rafael J. Wysocki
2017-06-21 21:59       ` Rafael J. Wysocki
2017-06-21 22:48       ` Florian Fainelli
2017-06-21 22:48         ` Florian Fainelli
2017-06-21 22:57         ` Rafael J. Wysocki
2017-06-21 22:57           ` Rafael J. Wysocki
2017-06-21 23:55           ` Florian Fainelli
2017-06-21 23:55             ` Florian Fainelli
2017-06-22  0:03             ` Rafael J. Wysocki
2017-06-22  0:03               ` Rafael J. Wysocki
2017-06-22 15:18               ` Florian Fainelli
2017-06-22 15:18                 ` Florian Fainelli
2017-06-22 16:09                 ` Rafael J. Wysocki
2017-06-22 16:09                   ` Rafael J. Wysocki
2017-06-22  8:51             ` Alexandre Belloni
2017-06-22  8:51               ` Alexandre Belloni
2017-06-22 16:00               ` Rafael J. Wysocki
2017-06-22 16:00                 ` Rafael J. Wysocki
2017-06-23  1:08               ` [RFC 0/2] PM / suspend: Add platform_suspend_target_state() Florian Fainelli
2017-06-23  1:08                 ` Florian Fainelli
2017-06-23  1:08                 ` [RFC 1/2] " Florian Fainelli
2017-06-23  1:08                   ` Florian Fainelli
2017-06-29 23:00                   ` Rafael J. Wysocki
2017-06-29 23:00                     ` Rafael J. Wysocki
2017-07-12 18:08                     ` Florian Fainelli
2017-07-12 18:08                       ` Florian Fainelli
2017-07-14 22:16                       ` Rafael J. Wysocki [this message]
2017-07-14 22:16                         ` Rafael J. Wysocki
2017-07-15  6:28                         ` Pavel Machek
2017-07-15  6:28                           ` Pavel Machek
2017-07-15 12:17                           ` Rafael J. Wysocki
2017-07-15 12:17                             ` Rafael J. Wysocki
2017-07-15 16:46                             ` Pavel Machek
2017-07-15 16:46                               ` Pavel Machek
2017-07-15 17:20                               ` Florian Fainelli
2017-07-15 17:20                                 ` Florian Fainelli
2017-07-15 18:33                                 ` Alexandre Belloni
2017-07-15 18:33                                   ` Alexandre Belloni
2017-07-06  3:18                                   ` Pavel Machek
2017-07-06  3:18                                     ` Pavel Machek
2017-07-16 13:41                                     ` Alexandre Belloni
2017-07-16 13:41                                       ` Alexandre Belloni
2017-07-16 15:35                                       ` Florian Fainelli
2017-07-16 15:35                                         ` Florian Fainelli
2017-07-15 23:24                                 ` Rafael J. Wysocki
2017-07-15 23:24                                   ` Rafael J. Wysocki
2017-07-15 23:34                                   ` Mason
2017-07-15 23:34                                     ` Mason
2017-07-15 23:38                                     ` Rafael J. Wysocki
2017-07-15 23:38                                       ` Rafael J. Wysocki
2017-07-16  2:36                                       ` Florian Fainelli
2017-07-16  2:36                                         ` Florian Fainelli
2017-07-16 10:22                                         ` Rafael J. Wysocki
2017-07-16 10:22                                           ` Rafael J. Wysocki
2017-07-16 13:38                                           ` Alexandre Belloni
2017-07-16 13:38                                             ` Alexandre Belloni
2017-07-16 18:24                                             ` Pavel Machek
2017-07-16 18:24                                               ` Pavel Machek
2017-07-16 15:41                                           ` Florian Fainelli
2017-07-16 15:41                                             ` Florian Fainelli
2017-07-15 23:29                               ` Rafael J. Wysocki
2017-07-15 23:29                                 ` Rafael J. Wysocki
2017-07-06  3:17                                 ` Pavel Machek
2017-07-06  3:17                                   ` Pavel Machek
2017-07-16 10:28                                   ` Rafael J. Wysocki
2017-07-16 10:28                                     ` Rafael J. Wysocki
2017-07-16 18:22                                     ` Pavel Machek
2017-07-16 18:22                                       ` Pavel Machek
2017-06-23  1:08                 ` [RFC 2/2] soc: bcm: brcmstb: PM: Implement target_state callback Florian Fainelli
2017-06-23  1:08                   ` Florian Fainelli
2017-06-29 23:04                   ` Rafael J. Wysocki
2017-06-29 23:04                     ` Rafael J. Wysocki
2017-07-16  2:36                 ` [PATCH 0/2] PM / suspend: Add platform_suspend_target_state() Florian Fainelli
2017-07-16  2:36                   ` Florian Fainelli
2017-07-16  2:36                   ` [PATCH 1/2] " Florian Fainelli
2017-07-16  2:36                     ` Florian Fainelli
2017-07-06  3:18                     ` Pavel Machek
2017-07-06  3:18                       ` Pavel Machek
2017-07-16 15:41                       ` Florian Fainelli
2017-07-16 15:41                         ` Florian Fainelli
2017-07-16 10:30                     ` Rafael J. Wysocki
2017-07-16 10:30                       ` Rafael J. Wysocki
2017-07-16  2:36                   ` [PATCH 2/2] soc: bcm: brcmstb: PM: Implement target_state callback Florian Fainelli
2017-07-16  2:36                     ` Florian Fainelli
2017-07-17 20:06                   ` [PATCH v2] PM / suspend: Add suspend_target_state() Florian Fainelli
2017-07-17 20:06                     ` Florian Fainelli
2017-07-17 20:16                     ` Pavel Machek
2017-07-17 20:16                       ` Pavel Machek
2017-07-17 21:03                       ` Rafael J. Wysocki
2017-07-17 21:03                         ` Rafael J. Wysocki
2017-07-17 21:21                         ` Florian Fainelli
2017-07-17 21:21                           ` Florian Fainelli
2017-07-20  8:03                     ` Pavel Machek
2017-07-20  8:03                       ` Pavel Machek
2017-07-17 22:10                   ` [PATCH v3] PM / suspend: Export pm_suspend_target_state Florian Fainelli
2017-07-17 22:10                     ` Florian Fainelli
2017-07-17 23:24                     ` Rafael J. Wysocki
2017-07-17 23:24                       ` Rafael J. Wysocki
2017-07-18  0:19                     ` [PATCH v4] " Florian Fainelli
2017-07-18  0:19                       ` Florian Fainelli
2017-07-24 20:55                       ` Rafael J. Wysocki
2017-07-24 20:55                         ` Rafael J. Wysocki
2017-07-13 12:03               ` Drivers taking different actions depending on sleep state Pavel Machek
2017-07-13 12:03                 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2497538.J9F6XFeBfd@aspire.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=f.fainelli@gmail.com \
    --cc=jb_lescher@sigmadesigns.com \
    --cc=khilman@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=slash.tmp@free.fr \
    --cc=thibaud_cornic@sigmadesigns.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.