Module Name:    src
Committed By:   tsutsui
Date:           Sat Dec  3 17:38:02 UTC 2016

Modified Files:
        src/distrib/sets/lists/comp: md.luna68k
        src/etc/etc.luna68k: MAKEDEV.conf
        src/sys/arch/luna68k/conf: GENERIC files.luna68k majors.luna68k
        src/sys/arch/luna68k/include: Makefile
        src/sys/arch/luna68k/luna68k: mainbus.c
Added Files:
        src/sys/arch/luna68k/dev: xp.c
        src/sys/arch/luna68k/include: xpio.h

Log Message:
Preliminary support for LUNA's HD647180X I/O processor (a.k.a. XP).

Demonstrated as "PSG tunes / PCM wav player on LUNA"
(using Z80 PSG/PCM drivers ported from NEC PC-6001)
at OSC2016 Kyoto and OSC2016 Hiroshima:
 http://mail-index.netbsd.org/netbsd-advocacy/2016/08/01/msg000712.html
 http://mail-index.netbsd.org/netbsd-advocacy/2016/11/29/msg000724.html


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/distrib/sets/lists/comp/md.luna68k
cvs rdiff -u -r1.8 -r1.9 src/etc/etc.luna68k/MAKEDEV.conf
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/luna68k/conf/GENERIC
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/luna68k/conf/files.luna68k
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/luna68k/conf/majors.luna68k
cvs rdiff -u -r0 -r1.1 src/sys/arch/luna68k/dev/xp.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/luna68k/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/luna68k/include/xpio.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/luna68k/luna68k/mainbus.c

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

Modified files:

Index: src/distrib/sets/lists/comp/md.luna68k
diff -u src/distrib/sets/lists/comp/md.luna68k:1.20 src/distrib/sets/lists/comp/md.luna68k:1.21
--- src/distrib/sets/lists/comp/md.luna68k:1.20	Thu Dec 24 14:16:46 2015
+++ src/distrib/sets/lists/comp/md.luna68k	Sat Dec  3 17:38:02 2016
@@ -1,4 +1,4 @@
-# $NetBSD: md.luna68k,v 1.20 2015/12/24 14:16:46 christos Exp $
+# $NetBSD: md.luna68k,v 1.21 2016/12/03 17:38:02 tsutsui Exp $
 ./usr/include/ieeefp.h				comp-c-include
 ./usr/include/luna68k				comp-c-include
 ./usr/include/luna68k/_G_config.h		comp-obsolete		obsolete
@@ -52,3 +52,4 @@
 ./usr/include/luna68k/varargs.h			comp-obsolete		obsolete
 ./usr/include/luna68k/vmparam.h			comp-c-include
 ./usr/include/luna68k/wchar_limits.h		comp-c-include
+./usr/include/luna68k/xpio.h			comp-c-include

Index: src/etc/etc.luna68k/MAKEDEV.conf
diff -u src/etc/etc.luna68k/MAKEDEV.conf:1.8 src/etc/etc.luna68k/MAKEDEV.conf:1.9
--- src/etc/etc.luna68k/MAKEDEV.conf:1.8	Mon Jan 14 09:15:57 2013
+++ src/etc/etc.luna68k/MAKEDEV.conf	Sat Dec  3 17:38:02 2016
@@ -1,9 +1,10 @@
-# $NetBSD: MAKEDEV.conf,v 1.8 2013/01/14 09:15:57 tsutsui Exp $
+# $NetBSD: MAKEDEV.conf,v 1.9 2016/12/03 17:38:02 tsutsui Exp $
 
 all_md)
 	makedev ttya sd0 sd1 sd2 sd3 cd0 cd1 st0 st1
 	makedev wscons
 	makedev scsibus0 scsibus1
+	makedev xp
 	;;
 
 tty[ab])

