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