All of lore.kernel.org
 help / color / mirror / Atom feed
From: lorenzo.pieralisi@arm.com (Lorenzo Pieralisi)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] drivers: firmware: psci: add system suspend support
Date: Wed, 17 Jun 2015 16:08:04 +0100	[thread overview]
Message-ID: <20150617150804.GE27017@red-moon> (raw)
In-Reply-To: <1434462640-19613-3-git-send-email-sudeep.holla@arm.com>

On Tue, Jun 16, 2015 at 02:50:40PM +0100, Sudeep Holla wrote:
> PSCI v1.0 introduces a new API called PSCI_SYSTEM_SUSPEND. This API
> provides the mechanism by which the calling OS can request entry into
> the deepest possible system sleep state.
> 
> It meets all the necessary preconditions for entrying suspend to RAM

s/entrying/entering/

> state in Linux. This patch adds support for PSCI_SYSTEM_SUSPEND in psci
> firmware and registers a psci system suspend operation to implement the
> suspend-to-RAM(s2r) in a generic way on all the platforms implementing
> PSCI.
> 
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/firmware/psci.c   | 39 +++++++++++++++++++++++++++++++++++++++
>  include/uapi/linux/psci.h |  2 ++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c
> index 68d0c2f6d004..4f0359516119 100644
> --- a/drivers/firmware/psci.c
> +++ b/drivers/firmware/psci.c
> @@ -20,11 +20,13 @@
>  #include <linux/printk.h>
>  #include <linux/psci.h>
>  #include <linux/reboot.h>
> +#include <linux/suspend.h>
>  
>  #include <uapi/linux/psci.h>
>  
>  #include <asm/system_misc.h>
>  #include <asm/smp_plat.h>
> +#include <asm/suspend.h>
>  
>  /*
>   * While a 64-bit OS can make calls with SMC32 calling conventions, for some
> @@ -222,6 +224,41 @@ static int __init psci_features(u32 psci_func_id)
>  			      psci_func_id, 0, 0);
>  }
>  
> +static int psci_system_suspend(unsigned long entry_point)
> +{
> +	return invoke_psci_fn(PSCI_0_2_FN_NATIVE(SYSTEM_SUSPEND),
> +			      entry_point, 0, 0);
> +}
> +
> +static int psci_system_suspend_finisher(unsigned long unused)
> +{
> +	return psci_system_suspend(virt_to_phys(cpu_resume));

Do we really need another level of indirection ? I would invoke
the PSCI function from here.

> +}
> +
> +static int psci_system_suspend_enter(suspend_state_t state)
> +{
> +	if (state != PM_SUSPEND_MEM)
> +		return 0;

suspend_valid_only_mem should check this, am I missing something ?

You should not return 0 on failure anyway.

> +
> +	return cpu_suspend(0, psci_system_suspend_finisher);
> +}
> +
> +static const struct platform_suspend_ops psci_suspend_ops = {
> +	.valid          = suspend_valid_only_mem,
> +	.enter          = psci_system_suspend_enter,
> +};
> +
> +static void __init psci_init_system_suspend(void)
> +{
> +	if (!IS_ENABLED(CONFIG_SUSPEND))
> +		return;
> +
> +	if (psci_features(PSCI_0_2_FN_NATIVE(SYSTEM_SUSPEND)))

Nit: I think we should use a 1_0 tag here for SYSTEM_SUSPEND.

> +		return;
> +
> +	suspend_set_ops(&psci_suspend_ops);
> +}
> +
>  static void __init psci_init_cpu_suspend(void)
>  {
>  	int feature = psci_features(psci_function_id[PSCI_FN_CPU_SUSPEND]);
> @@ -310,6 +347,8 @@ static int __init psci_probe(void)
>  
>  	psci_init_cpu_suspend();
>  
> +	psci_init_system_suspend();
> +
>  	return 0;
>  }
>  
> diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h
> index 2598d7c9bf20..62b054524819 100644
> --- a/include/uapi/linux/psci.h
> +++ b/include/uapi/linux/psci.h
> @@ -39,12 +39,14 @@
>  #define PSCI_0_2_FN_MIGRATE_INFO_UP_CPU		PSCI_0_2_FN(7)
>  #define PSCI_0_2_FN_SYSTEM_OFF			PSCI_0_2_FN(8)
>  #define PSCI_0_2_FN_SYSTEM_RESET		PSCI_0_2_FN(9)
> +#define PSCI_0_2_FN_SYSTEM_SUSPEND		PSCI_0_2_FN(14)

I think you should keep versioning consistent, namely SYSTEM_SUSPEND
is a 1.0 only feature and the tag should reflect that.

>  #define PSCI_0_2_FN64_CPU_SUSPEND		PSCI_0_2_FN64(1)
>  #define PSCI_0_2_FN64_CPU_ON			PSCI_0_2_FN64(3)
>  #define PSCI_0_2_FN64_AFFINITY_INFO		PSCI_0_2_FN64(4)
>  #define PSCI_0_2_FN64_MIGRATE			PSCI_0_2_FN64(5)
>  #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU	PSCI_0_2_FN64(7)
> +#define PSCI_0_2_FN64_SYSTEM_SUSPEND		PSCI_0_2_FN64(14)

Ditto.

Thanks,
Lorenzo

>  
>  #define PSCI_1_0_FN_PSCI_FEATURES		PSCI_0_2_FN(10)
>  
> -- 
> 1.9.1
> 

  reply	other threads:[~2015-06-17 15:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16 13:50 [PATCH 0/2] PSCI: system suspend support Sudeep Holla
2015-06-16 13:50 ` [PATCH 1/2] arm64: kernel: rename __cpu_suspend to keep it aligned with arm Sudeep Holla
2015-06-17 13:57   ` Lorenzo Pieralisi
2015-06-16 13:50 ` [PATCH 2/2] drivers: firmware: psci: add system suspend support Sudeep Holla
2015-06-17 15:08   ` Lorenzo Pieralisi [this message]
2015-06-17 15:41     ` Sudeep Holla
2015-06-18 14:41 ` [PATCH v2 0/3] PSCI: " Sudeep Holla
2015-06-18 14:41   ` [PATCH v2 1/3] arm64: kernel: rename __cpu_suspend to keep it aligned with arm Sudeep Holla
2015-06-18 14:55     ` Catalin Marinas
2015-06-18 15:08       ` Sudeep Holla
2015-06-19 13:50         ` Catalin Marinas
2015-06-18 14:41   ` [PATCH v2 2/3] drivers: firmware: psci: define more generic PSCI_FN_NATIVE macro Sudeep Holla
2015-09-14 13:17     ` Lorenzo Pieralisi
2015-09-14 13:21       ` Sudeep Holla
2015-06-18 14:41   ` [PATCH v2 3/3] drivers: firmware: psci: add system suspend support Sudeep Holla
2015-07-14  6:17     ` Jisheng Zhang
2015-07-14  9:14       ` Sudeep Holla
2015-07-14  9:50         ` Jisheng Zhang
2015-07-14 11:02           ` Sudeep Holla
2015-07-14 11:40             ` Jisheng Zhang
2015-07-14 13:18               ` Sudeep Holla
2015-07-15  2:34                 ` Jisheng Zhang
2015-07-15 10:20                   ` Sudeep Holla
2015-09-14 13:23     ` Lorenzo Pieralisi
2015-09-14 13:32       ` Sudeep Holla
2015-06-18 18:13   ` [PATCH v2 0/3] PSCI: " Ashwin Chaugule

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=20150617150804.GE27017@red-moon \
    --to=lorenzo.pieralisi@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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.