Index: src/sys/arch/luna68k/conf/GENERIC
diff -u src/sys/arch/luna68k/conf/GENERIC:1.119 src/sys/arch/luna68k/conf/GENERIC:1.120
--- src/sys/arch/luna68k/conf/GENERIC:1.119	Sun Nov 16 16:01:41 2014
+++ src/sys/arch/luna68k/conf/GENERIC	Sat Dec  3 17:38:02 2016
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.119 2014/11/16 16:01:41 manu Exp $
+# $NetBSD: GENERIC,v 1.120 2016/12/03 17:38:02 tsutsui Exp $
 #
 # GENERIC machine description file
 # 
@@ -22,7 +22,7 @@ include		"arch/luna68k/conf/std.luna68k"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.119 $"
+#ident 		"GENERIC-$Revision: 1.120 $"
 
 makeoptions	COPTS="-O2 -fno-reorder-blocks"	# see share/mk/sys.mk
 
@@ -163,6 +163,9 @@ spc1	at mainbus0		# 2nd SCSI on LUNA-II
 # framebuffer
 fb0	at mainbus0		# 16 or 256 pseudo color
 
+# HD647180X I/O processor
+xp0	at mainbus0
+
 # Workstation Console attachments
 wsdisplay*	at fb?
 wskbd*		at ws? console ? mux 1

Index: src/sys/arch/luna68k/conf/files.luna68k
diff -u src/sys/arch/luna68k/conf/files.luna68k:1.24 src/sys/arch/luna68k/conf/files.luna68k:1.25
--- src/sys/arch/luna68k/conf/files.luna68k:1.24	Sun Jul 20 11:14:56 2014
+++ src/sys/arch/luna68k/conf/files.luna68k	Sat Dec  3 17:38:02 2016
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: files.luna68k,v 1.24 2014/07/20 11:14:56 tsutsui Exp $
+#	$NetBSD: files.luna68k,v 1.25 2016/12/03 17:38:02 tsutsui Exp $
 #
 maxpartitions 8
 maxusers 2 8 64
@@ -43,6 +43,11 @@ device siotty: tty
 attach siotty at sio
 file arch/luna68k/dev/siotty.c		siotty needs-flag
 
+# HD647180X I/O processor
+device xp
+attach xp at mainbus
+file arch/luna68k/dev/xp.c		xp
+
 device ws: wskbddev,wsmousedev
 attach ws at sio
 file arch/luna68k/dev/lunaws.c		ws

Index: src/sys/arch/luna68k/conf/majors.luna68k
diff -u src/sys/arch/luna68k/conf/majors.luna68k:1.20 src/sys/arch/luna68k/conf/majors.luna68k:1.21
--- src/sys/arch/luna68k/conf/majors.luna68k:1.20	Thu Jun 30 20:09:32 2011
+++ src/sys/arch/luna68k/conf/majors.luna68k	Sat Dec  3 17:38:02 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: majors.luna68k,v 1.20 2011/06/30 20:09:32 wiz Exp $
+#	$NetBSD: majors.luna68k,v 1.21 2016/12/03 17:38:02 tsutsui Exp $
 #
 # Device majors for luna68k
 #
@@ -36,6 +36,7 @@ device-major	clockctl	char 35			clockctl
 device-major	cgd		char 37  block 15	cgd
 device-major	ksyms		char 38			ksyms
 device-major	wsfont		char 39			wsfont
+device-major	xp		char 40			xp
 
 device-major	nsmb		char 98			nsmb
 

Index: src/sys/arch/luna68k/include/Makefile
diff -u src/sys/arch/luna68k/include/Makefile:1.18 src/sys/arch/luna68k/include/Makefile:1.19
--- src/sys/arch/luna68k/include/Makefile:1.18	Thu Dec 24 14:13:35 2015
+++ src/sys/arch/luna68k/include/Makefile	Sat Dec  3 17:38:02 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.18 2015/12/24 14:13:35 christos Exp $
+#	$NetBSD: Makefile,v 1.19 2016/12/03 17:38:02 tsutsui Exp $
 
 INCSDIR= /usr/include/luna68k
 
