[PATCH 2/6] powerpc: powerpc.git version of sysstate interface
Dave C Boutcher
sleddog at us.ibm.com
Fri Jan 13 09:06:20 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 powerpc.git.patched2/arch/powerpc/platforms/pseries/Makefile powerpc.git.vpm/arch/powerpc/platforms/pseries/Makefile
--- powerpc.git.patched2/arch/powerpc/platforms/pseries/Makefile 2006-01-12 15:12:17.000000000 -0600
+++ powerpc.git.vpm/arch/powerpc/platforms/pseries/Makefile 2006-01-12 15:21:14.000000000 -0600
@@ -1,5 +1,6 @@
obj-y := pci.o lpar.o hvCall.o nvram.o reconfig.o \
- setup.o iommu.o ras.o rtasd.o pci_dlpar.o
+ setup.o iommu.o ras.o rtasd.o pci_dlpar.o \
+ sysstate.o
obj-$(CONFIG_SMP) += smp.o
obj-$(CONFIG_IBMVIO) += vio.o
obj-$(CONFIG_XICS) += xics.o
diff -uNr powerpc.git.patched2/arch/powerpc/platforms/pseries/sysstate.c powerpc.git.vpm/arch/powerpc/platforms/pseries/sysstate.c
--- powerpc.git.patched2/arch/powerpc/platforms/pseries/sysstate.c 1969-12-31 18:00:00.000000000 -0600
+++ powerpc.git.vpm/arch/powerpc/platforms/pseries/sysstate.c 2006-01-12 15:20:26.000000000 -0600
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ *
+ * Note that this is completely different than normal Linux "software suspend".
+ * This is a hypervisor function driven as part of logical partitioning to give
+ * the hypervisor a "sync point" across the operating system.
+ */
+
+#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 = RTAS_UNKNOWN_SERVICE;
+
+static void cpu_suspend(void *info)
+{
+ long rc;
+ long flags;
+ long *waiting = (long *)info;
+ int status;
+
+ /*
+ * 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;
+ */
+ local_irq_save(flags);
+ do {
+ rc = plpar_hcall_norets(H_JOIN);
+ smp_rmb();
+ } 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;
+
+ /* Call function on all other CPUs */
+ if (on_each_cpu(cpu_suspend, &waiting, 1, 0))
+ waiting = -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 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;
+
+ command[7] = '\0';
+
+ if (strcmp(command, "suspend") == 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->write_proc = write_proc;
+
+ return 0;
+}
+
+arch_initcall(sys_state_init);
--
Dave Boutcher
More information about the Linuxppc64-dev
mailing list