Module Name:    src
Committed By:   bouyer
Date:           Fri Jan 15 20:57:13 UTC 2010

Modified Files:
        src/sys/arch/sparc/conf: GENERIC files.sparc
        src/sys/dev: DEVNAMES
Added Files:
        src/sys/arch/sparc/dev: apc.c apcreg.h

Log Message:
Add apc(4), a driver for the Aurora Personality Chip (APC) found
on SPARCstation-4/5, and emulated by qemu to idle the simulator
when the CPU is idle. Infos about the registers from the linux driver.
Not enabled by default because it can cause some Sparc systems to
hang (so says the linux driver).
Only the CPU idle part implemented at this time; fan speed and
Convenience power outlet management to be added.
Tested on qemu.


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/sys/arch/sparc/conf/GENERIC
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/sparc/conf/files.sparc
cvs rdiff -u -r0 -r1.1 src/sys/arch/sparc/dev/apc.c \
    src/sys/arch/sparc/dev/apcreg.h
cvs rdiff -u -r1.254 -r1.255 src/sys/dev/DEVNAMES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc/conf/GENERIC
diff -u src/sys/arch/sparc/conf/GENERIC:1.218 src/sys/arch/sparc/conf/GENERIC:1.219
--- src/sys/arch/sparc/conf/GENERIC:1.218	Sat Dec  5 20:11:17 2009
+++ src/sys/arch/sparc/conf/GENERIC	Fri Jan 15 20:57:12 2010
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.218 2009/12/05 20:11:17 pooka Exp $
+# $NetBSD: GENERIC,v 1.219 2010/01/15 20:57:12 bouyer Exp $
 #
 # GENERIC machine description file
 # 
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.218 $"
+#ident 		"GENERIC-$Revision: 1.219 $"
 
 maxusers	32
 
@@ -712,6 +712,10 @@
 # Tadpole microcontroller
 tctrl0 at obio0
 
+# Aurora Personality Chip (APC) on SPARCstation-4/5
+# Not enabled by default as it may hang some systems
+#apc*		at sbus? slot ? offset ?
+
 ## Pseudo ttys, required for network logins and programs like screen.
 
 pseudo-device	pty			# pseudo-terminals

Index: src/sys/arch/sparc/conf/files.sparc
diff -u src/sys/arch/sparc/conf/files.sparc:1.148 src/sys/arch/sparc/conf/files.sparc:1.149
--- src/sys/arch/sparc/conf/files.sparc:1.148	Sun Sep 27 13:27:44 2009
+++ src/sys/arch/sparc/conf/files.sparc	Fri Jan 15 20:57:12 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sparc,v 1.148 2009/09/27 13:27:44 tsutsui Exp $
+#	$NetBSD: files.sparc,v 1.149 2010/01/15 20:57:12 bouyer Exp $
 
 # @(#)files.sparc	8.1 (Berkeley) 7/19/93
 # sparc-specific configuration info
@@ -224,6 +224,10 @@
 file	arch/sparc/dev/audioamd.c		audioamd
 file	arch/sparc/sparc/amd7930intr.s		audioamd
 
+device	apc
+attach	apc at sbus
+file	arch/sparc/dev/apc.c			apc
+
 attach bwtwo at obio with bwtwo_obio
 file	arch/sparc/dev/bwtwo_obio.c	bwtwo_obio & obio
 

Index: src/sys/dev/DEVNAMES
diff -u src/sys/dev/DEVNAMES:1.254 src/sys/dev/DEVNAMES:1.255
--- src/sys/dev/DEVNAMES:1.254	Thu Jan  7 09:24:45 2010
+++ src/sys/dev/DEVNAMES	Fri Jan 15 20:57:13 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: DEVNAMES,v 1.254 2010/01/07 09:24:45 jdc Exp $
+#	$NetBSD: DEVNAMES,v 1.255 2010/01/15 20:57:13 bouyer Exp $
 #
 # This file contains all used device names and defined attributes in
 # alphabetical order. New devices added to the system somewhere should first
@@ -81,6 +81,7 @@
 ams			macppc
 an			MI
 ap			newsmips