@@ -18,6 +18,7 @@ INCS=	ansi.h aout_machdep.h asm.h autoco
 	rwlock.h setjmp.h signal.h \
 	trap.h types.h \
 	vmparam.h \
-	wchar_limits.h
+	wchar_limits.h \
+	xpio.h
 
 .include <bsd.kinc.mk>

Index: src/sys/arch/luna68k/luna68k/mainbus.c
diff -u src/sys/arch/luna68k/luna68k/mainbus.c:1.13 src/sys/arch/luna68k/luna68k/mainbus.c:1.14
--- src/sys/arch/luna68k/luna68k/mainbus.c:1.13	Sat Jan 11 01:43:22 2014
+++ src/sys/arch/luna68k/luna68k/mainbus.c	Sat Dec  3 17:38:02 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.13 2014/01/11 01:43:22 tsutsui Exp $ */
+/* $NetBSD: mainbus.c,v 1.14 2016/12/03 17:38:02 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.13 2014/01/11 01:43:22 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2016/12/03 17:38:02 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,7 @@ static const struct mainbus_attach_args 
 	{ "clock",  0x45000000, -1 },	/* Mostek TimeKeeper */
 	{ "le",	    0xf1000000, 3 },	/* Am7990 */
 	{ "sio",    0x51000000, 6 },	/* uPD7201A */
+	{ "xp",     0x71000000, 1 },	/* HD647180XP */
 	{ "fb",	    0xc1100000, -1 },	/* BrookTree RAMDAC */
 	{ "spc",    0xe1000000, 2 },	/* MB89352 */
 };
@@ -52,6 +53,7 @@ static const struct mainbus_attach_args 
 	{ "clock",  0x45000000, -1 },	/* Dallas TimeKeeper */
 	{ "le",	    0xf1000000, 3 },	/* Am7990 */
 	{ "sio",    0x51000000, 6 },	/* uPD7201A */
+	{ "xp",     0x71000000, 1 },	/* HD647180XP */
 	{ "fb",	    0xc1100000, -1 },	/* BrookTree RAMDAC */
 	{ "spc",    0xe1000000, 2 },	/* internal MB89352 */
 	{ "spc",    0xe1000040, 2 },	/* external MB89352 */

Added files:

