Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 May 2011 02:18:18 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r222169 - in projects/pseries: conf powerpc/pseries
Message-ID:  <201105220218.p4M2IIIK054764@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sun May 22 02:18:18 2011
New Revision: 222169
URL: http://svn.freebsd.org/changeset/base/222169

Log:
  Add a driver for simple RTAS services. This supports the RTAS time of day
  clock interface, as well as power-off and reboot. Other potential features
  that could be added here are RTAS LED annunciator support, NVRAM access,
  etc.

Added:
  projects/pseries/powerpc/pseries/rtas_dev.c
Modified:
  projects/pseries/conf/files.powerpc

Modified: projects/pseries/conf/files.powerpc
==============================================================================
--- projects/pseries/conf/files.powerpc	Sun May 22 02:13:55 2011	(r222168)
+++ projects/pseries/conf/files.powerpc	Sun May 22 02:18:18 2011	(r222169)
@@ -211,7 +211,8 @@ powerpc/ps3/ps3-hvcall.S	optional	ps3 sc
 powerpc/pseries/phyp-hvcall.S	optional	pseries powerpc64
 powerpc/pseries/mmu_phyp.c	optional	pseries powerpc64
 powerpc/pseries/platform_chrp.c	optional	pseries
-powerpc/pseries/rtas_pci.c	optional	pseries
+powerpc/pseries/rtas_dev.c	optional	pseries
+powerpc/pseries/rtas_pci.c	optional	pseries pci
 powerpc/psim/iobus.c 		optional	psim
 powerpc/psim/ata_iobus.c	optional	ata psim
 powerpc/psim/openpic_iobus.c	optional	psim

Added: projects/pseries/powerpc/pseries/rtas_dev.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/pseries/powerpc/pseries/rtas_dev.c	Sun May 22 02:18:18 2011	(r222169)
@@ -0,0 +1,173 @@
+/*-
+ * Copyright (c) 2011 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: projects/pseries/powerpc/powermac/rtasdev.c 193156 2009-05-31 09:01:23Z nwhitehorn $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/clock.h>
+#include <sys/cpu.h>
+#include <sys/kernel.h>
+#include <sys/reboot.h>
+#include <sys/sysctl.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/openfirm.h>
+
+#include <machine/rtas.h>
+
+#include "clock_if.h"
+
+static int	rtasdev_probe(device_t);
+static int	rtasdev_attach(device_t);
+/* clock interface */
+static int	rtas_gettime(device_t dev, struct timespec *ts);
+static int	rtas_settime(device_t dev, struct timespec *ts);
+
+static void	rtas_shutdown(void *arg, int howto);
+
+static device_method_t  rtasdev_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		rtasdev_probe),
+	DEVMETHOD(device_attach,	rtasdev_attach),
+
+	/* clock interface */
+	DEVMETHOD(clock_gettime,	rtas_gettime),
+	DEVMETHOD(clock_settime,	rtas_settime),
+	
+	{ 0, 0 },
+};
+
+static driver_t rtasdev_driver = {
+	"rtas",
+	rtasdev_methods,
+	0
+};
+
+static devclass_t rtasdev_devclass;
+
+DRIVER_MODULE(rtasdev, nexus, rtasdev_driver, rtasdev_devclass, 0, 0);
+
+static int
+rtasdev_probe(device_t dev)
+{
+	const char *name = ofw_bus_get_name(dev);
+
+	if (strcmp(name, "rtas") != 0)
+		return (ENXIO);
+	if (!rtas_exists())
+		return (ENXIO);
+
+	device_set_desc(dev, "Run-Time Abstraction Services");
+	return (0);
+}
+
+static int
+rtasdev_attach(device_t dev)
+{
+	if (rtas_token_lookup("get-time-of-day") != -1)
+		clock_register(dev, 2000);
+	
+	EVENTHANDLER_REGISTER(shutdown_final, rtas_shutdown, NULL,
+	    SHUTDOWN_PRI_LAST);
+
+	return (0);
+}
+
+static int
+rtas_gettime(device_t dev, struct timespec *ts) {
+	struct clocktime ct;
+	cell_t tod[8];
+	cell_t token;
+	int error;
+	
+	token = rtas_token_lookup("get-time-of-day");
+	if (token == -1)
+		return (ENXIO);
+	error = rtas_call_method(token, 0, 8, &tod[0], &tod[1], &tod[2],
+	    &tod[3], &tod[4], &tod[5], &tod[6], &tod[7]);
+	if (error < 0)
+		return (ENXIO);
+	if (tod[0] != 0)
+		return ((tod[0] == -1) ? ENXIO : EAGAIN);
+
+        ct.year = tod[1];
+        ct.mon  = tod[2];
+        ct.day  = tod[3];
+        ct.hour = tod[4];
+        ct.min  = tod[5];
+        ct.sec  = tod[6];
+	ct.nsec = tod[7];
+
+	return (clock_ct_to_ts(&ct, ts));
+}
+
+static int
+rtas_settime(device_t dev, struct timespec *ts)
+{
+	struct clocktime ct;
+	cell_t token, status;
+	int error;
+	
+	token = rtas_token_lookup("set-time-of-day");
+	if (token == -1)
+		return (ENXIO);
+
+	clock_ts_to_ct(ts, &ct);
+	error = rtas_call_method(token, 7, 1, ct.year, ct.mon, ct.day, ct.hour,
+	    ct.min, ct.min, ct.sec, ct.nsec, &status);
+	if (error < 0)
+		return (ENXIO);
+	if (status != 0)
+		return (((int)status < 0) ? ENXIO : EAGAIN);
+
+	return (0);
+}
+
+static void
+rtas_shutdown(void *arg, int howto)
+{
+	cell_t token, status;
+	
+	if (howto & RB_HALT) {
+		token = rtas_token_lookup("power-off");
+		if (token == -1)
+			return;
+
+		rtas_call_method(token, 2, 1, 0, 0, &status);
+	} else {
+		token = rtas_token_lookup("system-reboot");
+		if (token == -1)
+			return;
+
+		rtas_call_method(token, 0, 1, &status);
+	}
+}
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201105220218.p4M2IIIK054764>