diff options
author | 2016-12-17 05:22:34 +0000 | |
---|---|---|
committer | 2016-12-17 05:22:34 +0000 | |
commit | 0641c1a2e60e893f344936ba3c21d3e501ad8a7c (patch) | |
tree | b7ac1ed6020b548522ba80ad699f68f5b3ad7baf | |
parent | sync (diff) | |
download | wireguard-openbsd-0641c1a2e60e893f344936ba3c21d3e501ad8a7c.tar.xz wireguard-openbsd-0641c1a2e60e893f344936ba3c21d3e501ad8a7c.zip |
Add new device xp(4), preliminary support for LUNA's I/O processor.
This is a straightforward port of NetBSD/luna68k by Izumi Tsutsui(*),
and makes LUNA's I/O auxiliary processor (called XP, actually
HD647180) possible to load and run programs.
(*): http://mail-index.netbsd.org/source-changes/2016/12/03/msg079493.html
-rw-r--r-- | sys/arch/luna88k/conf/GENERIC | 5 | ||||
-rw-r--r-- | sys/arch/luna88k/conf/files.luna88k | 6 | ||||
-rw-r--r-- | sys/arch/luna88k/dev/xp.c | 254 | ||||
-rw-r--r-- | sys/arch/luna88k/include/conf.h | 11 | ||||
-rw-r--r-- | sys/arch/luna88k/include/xpio.h | 44 | ||||
-rw-r--r-- | sys/arch/luna88k/luna88k/conf.c | 5 | ||||
-rw-r--r-- | sys/arch/luna88k/luna88k/mainbus.c | 3 |
7 files changed, 322 insertions, 6 deletions
diff --git a/sys/arch/luna88k/conf/GENERIC b/sys/arch/luna88k/conf/GENERIC index 2ae7fe8cab0..958a3744c3e 100644 --- a/sys/arch/luna88k/conf/GENERIC +++ b/sys/arch/luna88k/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.21 2016/09/03 16:18:21 tedu Exp $ +# $OpenBSD: GENERIC,v 1.22 2016/12/17 05:22:34 aoyama Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -47,6 +47,9 @@ wsdisplay* at fb? wskbd* at ws? mux 1 wsmouse* at ws? mux 0 +# HD647180X I/O processor +xp0 at mainbus0 + # PC-9801 extension board slot cbus0 at mainbus0 diff --git a/sys/arch/luna88k/conf/files.luna88k b/sys/arch/luna88k/conf/files.luna88k index f4d8fd9aa6c..4e7c327f055 100644 --- a/sys/arch/luna88k/conf/files.luna88k +++ b/sys/arch/luna88k/conf/files.luna88k @@ -1,4 +1,4 @@ -# $OpenBSD: files.luna88k,v 1.27 2015/05/11 06:46:21 ratchov Exp $ +# $OpenBSD: files.luna88k,v 1.28 2016/12/17 05:22:34 aoyama Exp $ # maxpartitions 16 @@ -25,6 +25,10 @@ device siotty: tty attach siotty at sio file arch/luna88k/dev/siotty.c siotty needs-flag +device xp +attach xp at mainbus +file arch/luna88k/dev/xp.c xp needs-flag + device ws: wskbddev,wsmousedev attach ws at sio file arch/luna88k/dev/lunaws.c ws diff --git a/sys/arch/luna88k/dev/xp.c b/sys/arch/luna88k/dev/xp.c new file mode 100644 index 00000000000..10957e531f3 --- /dev/null +++ b/sys/arch/luna88k/dev/xp.c @@ -0,0 +1,254 @@ +/* $OpenBSD: xp.c,v 1.1 2016/12/17 05:22:34 aoyama Exp $ */ +/* $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/param.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/device.h> +#include <sys/ioctl.h> +#include <sys/malloc.h> +#include <sys/errno.h> +#include <sys/types.h> + +#include <uvm/uvm_extern.h> + +#include <machine/autoconf.h> +#include <machine/board.h> +#include <machine/xpio.h> + +#define XP_SHM_BASE TRI_PORT_RAM +#define XP_SHM_SIZE 0x00010000 /* 64KB for XP; rest 64KB for lance */ +#define XP_TAS_ADDR OBIO_TAS + +struct xp_softc { + struct device sc_dev; + + vaddr_t sc_shm_base; + vsize_t sc_shm_size; + vaddr_t sc_tas; + + bool sc_isopen; +}; + +static int xp_match(struct device *, void *, void *); +static void xp_attach(struct device *, struct device *, void *); + +const struct cfattach xp_ca = { + sizeof (struct xp_softc), xp_match, xp_attach +}; + +struct cfdriver xp_cd = { + NULL, "xp", DV_DULL +}; + +/* #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 OBIO_PIO0_BASE +#define PORT_A (0 * 4) +#define PORT_B (1 * 4) +#define PORT_C (2 * 4) +#define CTRL (3 * 4) + +/* 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(struct device *parent, void *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(struct device *parent, struct device *self, void *aux) +{ + struct xp_softc *sc = (void *)self; + + printf(": 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 +xpopen(dev_t dev, int flags, int mode, struct proc *p) +{ + struct xp_softc *sc; + int unit; + + DPRINTF(XP_DEBUG_ALL, ("%s\n", __func__)); + + unit = minor(dev); + if (unit >= xp_cd.cd_ndevs) + return ENXIO; + sc = xp_cd.cd_devs[unit]; + if (sc == NULL) + return ENXIO; + if (sc->sc_isopen) + return EBUSY; + + sc->sc_isopen = true; + + return 0; +} + +int +xpclose(dev_t dev, int flags, int mode, struct proc *p) +{ + struct xp_softc *sc; + int unit; + + DPRINTF(XP_DEBUG_ALL, ("%s\n", __func__)); + + unit = minor(dev); + if (unit >= xp_cd.cd_ndevs) + return ENXIO; + sc = xp_cd.cd_devs[unit]; + sc->sc_isopen = false; + + return 0; +} + +int +xpioctl(dev_t dev, u_long cmd, void *addr, int flags, struct proc *p) +{ + 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); + if (unit >= xp_cd.cd_ndevs) + return ENXIO; + sc = xp_cd.cd_devs[unit]; + + switch (cmd) { + case XPIOCDOWNLD: + downld = addr; + loadsize = downld->size; + if (loadsize == 0 || loadsize >= XP_SHM_SIZE) { + return EINVAL; + } + + loadbuf = malloc(loadsize, M_DEVBUF, M_WAITOK); + 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)); + } + + free(loadbuf, M_DEVBUF, loadsize); + return error; + + default: + return ENOTTY; + } +} + +paddr_t +xpmmap(dev_t dev, off_t offset, int prot) +{ + struct xp_softc *sc; + int unit; + paddr_t pa; + + pa = -1; + + unit = minor(dev); + sc = xp_cd.cd_devs[unit]; + + if (offset >= 0 && + offset < sc->sc_shm_size) { + pa = (paddr_t)(trunc_page(sc->sc_shm_base) + offset); + } + + return pa; +} diff --git a/sys/arch/luna88k/include/conf.h b/sys/arch/luna88k/include/conf.h index d4cb26a62d4..08949da8876 100644 --- a/sys/arch/luna88k/include/conf.h +++ b/sys/arch/luna88k/include/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.4 2015/03/03 23:50:37 aoyama Exp $ */ +/* $OpenBSD: conf.h,v 1.5 2016/12/17 05:22:34 aoyama Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * All rights reserved. @@ -39,6 +39,8 @@ cdev_decl(lcd); cdev_decl(pcex); +cdev_decl(xp); + /* devices on PCMCIA */ /* block devices */ bdev_decl(wd); @@ -59,3 +61,10 @@ cdev_decl(wd); (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ (dev_type_stop((*))) enodev, 0, selfalse, \ dev_init(c,n,mmap) } + +/* open, close, ioctl, mmap */ +#define cdev_xp_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, selfalse, \ + dev_init(c,n,mmap) } diff --git a/sys/arch/luna88k/include/xpio.h b/sys/arch/luna88k/include/xpio.h new file mode 100644 index 00000000000..7f6beccef13 --- /dev/null +++ b/sys/arch/luna88k/include/xpio.h @@ -0,0 +1,44 @@ +/* $OpenBSD: xpio.h,v 1.1 2016/12/17 05:22:34 aoyama Exp $ */ +/* $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 _LUNA88K_XPIO_H_ +#define _LUNA88K_XPIO_H_ + +#include <sys/ioctl.h> +#include <sys/ioccom.h> + +struct xp_download { + u_int size; /* size to be downloaded to XP shared mem */ + u_char *data; /* pointer to code to be downloaded */ +}; +#define XPIOCDOWNLD _IOW('x', 1, struct xp_download) + +#endif /* _LUNA88K_XPIO_H_ */ diff --git a/sys/arch/luna88k/luna88k/conf.c b/sys/arch/luna88k/luna88k/conf.c index e0468a5969b..bf0a440bc38 100644 --- a/sys/arch/luna88k/luna88k/conf.c +++ b/sys/arch/luna88k/luna88k/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.30 2016/09/04 10:51:23 naddy Exp $ */ +/* $OpenBSD: conf.c,v 1.31 2016/12/17 05:22:34 aoyama Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -60,6 +60,7 @@ #include "lcd.h" #include "pcex.h" #include "siotty.h" +#include "xp.h" #include "wsdisplay.h" #include "wskbd.h" @@ -109,7 +110,7 @@ struct cdevsw cdevsw[] = cdev_disk_init(NSD,sd), /* 8: SCSI disk */ cdev_disk_init(NCD,cd), /* 9: SCSI CD-ROM */ cdev_lcd_init(NLCD,lcd), /* 10: /dev/lcd */ - cdev_notdef(), /* 11 */ + cdev_xp_init(NXP,xp), /* 11: HD647180XP */ cdev_tty_init(NSIOTTY,sio), /* 12: on-board UART (ttya) */ cdev_wsdisplay_init(NWSDISPLAY, /* 13: frame buffers, etc. */ wsdisplay), diff --git a/sys/arch/luna88k/luna88k/mainbus.c b/sys/arch/luna88k/luna88k/mainbus.c index 30a17e7b90a..e909a82104d 100644 --- a/sys/arch/luna88k/luna88k/mainbus.c +++ b/sys/arch/luna88k/luna88k/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.12 2014/12/08 13:24:04 aoyama Exp $ */ +/* $OpenBSD: mainbus.c,v 1.13 2016/12/17 05:22:34 aoyama Exp $ */ /* $NetBSD: mainbus.c,v 1.2 2000/01/07 05:13:08 nisimura Exp $ */ /*- @@ -51,6 +51,7 @@ static const struct mainbus_attach_args devs[] = { #endif { "le", 0xf1000000, 4, LUNA_88K|LUNA_88K2 }, /* Am7990 */ { "sio", 0x51000000, 5, LUNA_88K|LUNA_88K2 }, /* uPD7201A */ + { "xp", 0x71000000, 1, LUNA_88K|LUNA_88K2 }, /* HD647180XP */ { "fb", 0xc1100000, -1, LUNA_88K|LUNA_88K2 }, /* BrookTree RAMDAC */ { "spc", 0xe1000000, 3, LUNA_88K|LUNA_88K2 }, /* MB89352 */ { "spc", 0xe1000040, 3, LUNA_88K2 }, /* ditto, LUNA-88K2 only */ |