Index: src/sys/arch/luna68k/dev/xp.c
diff -u /dev/null src/sys/arch/luna68k/dev/xp.c:1.1
--- /dev/null	Sat Dec  3 17:38:02 2016
+++ src/sys/arch/luna68k/dev/xp.c	Sat Dec  3 17:38:02 2016
@@ -0,0 +1,285 @@
+/* $NetBSD: xp.c,v 1.1 2016/12/03 17:38:02 tsutsui Exp $ */
+
+/*-
+ * Copyright (c) 2016 Izumi Tsutsui.  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 ``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.
+ */
+
+/*
+ * LUNA's Hitachi HD647180 "XP" I/O processor driver
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: xp.c,v 1.1 2016/12/03 17:38:02 tsutsui Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/kmem.h>
+#include <sys/errno.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/autoconf.h>
+#include <machine/xpio.h>
+
+#include "ioconf.h"
+
+#define XP_SHM_BASE	0x71000000
+#define XP_SHM_SIZE	0x00010000	/* 64KB for XP; rest 64KB for lance */
+#define XP_TAS_ADDR	0x61000000
+
+struct xp_softc {
+	device_t	sc_dev;
+
+	vaddr_t		sc_shm_base;
+	vsize_t		sc_shm_size;
+	vaddr_t		sc_tas;
+
+	bool		sc_isopen;
+};
+
+static int xp_match(device_t, cfdata_t, void *);
+static void xp_attach(device_t, device_t, void *);
+
+dev_type_open(xp_open);
+dev_type_close(xp_close);
+dev_type_read(xp_read);
+dev_type_write(xp_write);
+dev_type_ioctl(xp_ioctl);
+dev_type_mmap(xp_mmap);
+
+const struct cdevsw xp_cdevsw = {
+	.d_open     = xp_open,
+	.d_close    = xp_close,
+	.d_read     = xp_read,
+	.d_write    = xp_write,
+	.d_ioctl    = xp_ioctl,
+	.d_stop     = nostop,
+	.d_tty      = notty,
+	.d_poll     = nopoll,
+	.d_mmap     = xp_mmap,
+	.d_kqfilter = nokqfilter,
+	.d_discard  = nodiscard,
+	.d_flag     = 0
+};
+
+CFATTACH_DECL_NEW(xp, sizeof(struct xp_softc),
+    xp_match, xp_attach, NULL, NULL);
+
+/* #define XP_DEBUG */
+
+#ifdef XP_DEBUG
+#define XP_DEBUG_ALL	0xff
+uint32_t xp_debug = 0;
+#define DPRINTF(x, y)	if (xp_debug & (x)) printf y
+#else
+#define DPRINTF(x, y)	/* nothing */
+#endif
+
+static bool xp_matched;
+
+/*
+ * PIO 0 port C is connected to XP's reset line
+ *
+ * XXX: PIO port functions should be shared with machdep.c for DIP SWs
+ */
+#define PIO_ADDR	0x49000000
+#define PORT_A		0
+#define PORT_B		1
+#define PORT_C		2
+#define CTRL		3
+
+/* PIO0 Port C bit definition */
+#define XP_INT1_REQ	0	/* INTR B */
+	/* unused */		/* IBF B */
+#define XP_INT1_ENA	2	/* INTE B */
+#define XP_INT5_REQ	3	/* INTR A */
+#define XP_INT5_ENA	4	/* INTE A */
+	/* unused */		/* IBF A */
+#define PARITY		6	/* PC6 output to enable parity error */
+#define XP_RESET	7	/* PC7 output to reset HD647180 XP */
+
+/* Port control for PC6 and PC7 */
+#define ON		1
+#define OFF		0
+
+static uint8_t put_pio0c(uint8_t bit, uint8_t set)
+{
+	volatile uint8_t * const pio0 = (uint8_t *)PIO_ADDR;
+
+	pio0[CTRL] = (bit << 1) | (set & 0x01);
+
+	return pio0[PORT_C];
+}
+
+static int
+xp_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct mainbus_attach_args *maa = aux;
+
+	/* only one XP processor */
+	if (xp_matched)
+		return 0;
+
+	if (strcmp(maa->ma_name, xp_cd.cd_name))
+		return 0;
+
+	if (maa->ma_addr != XP_SHM_BASE)
+		return 0;
+
+	xp_matched = true;
+	return 1;
+}
+
+static void
+xp_attach(device_t parent, device_t self, void *aux)
+{
+	struct xp_softc *sc = device_private(self);
+
+	sc->sc_dev = self;
+
+	aprint_normal(": HD647180X I/O processor\n");
+
+	sc->sc_shm_base = XP_SHM_BASE;
+	sc->sc_shm_size = XP_SHM_SIZE;
+	sc->sc_tas      = XP_TAS_ADDR;
+}
+
+int
+xp_open(dev_t dev, int flags, int devtype, struct lwp *l)
+{
+	struct xp_softc *sc;
+	int unit;
+	
+	DPRINTF(XP_DEBUG_ALL, ("%s\n", __func__));
+
+	unit = minor(dev);
+	sc = device_lookup_private(&xp_cd, unit);
+	if (sc == NULL)
+		return ENXIO;
+	if (sc->sc_isopen)
+		return EBUSY;
+
+	sc->sc_isopen = true;
+
+	return 0;
+}
+
+int
+xp_close(dev_t dev, int flags, int mode, struct lwp *l)
+{
+	struct xp_softc *sc;
+	int unit;
+
+	DPRINTF(XP_DEBUG_ALL, ("%s\n", __func__));
+
+	unit = minor(dev);
+	sc = device_lookup_private(&xp_cd, unit);
+	sc->sc_isopen = false;
+
+	return 0;
+}
+
+int
+xp_ioctl(dev_t dev, u_long cmd, void *addr, int flags, struct lwp *l)
+{
+	struct xp_softc *sc;
+	int unit, error;
+	struct xp_download *downld;
+	uint8_t *loadbuf;
+	size_t loadsize;
+
+	DPRINTF(XP_DEBUG_ALL, ("%s\n", __func__));
+
+	unit = minor(dev);
+	sc = device_lookup_private(&xp_cd, unit);
+
+	switch (cmd) {
+	case XPIOCDOWNLD:
+		downld = addr;
+		loadsize = downld->size;
+		if (loadsize == 0 || loadsize >= XP_SHM_SIZE) {
+			return EINVAL;
+		}
+
+		loadbuf = kmem_alloc(loadsize, KM_SLEEP);
+		if (loadbuf == NULL) {
+			return ENOMEM;
+		}
+		error = copyin(downld->data, loadbuf, loadsize);
+		if (error == 0) {
+			put_pio0c(XP_RESET, ON);
+			delay(100);
+			memcpy((void *)sc->sc_shm_base, loadbuf, loadsize);
+			delay(100);
+			put_pio0c(XP_RESET, OFF);
+		} else {
+			DPRINTF(XP_DEBUG_ALL, ("%s: ioctl failed (err =  %d)\n",
+			    __func__, error));
+		}
+
+		kmem_free(loadbuf, loadsize);
+		return error;
+
+	default:
+		return ENOTTY;
+	}
+
+	panic("%s: cmd (%ld) is not handled", device_xname(sc->sc_dev), cmd);
+}
+
+paddr_t
+xp_mmap(dev_t dev, off_t offset, int prot)
+{
+	struct xp_softc *sc;
+	int unit;
+	paddr_t pa;
+
+	pa = -1;
+
+	unit = minor(dev);
+	sc = device_lookup_private(&xp_cd, unit);
+
+	if (offset >= 0 &&
+	    offset < sc->sc_shm_size) {
+		pa = m68k_btop(m68k_trunc_page(sc->sc_shm_base) + offset);
+	}
+
+	return pa;
+}
+
+int
+xp_read(dev_t dev, struct uio *uio, int flags)
+{
+
+	return ENODEV;
+}
+
+int
+xp_write(dev_t dev, struct uio *uio, int flags)
+{
+
+	return ENODEV;
+}

Index: src/sys/arch/luna68k/include/xpio.h
diff -u /dev/null src/sys/arch/luna68k/include/xpio.h:1.1
--- /dev/null	Sat Dec  3 17:38:02 2016
+++ src/sys/arch/luna68k/include/xpio.h	Sat Dec  3 17:38:02 2016
@@ -0,0 +1,43 @@
+/* $NetBSD: xpio.h,v 1.1 2016/12/03 17:38:02 tsutsui Exp $ */
+
+/*-
+ * Copyright (c) 2016 Izumi Tsutsui.  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 ``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.
+ */
+
+/*
+ * ioctl for LUNA's Hitachi HD647180 "XP" I/O processor driver
+ */
+
+#ifndef _LUNA68K_XPIO_H_
+#define _LUNA68K_XPIO_H_
+
+#include <sys/ioctl.h>
+#include <sys/ioccom.h>
+
+struct xp_download {
+	u_int	size;		/* size to be downloaded to XP shared mem */
+	uint8_t	*data;		/* pointer to code to be downloaded */
+};
+#define XPIOCDOWNLD	_IOW('x', 1, struct xp_download)
+
+#endif /* _LUNA68K_XPIO_H_ */

Reply via email to