From patchwork Fri Jan 30 00:27:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 434689 X-Patchwork-Delegate: michael@ellerman.id.au Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5E59F1402B1 for ; Fri, 30 Jan 2015 11:28:49 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 335881A0F42 for ; Fri, 30 Jan 2015 11:28:49 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x234.google.com (mail-pa0-x234.google.com [IPv6:2607:f8b0:400e:c03::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 046DF1A0CED for ; Fri, 30 Jan 2015 11:28:12 +1100 (AEDT) Received: by mail-pa0-f52.google.com with SMTP id kx10so44975465pab.11 for ; Thu, 29 Jan 2015 16:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=from:to:cc:subject:date:message-id; bh=EbWviDykFpxuMew9ouBKLPuPflCkOQJIb8WF1Q2hzcI=; b=X/2uREXDPp3j7sQyMqvk4yKUHj70goUtj4pi4gZgqbPRY1zTK8o+RIpjwDH25u1xxT dPFzZcTYQv7/eysHeMw9JmsVtJc53lhPQ3yMrH7VQmjdSiCSXEltel5iHq/PsEjhCiIb MCMHsFIIb0KsUHP9O5o2cOw38hhiQQdPWzF8k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EbWviDykFpxuMew9ouBKLPuPflCkOQJIb8WF1Q2hzcI=; b=WoQ7OynUsL0DFTJf6pKp8whryHtwD+ycrnw1L5MrmujOc4RLzn0de0McNKF75HQOMK iPu4X90Kk+uSo6yRvr4SncI2juWZt4zvlgvBBnQMHJXwE7qPLn4/x2KsCMXo4eZ+Vpis ZD9NgwtHhrlwh3LWGDOJrongE0DkmZrsna4iLOIx7HS/RM8zbUcHqChgg0qbbO3T8St7 hE5lAjVq+9PiRcbbmkGdRyVxBW9os/AnKdqwCr17MlIheknr23+6QNhG8k9dexn/sTKl PcGOgLBE8N5dFClqj351YyDp5EhTRCyHBA9nKJ6Gj/UW5NE496exZT3uE9xroo7Tm+Vu qmgQ== X-Gm-Message-State: ALoCoQmgEStvkXj8hADg7O6CQ/C3zoQKHZO3lZ0QmTl1o7hu6ZB14Y9qIzadJLKS7UCQ8i5jzCiC X-Received: by 10.70.55.136 with SMTP id s8mr4807673pdp.96.1422577689615; Thu, 29 Jan 2015 16:28:09 -0800 (PST) Received: from icarus.au.ibm.com (ppp121-45-7-169.lns20.adl2.internode.on.net. [121.45.7.169]) by mx.google.com with ESMTPSA id th8sm8888750pbc.38.2015.01.29.16.28.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 16:28:08 -0800 (PST) From: Joel Stanley To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powernv: Add OPAL soft-poweroff routine Date: Fri, 30 Jan 2015 10:57:58 +1030 Message-Id: <1422577678-17831-1-git-send-email-joel@jms.id.au> X-Mailer: git-send-email 2.1.4 Cc: jk@ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 --- arch/powerpc/include/asm/opal.h | 2 +- arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/opal-power.c | 68 +++++++++++++++++++++++++++++ 3 files changed, 70 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..c047d7e --- /dev/null +++ b/arch/powerpc/platforms/powernv/opal-power.c @@ -0,0 +1,68 @@ +/* + * 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 +#include +#include + +#include +#include + +#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_OFF: + pr_info("OPAL: poweroff requested\n"); + orderly_poweroff(true); + break; + case SOFT_REBOOT: + pr_info("OPAL: reboot requested\n"); + /* TODO: shutdown such that userspace knows it's rebooting */ + 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);