Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.50.2.3
      1  1.50.2.3    mellon /*	$NetBSD: zs.c,v 1.50.2.3 1997/11/14 02:13:00 mellon Exp $	*/
      2      1.18   deraadt 
      3      1.50       gwr /*-
      4      1.50       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5      1.50       gwr  * All rights reserved.
      6       1.1   deraadt  *
      7      1.50       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8      1.50       gwr  * by Gordon W. Ross.
      9       1.1   deraadt  *
     10       1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     11       1.1   deraadt  * modification, are permitted provided that the following conditions
     12       1.1   deraadt  * are met:
     13       1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     14       1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     15       1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     18       1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     19       1.1   deraadt  *    must display the following acknowledgement:
     20      1.50       gwr  *        This product includes software developed by the NetBSD
     21      1.50       gwr  *        Foundation, Inc. and its contributors.
     22      1.50       gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.50       gwr  *    contributors may be used to endorse or promote products derived
     24      1.50       gwr  *    from this software without specific prior written permission.
     25      1.50       gwr  *
     26      1.50       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.50       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.50       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.50       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.50       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.50       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.50       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.50       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.50       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.50       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.50       gwr  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   deraadt  */
     38       1.1   deraadt 
     39       1.1   deraadt /*
     40      1.50       gwr  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41      1.50       gwr  *
     42      1.50       gwr  * Runs two serial lines per chip using slave drivers.
     43      1.50       gwr  * Plain tty/async lines use the zs_async slave.
     44      1.50       gwr  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     45       1.1   deraadt  */
     46      1.38       mrg 
     47       1.1   deraadt #include <sys/param.h>
     48      1.34  christos #include <sys/systm.h>
     49      1.50       gwr #include <sys/conf.h>
     50       1.1   deraadt #include <sys/device.h>
     51       1.1   deraadt #include <sys/file.h>
     52       1.1   deraadt #include <sys/ioctl.h>
     53      1.50       gwr #include <sys/kernel.h>
     54      1.50       gwr #include <sys/proc.h>
     55       1.1   deraadt #include <sys/tty.h>
     56       1.1   deraadt #include <sys/time.h>
     57       1.1   deraadt #include <sys/syslog.h>
     58       1.1   deraadt 
     59       1.1   deraadt #include <machine/autoconf.h>
     60      1.50       gwr #include <machine/bsd_openprom.h>
     61      1.37  christos #include <machine/conf.h>
     62       1.1   deraadt #include <machine/cpu.h>
     63      1.50       gwr #include <machine/eeprom.h>
     64      1.50       gwr #include <machine/psl.h>
     65      1.50       gwr #include <machine/z8530var.h>
     66      1.50       gwr 
     67      1.50       gwr #include <dev/cons.h>
     68      1.50       gwr #include <dev/ic/z8530reg.h>
     69       1.1   deraadt 
     70       1.1   deraadt #include <sparc/sparc/vaddrs.h>
     71       1.1   deraadt #include <sparc/sparc/auxreg.h>
     72      1.50       gwr #include <sparc/dev/cons.h>
     73      1.50       gwr 
     74      1.50       gwr #include "kbd.h"	/* NKBD */
     75      1.50       gwr #include "zs.h" 	/* NZS */
     76       1.1   deraadt 
     77      1.50       gwr /* Make life easier for the initialized arrays here. */
     78      1.50       gwr #if NZS < 3
     79      1.50       gwr #undef  NZS
     80      1.50       gwr #define NZS 3
     81       1.1   deraadt #endif
     82       1.1   deraadt 
     83      1.50       gwr /*
     84      1.50       gwr  * Some warts needed by z8530tty.c -
     85      1.50       gwr  * The default parity REALLY needs to be the same as the PROM uses,
     86      1.50       gwr  * or you can not see messages done with printf during boot-up...
     87      1.50       gwr  */
     88      1.50       gwr int zs_def_cflag = (CREAD | CS8 | HUPCL);
     89      1.50       gwr int zs_major = 12;
     90       1.1   deraadt 
     91      1.50       gwr /*
     92      1.50       gwr  * The Sun provides a 4.9152 MHz clock to the ZS chips.
     93      1.50       gwr  */
     94      1.50       gwr #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     95       1.1   deraadt 
     96       1.1   deraadt /*
     97       1.1   deraadt  * Select software interrupt bit based on TTY ipl.
     98       1.1   deraadt  */
     99       1.1   deraadt #if PIL_TTY == 1
    100       1.1   deraadt # define IE_ZSSOFT IE_L1
    101       1.1   deraadt #elif PIL_TTY == 4
    102       1.1   deraadt # define IE_ZSSOFT IE_L4
    103       1.1   deraadt #elif PIL_TTY == 6
    104       1.1   deraadt # define IE_ZSSOFT IE_L6
    105       1.1   deraadt #else
    106       1.1   deraadt # error "no suitable software interrupt bit"
    107       1.1   deraadt #endif
    108       1.1   deraadt 
    109  1.50.2.3    mellon /*
    110  1.50.2.3    mellon  * The next three variables provide a shortcut to the channel state
    111  1.50.2.3    mellon  * structure used by zscnputc().
    112  1.50.2.3    mellon  */
    113  1.50.2.3    mellon int zs_console_unit = -1;
    114  1.50.2.3    mellon int zs_console_channel = -1;
    115  1.50.2.3    mellon struct zs_chanstate *zs_conschanstate;
    116  1.50.2.3    mellon 
    117      1.50       gwr #define	ZS_DELAY()		(CPU_ISSUN4C ? (0) : delay(2))
    118       1.1   deraadt 
    119      1.50       gwr /* The layout of this is hardware-dependent (padding, order). */
    120      1.50       gwr struct zschan {
    121      1.50       gwr 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
    122      1.50       gwr 	u_char		zc_xxx0;
    123      1.50       gwr 	volatile u_char	zc_data;	/* data */
    124      1.50       gwr 	u_char		zc_xxx1;
    125      1.35   thorpej };
    126      1.50       gwr struct zsdevice {
    127      1.50       gwr 	/* Yes, they are backwards. */
    128      1.50       gwr 	struct	zschan zs_chan_b;
    129      1.50       gwr 	struct	zschan zs_chan_a;
    130      1.35   thorpej };
    131       1.1   deraadt 
    132      1.50       gwr /* Saved PROM mappings */
    133      1.50       gwr static struct zsdevice *zsaddr[NZS];
    134       1.1   deraadt 
    135      1.50       gwr /* Flags from cninit() */
    136      1.50       gwr static int zs_hwflags[NZS][2];
    137       1.1   deraadt 
    138      1.50       gwr /* Default speed for each channel */
    139      1.50       gwr static int zs_defspeed[NZS][2] = {
    140      1.50       gwr 	{ 9600, 	/* ttya */
    141      1.50       gwr 	  9600 },	/* ttyb */
    142      1.50       gwr 	{ 1200, 	/* keyboard */
    143      1.50       gwr 	  1200 },	/* mouse */
    144      1.50       gwr 	{ 9600, 	/* ttyc */
    145      1.50       gwr 	  9600 },	/* ttyd */
    146      1.50       gwr };
    147       1.1   deraadt 
    148      1.50       gwr static u_char zs_init_reg[16] = {
    149      1.50       gwr 	0,	/* 0: CMD (reset, etc.) */
    150      1.50       gwr 	0,	/* 1: No interrupts yet. */
    151      1.50       gwr 	0,	/* 2: IVECT */
    152      1.50       gwr 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    153      1.50       gwr 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    154      1.50       gwr 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    155      1.50       gwr 	0,	/* 6: TXSYNC/SYNCLO */
    156      1.50       gwr 	0,	/* 7: RXSYNC/SYNCHI */
    157      1.50       gwr 	0,	/* 8: alias for data port */
    158      1.50       gwr 	ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
    159      1.50       gwr 	0,	/*10: Misc. TX/RX control bits */
    160      1.50       gwr 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    161      1.50       gwr 	14,	/*12: BAUDLO (default=9600) */
    162      1.50       gwr 	0,	/*13: BAUDHI (default=9600) */
    163      1.50       gwr 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    164      1.50       gwr 	ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
    165      1.50       gwr };
    166       1.1   deraadt 
    167      1.50       gwr struct zschan *
    168      1.50       gwr zs_get_chan_addr(zs_unit, channel)
    169      1.50       gwr 	int zs_unit, channel;
    170      1.50       gwr {
    171      1.50       gwr 	struct zsdevice *addr;
    172      1.50       gwr 	struct zschan *zc;
    173      1.50       gwr 
    174      1.50       gwr 	if (zs_unit >= NZS)
    175      1.50       gwr 		return NULL;
    176      1.50       gwr 	addr = zsaddr[zs_unit];
    177      1.50       gwr 	if (addr == NULL)
    178      1.50       gwr 		addr = zsaddr[zs_unit] = findzs(zs_unit);
    179      1.50       gwr 	if (addr == NULL)
    180      1.50       gwr 		return NULL;
    181      1.50       gwr 	if (channel == 0) {
    182      1.50       gwr 		zc = &addr->zs_chan_a;
    183      1.50       gwr 	} else {
    184      1.50       gwr 		zc = &addr->zs_chan_b;
    185      1.50       gwr 	}
    186      1.50       gwr 	return (zc);
    187      1.50       gwr }
    188      1.34  christos 
    189      1.34  christos 
    190      1.50       gwr /****************************************************************
    191      1.50       gwr  * Autoconfig
    192      1.50       gwr  ****************************************************************/
    193       1.1   deraadt 
    194      1.50       gwr /* Definition of the driver for autoconfig. */
    195      1.50       gwr static int	zs_match __P((struct device *, struct cfdata *, void *));
    196      1.50       gwr static void	zs_attach __P((struct device *, struct device *, void *));
    197      1.50       gwr static int  zs_print __P((void *, const char *name));
    198       1.1   deraadt 
    199      1.50       gwr struct cfattach zs_ca = {
    200      1.50       gwr 	sizeof(struct zsc_softc), zs_match, zs_attach
    201      1.50       gwr };
    202       1.1   deraadt 
    203      1.50       gwr struct cfdriver zs_cd = {
    204      1.50       gwr 	NULL, "zs", DV_DULL
    205      1.50       gwr };
    206      1.34  christos 
    207      1.50       gwr /* Interrupt handlers. */
    208      1.50       gwr static int zshard __P((void *));
    209      1.50       gwr static int zssoft __P((void *));
    210      1.50       gwr static struct intrhand levelhard = { zshard };
    211      1.50       gwr static struct intrhand levelsoft = { zssoft };
    212      1.12   deraadt 
    213      1.50       gwr static int zs_get_speed __P((struct zs_chanstate *));
    214      1.12   deraadt 
    215      1.12   deraadt 
    216       1.1   deraadt /*
    217      1.50       gwr  * Is the zs chip present?
    218       1.1   deraadt  */
    219       1.1   deraadt static int
    220      1.50       gwr zs_match(parent, cf, aux)
    221      1.16   deraadt 	struct device *parent;
    222      1.45        pk 	struct cfdata *cf;
    223      1.45        pk 	void *aux;
    224       1.1   deraadt {
    225      1.13   deraadt 	struct confargs *ca = aux;
    226      1.13   deraadt 	struct romaux *ra = &ca->ca_ra;
    227       1.1   deraadt 
    228      1.14   deraadt 	if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
    229      1.14   deraadt 		return (0);
    230      1.33        pk 	if ((ca->ca_bustype == BUS_MAIN && !CPU_ISSUN4) ||
    231      1.33        pk 	    (ca->ca_bustype == BUS_OBIO && CPU_ISSUN4M))
    232      1.14   deraadt 		return (getpropint(ra->ra_node, "slave", -2) == cf->cf_unit);
    233      1.15   deraadt 	ra->ra_len = NBPG;
    234      1.15   deraadt 	return (probeget(ra->ra_vaddr, 1) != -1);
    235       1.1   deraadt }
    236       1.1   deraadt 
    237       1.1   deraadt /*
    238       1.1   deraadt  * Attach a found zs.
    239       1.1   deraadt  *
    240       1.1   deraadt  * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
    241       1.1   deraadt  * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
    242       1.1   deraadt  */
    243       1.1   deraadt static void
    244      1.50       gwr zs_attach(parent, self, aux)
    245      1.16   deraadt 	struct device *parent;
    246      1.50       gwr 	struct device *self;
    247      1.16   deraadt 	void *aux;
    248       1.1   deraadt {
    249      1.50       gwr 	struct zsc_softc *zsc = (void *) self;
    250      1.50       gwr 	struct confargs *ca = aux;
    251      1.50       gwr 	struct romaux *ra = &ca->ca_ra;
    252      1.50       gwr 	struct zsc_attach_args zsc_args;
    253      1.50       gwr 	volatile struct zschan *zc;
    254      1.50       gwr 	struct zs_chanstate *cs;
    255      1.50       gwr 	int pri, s, zs_unit, channel;
    256       1.1   deraadt 	static int didintr, prevpri;
    257       1.1   deraadt 
    258      1.50       gwr 	zs_unit = zsc->zsc_dev.dv_unit;
    259      1.50       gwr 
    260      1.50       gwr 	/* Use the mapping setup by the Sun PROM. */
    261      1.50       gwr 	if (zsaddr[zs_unit] == NULL)
    262      1.50       gwr 		zsaddr[zs_unit] = findzs(zs_unit);
    263      1.50       gwr 
    264      1.14   deraadt 	if (ca->ca_bustype==BUS_MAIN)
    265      1.50       gwr 		if ((void*)zsaddr[zs_unit] != ra->ra_vaddr)
    266      1.14   deraadt 			panic("zsattach");
    267       1.1   deraadt 	if (ra->ra_nintr != 1) {
    268      1.44  christos 		printf(": expected 1 interrupt, got %d\n", ra->ra_nintr);
    269       1.1   deraadt 		return;
    270       1.1   deraadt 	}
    271       1.1   deraadt 	pri = ra->ra_intr[0].int_pri;
    272      1.44  christos 	printf(" pri %d, softpri %d\n", pri, PIL_TTY);
    273      1.50       gwr 
    274      1.50       gwr 	/*
    275      1.50       gwr 	 * Initialize software state for each channel.
    276      1.50       gwr 	 */
    277      1.50       gwr 	for (channel = 0; channel < 2; channel++) {
    278      1.50       gwr 		zsc_args.channel = channel;
    279      1.50       gwr 		zsc_args.hwflags = zs_hwflags[zs_unit][channel];
    280      1.50       gwr 		cs = &zsc->zsc_cs_store[channel];
    281      1.50       gwr 		zsc->zsc_cs[channel] = cs;
    282  1.50.2.3    mellon 		if (zs_unit == zs_console_unit &&
    283  1.50.2.3    mellon 		    channel == zs_console_channel) {
    284  1.50.2.3    mellon 			zs_conschanstate = cs;
    285  1.50.2.3    mellon 		}
    286      1.50       gwr 
    287      1.50       gwr 		cs->cs_channel = channel;
    288      1.50       gwr 		cs->cs_private = NULL;
    289      1.50       gwr 		cs->cs_ops = &zsops_null;
    290      1.50       gwr 		cs->cs_brg_clk = PCLK / 16;
    291      1.50       gwr 
    292      1.50       gwr 		zc = zs_get_chan_addr(zs_unit, channel);
    293      1.50       gwr 		cs->cs_reg_csr  = &zc->zc_csr;
    294      1.50       gwr 		cs->cs_reg_data = &zc->zc_data;
    295      1.50       gwr 
    296      1.50       gwr 		bcopy(zs_init_reg, cs->cs_creg, 16);
    297      1.50       gwr 		bcopy(zs_init_reg, cs->cs_preg, 16);
    298      1.50       gwr 
    299      1.50       gwr 		/* XXX: Get these from the PROM properties! */
    300      1.50       gwr 		/* XXX: See the mvme167 code.  Better. */
    301      1.50       gwr 		if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
    302      1.50       gwr 			cs->cs_defspeed = zs_get_speed(cs);
    303      1.50       gwr 		else
    304      1.50       gwr 			cs->cs_defspeed = zs_defspeed[zs_unit][channel];
    305      1.50       gwr 		cs->cs_defcflag = zs_def_cflag;
    306      1.50       gwr 
    307      1.50       gwr 		/* Make these correspond to cs_defcflag (-crtscts) */
    308      1.50       gwr 		cs->cs_rr0_dcd = ZSRR0_DCD;
    309      1.50       gwr 		cs->cs_rr0_cts = 0;
    310      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    311      1.50       gwr 		cs->cs_wr5_rts = 0;
    312      1.50       gwr 
    313      1.50       gwr 		/*
    314      1.50       gwr 		 * Clear the master interrupt enable.
    315      1.50       gwr 		 * The INTENA is common to both channels,
    316      1.50       gwr 		 * so just do it on the A channel.
    317      1.50       gwr 		 */
    318      1.50       gwr 		if (channel == 0) {
    319      1.50       gwr 			zs_write_reg(cs, 9, 0);
    320      1.50       gwr 		}
    321      1.50       gwr 
    322      1.50       gwr 		/*
    323      1.50       gwr 		 * Look for a child driver for this channel.
    324      1.50       gwr 		 * The child attach will setup the hardware.
    325      1.50       gwr 		 */
    326      1.50       gwr 		if (!config_found(self, (void *)&zsc_args, zs_print)) {
    327      1.50       gwr 			/* No sub-driver.  Just reset it. */
    328      1.50       gwr 			u_char reset = (channel == 0) ?
    329      1.50       gwr 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    330      1.50       gwr 			s = splhigh();
    331      1.50       gwr 			zs_write_reg(cs,  9, reset);
    332      1.50       gwr 			splx(s);
    333      1.50       gwr 		}
    334      1.50       gwr 	}
    335      1.50       gwr 
    336      1.50       gwr 	/*
    337      1.50       gwr 	 * Now safe to install interrupt handlers.  Note the arguments
    338      1.50       gwr 	 * to the interrupt handlers aren't used.  Note, we only do this
    339      1.50       gwr 	 * once since both SCCs interrupt at the same level and vector.
    340      1.50       gwr 	 */
    341       1.1   deraadt 	if (!didintr) {
    342       1.1   deraadt 		didintr = 1;
    343       1.1   deraadt 		prevpri = pri;
    344       1.1   deraadt 		intr_establish(pri, &levelhard);
    345       1.1   deraadt 		intr_establish(PIL_TTY, &levelsoft);
    346       1.1   deraadt 	} else if (pri != prevpri)
    347       1.1   deraadt 		panic("broken zs interrupt scheme");
    348      1.50       gwr 	evcnt_attach(&zsc->zsc_dev, "intr", &zsc->zsc_intrcnt);
    349       1.1   deraadt 
    350       1.1   deraadt 	/*
    351      1.50       gwr 	 * Set the master interrupt enable and interrupt vector.
    352      1.50       gwr 	 * (common to both channels, do it on A)
    353       1.1   deraadt 	 */
    354      1.50       gwr 	cs = zsc->zsc_cs[0];
    355       1.1   deraadt 	s = splhigh();
    356      1.50       gwr 	/* interrupt vector */
    357      1.50       gwr 	zs_write_reg(cs, 2, zs_init_reg[2]);
    358      1.50       gwr 	/* master interrupt control (enable) */
    359      1.50       gwr 	zs_write_reg(cs, 9, zs_init_reg[9]);
    360      1.50       gwr 	splx(s);
    361      1.50       gwr 
    362      1.50       gwr #if 0
    363      1.47        pk 	/*
    364      1.50       gwr 	 * XXX: L1A hack - We would like to be able to break into
    365      1.50       gwr 	 * the debugger during the rest of autoconfiguration, so
    366      1.50       gwr 	 * lower interrupts just enough to let zs interrupts in.
    367      1.50       gwr 	 * This is done after both zs devices are attached.
    368      1.50       gwr 	 */
    369      1.50       gwr 	if (zs_unit == 1) {
    370      1.50       gwr 		printf("zs1: enabling zs interrupts\n");
    371      1.50       gwr 		(void)splfd(); /* XXX: splzs - 1 */
    372      1.47        pk 	}
    373      1.50       gwr #endif
    374       1.1   deraadt }
    375       1.1   deraadt 
    376      1.50       gwr static int
    377      1.50       gwr zs_print(aux, name)
    378      1.50       gwr 	void *aux;
    379      1.50       gwr 	const char *name;
    380       1.1   deraadt {
    381      1.50       gwr 	struct zsc_attach_args *args = aux;
    382       1.1   deraadt 
    383      1.50       gwr 	if (name != NULL)
    384      1.50       gwr 		printf("%s: ", name);
    385       1.1   deraadt 
    386      1.50       gwr 	if (args->channel != -1)
    387      1.50       gwr 		printf(" channel %d", args->channel);
    388       1.1   deraadt 
    389      1.50       gwr 	return UNCONF;
    390       1.1   deraadt }
    391       1.1   deraadt 
    392      1.50       gwr static volatile int zssoftpending;
    393       1.1   deraadt 
    394       1.1   deraadt /*
    395      1.50       gwr  * Our ZS chips all share a common, autovectored interrupt,
    396      1.50       gwr  * so we have to look at all of them on each interrupt.
    397       1.1   deraadt  */
    398       1.1   deraadt static int
    399      1.50       gwr zshard(arg)
    400      1.50       gwr 	void *arg;
    401       1.1   deraadt {
    402      1.50       gwr 	register struct zsc_softc *zsc;
    403      1.50       gwr 	register int unit, rr3, rval, softreq;
    404       1.1   deraadt 
    405      1.50       gwr 	rval = softreq = 0;
    406      1.50       gwr 	for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
    407      1.50       gwr 		zsc = zs_cd.cd_devs[unit];
    408      1.50       gwr 		if (zsc == NULL)
    409      1.50       gwr 			continue;
    410      1.50       gwr 		rr3 = zsc_intr_hard(zsc);
    411      1.50       gwr 		/* Count up the interrupts. */
    412      1.50       gwr 		if (rr3) {
    413      1.50       gwr 			rval |= rr3;
    414      1.50       gwr 			zsc->zsc_intrcnt.ev_count++;
    415      1.50       gwr 		}
    416      1.50       gwr 		softreq |= zsc->zsc_cs[0]->cs_softreq;
    417      1.50       gwr 		softreq |= zsc->zsc_cs[1]->cs_softreq;
    418      1.50       gwr 	}
    419       1.1   deraadt 
    420      1.50       gwr 	/* We are at splzs here, so no need to lock. */
    421      1.50       gwr 	if (softreq && (zssoftpending == 0)) {
    422      1.50       gwr 		zssoftpending = IE_ZSSOFT;
    423      1.50       gwr #if defined(SUN4M)
    424      1.50       gwr 		if (CPU_ISSUN4M)
    425      1.50       gwr 			raise(0, PIL_TTY);
    426      1.50       gwr 		else
    427      1.50       gwr #endif
    428      1.50       gwr 		ienab_bis(IE_ZSSOFT);
    429      1.50       gwr 	}
    430      1.50       gwr 	return (rval);
    431       1.1   deraadt }
    432       1.1   deraadt 
    433       1.1   deraadt /*
    434      1.50       gwr  * Similar scheme as for zshard (look at all of them)
    435       1.1   deraadt  */
    436      1.50       gwr static int
    437      1.50       gwr zssoft(arg)
    438      1.50       gwr 	void *arg;
    439       1.1   deraadt {
    440      1.50       gwr 	register struct zsc_softc *zsc;
    441      1.50       gwr 	register int s, unit;
    442       1.1   deraadt 
    443      1.50       gwr 	/* This is not the only ISR on this IPL. */
    444      1.50       gwr 	if (zssoftpending == 0)
    445      1.50       gwr 		return (0);
    446       1.1   deraadt 
    447      1.50       gwr 	/*
    448      1.50       gwr 	 * The soft intr. bit will be set by zshard only if
    449      1.50       gwr 	 * the variable zssoftpending is zero.  The order of
    450      1.50       gwr 	 * these next two statements prevents our clearing
    451      1.50       gwr 	 * the soft intr bit just after zshard has set it.
    452      1.50       gwr 	 */
    453      1.50       gwr 	/* ienab_bic(IE_ZSSOFT); */
    454      1.50       gwr 	zssoftpending = 0;
    455       1.1   deraadt 
    456      1.50       gwr 	/* Make sure we call the tty layer at spltty. */
    457       1.1   deraadt 	s = spltty();
    458      1.50       gwr 	for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
    459      1.50       gwr 		zsc = zs_cd.cd_devs[unit];
    460      1.50       gwr 		if (zsc == NULL)
    461      1.50       gwr 			continue;
    462      1.50       gwr 		(void) zsc_intr_soft(zsc);
    463       1.1   deraadt 	}
    464       1.1   deraadt 	splx(s);
    465      1.50       gwr 	return (1);
    466       1.1   deraadt }
    467       1.1   deraadt 
    468      1.50       gwr 
    469       1.1   deraadt /*
    470      1.50       gwr  * Compute the current baud rate given a ZS channel.
    471       1.1   deraadt  */
    472      1.50       gwr static int
    473      1.50       gwr zs_get_speed(cs)
    474      1.50       gwr 	struct zs_chanstate *cs;
    475      1.50       gwr {
    476      1.50       gwr 	int tconst;
    477      1.50       gwr 
    478      1.50       gwr 	tconst = zs_read_reg(cs, 12);
    479      1.50       gwr 	tconst |= zs_read_reg(cs, 13) << 8;
    480      1.50       gwr 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    481       1.1   deraadt }
    482       1.1   deraadt 
    483       1.1   deraadt /*
    484      1.50       gwr  * MD functions for setting the baud rate and control modes.
    485       1.1   deraadt  */
    486       1.1   deraadt int
    487      1.50       gwr zs_set_speed(cs, bps)
    488      1.50       gwr 	struct zs_chanstate *cs;
    489      1.50       gwr 	int bps;	/* bits per second */
    490       1.1   deraadt {
    491      1.50       gwr 	int tconst, real_bps;
    492      1.50       gwr 
    493      1.50       gwr 	if (bps == 0)
    494      1.50       gwr 		return (0);
    495       1.1   deraadt 
    496      1.50       gwr #ifdef	DIAGNOSTIC
    497      1.50       gwr 	if (cs->cs_brg_clk == 0)
    498      1.50       gwr 		panic("zs_set_speed");
    499      1.50       gwr #endif
    500      1.50       gwr 
    501      1.50       gwr 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    502      1.50       gwr 	if (tconst < 0)
    503      1.50       gwr 		return (EINVAL);
    504      1.28        pk 
    505      1.50       gwr 	/* Convert back to make sure we can do it. */
    506      1.50       gwr 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    507       1.1   deraadt 
    508      1.50       gwr 	/* XXX - Allow some tolerance here? */
    509      1.50       gwr 	if (real_bps != bps)
    510      1.50       gwr 		return (EINVAL);
    511      1.28        pk 
    512      1.50       gwr 	cs->cs_preg[12] = tconst;
    513      1.50       gwr 	cs->cs_preg[13] = tconst >> 8;
    514       1.1   deraadt 
    515      1.50       gwr 	/* Caller will stuff the pending registers. */
    516      1.50       gwr 	return (0);
    517      1.28        pk }
    518      1.28        pk 
    519      1.50       gwr int
    520      1.50       gwr zs_set_modes(cs, cflag)
    521      1.50       gwr 	struct zs_chanstate *cs;
    522      1.50       gwr 	int cflag;	/* bits per second */
    523      1.28        pk {
    524      1.50       gwr 	int s;
    525      1.28        pk 
    526      1.50       gwr 	/*
    527      1.50       gwr 	 * Output hardware flow control on the chip is horrendous:
    528      1.50       gwr 	 * if carrier detect drops, the receiver is disabled, and if
    529      1.50       gwr 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    530      1.50       gwr 	 * Therefore, NEVER set the HFC bit, and instead use the
    531      1.50       gwr 	 * status interrupt to detect CTS changes.
    532      1.50       gwr 	 */
    533      1.50       gwr 	s = splzs();
    534  1.50.2.2    mellon 	if ((cflag & (CLOCAL | MDMBUF)) != 0)
    535      1.50       gwr 		cs->cs_rr0_dcd = 0;
    536  1.50.2.2    mellon 	else
    537      1.50       gwr 		cs->cs_rr0_dcd = ZSRR0_DCD;
    538  1.50.2.2    mellon 	if ((cflag & CRTSCTS) != 0) {
    539      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR;
    540      1.50       gwr 		cs->cs_wr5_rts = ZSWR5_RTS;
    541      1.50       gwr 		cs->cs_rr0_cts = ZSRR0_CTS;
    542  1.50.2.2    mellon 	} else if ((cflag & CDTRCTS) != 0) {
    543  1.50.2.2    mellon 		cs->cs_wr5_dtr = 0;
    544  1.50.2.2    mellon 		cs->cs_wr5_rts = ZSWR5_DTR;
    545  1.50.2.2    mellon 		cs->cs_rr0_cts = ZSRR0_CTS;
    546  1.50.2.2    mellon 	} else if ((cflag & MDMBUF) != 0) {
    547  1.50.2.2    mellon 		cs->cs_wr5_dtr = 0;
    548  1.50.2.2    mellon 		cs->cs_wr5_rts = ZSWR5_DTR;
    549  1.50.2.2    mellon 		cs->cs_rr0_cts = ZSRR0_DCD;
    550      1.50       gwr 	} else {
    551      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    552      1.50       gwr 		cs->cs_wr5_rts = 0;
    553      1.50       gwr 		cs->cs_rr0_cts = 0;
    554      1.50       gwr 	}
    555      1.50       gwr 	splx(s);
    556      1.28        pk 
    557      1.50       gwr 	/* Caller will stuff the pending registers. */
    558      1.50       gwr 	return (0);
    559      1.38       mrg }
    560      1.28        pk 
    561       1.1   deraadt 
    562       1.1   deraadt /*
    563      1.50       gwr  * Read or write the chip with suitable delays.
    564       1.1   deraadt  */
    565      1.50       gwr 
    566      1.50       gwr u_char
    567      1.50       gwr zs_read_reg(cs, reg)
    568      1.50       gwr 	struct zs_chanstate *cs;
    569      1.50       gwr 	u_char reg;
    570       1.1   deraadt {
    571      1.50       gwr 	u_char val;
    572      1.14   deraadt 
    573      1.50       gwr 	*cs->cs_reg_csr = reg;
    574      1.50       gwr 	ZS_DELAY();
    575      1.50       gwr 	val = *cs->cs_reg_csr;
    576      1.50       gwr 	ZS_DELAY();
    577      1.50       gwr 	return val;
    578       1.1   deraadt }
    579       1.1   deraadt 
    580      1.50       gwr void
    581      1.50       gwr zs_write_reg(cs, reg, val)
    582      1.50       gwr 	struct zs_chanstate *cs;
    583      1.50       gwr 	u_char reg, val;
    584       1.1   deraadt {
    585      1.50       gwr 	*cs->cs_reg_csr = reg;
    586      1.14   deraadt 	ZS_DELAY();
    587      1.50       gwr 	*cs->cs_reg_csr = val;
    588      1.14   deraadt 	ZS_DELAY();
    589      1.50       gwr }
    590       1.1   deraadt 
    591      1.50       gwr u_char zs_read_csr(cs)
    592      1.50       gwr 	struct zs_chanstate *cs;
    593      1.50       gwr {
    594      1.50       gwr 	register u_char val;
    595       1.1   deraadt 
    596      1.50       gwr 	val = *cs->cs_reg_csr;
    597      1.14   deraadt 	ZS_DELAY();
    598      1.50       gwr 	return val;
    599       1.1   deraadt }
    600       1.1   deraadt 
    601      1.50       gwr void  zs_write_csr(cs, val)
    602      1.50       gwr 	struct zs_chanstate *cs;
    603      1.50       gwr 	u_char val;
    604      1.50       gwr {
    605      1.50       gwr 	*cs->cs_reg_csr = val;
    606      1.14   deraadt 	ZS_DELAY();
    607       1.1   deraadt }
    608       1.1   deraadt 
    609      1.50       gwr u_char zs_read_data(cs)
    610      1.50       gwr 	struct zs_chanstate *cs;
    611       1.1   deraadt {
    612      1.50       gwr 	register u_char val;
    613       1.1   deraadt 
    614      1.50       gwr 	val = *cs->cs_reg_data;
    615      1.29        pk 	ZS_DELAY();
    616      1.50       gwr 	return val;
    617      1.50       gwr }
    618      1.50       gwr 
    619      1.50       gwr void  zs_write_data(cs, val)
    620      1.50       gwr 	struct zs_chanstate *cs;
    621      1.50       gwr 	u_char val;
    622      1.50       gwr {
    623      1.50       gwr 	*cs->cs_reg_data = val;
    624      1.14   deraadt 	ZS_DELAY();
    625       1.1   deraadt }
    626       1.1   deraadt 
    627      1.50       gwr /****************************************************************
    628      1.50       gwr  * Console support functions (Sun specific!)
    629      1.50       gwr  * Note: this code is allowed to know about the layout of
    630      1.50       gwr  * the chip registers, and uses that to keep things simple.
    631      1.50       gwr  * XXX - I think I like the mvme167 code better. -gwr
    632      1.50       gwr  ****************************************************************/
    633      1.50       gwr 
    634      1.50       gwr extern void Debugger __P((void));
    635      1.50       gwr void *zs_conschan;
    636      1.50       gwr 
    637      1.50       gwr /*
    638      1.50       gwr  * Handle user request to enter kernel debugger.
    639      1.50       gwr  */
    640      1.34  christos void
    641      1.50       gwr zs_abort(cs)
    642      1.50       gwr 	struct zs_chanstate *cs;
    643       1.1   deraadt {
    644      1.50       gwr 	register volatile struct zschan *zc = zs_conschan;
    645      1.50       gwr 	int rr0;
    646      1.50       gwr 
    647      1.50       gwr 	/* Wait for end of break to avoid PROM abort. */
    648      1.50       gwr 	/* XXX - Limit the wait? */
    649      1.50       gwr 	do {
    650      1.50       gwr 		rr0 = zc->zc_csr;
    651      1.50       gwr 		ZS_DELAY();
    652      1.50       gwr 	} while (rr0 & ZSRR0_BREAK);
    653       1.1   deraadt 
    654      1.49        pk #if defined(KGDB)
    655      1.50       gwr 	zskgdb(cs);
    656      1.49        pk #elif defined(DDB)
    657       1.5        pk 	Debugger();
    658       1.5        pk #else
    659      1.44  christos 	printf("stopping on keyboard abort\n");
    660       1.1   deraadt 	callrom();
    661       1.5        pk #endif
    662       1.1   deraadt }
    663       1.1   deraadt 
    664       1.1   deraadt /*
    665      1.50       gwr  * Polled input char.
    666       1.1   deraadt  */
    667      1.50       gwr int
    668      1.50       gwr zs_getc(arg)
    669      1.50       gwr 	void *arg;
    670       1.1   deraadt {
    671      1.50       gwr 	register volatile struct zschan *zc = arg;
    672      1.50       gwr 	register int s, c, rr0;
    673       1.1   deraadt 
    674      1.50       gwr 	s = splhigh();
    675      1.50       gwr 	/* Wait for a character to arrive. */
    676      1.50       gwr 	do {
    677      1.50       gwr 		rr0 = zc->zc_csr;
    678      1.50       gwr 		ZS_DELAY();
    679      1.50       gwr 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    680       1.1   deraadt 
    681      1.50       gwr 	c = zc->zc_data;
    682      1.50       gwr 	ZS_DELAY();
    683      1.50       gwr 	splx(s);
    684       1.1   deraadt 
    685      1.50       gwr 	/*
    686      1.50       gwr 	 * This is used by the kd driver to read scan codes,
    687      1.50       gwr 	 * so don't translate '\r' ==> '\n' here...
    688      1.50       gwr 	 */
    689      1.50       gwr 	return (c);
    690       1.1   deraadt }
    691       1.1   deraadt 
    692       1.1   deraadt /*
    693      1.50       gwr  * Polled output char.
    694       1.1   deraadt  */
    695      1.50       gwr void
    696      1.50       gwr zs_putc(arg, c)
    697      1.16   deraadt 	void *arg;
    698      1.50       gwr 	int c;
    699       1.1   deraadt {
    700      1.50       gwr 	register volatile struct zschan *zc = arg;
    701      1.50       gwr 	register int s, rr0;
    702       1.1   deraadt 
    703      1.50       gwr 	s = splhigh();
    704      1.50       gwr 	/* Wait for transmitter to become ready. */
    705      1.50       gwr 	do {
    706      1.50       gwr 		rr0 = zc->zc_csr;
    707      1.50       gwr 		ZS_DELAY();
    708      1.50       gwr 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    709      1.21   deraadt 
    710  1.50.2.3    mellon 	/*
    711  1.50.2.3    mellon 	 * If the transmitter was busy doing regular tty I/O (ZSWR1_TIE on),
    712  1.50.2.3    mellon 	 * defer our output until the transmit interrupt runs. We still
    713  1.50.2.3    mellon 	 * sync with TX_READY so we can get by with a single-char "queue".
    714  1.50.2.3    mellon 	 */
    715  1.50.2.3    mellon 	if (zs_conschanstate && (zs_conschanstate->cs_preg[1] & ZSWR1_TIE)) {
    716  1.50.2.3    mellon 		/*
    717  1.50.2.3    mellon 		 * If a previous held character has not yet gone out, we can
    718  1.50.2.3    mellon 		 * send it now;  zsxint() will field the interrupt for our
    719  1.50.2.3    mellon 		 * char, but doesn't care. We're running at sufficiently
    720  1.50.2.3    mellon 		 * high spl for this to work.
    721  1.50.2.3    mellon 		 */
    722  1.50.2.3    mellon 		if (zs_conschanstate->cs_heldchar != 0)
    723  1.50.2.3    mellon 			zc->zc_data = zs_conschanstate->cs_heldchar;
    724  1.50.2.3    mellon 		zs_conschanstate->cs_heldchar = c;
    725  1.50.2.3    mellon 		ZS_DELAY();
    726  1.50.2.3    mellon 		splx(s);
    727  1.50.2.3    mellon 		return;
    728  1.50.2.3    mellon 	}
    729  1.50.2.3    mellon 
    730      1.50       gwr 	zc->zc_data = c;
    731      1.50       gwr 	ZS_DELAY();
    732      1.50       gwr 	splx(s);
    733      1.50       gwr }
    734      1.21   deraadt 
    735      1.50       gwr /*****************************************************************/
    736      1.21   deraadt 
    737      1.50       gwr static void zscninit __P((struct consdev *));
    738      1.50       gwr static int  zscngetc __P((dev_t));
    739      1.50       gwr static void zscnputc __P((dev_t, int));
    740       1.1   deraadt 
    741       1.1   deraadt /*
    742      1.50       gwr  * Console table shared by ttya, ttyb
    743       1.1   deraadt  */
    744      1.50       gwr struct consdev consdev_tty = {
    745      1.50       gwr 	nullcnprobe,
    746      1.50       gwr 	zscninit,
    747      1.50       gwr 	zscngetc,
    748      1.50       gwr 	zscnputc,
    749      1.50       gwr 	nullcnpollc,
    750      1.50       gwr };
    751      1.50       gwr 
    752       1.1   deraadt static void
    753      1.50       gwr zscninit(cn)
    754      1.50       gwr 	struct consdev *cn;
    755       1.1   deraadt {
    756       1.1   deraadt }
    757       1.1   deraadt 
    758       1.1   deraadt /*
    759      1.50       gwr  * Polled console input putchar.
    760       1.1   deraadt  */
    761      1.50       gwr static int
    762      1.50       gwr zscngetc(dev)
    763      1.50       gwr 	dev_t dev;
    764      1.50       gwr {
    765      1.50       gwr 	return (zs_getc(zs_conschan));
    766       1.1   deraadt }
    767       1.1   deraadt 
    768       1.1   deraadt /*
    769      1.50       gwr  * Polled console output putchar.
    770       1.1   deraadt  */
    771      1.50       gwr static void
    772      1.50       gwr zscnputc(dev, c)
    773      1.50       gwr 	dev_t dev;
    774      1.50       gwr 	int c;
    775      1.50       gwr {
    776      1.50       gwr 	zs_putc(zs_conschan, c);
    777      1.50       gwr }
    778       1.1   deraadt 
    779      1.50       gwr /*****************************************************************/
    780       1.1   deraadt 
    781      1.50       gwr static void prom_cninit __P((struct consdev *));
    782      1.50       gwr static int  prom_cngetc __P((dev_t));
    783      1.50       gwr static void prom_cnputc __P((dev_t, int));
    784       1.1   deraadt 
    785      1.50       gwr /*
    786      1.50       gwr  * The console is set to this one initially,
    787      1.50       gwr  * which lets us use the PROM until consinit()
    788      1.50       gwr  * is called to select a real console.
    789      1.50       gwr  */
    790      1.50       gwr struct consdev consdev_prom = {
    791      1.50       gwr 	nullcnprobe,
    792      1.50       gwr 	prom_cninit,
    793      1.50       gwr 	prom_cngetc,
    794      1.50       gwr 	prom_cnputc,
    795      1.50       gwr 	nullcnpollc,
    796      1.50       gwr };
    797       1.1   deraadt 
    798       1.1   deraadt /*
    799      1.50       gwr  * The console table pointer is statically initialized
    800      1.50       gwr  * to point to the PROM (output only) table, so that
    801      1.50       gwr  * early calls to printf will work.
    802       1.1   deraadt  */
    803      1.50       gwr struct consdev *cn_tab = &consdev_prom;
    804      1.50       gwr 
    805      1.50       gwr void
    806      1.50       gwr nullcnprobe(cn)
    807      1.50       gwr 	struct consdev *cn;
    808       1.1   deraadt {
    809       1.1   deraadt }
    810       1.1   deraadt 
    811       1.1   deraadt static void
    812      1.50       gwr prom_cninit(cn)
    813      1.50       gwr 	struct consdev *cn;
    814       1.1   deraadt {
    815       1.1   deraadt }
    816       1.1   deraadt 
    817       1.1   deraadt /*
    818      1.50       gwr  * PROM console input putchar.
    819      1.50       gwr  * (dummy - this is output only)
    820       1.1   deraadt  */
    821       1.1   deraadt static int
    822      1.50       gwr prom_cngetc(dev)
    823      1.50       gwr 	dev_t dev;
    824       1.1   deraadt {
    825      1.50       gwr 	return (0);
    826       1.1   deraadt }
    827       1.1   deraadt 
    828       1.1   deraadt /*
    829      1.50       gwr  * PROM console output putchar.
    830       1.1   deraadt  */
    831       1.1   deraadt static void
    832      1.50       gwr prom_cnputc(dev, c)
    833      1.50       gwr 	dev_t dev;
    834      1.16   deraadt 	int c;
    835       1.1   deraadt {
    836      1.50       gwr 	char c0 = (c & 0x7f);
    837       1.1   deraadt 
    838      1.50       gwr 	if (promvec->pv_romvec_vers > 2)
    839      1.50       gwr 		(*promvec->pv_v2devops.v2_write)
    840      1.50       gwr 			(*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
    841      1.50       gwr 	else
    842      1.50       gwr 		(*promvec->pv_putchar)(c);
    843       1.1   deraadt }
    844       1.1   deraadt 
    845      1.50       gwr /*****************************************************************/
    846      1.50       gwr 
    847      1.50       gwr extern struct consdev consdev_kd;
    848      1.50       gwr 
    849      1.50       gwr static char *prom_inSrc_name[] = {
    850      1.50       gwr 	"keyboard/display",
    851      1.50       gwr 	"ttya", "ttyb",
    852      1.50       gwr 	"ttyc", "ttyd" };
    853      1.50       gwr 
    854       1.1   deraadt /*
    855      1.50       gwr  * This function replaces sys/dev/cninit.c
    856      1.50       gwr  * Determine which device is the console using
    857      1.50       gwr  * the PROM "input source" and "output sink".
    858       1.1   deraadt  */
    859       1.1   deraadt void
    860      1.50       gwr consinit()
    861       1.1   deraadt {
    862      1.50       gwr 	struct zschan *zc;
    863      1.50       gwr 	struct consdev *cn;
    864      1.50       gwr 	int channel, zs_unit, zstty_unit;
    865      1.50       gwr 	int inSource, outSink;
    866      1.50       gwr 
    867      1.50       gwr 	if (promvec->pv_romvec_vers > 2) {
    868      1.50       gwr 		/* We need to probe the PROM device tree */
    869      1.50       gwr 		register int node,fd;
    870      1.50       gwr 		char buffer[128];
    871      1.50       gwr 		register struct nodeops *no;
    872      1.50       gwr 		register struct v2devops *op;
    873      1.50       gwr 		register char *cp;
    874      1.50       gwr 		extern int fbnode;
    875      1.50       gwr 
    876      1.50       gwr 		inSource = outSink = -1;
    877      1.50       gwr 		no = promvec->pv_nodeops;
    878      1.50       gwr 		op = &promvec->pv_v2devops;
    879      1.50       gwr 
    880      1.50       gwr 		node = findroot();
    881      1.50       gwr 		if (no->no_proplen(node, "stdin-path") >= sizeof(buffer)) {
    882      1.50       gwr 			printf("consinit: increase buffer size and recompile\n");
    883      1.50       gwr 			goto setup_output;
    884      1.50       gwr 		}
    885      1.50       gwr 		/* XXX: fix above */
    886      1.50       gwr 
    887      1.50       gwr 		no->no_getprop(node, "stdin-path",buffer);
    888      1.50       gwr 
    889      1.50       gwr 		/*
    890      1.50       gwr 		 * Open an "instance" of this device.
    891      1.50       gwr 		 * You'd think it would be appropriate to call v2_close()
    892      1.50       gwr 		 * on the handle when we're done with it. But that seems
    893      1.50       gwr 		 * to cause the device to shut down somehow; for the moment,
    894      1.50       gwr 		 * we simply leave it open...
    895      1.50       gwr 		 */
    896      1.50       gwr 		if ((fd = op->v2_open(buffer)) == 0 ||
    897      1.50       gwr 		     (node = op->v2_fd_phandle(fd)) == 0) {
    898      1.50       gwr 			printf("consinit: bogus stdin path %s.\n",buffer);
    899      1.50       gwr 			goto setup_output;
    900      1.50       gwr 		}
    901      1.50       gwr 		if (no->no_proplen(node,"keyboard") >= 0) {
    902      1.50       gwr 			inSource = PROMDEV_KBD;
    903      1.50       gwr 			goto setup_output;
    904      1.50       gwr 		}
    905      1.50       gwr 		if (strcmp(getpropstring(node,"device_type"),"serial") != 0) {
    906      1.50       gwr 			/* not a serial, not keyboard. what is it?!? */
    907      1.50       gwr 			inSource = -1;
    908      1.50       gwr 			goto setup_output;
    909      1.50       gwr 		}
    910      1.50       gwr 		/*
    911      1.50       gwr 		 * At this point we assume the device path is in the form
    912      1.50       gwr 		 *   ....device@x,y:a for ttya and ...device@x,y:b for ttyb.
    913      1.50       gwr 		 * If it isn't, we defer to the ROM
    914      1.50       gwr 		 */
    915      1.50       gwr 		cp = buffer;
    916      1.50       gwr 		while (*cp)
    917      1.50       gwr 		    cp++;
    918      1.50       gwr 		cp -= 2;
    919      1.50       gwr #ifdef DEBUG
    920      1.50       gwr 		if (cp < buffer)
    921      1.50       gwr 		    panic("consinit: bad stdin path %s",buffer);
    922      1.50       gwr #endif
    923      1.50       gwr 		/* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
    924      1.50       gwr 		if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
    925      1.50       gwr 		    inSource = PROMDEV_TTYA + (cp[1] - 'a');
    926      1.50       gwr 		/* else use rom */
    927      1.50       gwr setup_output:
    928      1.50       gwr 		node = findroot();
    929      1.50       gwr 		if (no->no_proplen(node, "stdout-path") >= sizeof(buffer)) {
    930      1.50       gwr 			printf("consinit: increase buffer size and recompile\n");
    931      1.50       gwr 			goto setup_console;
    932      1.50       gwr 		}
    933      1.50       gwr 		/* XXX: fix above */
    934      1.50       gwr 
    935      1.50       gwr 		no->no_getprop(node, "stdout-path", buffer);
    936      1.50       gwr 
    937      1.50       gwr 		if ((fd = op->v2_open(buffer)) == 0 ||
    938      1.50       gwr 		     (node = op->v2_fd_phandle(fd)) == 0) {
    939      1.50       gwr 			printf("consinit: bogus stdout path %s.\n",buffer);
    940      1.50       gwr 			goto setup_output;
    941      1.50       gwr 		}
    942      1.50       gwr 		if (strcmp(getpropstring(node,"device_type"),"display") == 0) {
    943      1.50       gwr 			/* frame buffer output */
    944      1.50       gwr 			outSink = PROMDEV_SCREEN;
    945      1.50       gwr 			fbnode = node;
    946      1.50       gwr 		} else if (strcmp(getpropstring(node,"device_type"), "serial")
    947      1.50       gwr 			   != 0) {
    948      1.50       gwr 			/* not screen, not serial. Whatzit? */
    949      1.50       gwr 			outSink = -1;
    950      1.50       gwr 		} else { /* serial console. which? */
    951      1.50       gwr 			/*
    952      1.50       gwr 			 * At this point we assume the device path is in the
    953      1.50       gwr 			 * form:
    954      1.50       gwr 			 * ....device@x,y:a for ttya, etc.
    955      1.50       gwr 			 * If it isn't, we defer to the ROM
    956      1.50       gwr 			 */
    957      1.50       gwr 			cp = buffer;
    958      1.50       gwr 			while (*cp)
    959      1.50       gwr 			    cp++;
    960      1.50       gwr 			cp -= 2;
    961      1.50       gwr #ifdef DEBUG
    962      1.50       gwr 			if (cp < buffer)
    963      1.50       gwr 				panic("consinit: bad stdout path %s",buffer);
    964      1.50       gwr #endif
    965      1.50       gwr 			/* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
    966      1.50       gwr 			if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
    967      1.50       gwr 			    outSink = PROMDEV_TTYA + (cp[1] - 'a');
    968      1.50       gwr 			else outSink = -1;
    969      1.50       gwr 		}
    970      1.50       gwr 	} else {
    971      1.50       gwr 		inSource = *promvec->pv_stdin;
    972      1.50       gwr 		outSink  = *promvec->pv_stdout;
    973      1.50       gwr 	}
    974      1.50       gwr 
    975      1.50       gwr setup_console:
    976      1.50       gwr 
    977      1.50       gwr 	if (inSource != outSink) {
    978      1.50       gwr 		printf("cninit: mismatched PROM output selector\n");
    979      1.50       gwr 	}
    980      1.50       gwr 
    981      1.50       gwr 	switch (inSource) {
    982      1.50       gwr 	default:
    983      1.50       gwr 		printf("cninit: invalid inSource=%d\n", inSource);
    984      1.50       gwr 		callrom();
    985      1.50       gwr 		inSource = PROMDEV_KBD;
    986      1.50       gwr 		/* fall through */
    987      1.50       gwr 
    988      1.50       gwr 	case 0:	/* keyboard/display */
    989      1.50       gwr #if NKBD > 0
    990  1.50.2.1    mellon 		zs_unit = 1;	/* XXX - config info! */
    991      1.50       gwr 		channel = 0;
    992      1.50       gwr 		cn = &consdev_kd;
    993      1.50       gwr 		/* Set cn_dev, cn_pri in kd.c */
    994      1.50       gwr 		break;
    995      1.50       gwr #else	/* NKBD */
    996      1.50       gwr 		printf("cninit: kdb/display not configured\n");
    997      1.50       gwr 		callrom();
    998      1.50       gwr 		inSource = PROMDEV_TTYA;
    999      1.50       gwr 		/* fall through */
   1000      1.50       gwr #endif	/* NKBD */
   1001      1.50       gwr 
   1002      1.50       gwr 	case PROMDEV_TTYA:
   1003      1.50       gwr 	case PROMDEV_TTYB:
   1004      1.50       gwr 		zstty_unit = inSource - PROMDEV_TTYA;
   1005  1.50.2.1    mellon 		zs_unit = 0;	/* XXX - config info! */
   1006      1.50       gwr 		channel = zstty_unit & 1;
   1007      1.50       gwr 		cn = &consdev_tty;
   1008      1.50       gwr 		cn->cn_dev = makedev(zs_major, zstty_unit);
   1009      1.50       gwr 		cn->cn_pri = CN_REMOTE;
   1010  1.50.2.3    mellon 		zs_console_unit = zs_unit;
   1011  1.50.2.3    mellon 		zs_console_channel = channel;
   1012      1.50       gwr 		break;
   1013      1.50       gwr 
   1014      1.50       gwr 	}
   1015      1.50       gwr 	/* Now that inSource has been validated, print it. */
   1016      1.50       gwr 	printf("console is %s\n", prom_inSrc_name[inSource]);
   1017       1.1   deraadt 
   1018      1.50       gwr 	zc = zs_get_chan_addr(zs_unit, channel);
   1019      1.50       gwr 	if (zc == NULL) {
   1020      1.50       gwr 		printf("cninit: zs not mapped.\n");
   1021       1.1   deraadt 		return;
   1022       1.1   deraadt 	}
   1023      1.50       gwr 	zs_conschan = zc;
   1024      1.50       gwr 	zs_hwflags[zs_unit][channel] = ZS_HWFLAG_CONSOLE;
   1025      1.50       gwr 	cn_tab = cn;
   1026      1.50       gwr 	(*cn->cn_init)(cn);
   1027      1.50       gwr #ifdef	KGDB
   1028      1.50       gwr 	zs_kgdb_init();
   1029      1.50       gwr #endif
   1030       1.1   deraadt }
   1031