+apc			sparc
 apecs			alpha
 apm			i386
 aps			MI

Added files:

Index: src/sys/arch/sparc/dev/apc.c
diff -u /dev/null src/sys/arch/sparc/dev/apc.c:1.1
--- /dev/null	Fri Jan 15 20:57:13 2010
+++ src/sys/arch/sparc/dev/apc.c	Fri Jan 15 20:57:12 2010
@@ -0,0 +1,97 @@
+/*	$NetBSD: apc.c,v 1.1 2010/01/15 20:57:12 bouyer Exp $	*/
+
+/*
+ * Copyright (c) 2010 Manuel Bouyer.
+ *
+ * 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 ``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 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>
+__KERNEL_RCSID(0, "$NetBSD: apc.c,v 1.1 2010/01/15 20:57:12 bouyer Exp $");
+
+
+/*
+ * driver for the power management functions of the Aurora Personality Chip
+ * on SPARCstation-4/5 and derivatives
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+
+#include <machine/autoconf.h>
+
+#include <sparc/dev/apcreg.h>
+
+static int apcmatch(device_t, struct cfdata *, void *);
+static void apcattach(device_t, device_t, void *);
+static void apc_cpu_sleep(struct cpu_info *);
+
+struct apc_softc {
+	device_t	sc_dev;
+	bus_space_tag_t	sc_bt;
+	bus_space_handle_t sc_bh;
+};
+
+struct apc_softc *apc = NULL;
+
+CFATTACH_DECL_NEW(apc, sizeof(struct apc_softc),
+    apcmatch, apcattach, NULL, NULL);
+
+
+static int
+apcmatch(device_t parent, struct cfdata *cf, void *aux)
+{
+	struct sbus_attach_args *sa = aux;
+	if (apc != NULL) /* only one instance */
+		return 0;
+	return strcmp("power-management", sa->sa_name) == 0;
+}
+
+static void
+apcattach(device_t parent, device_t self, void *aux)
+{
+	struct sbus_attach_args *sa = aux;
+	struct apc_softc *sc = device_private(self);
+
+	sc->sc_bt = sa->sa_bustag;
+	if (sbus_bus_map(sa->sa_bustag,
+	    sa->sa_slot, sa->sa_offset, APC_REG_SIZE, 0, &sc->sc_bh) != 0) {
+		aprint_error(": cannot map registers\n");
+		return;
+	}
+	aprint_normal("\n");
+	apc = sc;
+	curcpu()->idlespin = apc_cpu_sleep;
+}
+
+static void
+apc_cpu_sleep(struct cpu_info *ci)
+{
+	uint8_t val;
+	if (apc == NULL)
+		return;
+	val = bus_space_read_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG);
+	bus_space_write_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG,
+	    val | APC_IDLE_REG_IDLE);
+}
Index: src/sys/arch/sparc/dev/apcreg.h
diff -u /dev/null src/sys/arch/sparc/dev/apcreg.h:1.1
--- /dev/null	Fri Jan 15 20:57:13 2010
+++ src/sys/arch/sparc/dev/apcreg.h	Fri Jan 15 20:57:12 2010
@@ -0,0 +1,37 @@
+/*	$NetBSD: apcreg.h,v 1.1 2010/01/15 20:57:12 bouyer Exp $	*/
+
+/*
+ * Copyright (c) 2010 Manuel Bouyer.
+ *
+ * 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 ``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 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.
+ */
+
+#define APC_IDLE_REG	0x00
+#define APC_IDLE_REG_IDLE	0x01	/* suspend CPU */
+#define APC_FANCTL_REG	0x20
+#define APC_FANCTL_REG_HI	0x00	/* full speed */
+#define APC_FANCTL_REG_LOW	0x01	/* low speed */
+#define APC_CPOWER_REG	0x24
+#define APC_CPOWER_REG_ON	0x00	/* Convenience power outlet on */
+#define APC_CPOWER_REG_OFF	0x01	/* Convenience power outlet off */
+#define APC_BPORT_REG	0x30
+
+#define APC_REG_SIZE	0x34

Reply via email to