All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] powernv: Add OPAL soft-poweroff routine
@ 2015-01-30  6:43 Joel Stanley
  2015-02-09  9:39 ` Vasant Hegde
  2015-02-09 21:03 ` Stewart Smith
  0 siblings, 2 replies; 4+ messages in thread
From: Joel Stanley @ 2015-01-30  6:43 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: jk

Register a notifier for a OPAL message indicating that the machine
should prepare itself for a graceful power off.

OPAL will tell us if the power off is a reboot or shutdown, but for now
we perform the same orderly_poweroff action.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
v2:
  - combine the reboot and off cases, as they are the same code

 arch/powerpc/include/asm/opal.h             |  2 +-
 arch/powerpc/platforms/powernv/Makefile     |  2 +-
 arch/powerpc/platforms/powernv/opal-power.c | 66 +++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-power.c

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index ca2dd45..cdf32c0 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -250,7 +250,7 @@ enum OpalMessageType {
 					 */
 	OPAL_MSG_MEM_ERR,
 	OPAL_MSG_EPOW,
-	OPAL_MSG_SHUTDOWN,
+	OPAL_MSG_SHUTDOWN,		/* params[0] = 1 reboot, 0 shutdown */
 	OPAL_MSG_HMI_EVT,
 	OPAL_MSG_TYPE_MAX,
 };
diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile
index f241acc..6f3c5d3 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -1,7 +1,7 @@
 obj-y			+= setup.o opal-wrappers.o opal.o opal-async.o
 obj-y			+= opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
 obj-y			+= rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o
-obj-y			+= opal-msglog.o opal-hmi.o
+obj-y			+= opal-msglog.o opal-hmi.o opal-power.o
 
 obj-$(CONFIG_SMP)	+= smp.o subcore.o subcore-asm.o
 obj-$(CONFIG_PCI)	+= pci.o pci-p5ioc2.o pci-ioda.o
