diff options
Diffstat (limited to 'sys/arch/sun3/dev/zs.c')
-rw-r--r-- | sys/arch/sun3/dev/zs.c | 1784 |
1 files changed, 360 insertions, 1424 deletions
diff --git a/sys/arch/sun3/dev/zs.c b/sys/arch/sun3/dev/zs.c index 550f60b1d51..152b40b67f3 100644 --- a/sys/arch/sun3/dev/zs.c +++ b/sys/arch/sun3/dev/zs.c @@ -1,18 +1,8 @@ -/* $NetBSD: zs.c,v 1.30 1995/10/08 23:42:59 gwr Exp $ */ +/* $NetBSD: zs.c,v 1.31 1996/01/24 22:40:25 gwr Exp $ */ /* - * Copyright (c) 1994 Gordon W. Ross - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Lawrence Berkeley Laboratory. + * Copyright (c) 1995 Gordon W. Ross + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -22,38 +12,31 @@ * 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. - * 3. All advertising materials mentioning features or use of this software + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * 4. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * This product includes software developed by Gordon Ross * - * @(#)zs.c 8.1 (Berkeley) 7/19/93 + * 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. */ /* - * Zilog Z8530 (ZSCC) driver. + * Zilog Z8530 Dual UART driver (machine-dependent part) * - * Runs two tty ports (ttya and ttyb) on zs0, - * and runs a keyboard and mouse on zs1. - * - * This driver knows far too much about chip to usage mappings. + * Runs two serial lines per chip using slave drivers. + * Plain tty/async lines use the zs_async slave. + * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves. */ -#define NZS 2 /* XXX */ #include <sys/param.h> #include <sys/systm.h> @@ -67,34 +50,22 @@ #include <sys/kernel.h> #include <sys/syslog.h> +#include <dev/cons.h> +#include <dev/ic/z8530reg.h> +#include <machine/z8530var.h> + #include <machine/autoconf.h> #include <machine/cpu.h> +#include <machine/eeprom.h> #include <machine/isr.h> #include <machine/obio.h> #include <machine/mon.h> -#include <machine/eeprom.h> -#include <machine/kbd.h> - -#include <dev/cons.h> - -#include <dev/ic/z8530reg.h> -#include <sun3/dev/zsvar.h> /* - * The default parity REALLY needs to be the same as the PROM uses, - * or you can not see messages done with printf during boot-up... + * XXX: Hard code this to make console init easier... */ -#undef TTYDEF_CFLAG -#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) - -#ifdef KGDB -#include <machine/remote-sl.h> -#endif - -#define ZSMAJOR 12 /* XXX */ +#define NZS 2 /* XXX */ -#define ZS_KBD 2 /* XXX */ -#define ZS_MOUSE 3 /* XXX */ /* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */ #define PCLK (9600 * 512) /* PCLK pin input clock rate */ @@ -105,80 +76,68 @@ #define ZSHARD_PRI 6 /* Wired on the CPU board... */ #define ZSSOFT_PRI 3 /* Want tty pri (4) but this is OK. */ -/* - * Software state per found chip. This would be called `zs_softc', - * but the previous driver had a rather different zs_softc.... - */ -struct zsinfo { - struct device zi_dev; /* base device */ - volatile struct zsdevice *zi_zs;/* chip registers */ - struct zs_chanstate zi_cs[2]; /* channel A and B software state */ + +/* The layout of this is hardware-dependent (padding, order). */ +struct zschan { + volatile u_char zc_csr; /* ctrl,status, and indirect access */ + u_char zc_xxx0; + volatile u_char zc_data; /* data */ + u_char zc_xxx1; +}; +struct zsdevice { + /* Yes, they are backwards. */ + struct zschan zs_chan_b; + struct zschan zs_chan_a; }; -static struct tty *zs_tty[NZS * 2]; /* XXX should be dynamic */ -/* Definition of the driver for autoconfig. */ -static int zs_match(struct device *, void *, void *); -static void zs_attach(struct device *, struct device *, void *); - -struct cfdriver zscd = { - NULL, "zs", zs_match, zs_attach, - DV_TTY, sizeof(struct zsinfo) }; - -/* Interrupt handlers. */ -static int zshard(int); -static int zssoft(int); - -struct zs_chanstate *zslist; - -/* Routines called from other code. */ -int zsopen(dev_t, int, int, struct proc *); -int zsclose(dev_t, int, int, struct proc *); -static void zsiopen(struct tty *); -static void zsiclose(struct tty *); -static void zsstart(struct tty *); -void zsstop(struct tty *, int); -static int zsparam(struct tty *, struct termios *); - -/* Routines purely local to this driver. */ -static int zs_getspeed(volatile struct zschan *); -static void zs_reset(volatile struct zschan *, int, int); -static void zs_modem(struct zs_chanstate *, int); -static void zs_loadchannelregs(volatile struct zschan *, u_char *); -static u_char zs_read(volatile struct zschan *, u_char); -static u_char zs_write(volatile struct zschan *, u_char, u_char); - -/* Console stuff. */ -static volatile struct zschan *zs_conschan; - -#ifdef KGDB -/* KGDB stuff. Must reboot to change zs_kgdbunit. */ -extern int kgdb_dev, kgdb_rate; -static int zs_kgdb_savedspeed; -static void zs_checkkgdb(int, struct zs_chanstate *, struct tty *); -#endif +/* Default OBIO addresses. */ +static int zs_physaddr[NZS] = { OBIO_KEYBD_MS, OBIO_ZS }; +/* Saved PROM mappings */ +static struct zsdevice *zsaddr[NZS]; /* See zs_init() */ +/* Flags from cninit() */ +static int zs_hwflags[NZS][2]; +/* Default speed for each channel */ +static int zs_defspeed[NZS][2] = { + { 1200, /* keyboard */ + 1200 }, /* mouse */ + { 9600, /* ttya */ + 9600 }, /* ttyb */ +}; -/* - * Console keyboard L1-A processing is done in the hardware interrupt code, - * so we need to duplicate some of the console keyboard decode state. (We - * must not use the regular state as the hardware code keeps ahead of the - * software state: the software state tracks the most recent ring input but - * the hardware state tracks the most recent ZSCC input.) See also kbd.h. - */ -static struct conk_state { /* console keyboard state */ - char conk_id; /* true => ID coming up (console only) */ - char conk_l1; /* true => L1 pressed (console only) */ -} zsconk_state; -int zshardscope; -int zsshortcuts; /* number of "shortcut" software interrupts */ +/* Find PROM mappings (for console support). */ +void zs_init() +{ + int i; + + for (i = 0; i < NZS; i++) { + zsaddr[i] = (struct zsdevice *) + obio_find_mapping(zs_physaddr[i], OBIO_ZS_SIZE); + } +} + -int zssoftpending; /* We have done isr_soft_request() */ +struct zschan * +zs_get_chan_addr(zsc_unit, channel) + int zsc_unit, channel; +{ + struct zsdevice *addr; + struct zschan *zc; -static struct zsdevice *zsaddr[NZS]; /* XXX, but saves work */ + if (zsc_unit >= NZS) + return NULL; + addr = zsaddr[zsc_unit]; + if (addr == NULL) + return NULL; + if (channel == 0) { + zc = &addr->zs_chan_a; + } else { + zc = &addr->zs_chan_b; + } + return (zc); +} -/* Default OBIO addresses. */ -static int zs_physaddr[NZS] = { OBIO_ZS, OBIO_KEYBD_MS }; static u_char zs_init_reg[16] = { 0, /* 0: CMD (reset, etc.) */ @@ -190,35 +149,44 @@ static u_char zs_init_reg[16] = { 0, /* 6: TXSYNC/SYNCLO */ 0, /* 7: RXSYNC/SYNCHI */ 0, /* 8: alias for data port */ - 0, /* 9: ZSWR9_MASTER_IE (later) */ + ZSWR9_MASTER_IE, 0, /*10: Misc. TX/RX control bits */ ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD, - 0, /*12: BAUDLO (later) */ - 0, /*13: BAUDHI (later) */ + 14, /*12: BAUDLO (default=9600) */ + 0, /*13: BAUDHI (default=9600) */ ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA, ZSWR15_BREAK_IE | ZSWR15_DCD_IE, }; -/* Find PROM mappings (for console support). */ -void zs_init() -{ - int i; - for (i = 0; i < NZS; i++) { - zsaddr[i] = (struct zsdevice *) - obio_find_mapping(zs_physaddr[i], OBIO_ZS_SIZE); - } -} +/**************************************************************** + * Autoconfig + ****************************************************************/ + +/* Definition of the driver for autoconfig. */ +static int zsc_match(struct device *, void *, void *); +static void zsc_attach(struct device *, struct device *, void *); + +struct cfdriver zsccd = { + NULL, "zsc", zsc_match, zsc_attach, + DV_DULL, sizeof(struct zsc_softc), NULL, +}; + +static int zshard(void *); +static int zssoft(void *); + /* - * Match slave number to zs unit number, so that misconfiguration will - * not set up the keyboard as ttya, etc. + * Is the zs chip present? */ static int -zs_match(struct device *parent, void *vcf, void *args) +zsc_match(parent, vcf, aux) + struct device *parent; + void *vcf; + void *aux; { struct cfdata *cf = vcf; - struct confargs *ca = args; + struct confargs *ca = aux; int unit, x; void *zsva; @@ -226,6 +194,7 @@ zs_match(struct device *parent, void *vcf, void *args) if (unit < 0 || unit >= NZS) return (0); + /* Make sure zs_init() found mappings. */ zsva = zsaddr[unit]; if (zsva == NULL) return (0); @@ -240,279 +209,227 @@ zs_match(struct device *parent, void *vcf, void *args) return (x != -1); } +static int +zsc_print(aux, name) + void *aux; + char *name; +{ + struct zsc_attach_args *args = aux; + + if (name != NULL) + printf("%s: ", name); + + if (args->channel != -1) + printf(" channel %d", args->channel); + + return UNCONF; +} + /* * Attach a found zs. * - * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR - * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE? + * Match slave number to zs unit number, so that misconfiguration will + * not set up the keyboard as ttya, etc. */ static void -zs_attach(struct device *parent, struct device *self, void *args) -{ - struct cfdata *cf; - struct confargs *ca; - register int zs, unit; - register struct zsinfo *zi; - register struct zs_chanstate *cs; - register volatile struct zsdevice *addr; - register struct tty *tp, *ctp; - int softcar; +zsc_attach(parent, self, aux) + struct device *parent; + struct device *self; + void *aux; +{ + struct zsc_softc *zsc = (void *) self; + struct confargs *ca = aux; + struct zsc_attach_args zsc_args; + volatile struct zschan *zc; + struct zs_chanstate *cs; + int zsc_unit, channel; + int reset, s; static int didintr; - cf = self->dv_cfdata; - zs = self->dv_unit; - ca = args; + zsc_unit = zsc->zsc_dev.dv_unit; printf(" softpri %d\n", ZSSOFT_PRI); - if (zsaddr[zs] == NULL) - panic("zs_attach: zs%d not mapped\n", zs); - addr = zsaddr[zs]; + /* Use the mapping setup by the Sun PROM. */ + if (zsaddr[zsc_unit] == NULL) + panic("zs_attach: zs%d not mapped\n", zsc_unit); - if (!didintr) { - didintr = 1; - isr_add_autovect(zssoft, NULL, ZSSOFT_PRI); - isr_add_autovect(zshard, NULL, ZSHARD_PRI); - } + /* + * Initialize software state for each channel. + */ + for (channel = 0; channel < 2; channel++) { + cs = &zsc->zsc_cs[channel]; - zi = (struct zsinfo *)self; - zi->zi_zs = addr; - unit = zs * 2; - cs = zi->zi_cs; - softcar = cf->cf_flags; - - if(!zs_tty[unit]) - zs_tty[unit] = ttymalloc(); - if(!zs_tty[unit+1]) - zs_tty[unit+1] = ttymalloc(); - - /* link into interrupt list with order (A,B) (B=A+1) */ - cs[0].cs_next = &cs[1]; - cs[1].cs_next = zslist; - zslist = cs; - - tp = zs_tty[unit]; - cs->cs_unit = unit; - cs->cs_zc = &addr->zs_chan[ZS_CHAN_A]; - cs->cs_speed = zs_getspeed(cs->cs_zc); -#ifdef DEBUG - mon_printf("zs%da speed %d ", zs, cs->cs_speed); -#endif - cs->cs_softcar = softcar & 1; - cs->cs_ttyp = tp; - tp->t_dev = makedev(ZSMAJOR, unit); - tp->t_oproc = zsstart; - tp->t_param = zsparam; - if (cs->cs_zc == zs_conschan) { - /* This unit is the console. */ - cs->cs_consio = 1; - cs->cs_brkabort = 1; - cs->cs_softcar = 1; - /* Call zsparam so interrupts get enabled. */ - tp->t_ispeed = tp->t_ospeed = cs->cs_speed; - tp->t_cflag = TTYDEF_CFLAG; - (void) zsparam(tp, &tp->t_termios); - } else { - /* Can not run kgdb on the console? */ -#ifdef KGDB - zs_checkkgdb(unit, cs, tp); -#endif - } -#if 0 - /* XXX - Drop carrier here? -gwr */ - zs_modem(cs, cs->cs_softcar ? 1 : 0); -#endif + zc = zs_get_chan_addr(zsc_unit, channel); + cs->cs_reg_csr = &zc->zc_csr; + cs->cs_reg_data = &zc->zc_data; + + cs->cs_channel = channel; + cs->cs_private = NULL; + cs->cs_ops = &zsops_null; + + /* Define BAUD rate clock for the MI code. */ + cs->cs_pclk_div16 = PCLK / 16; + + /* XXX: get defspeed from EEPROM instead? */ + cs->cs_defspeed = zs_defspeed[zsc_unit][channel]; + + bcopy(zs_init_reg, cs->cs_creg, 16); + bcopy(zs_init_reg, cs->cs_preg, 16); - if (unit == ZS_KBD) { /* - * Keyboard: tell /dev/kbd driver how to talk to us. + * Clear the master interrupt enable. + * The INTENA is common to both channels, + * so just do it on the A channel. */ - tp->t_ispeed = tp->t_ospeed = cs->cs_speed; - tp->t_cflag = CS8; - /* zsparam called by zsiopen */ - kbd_serial(tp, zsiopen, zsiclose); - cs->cs_conk = 1; /* do L1-A processing */ - } - unit++; - cs++; - tp = zs_tty[unit]; - - cs->cs_unit = unit; - cs->cs_zc = &addr->zs_chan[ZS_CHAN_B]; - cs->cs_speed = zs_getspeed(cs->cs_zc); -#ifdef DEBUG - mon_printf("zs%db speed %d\n", zs, cs->cs_speed); -#endif - cs->cs_softcar = softcar & 2; - cs->cs_ttyp = tp; - tp->t_dev = makedev(ZSMAJOR, unit); - tp->t_oproc = zsstart; - tp->t_param = zsparam; - if (cs->cs_zc == zs_conschan) { - /* This unit is the console. */ - cs->cs_consio = 1; - cs->cs_brkabort = 1; - cs->cs_softcar = 1; - tp->t_ispeed = tp->t_ospeed = cs->cs_speed; - tp->t_cflag = TTYDEF_CFLAG; - (void) zsparam(tp, &tp->t_termios); - } else { - /* Can not run kgdb on the console? */ -#ifdef KGDB - zs_checkkgdb(unit, cs, tp); -#endif - } -#if 0 - /* XXX - Drop carrier here? -gwr */ - zs_modem(cs, cs->cs_softcar ? 1 : 0); -#endif + if (channel == 0) { + ZS_WRITE(cs, 9, 0); + } - if (unit == ZS_MOUSE) { /* - * Mouse: tell /dev/mouse driver how to talk to us. + * Look for a child driver for this channel. + * The child attach will setup the hardware. */ - tp->t_ispeed = tp->t_ospeed = cs->cs_speed; - tp->t_cflag = CS8; - /* zsparam called by zsiopen */ - ms_serial(tp, zsiopen, zsiclose); + zsc_args.channel = channel; + zsc_args.hwflags = zs_hwflags[zsc_unit][channel]; + if (!config_found(self, (void *) &zsc_args, zsc_print)) { + /* No sub-driver. Just reset it. */ + reset = (channel == 0) ? + ZSWR9_A_RESET : ZSWR9_B_RESET; + s = splzs(); + ZS_WRITE(cs, 9, reset); + splx(s); + } } -} -/* - * XXX - Temporary hack... - */ -struct tty * -zstty(dev) - dev_t dev; -{ - int unit = minor(dev); + /* Now safe to install interrupt handlers */ + if (!didintr) { + didintr = 1; + isr_add_autovect(zssoft, NULL, ZSSOFT_PRI); + isr_add_autovect(zshard, NULL, ZSHARD_PRI); + } - return (zs_tty[unit]); + /* + * Set the master interrupt enable and interrupt vector. + * (common to both channels, do it on A) + */ + cs = &zsc->zsc_cs[0]; + s = splzs(); + /* interrupt vector */ + ZS_WRITE(cs, 2, zs_init_reg[2]); + /* master interrupt control (enable) */ + ZS_WRITE(cs, 9, zs_init_reg[9]); + splx(s); } -/* - * Put a channel in a known state. Interrupts may be left disabled - * or enabled, as desired. (Used only by kgdb) - */ -static void -zs_reset(zc, inten, speed) - volatile struct zschan *zc; - int inten, speed; +static int +zshard(arg) + void *arg; { - int tconst; - u_char reg[16]; - - bcopy(zs_init_reg, reg, 16); - if (inten) - reg[9] |= ZSWR9_MASTER_IE; - - tconst = BPS_TO_TCONST(PCLK / 16, speed); - reg[12] = tconst; - reg[13] = tconst >> 8; - zs_loadchannelregs(zc, reg); + struct zsc_softc *zsc; + int unit, rval; + + /* Do ttya/ttyb first, because they go faster. */ + rval = 0; + unit = zsccd.cd_ndevs; + while (--unit >= 0) { + zsc = zsccd.cd_devs[unit]; + if (zsc != NULL) { + rval |= zsc_intr_hard(zsc); + } + } + return (rval); } -/* - * Console support - */ +int zssoftpending; -/* - * Used by the kd driver to find out if it can work. - */ -int -zscnprobe_kbd() -{ - if (zsaddr[1] == NULL) { - mon_printf("zscnprobe_kbd: zs1 not yet mapped\n"); - return CN_DEAD; +void +zsc_req_softint(zsc) + struct zsc_softc *zsc; +{ + if (zssoftpending == 0) { + /* We are at splzs here, so no need to lock. */ + zssoftpending = ZSSOFT_PRI; + isr_soft_request(ZSSOFT_PRI); } - return CN_INTERNAL; } -/* - * This is the console probe routine for ttya and ttyb. - */ static int -zscnprobe(struct consdev *cn, int unit) +zssoft(arg) + void *arg; { - int maj; - - if (zsaddr[0] == NULL) { - mon_printf("zscnprobe: zs0 not mapped\n"); - cn->cn_pri = CN_DEAD; - return 0; - } - /* XXX - Also try to make sure it exists? */ - - /* locate the major number */ - for (maj = 0; maj < nchrdev; maj++) - if (cdevsw[maj].d_open == (void*)zsopen) - break; + struct zsc_softc *zsc; + int unit; - cn->cn_dev = makedev(maj, unit); + /* This is not the only ISR on this IPL. */ + if (zssoftpending == 0) + return (0); - /* Use EEPROM console setting to decide "remote" console. */ - /* Note: EE_CONS_TTYA + 1 == EE_CONS_TTYB */ - if (ee_console == (EE_CONS_TTYA + unit)) { - cn->cn_pri = CN_REMOTE; - } else { - cn->cn_pri = CN_NORMAL; + /* + * The soft intr. bit will be set by zshard only if + * the variable zssoftpending is zero. The order of + * these next two statements prevents our clearing + * the soft intr bit just after zshard has set it. + */ + isr_soft_clear(ZSSOFT_PRI); + zssoftpending = 0; + + /* Do ttya/ttyb first, because they go faster. */ + unit = zsccd.cd_ndevs; + while (--unit >= 0) { + zsc = zsccd.cd_devs[unit]; + if (zsc != NULL) { + (void) zsc_intr_soft(zsc); + } } - return (0); + return (1); } -/* This is the constab entry for TTYA. */ -int -zscnprobe_a(struct consdev *cn) -{ - return (zscnprobe(cn, 0)); -} -/* This is the constab entry for TTYB. */ -int -zscnprobe_b(struct consdev *cn) -{ - return (zscnprobe(cn, 1)); -} +/* + * Read or write the chip with suitable delays. + */ -/* Called by kdcninit() or below. */ -void -zs_set_conschan(unit, ab) - int unit, ab; +u_char +zs_read_reg(cs, reg) + struct zs_chanstate *cs; + u_char reg; { - volatile struct zsdevice *addr; + u_char val; - addr = zsaddr[unit]; - zs_conschan = ((ab == 0) ? - &addr->zs_chan[ZS_CHAN_A] : - &addr->zs_chan[ZS_CHAN_B] ); + *cs->cs_reg_csr = reg; + ZS_DELAY(); + val = *cs->cs_reg_csr; + ZS_DELAY(); + return val; } -/* Attach as console. Also set zs_conschan */ -int -zscninit(struct consdev *cn) +void +zs_write_reg(cs, reg, val) + struct zs_chanstate *cs; + u_char reg, val; { - int ab = minor(cn->cn_dev) & 1; - zs_set_conschan(0, ab); - mon_printf("console on zs0 (tty%c)\n", 'a' + ab); + *cs->cs_reg_csr = reg; + ZS_DELAY(); + *cs->cs_reg_csr = val; + ZS_DELAY(); } +/**************************************************************** + * Console support functions (Sun3 specific!) + ****************************************************************/ /* - * Polled console input putchar. + * Polled input char. */ int -zscngetc(dev) - dev_t dev; +zs_getc(arg) + void *arg; { - register volatile struct zschan *zc = zs_conschan; + register volatile struct zschan *zc = arg; register int s, c, rr0; - if (zc == NULL) - return (0); - s = splhigh(); - /* Wait for a character to arrive. */ do { rr0 = zc->zc_csr; @@ -521,7 +438,6 @@ zscngetc(dev) c = zc->zc_data; ZS_DELAY(); - splx(s); /* @@ -532,24 +448,17 @@ zscngetc(dev) } /* - * Polled console output putchar. + * Polled output char. */ -int -zscnputc(dev, c) - dev_t dev; +void +zs_putc(arg, c) + void *arg; int c; { - register volatile struct zschan *zc = zs_conschan; + register volatile struct zschan *zc = arg; register int s, rr0; - if (zc == NULL) { - s = splhigh(); - mon_putchar(c); - splx(s); - return (0); - } s = splhigh(); - /* Wait for transmitter to become ready. */ do { rr0 = zc->zc_csr; @@ -561,1105 +470,132 @@ zscnputc(dev, c) splx(s); } -#ifdef KGDB -/* - * The kgdb zs port, if any, was altered at boot time (see zs_kgdb_init). - * Pick up the current speed and character size and restore the original - * speed. - */ -static void -zs_checkkgdb(int unit, struct zs_chanstate *cs, struct tty *tp) -{ - - if (kgdb_dev == makedev(ZSMAJOR, unit)) { - tp->t_ispeed = tp->t_ospeed = kgdb_rate; - tp->t_cflag = CS8; - cs->cs_kgdb = 1; - cs->cs_speed = zs_kgdb_savedspeed; - (void) zsparam(tp, &tp->t_termios); - } -} -#endif - -/* - * Compute the current baud rate given a ZSCC channel. - */ -static int -zs_getspeed(zc) - register volatile struct zschan *zc; -{ - register int tconst; - - tconst = ZS_READ(zc, 12); - tconst |= ZS_READ(zc, 13) << 8; - return (TCONST_TO_BPS(PCLK / 16, tconst)); -} - +extern struct consdev consdev_kd; /* keyboard/display */ +extern struct consdev consdev_tty; +extern struct consdev *cn_tab; /* physical console device info */ +extern void nullcnpollc(); -/* - * Do an internal open. - */ -static void -zsiopen(tp) - struct tty *tp; -{ - - (void) zsparam(tp, &tp->t_termios); - ttsetwater(tp); - tp->t_state = TS_ISOPEN | TS_CARR_ON; -} +void *zs_conschan; /* - * Do an internal close. Eventually we should shut off the chip when both - * ports on it are closed. + * This function replaces sys/dev/cninit.c + * Determine which device is the console using + * the "console" byte from the EEPROM. */ -static void -zsiclose(tp) - struct tty *tp; +void +cninit() { + struct zschan *zc; + struct consdev *cn; + int zsc_unit, channel; - ttylclose(tp, 0); /* ??? */ - ttyclose(tp); /* ??? */ - tp->t_state = 0; -} + switch (ee_console) { + case EE_CONS_TTYA: + case EE_CONS_TTYB: + zsc_unit = 1; + channel = (ee_console & 1); + cn = &consdev_tty; + cn->cn_dev = makedev(ZSTTY_MAJOR, channel); + cn->cn_pri = CN_REMOTE; + break; -/* - * Open a zs serial port. This interface may not be used to open - * the keyboard and mouse ports. (XXX) - */ -int -zsopen(dev, flags, mode, p) - dev_t dev; - int flags; - int mode; - struct proc *p; -{ - register struct tty *tp; - register struct zs_chanstate *cs; - struct zsinfo *zi; - int unit = minor(dev), zs = unit >> 1, error, s; - -#ifdef DEBUG - mon_printf("zs_open\n"); -#endif - if (zs >= zscd.cd_ndevs || (zi = zscd.cd_devs[zs]) == NULL || - unit == ZS_KBD || unit == ZS_MOUSE) - return (ENXIO); - cs = &zi->zi_cs[unit & 1]; - tp = cs->cs_ttyp; - s = spltty(); - if ((tp->t_state & TS_ISOPEN) == 0) { - ttychars(tp); - tp->t_iflag = TTYDEF_IFLAG; - tp->t_oflag = TTYDEF_OFLAG; - tp->t_cflag = TTYDEF_CFLAG; - tp->t_lflag = TTYDEF_LFLAG; - tp->t_ispeed = tp->t_ospeed = cs->cs_speed; - (void) zsparam(tp, &tp->t_termios); - ttsetwater(tp); - } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { - splx(s); - return (EBUSY); - } - error = 0; -#ifdef DEBUG - mon_printf("wait for carrier...\n"); -#endif - for (;;) { - register int rr0; - - /* loop, turning on the device, until carrier present */ - zs_modem(cs, 1); - /* May never get status intr if carrier already on. -gwr */ - rr0 = cs->cs_zc->zc_csr; - ZS_DELAY(); - if (rr0 & ZSRR0_DCD) - tp->t_state |= TS_CARR_ON; - if (cs->cs_softcar) - tp->t_state |= TS_CARR_ON; - if (flags & O_NONBLOCK || tp->t_cflag & CLOCAL || - tp->t_state & TS_CARR_ON) - break; - tp->t_state |= TS_WOPEN; - if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, - ttopen, 0)) { - if (!(tp->t_state & TS_ISOPEN)) { - zs_modem(cs, 0); - tp->t_state &= ~TS_WOPEN; - ttwakeup(tp); - } - splx(s); - return error; - } + default: + mon_printf("cninit: unknown eeprom console setting\n"); + /* assume keyboard/display */ + /* fallthrough */ + case EE_CONS_BW: + case EE_CONS_COLOR: + case EE_CONS_P4OPT: + zsc_unit = 0; + channel = 0; + cn = &consdev_kd; + /* Set cn_dev, cn_pri in kd.c */ + break; } -#ifdef DEBUG - mon_printf("...carrier %s\n", - (tp->t_state & TS_CARR_ON) ? "on" : "off"); -#endif - splx(s); - if (error == 0) - error = linesw[tp->t_line].l_open(dev, tp); - if (error) - zs_modem(cs, 0); - return (error); -} -/* - * Close a zs serial port. - */ -int -zsclose(dev, flags, mode, p) - dev_t dev; - int flags; - int mode; - struct proc *p; -{ - register struct zs_chanstate *cs; - register struct tty *tp; - struct zsinfo *zi; - int unit = minor(dev), s; - -#ifdef DEBUG - mon_printf("zs_close\n"); -#endif - zi = zscd.cd_devs[unit >> 1]; - cs = &zi->zi_cs[unit & 1]; - tp = cs->cs_ttyp; - linesw[tp->t_line].l_close(tp, flags); - if (tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN || - (tp->t_state & TS_ISOPEN) == 0) { - zs_modem(cs, 0); - /* hold low for 1 second */ - (void) tsleep((caddr_t)cs, TTIPRI, ttclos, hz); - } - if (cs->cs_creg[5] & ZSWR5_BREAK) - { - s = splzs(); - cs->cs_preg[5] &= ~ZSWR5_BREAK; - cs->cs_creg[5] &= ~ZSWR5_BREAK; - ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]); - splx(s); - } - ttyclose(tp); -#ifdef KGDB - /* Reset the speed if we're doing kgdb on this port */ - if (cs->cs_kgdb) { - tp->t_ispeed = tp->t_ospeed = kgdb_rate; - (void) zsparam(tp, &tp->t_termios); + zc = zs_get_chan_addr(zsc_unit, channel); + if (zc == NULL) { + mon_printf("cninit: zs not mapped.\n"); + return; } -#endif - return (0); + zs_conschan = zc; + zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE; + cn_tab = cn; + (*cn->cn_init)(cn); } -/* - * Read/write zs serial port. - */ -int -zsread(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - register struct tty *tp = zs_tty[minor(dev)]; - return (linesw[tp->t_line].l_read(tp, uio, flags)); +/* We never call this. */ +void +nullcnprobe(cn) + struct consdev *cn; +{ } -int -zswrite(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; +void +zscninit(cn) + struct consdev *cn; { - register struct tty *tp = zs_tty[minor(dev)]; + int unit = minor(cn->cn_dev) & 1; - return (linesw[tp->t_line].l_write(tp, uio, flags)); + mon_printf("console is zstty%d (tty%c)\n", + unit, unit + 'a'); } /* - * ZS hardware interrupt. Scan all ZS channels. NB: we know here that - * channels are kept in (A,B) pairs. - * - * Do just a little, then get out; set a software interrupt if more - * work is needed. - * - * We deliberately ignore the vectoring Zilog gives us, and match up - * only the number of `reset interrupt under service' operations, not - * the order. + * Polled console input putchar. */ -/* ARGSUSED */ int -zshard(intrarg) - int intrarg; -{ - register struct zs_chanstate *a; -#define b (a + 1) - register volatile struct zschan *zc; - register int rr3, intflags = 0, v, i; - static int zsrint(struct zs_chanstate *, volatile struct zschan *); - static int zsxint(struct zs_chanstate *, volatile struct zschan *); - static int zssint(struct zs_chanstate *, volatile struct zschan *); - - for (a = zslist; a != NULL; a = b->cs_next) { - rr3 = ZS_READ(a->cs_zc, 3); - - /* XXX - This should loop to empty the on-chip fifo. */ - if (rr3 & (ZSRR3_IP_A_RX|ZSRR3_IP_A_TX|ZSRR3_IP_A_STAT)) { - intflags |= 2; - zc = a->cs_zc; - i = a->cs_rbput; - if (rr3 & ZSRR3_IP_A_RX && (v = zsrint(a, zc)) != 0) { - a->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - if (rr3 & ZSRR3_IP_A_TX && (v = zsxint(a, zc)) != 0) { - a->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - if (rr3 & ZSRR3_IP_A_STAT && (v = zssint(a, zc)) != 0) { - a->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - a->cs_rbput = i; - } - - /* XXX - This should loop to empty the on-chip fifo. */ - if (rr3 & (ZSRR3_IP_B_RX|ZSRR3_IP_B_TX|ZSRR3_IP_B_STAT)) { - intflags |= 2; - zc = b->cs_zc; - i = b->cs_rbput; - if (rr3 & ZSRR3_IP_B_RX && (v = zsrint(b, zc)) != 0) { - b->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - if (rr3 & ZSRR3_IP_B_TX && (v = zsxint(b, zc)) != 0) { - b->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - if (rr3 & ZSRR3_IP_B_STAT && (v = zssint(b, zc)) != 0) { - b->cs_rbuf[i++ & ZLRB_RING_MASK] = v; - intflags |= 1; - } - b->cs_rbput = i; - } - } -#undef b - if (intflags & 1) { - if (zssoftpending == 0) { - /* We are at splzs here, so no need to lock. */ - zssoftpending = ZSSOFT_PRI; - isr_soft_request(ZSSOFT_PRI); - } - } - return (intflags & 2); -} - -static int -zsrint(cs, zc) - register struct zs_chanstate *cs; - register volatile struct zschan *zc; +zscngetc(dev) + dev_t dev; { + register volatile struct zschan *zc = zs_conschan; register int c; - c = zc->zc_data; - ZS_DELAY(); - - if (cs->cs_conk) { - register struct conk_state *conk = &zsconk_state; - - /* - * Check here for console abort function, so that we - * can abort even when interrupts are locking up the - * machine. - */ - if (c == KBD_RESET) { - conk->conk_id = 1; /* ignore next byte */ - conk->conk_l1 = 0; - } else if (conk->conk_id) - conk->conk_id = 0; /* stop ignoring bytes */ - else if (c == KBD_L1) - conk->conk_l1 = 1; /* L1 went down */ - else if (c == (KBD_L1|KBD_UP)) - conk->conk_l1 = 0; /* L1 went up */ - else if (c == KBD_A && conk->conk_l1) { - zsabort(); - /* Debugger done. Send L1-up in case X is running. */ - conk->conk_l1 = 0; - c = (KBD_L1|KBD_UP); - } - } -#ifdef KGDB - if (c == FRAME_START && cs->cs_kgdb && - (cs->cs_ttyp->t_state & TS_ISOPEN) == 0) { - zskgdb(cs->cs_unit); - c = 0; - goto clearit; - } -#endif - /* compose receive character and status */ - c <<= 8; - c |= ZS_READ(zc, 1); - c = ZRING_MAKE(ZRING_RINT, c); - -clearit: - /* clear receive error & interrupt condition */ - zc->zc_csr = ZSWR0_RESET_ERRORS; - ZS_DELAY(); - zc->zc_csr = ZSWR0_CLR_INTR; - ZS_DELAY(); + c = zs_getc(zc); return (c); } -static int -zsxint(cs, zc) - register struct zs_chanstate *cs; - register volatile struct zschan *zc; -{ - register int i = cs->cs_tbc; - - if (i == 0) { - zc->zc_csr = ZSWR0_RESET_TXINT; - ZS_DELAY(); - zc->zc_csr = ZSWR0_CLR_INTR; - ZS_DELAY(); - return (ZRING_MAKE(ZRING_XINT, 0)); - } - cs->cs_tbc = i - 1; - zc->zc_data = *cs->cs_tba++; - ZS_DELAY(); - zc->zc_csr = ZSWR0_CLR_INTR; - ZS_DELAY(); - return (0); -} - -static int -zssint(cs, zc) - register struct zs_chanstate *cs; - register volatile struct zschan *zc; -{ - register int rr0; - - rr0 = zc->zc_csr; - ZS_DELAY(); - zc->zc_csr = ZSWR0_RESET_STATUS; - ZS_DELAY(); - zc->zc_csr = ZSWR0_CLR_INTR; - ZS_DELAY(); - /* - * The chip's hardware flow control is, as noted in zsreg.h, - * busted---if the DCD line goes low the chip shuts off the - * receiver (!). If we want hardware CTS flow control but do - * not have it, and carrier is now on, turn HFC on; if we have - * HFC now but carrier has gone low, turn it off. - */ - if (rr0 & ZSRR0_DCD) { - if (cs->cs_ttyp->t_cflag & CCTS_OFLOW && - (cs->cs_creg[3] & ZSWR3_HFC) == 0) { - cs->cs_creg[3] |= ZSWR3_HFC; - ZS_WRITE(zc, 3, cs->cs_creg[3]); - } - } else { - if (cs->cs_creg[3] & ZSWR3_HFC) { - cs->cs_creg[3] &= ~ZSWR3_HFC; - ZS_WRITE(zc, 3, cs->cs_creg[3]); - } - } - if ((rr0 & ZSRR0_BREAK) && cs->cs_brkabort) { - /* Wait for end of break to avoid PROM abort. */ - do { - rr0 = zc->zc_csr; - ZS_DELAY(); - } while (rr0 & ZSRR0_BREAK); - zsabort(); - return (0); - } - return (ZRING_MAKE(ZRING_SINT, rr0)); -} - -zsabort() -{ - /* XXX - Always available, but may be the PROM monitor. */ - Debugger(); -} - -#ifdef KGDB /* - * KGDB framing character received: enter kernel debugger. This probably - * should time out after a few seconds to avoid hanging on spurious input. - */ -zskgdb(unit) - int unit; -{ - - printf("zs%d%c: kgdb interrupt\n", unit >> 1, (unit & 1) + 'a'); - kgdb_connect(1); -} -#endif - -/* - * Print out a ring or fifo overrun error message. - */ -static void -zsoverrun(unit, ptime, what) - int unit; - long *ptime; - char *what; -{ - - if (*ptime != time.tv_sec) { - *ptime = time.tv_sec; - log(LOG_WARNING, "zs%d%c: %s overrun\n", unit >> 1, - (unit & 1) + 'a', what); - } -} - -/* - * ZS software interrupt. Scan all channels for deferred interrupts. + * Polled console output putchar. */ -int -zssoft(arg) - int arg; -{ - register struct zs_chanstate *cs; - register volatile struct zschan *zc; - register struct linesw *line; - register struct tty *tp; - register int get, n, c, cc, unit, s; - - /* This is not the only ISR on this IPL. */ - if (zssoftpending == 0) - return (0); - - /* - * The soft intr. bit will be set by zshard only if - * the variable zssoftpending is zero. The order of - * these next two statements prevents our clearing - * the soft intr bit just after zshard has set it. - */ - isr_soft_clear(ZSSOFT_PRI); - zssoftpending = 0; /* Now zshard may set it again. */ - - for (cs = zslist; cs != NULL; cs = cs->cs_next) { - get = cs->cs_rbget; -again: - n = cs->cs_rbput; /* atomic */ - if (get == n) /* nothing more on this line */ - continue; - unit = cs->cs_unit; /* set up to handle interrupts */ - zc = cs->cs_zc; - tp = cs->cs_ttyp; - line = &linesw[tp->t_line]; - /* - * Compute the number of interrupts in the receive ring. - * If the count is overlarge, we lost some events, and - * must advance to the first valid one. It may get - * overwritten if more data are arriving, but this is - * too expensive to check and gains nothing (we already - * lost out; all we can do at this point is trade one - * kind of loss for another). - */ - n -= get; - if (n > ZLRB_RING_SIZE) { - zsoverrun(unit, &cs->cs_rotime, "ring"); - get += n - ZLRB_RING_SIZE; - n = ZLRB_RING_SIZE; - } - while (--n >= 0) { - /* race to keep ahead of incoming interrupts */ - c = cs->cs_rbuf[get++ & ZLRB_RING_MASK]; - switch (ZRING_TYPE(c)) { - - case ZRING_RINT: - c = ZRING_VALUE(c); - if (c & ZSRR1_DO) - zsoverrun(unit, &cs->cs_fotime, "fifo"); - cc = c >> 8; - if (c & ZSRR1_FE) - cc |= TTY_FE; - if (c & ZSRR1_PE) - cc |= TTY_PE; - /* - * this should be done through - * bstreams XXX gag choke - */ - if (unit == ZS_KBD) - kbd_rint(cc); - else if (unit == ZS_MOUSE) - ms_rint(cc); - else - line->l_rint(cc, tp); - break; - - case ZRING_XINT: - /* - * Transmit done: change registers and resume, - * or clear BUSY. - */ - if (cs->cs_heldchange) { - s = splzs(); - c = zc->zc_csr; - ZS_DELAY(); - if ((c & ZSRR0_DCD) == 0) - cs->cs_preg[3] &= ~ZSWR3_HFC; - bcopy((caddr_t)cs->cs_preg, - (caddr_t)cs->cs_creg, 16); - zs_loadchannelregs(zc, cs->cs_creg); - splx(s); - cs->cs_heldchange = 0; - if (cs->cs_heldtbc && - (tp->t_state & TS_TTSTOP) == 0) { - cs->cs_tbc = cs->cs_heldtbc - 1; - zc->zc_data = *cs->cs_tba++; - ZS_DELAY(); - goto again; - } - } - tp->t_state &= ~TS_BUSY; - if (tp->t_state & TS_FLUSH) - tp->t_state &= ~TS_FLUSH; - else - ndflush(&tp->t_outq, cs->cs_tba - - (caddr_t) tp->t_outq.c_cf); - line->l_start(tp); - break; - - case ZRING_SINT: - /* - * Status line change. HFC bit is run in - * hardware interrupt, to avoid locking - * at splzs here. - */ - c = ZRING_VALUE(c); - if ((c ^ cs->cs_rr0) & ZSRR0_DCD) { - cc = (c & ZSRR0_DCD) != 0; - if (line->l_modem(tp, cc) == 0) - zs_modem(cs, cc); - } - cs->cs_rr0 = c; - break; - - default: - log(LOG_ERR, "zs%d%c: bad ZRING_TYPE (%x)\n", - unit >> 1, (unit & 1) + 'a', c); - break; - } - } - cs->cs_rbget = get; - goto again; - } - return (1); -} - -int -zsioctl(dev, cmd, data, flag, p) +void +zscnputc(dev, c) dev_t dev; - u_long cmd; - caddr_t data; - int flag; - struct proc *p; + int c; { - int unit = minor(dev); - struct zsinfo *zi = zscd.cd_devs[unit >> 1]; - register struct zs_chanstate *cs = &zi->zi_cs[unit & 1]; - register struct tty *tp = cs->cs_ttyp; - register int error, s; - - error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p); - if (error >= 0) - return (error); - error = ttioctl(tp, cmd, data, flag, p); - if (error >= 0) - return (error); - - switch (cmd) { - - case TIOCSBRK: - s = splzs(); - cs->cs_preg[5] |= ZSWR5_BREAK; - cs->cs_creg[5] |= ZSWR5_BREAK; - ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]); - splx(s); - break; - - case TIOCCBRK: - s = splzs(); - cs->cs_preg[5] &= ~ZSWR5_BREAK; - cs->cs_creg[5] &= ~ZSWR5_BREAK; - ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]); - splx(s); - break; - - case TIOCGFLAGS: { - int bits = 0; - - if (cs->cs_softcar) - bits |= TIOCFLAG_SOFTCAR; - if (cs->cs_creg[15] & ZSWR15_DCD_IE) - bits |= TIOCFLAG_CLOCAL; - if (cs->cs_creg[3] & ZSWR3_HFC) - bits |= TIOCFLAG_CRTSCTS; - *(int *)data = bits; - break; - } - - case TIOCSFLAGS: { - int userbits, driverbits = 0; - - error = suser(p->p_ucred, &p->p_acflag); - if (error != 0) - return (EPERM); - - userbits = *(int *)data; - - /* - * can have `local' or `softcar', and `rtscts' or `mdmbuf' - * defaulting to software flow control. - */ - if (userbits & TIOCFLAG_SOFTCAR && userbits & TIOCFLAG_CLOCAL) - return(EINVAL); - if (userbits & TIOCFLAG_MDMBUF) /* don't support this (yet?) */ - return(ENXIO); - - s = splzs(); - if ((userbits & TIOCFLAG_SOFTCAR) || - (cs->cs_zc == zs_conschan)) - { - cs->cs_softcar = 1; /* turn on softcar */ - cs->cs_preg[15] &= ~ZSWR15_DCD_IE; /* turn off dcd */ - cs->cs_creg[15] &= ~ZSWR15_DCD_IE; - ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]); - } else if (userbits & TIOCFLAG_CLOCAL) { - cs->cs_softcar = 0; /* turn off softcar */ - cs->cs_preg[15] |= ZSWR15_DCD_IE; /* turn on dcd */ - cs->cs_creg[15] |= ZSWR15_DCD_IE; - ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]); - tp->t_termios.c_cflag |= CLOCAL; - } - if (userbits & TIOCFLAG_CRTSCTS) { - cs->cs_preg[15] |= ZSWR15_CTS_IE; - cs->cs_creg[15] |= ZSWR15_CTS_IE; - ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]); - cs->cs_preg[3] |= ZSWR3_HFC; - cs->cs_creg[3] |= ZSWR3_HFC; - ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]); - tp->t_termios.c_cflag |= CRTSCTS; - } else { - /* no mdmbuf, so we must want software flow control */ - cs->cs_preg[15] &= ~ZSWR15_CTS_IE; - cs->cs_creg[15] &= ~ZSWR15_CTS_IE; - ZS_WRITE(cs->cs_zc, 15, cs->cs_creg[15]); - cs->cs_preg[3] &= ~ZSWR3_HFC; - cs->cs_creg[3] &= ~ZSWR3_HFC; - ZS_WRITE(cs->cs_zc, 3, cs->cs_creg[3]); - tp->t_termios.c_cflag &= ~CRTSCTS; - } - splx(s); - break; - } - - case TIOCSDTR: - zs_modem(cs, 1); - break; - case TIOCCDTR: - zs_modem(cs, 0); - break; + register volatile struct zschan *zc = zs_conschan; - case TIOCMSET: - case TIOCMBIS: - case TIOCMBIC: - case TIOCMGET: - default: - return (ENOTTY); - } - return (0); + zs_putc(zc, c); } -/* - * Start or restart transmission. - */ -static void -zsstart(tp) - register struct tty *tp; -{ - register struct zs_chanstate *cs; - register int s, nch; - int unit = minor(tp->t_dev); - struct zsinfo *zi = zscd.cd_devs[unit >> 1]; - cs = &zi->zi_cs[unit & 1]; - s = spltty(); - - /* - * If currently active or delaying, no need to do anything. - */ - if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) - goto out; - - /* - * If there are sleepers, and output has drained below low - * water mark, awaken. - */ - if (tp->t_outq.c_cc <= tp->t_lowat) { - if (tp->t_state & TS_ASLEEP) { - tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); - } - selwakeup(&tp->t_wsel); - } +struct consdev consdev_tty = { + nullcnprobe, + zscninit, + zscngetc, + zscnputc, + nullcnpollc, +}; - nch = ndqb(&tp->t_outq, 0); /* XXX */ - if (nch) { - register char *p = tp->t_outq.c_cf; - - /* mark busy, enable tx done interrupts, & send first byte */ - tp->t_state |= TS_BUSY; - (void) splzs(); - cs->cs_preg[1] |= ZSWR1_TIE; - cs->cs_creg[1] |= ZSWR1_TIE; - ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]); - cs->cs_zc->zc_data = *p; - ZS_DELAY(); - cs->cs_tba = p + 1; - cs->cs_tbc = nch - 1; - } else { - /* - * Nothing to send, turn off transmit done interrupts. - * This is useful if something is doing polled output. - */ - (void) splzs(); - cs->cs_preg[1] &= ~ZSWR1_TIE; - cs->cs_creg[1] &= ~ZSWR1_TIE; - ZS_WRITE(cs->cs_zc, 1, cs->cs_creg[1]); - } -out: - splx(s); -} /* - * Stop output, e.g., for ^S or output flush. + * Handle user request to enter kernel debugger. */ void -zsstop(tp, flag) - register struct tty *tp; - int flag; -{ - register struct zs_chanstate *cs; - register int s, unit = minor(tp->t_dev); - struct zsinfo *zi = zscd.cd_devs[unit >> 1]; - - cs = &zi->zi_cs[unit & 1]; - s = splzs(); - if (tp->t_state & TS_BUSY) { - /* - * Device is transmitting; must stop it. - */ - cs->cs_tbc = 0; - if ((tp->t_state & TS_TTSTOP) == 0) - tp->t_state |= TS_FLUSH; - } - splx(s); -} - -/* - * Set ZS tty parameters from termios. - */ -static int -zsparam(tp, t) - register struct tty *tp; - register struct termios *t; -{ - int unit = minor(tp->t_dev); - struct zsinfo *zi = zscd.cd_devs[unit >> 1]; - register struct zs_chanstate *cs = &zi->zi_cs[unit & 1]; - register int tmp, tmp5, cflag, s; - - /* - * Because PCLK is only run at 4.9 MHz, the fastest we - * can go is 51200 baud (this corresponds to TC=1). - * This is somewhat unfortunate as there is no real - * reason we should not be able to handle higher rates. - */ - tmp = t->c_ospeed; - if (tmp < 0 || (t->c_ispeed && t->c_ispeed != tmp)) - return (EINVAL); - if (tmp == 0) { - /* stty 0 => drop DTR and RTS */ - zs_modem(cs, 0); - return (0); - } - tmp = BPS_TO_TCONST(PCLK / 16, tmp); - if (tmp < 2) - return (EINVAL); - - cflag = t->c_cflag; - tp->t_ispeed = tp->t_ospeed = TCONST_TO_BPS(PCLK / 16, tmp); - tp->t_cflag = cflag; - - /* - * Block interrupts so that state will not - * be altered until we are done setting it up. - */ - s = splzs(); - bcopy(zs_init_reg, cs->cs_preg, 16); - cs->cs_preg[12] = tmp; - cs->cs_preg[13] = tmp >> 8; - cs->cs_preg[9] |= ZSWR9_MASTER_IE; - switch (cflag & CSIZE) { - case CS5: - tmp = ZSWR3_RX_5; - tmp5 = ZSWR5_TX_5; - break; - case CS6: - tmp = ZSWR3_RX_6; - tmp5 = ZSWR5_TX_6; - break; - case CS7: - tmp = ZSWR3_RX_7; - tmp5 = ZSWR5_TX_7; - break; - case CS8: - default: - tmp = ZSWR3_RX_8; - tmp5 = ZSWR5_TX_8; - break; - } - - /* - * Output hardware flow control on the chip is horrendous: if - * carrier detect drops, the receiver is disabled. Hence we - * can only do this when the carrier is on. - */ - tmp |= ZSWR3_RX_ENABLE; - if (cflag & CCTS_OFLOW) { - if (cs->cs_zc->zc_csr & ZSRR0_DCD) - tmp |= ZSWR3_HFC; - ZS_DELAY(); - } - - cs->cs_preg[3] = tmp; - cs->cs_preg[5] = tmp5 | ZSWR5_TX_ENABLE | ZSWR5_DTR | ZSWR5_RTS; - - tmp = ZSWR4_CLK_X16 | (cflag & CSTOPB ? ZSWR4_TWOSB : ZSWR4_ONESB); - if ((cflag & PARODD) == 0) - tmp |= ZSWR4_EVENP; - if (cflag & PARENB) - tmp |= ZSWR4_PARENB; - cs->cs_preg[4] = tmp; - - /* - * If nothing is being transmitted, set up new current values, - * else mark them as pending. - */ - if (cs->cs_heldchange == 0) { - if (cs->cs_ttyp->t_state & TS_BUSY) { - cs->cs_heldtbc = cs->cs_tbc; - cs->cs_tbc = 0; - cs->cs_heldchange = 1; - } else { - bcopy((caddr_t)cs->cs_preg, (caddr_t)cs->cs_creg, 16); - zs_loadchannelregs(cs->cs_zc, cs->cs_creg); - } - } - splx(s); - return (0); -} - -/* - * Raise or lower modem control (DTR/RTS) signals. If a character is - * in transmission, the change is deferred. - */ -static void -zs_modem(cs, onoff) - struct zs_chanstate *cs; - int onoff; -{ - int s, bis, and; - - if (onoff) { - bis = ZSWR5_DTR | ZSWR5_RTS; - and = ~0; - } else { - bis = 0; - and = ~(ZSWR5_DTR | ZSWR5_RTS); - } - s = splzs(); - cs->cs_preg[5] = (cs->cs_preg[5] | bis) & and; - if (cs->cs_heldchange == 0) { - if (cs->cs_ttyp->t_state & TS_BUSY) { - cs->cs_heldtbc = cs->cs_tbc; - cs->cs_tbc = 0; - cs->cs_heldchange = 1; - } else { - cs->cs_creg[5] = (cs->cs_creg[5] | bis) & and; - ZS_WRITE(cs->cs_zc, 5, cs->cs_creg[5]); - } - } - splx(s); -} - -/* - * Write the given register set to the given zs channel in the proper order. - * The channel must not be transmitting at the time. The receiver will - * be disabled for the time it takes to write all the registers. - */ -static void -zs_loadchannelregs(zc, reg) - volatile struct zschan *zc; - u_char *reg; -{ - int i; - - zc->zc_csr = ZSM_RESET_ERR; /* reset error condition */ - ZS_DELAY(); - -#if 1 /* XXX - Is this really a good idea? -gwr */ - i = zc->zc_data; /* drain fifo */ - ZS_DELAY(); - i = zc->zc_data; - ZS_DELAY(); - i = zc->zc_data; - ZS_DELAY(); -#endif - - /* baud clock divisor, stop bits, parity */ - ZS_WRITE(zc, 4, reg[4]); - - /* misc. TX/RX control bits */ - ZS_WRITE(zc, 10, reg[10]); - - /* char size, enable (RX/TX) */ - ZS_WRITE(zc, 3, reg[3] & ~ZSWR3_RX_ENABLE); - ZS_WRITE(zc, 5, reg[5] & ~ZSWR5_TX_ENABLE); - - /* interrupt enables: TX, TX, STATUS */ - ZS_WRITE(zc, 1, reg[1]); - - /* interrupt vector */ - ZS_WRITE(zc, 2, reg[2]); - - /* master interrupt control */ - ZS_WRITE(zc, 9, reg[9]); - - /* clock mode control */ - ZS_WRITE(zc, 11, reg[11]); - - /* baud rate (lo/hi) */ - ZS_WRITE(zc, 12, reg[12]); - ZS_WRITE(zc, 13, reg[13]); - - /* Misc. control bits */ - ZS_WRITE(zc, 14, reg[14]); - - /* which lines cause status interrupts */ - ZS_WRITE(zc, 15, reg[15]); - - /* char size, enable (RX/TX)*/ - ZS_WRITE(zc, 3, reg[3]); - ZS_WRITE(zc, 5, reg[5]); -} - -static u_char -zs_read(zc, reg) - volatile struct zschan *zc; - u_char reg; -{ - u_char val; - - zc->zc_csr = reg; - ZS_DELAY(); - val = zc->zc_csr; - ZS_DELAY(); - return val; -} - -static u_char -zs_write(zc, reg, val) - volatile struct zschan *zc; - u_char reg, val; -{ - zc->zc_csr = reg; - ZS_DELAY(); - zc->zc_csr = val; - ZS_DELAY(); - return val; -} - -#ifdef KGDB -/* - * Get a character from the given kgdb channel. Called at splhigh(). - * XXX - Add delays, or combine with zscngetc()... - */ -static int -zs_kgdb_getc(arg) - void *arg; -{ - register volatile struct zschan *zc = (volatile struct zschan *)arg; - register int c, rr0; - - do { - rr0 = zc->zc_csr; - ZS_DELAY(); - } while ((rr0 & ZSRR0_RX_READY) == 0); - c = zc->zc_data; - ZS_DELAY(); - return (c); -} - -/* - * Put a character to the given kgdb channel. Called at splhigh(). - */ -static void -zs_kgdb_putc(arg, c) - void *arg; - int c; +zs_abort() { - register volatile struct zschan *zc = (volatile struct zschan *)arg; - register int c, rr0; + register volatile struct zschan *zc = zs_conschan; + int rr0; + /* Wait for end of break to avoid PROM abort. */ + /* XXX - Limit the wait? */ do { rr0 = zc->zc_csr; ZS_DELAY(); - } while ((rr0 & ZSRR0_TX_READY) == 0); - zc->zc_data = c; - ZS_DELAY(); -} - -/* - * Set up for kgdb; called at boot time before configuration. - * KGDB interrupts will be enabled later when zs0 is configured. - */ -void -zs_kgdb_init() -{ - volatile struct zsdevice *addr; - volatile struct zschan *zc; - int unit, zs; + } while (rr0 & ZSRR0_BREAK); - if (major(kgdb_dev) != ZSMAJOR) - return; - unit = minor(kgdb_dev); - /* - * Unit must be 0 or 1 (zs0). - */ - if ((unsigned)unit >= ZS_KBD) { - printf("zs_kgdb_init: bad minor dev %d\n", unit); - return; - } - zs = unit >> 1; - unit &= 1; - - if (zsaddr[0] == NULL) - panic("kbdb_attach: zs0 not yet mapped"); - addr = zsaddr[0]; - - zc = (unit == 0) ? - &addr->zs_chan[ZS_CHAN_A] : - &addr->zs_chan[ZS_CHAN_B]; - zs_kgdb_savedspeed = zs_getspeed(zc); - printf("zs_kgdb_init: attaching zs%d%c at %d baud\n", - zs, unit + 'a', kgdb_rate); - zs_reset(zc, 1, kgdb_rate); - kgdb_attach(zs_kgdb_getc, zs_kgdb_putc, (void *)zc); + /* XXX - Always available, but may be the PROM monitor. */ + Debugger(); } -#endif /* KGDB */ |