[PATCH] powerpc: add ibm,suspend-me rtas interface

Dave C Boutcher sleddog at us.ibm.com
Wed Jan 11 20:56:33 EST 2006


Create a proc file that lets us call the ibm,suspend-me
RTAS call.  This call has to be wrapped in some hypervisor
calls that synchronize all the CPUs, so it can't be done
from userland.

This depends on a prior patch to add additional hypervisor
call constants.

Signed-off-by: Dave Boutcher <sleddog at us.ibm.com>

 arch/powerpc/platforms/pseries/Makefile   |    2 
 arch/powerpc/platforms/pseries/sysstate.c |  157 ++++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletion(-)

diff -uNr -X exclude-files linux-2.6.15/arch/powerpc/platforms/pseries/Makefile linux-2.6.15-vpm/arch/powerpc/platforms/pseries/Makefile
--- linux-2.6.15/arch/powerpc/platforms/pseries/Makefile	2006-01-02 21:21:10.000000000 -0600
+++ linux-2.6.15-vpm/arch/powerpc/platforms/pseries/Makefile	2006-01-10 14:32:56.000000000 -0600
@@ -1,5 +1,5 @@
 obj-y			:= pci.o lpar.o hvCall.o nvram.o reconfig.o \
-			   setup.o iommu.o ras.o rtasd.o
+			   setup.o iommu.o ras.o rtasd.o sysstate.o
 obj-$(CONFIG_SMP)	+= smp.o
 obj-$(CONFIG_IBMVIO)	+= vio.o
 obj-$(CONFIG_XICS)	+= xics.o
diff -uNr -X exclude-files linux-2.6.15/arch/powerpc/platforms/pseries/sysstate.c linux-2.6.15-vpm/arch/powerpc/platforms/pseries/sysstate.c
--- linux-2.6.15/arch/powerpc/platforms/pseries/sysstate.c	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.15-vpm/arch/powerpc/platforms/pseries/sysstate.c	2006-01-11 02:17:22.000000000 -0600
@@ -0,0 +1,157 @@
+/*
+ * arch/ppc64/sys-state.c - Logical Partition State
+ *
+ * Copyright (c) 2005 Dave Boutcher
+ * 
+ * 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.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ ***************************************************************************
+ * This file handles the pSeries firmware supported "ibm,suspend-me" RTAS
+ * call.  It can't be done from userland, since all of the CPUs must be first
+ * synchronized using the H_JOIN hypervisor call prior to making the 
+ * ibm,suspend-me RTAS call.
+ ***************************************************************************
+ */
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/proc_fs.h>
+#include <asm/uaccess.h>
+
+#include <asm/rtas.h>
+
+static int suspend_me_tok = -1;
+
+/*
+ * We use "waiting" to indicate our state.  As long 
+ * as it is >0, we are still trying to all join up.
+ * If it goes to 0, we have successfully joined up and
+ * one thread got H_Continue.  If any error happens,
+ * we set it to <0;
+ */
+static void cpu_suspend(void *info) 
+{
+	long rc;
+	long flags;
+	long *waiting = (long *)info;
+	int status;
+
+	local_irq_save(flags);
+	do {
+	    rc = plpar_hcall_norets(H_JOIN);
+	    mb();
+	} while ((rc == H_Success) && (*waiting > 0));
+	if (rc == H_Success) 
+	    goto out;
+
+	if (rc == H_Continue) {
+		*waiting = 0;
+		if (suspend_me_tok != RTAS_UNKNOWN_SERVICE) {
+			status = rtas_call(suspend_me_tok, 0, 1, NULL);
+			if (status != 0) 
+				printk(KERN_ERR
+				       "RTAS ibm,suspend-me failed: %i\n", 
+				       status);
+		}
+	} else {
+		*waiting = -EBUSY;
+		printk(KERN_ERR "Error on H_Join hypervisor call\n");
+	}
+
+ out:
+	local_irq_restore(flags);
+	return;
+}
+
+static int do_suspend(void)
+{
+	int i;
+	long waiting = 1;
+	
+	smp_rmb();
+	
+	/* Call function on all other CPUs */
+	if (on_each_cpu(cpu_suspend, 
+			&waiting,
+			1, 0)) {
+		printk(KERN_ERR "Error calling on_each_cpu!\n");
+		/* TODO: Prod everyone here */
+		return -EINVAL;
+	} 
+	
+	if (waiting != 0) {
+		printk(KERN_ERR "Error doing global join!\n");
+	}
+	
+	/* Prod each CPU.  This won't hurt, and will wake
+	 * anyone we successfully put to sleep with H_Join
+	 */
+	for_each_cpu(i) 
+			plpar_hcall_norets(H_PROD,i);
+
+	return 0;
+}
+
+static int read_proc(char *page, char **start, off_t off,
+		     int count, int *eof, void *data)
+{
+	int len;
+
+	len = sprintf(page, "%d\n", 
+		      0);
+
+	return len;
+}
+
+static int write_proc(struct file *file, const char __user *buffer,
+		      unsigned long count, void *data)
+{
+	char command[32];
+
+	if (count > sizeof(command))
+		count = sizeof(command);
+
+	if (copy_from_user(command, buffer, count))
+		return -EFAULT;
+
+	if (strncmp(command, "suspend", sizeof(command)) == 0) {
+		do_suspend();
+	}
+	return count;
+}
+
+static int __init sys_state_init(void)
+{
+	struct proc_dir_entry *entry;
+	suspend_me_tok = rtas_token("ibm,suspend-me");
+	if (suspend_me_tok == RTAS_UNKNOWN_SERVICE) 
+		return 0;
+
+	entry =	create_proc_entry("ppc64/rtas/platform_state", S_IWUSR, NULL);
+	if (!entry) {
+		printk(KERN_ERR "Failed to create platform_state proc entry\n");
+		return 0;
+	}
+
+	entry->read_proc = read_proc;
+	entry->write_proc = write_proc;
+
+	return 0;
+}
+
+arch_initcall(sys_state_init);

-- 
Dave Boutcher



More information about the Linuxppc64-dev mailing list