diff --git a/arch/powerpc/platforms/powernv/opal-power.c b/arch/powerpc/platforms/powernv/opal-power.c
new file mode 100644
index 0000000..bbc1054
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-power.c
@@ -0,0 +1,66 @@
+/*
+ * PowerNV OPAL power control for graceful shutdown handling
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/reboot.h>
+#include <linux/notifier.h>
+
+#include <asm/opal.h>
+#include <asm/machdep.h>
+
+#define SOFT_OFF 0x00
+#define SOFT_REBOOT 0x01
+
+static int opal_power_control_event(struct notifier_block *nb,
+				    unsigned long msg_type, void *msg)
+{
+	struct opal_msg *power_msg = msg;
+	uint64_t type;
+
+	type = be64_to_cpu(power_msg->params[0]);
+
+	switch (type) {
+	case SOFT_REBOOT:
+		/* Fall through. The service processor is responsible for
+		 * bringing the machine back up */
+	case SOFT_OFF:
+		pr_info("OPAL: poweroff requested\n");
+		orderly_poweroff(true);
+		break;
+	default:
+		pr_err("OPAL: power control type unexpected %016llx\n", type);
+	}
+
+	return 0;
+}
+
+static struct notifier_block opal_power_control_nb = {
+	.notifier_call	= opal_power_control_event,
+	.next		= NULL,
+	.priority	= 0,
+};
+
+static int __init opal_power_control_init(void)
+{
+	int ret;
+
+	ret = opal_message_notifier_register(OPAL_MSG_SHUTDOWN,
+					     &opal_power_control_nb);
+	if (ret) {
+		pr_err("%s: Can't register OPAL event notifier (%d)\n",
+				__func__, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+machine_subsys_initcall(powernv, opal_power_control_init);
-- 
2.1.4

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

* Re: [PATCH v2] powernv: Add OPAL soft-poweroff routine
  2015-01-30  6:43 [PATCH v2] powernv: Add OPAL soft-poweroff routine Joel Stanley
@ 2015-02-09  9:39 ` Vasant Hegde
  2015-02-11  2:14   ` Joel Stanley
  2015-02-09 21:03 ` Stewart Smith
  1 sibling, 1 reply; 4+ messages in thread
From: Vasant Hegde @ 2015-02-09  9:39 UTC (permalink / raw)
  To: Joel Stanley, linuxppc-dev; +Cc: jk

On 01/30/2015 12:13 PM, Joel Stanley wrote:
> Register a notifier for a OPAL message indicating that the machine
> should prepare itself for a graceful power off.
> 
> OPAL will tell us if the power off is a reboot or shutdown, but for now
> we perform the same orderly_poweroff action.
> 
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
> v2:
>   - combine the reboot and off cases, as they are the same code
> 
>  arch/powerpc/include/asm/opal.h             |  2 +-
>  arch/powerpc/platforms/powernv/Makefile     |  2 +-
>  arch/powerpc/platforms/powernv/opal-power.c | 66 +++++++++++++++++++++++++++++
>  3 files changed, 68 insertions(+), 2 deletions(-)
>  create mode 100644 arch/powerpc/platforms/powernv/opal-power.c
> 
> diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
> index ca2dd45..cdf32c0 100644
> --- a/arch/powerpc/include/asm/opal.h
> +++ b/arch/powerpc/include/asm/opal.h
> @@ -250,7 +250,7 @@ enum OpalMessageType {
>  					 */
>  	OPAL_MSG_MEM_ERR,
>  	OPAL_MSG_EPOW,
> -	OPAL_MSG_SHUTDOWN,
> +	OPAL_MSG_SHUTDOWN,		/* params[0] = 1 reboot, 0 shutdown */
>  	OPAL_MSG_HMI_EVT,
>  	OPAL_MSG_TYPE_MAX,
>  };
> diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile
> index f241acc..6f3c5d3 100644
> --- a/arch/powerpc/platforms/powernv/Makefile
> +++ b/arch/powerpc/platforms/powernv/Makefile
> @@ -1,7 +1,7 @@
>  obj-y			+= setup.o opal-wrappers.o opal.o opal-async.o
>  obj-y			+= opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
>  obj-y			+= rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o
> -obj-y			+= opal-msglog.o opal-hmi.o
> +obj-y			+= opal-msglog.o opal-hmi.o opal-power.o
>  
>  obj-$(CONFIG_SMP)	+= smp.o subcore.o subcore-asm.o
>  obj-$(CONFIG_PCI)	+= pci.o pci-p5ioc2.o pci-ioda.o
> diff --git a/arch/powerpc/platforms/powernv/opal-power.c b/arch/powerpc/platforms/powernv/opal-power.c
> new file mode 100644
> index 0000000..bbc1054
> --- /dev/null
> +++ b/arch/powerpc/platforms/powernv/opal-power.c
> @@ -0,0 +1,66 @@
> +/*
> + * PowerNV OPAL power control for graceful shutdown handling
> + *
> + * Copyright 2015 IBM Corp.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version
> + * 2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/reboot.h>
> +#include <linux/notifier.h>
> +
> +#include <asm/opal.h>
> +#include <asm/machdep.h>
> +
> +#define SOFT_OFF 0x00
> +#define SOFT_REBOOT 0x01

Better move these macros to opal.h as its coming from OPAL API?
Also I think its to merge this code and Anshumans' EPOW driver and create single
event file.

-Vasant

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

* Re: [PATCH v2] powernv: Add OPAL soft-poweroff routine
  2015-01-30  6:43 [PATCH v2] powernv: Add OPAL soft-poweroff routine Joel Stanley
  2015-02-09  9:39 ` Vasant Hegde
@ 2015-02-09 21:03 ` Stewart Smith
  1 sibling, 0 replies; 4+ messages in thread
From: Stewart Smith @ 2015-02-09 21:03 UTC (permalink / raw)
  To: Joel Stanley, linuxppc-dev; +Cc: jk

Joel Stanley <joel@jms.id.au> writes:
> Register a notifier for a OPAL message indicating that the machine
> should prepare itself for a graceful power off.
>
> OPAL will tell us if the power off is a reboot or shutdown, but for now
> we perform the same orderly_poweroff action.
>
> Signed-off-by: Joel Stanley <joel@jms.id.au>

I merged the firmware side of things, this looks like it implements what
firmware exports.

Acked-by: Stewart Smith <stewart@linux.vnet.ibm.com>

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

* Re: [PATCH v2] powernv: Add OPAL soft-poweroff routine
  2015-02-09  9:39 ` Vasant Hegde
@ 2015-02-11  2:14   ` Joel Stanley
  0 siblings, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2015-02-11  2:14 UTC (permalink / raw)
  To: Vasant Hegde; +Cc: linuxppc-dev, Jeremy Kerr

On Mon, Feb 9, 2015 at 8:09 PM, Vasant Hegde
<hegdevasant@linux.vnet.ibm.com> wrote:
>> +
>> +#define SOFT_OFF 0x00
>> +#define SOFT_REBOOT 0x01
>
> Better move these macros to opal.h as its coming from OPAL API?

Okay. Mpe has already merged this, so I'll send a follow up.

> Also I think its to merge this code and Anshumans' EPOW driver and create single
> event file.

Agreed, there is consensus that there should be one path for power off
in powernv. I will keep chatting to the guys working on the EPOW
patch.

Cheers,

Joel

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

end of thread, other threads:[~2015-02-11  2:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30  6:43 [PATCH v2] powernv: Add OPAL soft-poweroff routine Joel Stanley
2015-02-09  9:39 ` Vasant Hegde
2015-02-11  2:14   ` Joel Stanley
2015-02-09 21:03 ` Stewart Smith

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.