Home | History | Annotate | Line # | Download | only in dev
kd.c revision 1.2
      1  1.2  mjacob /*	$NetBSD: kd.c,v 1.2 1997/12/03 22:32:29 mjacob Exp $	*/
      2  1.1     gwr 
      3  1.1     gwr /*-
      4  1.1     gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.1     gwr  * All rights reserved.
      6  1.1     gwr  *
      7  1.1     gwr  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     gwr  * by Gordon W. Ross.
      9  1.1     gwr  *
     10  1.1     gwr  * Redistribution and use in source and binary forms, with or without
     11  1.1     gwr  * modification, are permitted provided that the following conditions
     12  1.1     gwr  * are met:
     13  1.1     gwr  * 1. Redistributions of source code must retain the above copyright
     14  1.1     gwr  *    notice, this list of conditions and the following disclaimer.
     15  1.1     gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     gwr  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     gwr  *    documentation and/or other materials provided with the distribution.
     18  1.1     gwr  * 3. All advertising materials mentioning features or use of this software
     19  1.1     gwr  *    must display the following acknowledgement:
     20  1.1     gwr  *        This product includes software developed by the NetBSD
     21  1.1     gwr  *        Foundation, Inc. and its contributors.
     22  1.1     gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1     gwr  *    contributors may be used to endorse or promote products derived
     24  1.1     gwr  *    from this software without specific prior written permission.
     25  1.1     gwr  *
     26  1.1     gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1     gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1     gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1     gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1     gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1     gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1     gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1     gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1     gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1     gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1     gwr  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1     gwr  */
     38  1.1     gwr 
     39  1.1     gwr /*
     40  1.1     gwr  * Keyboard/Display device.
     41  1.1     gwr  *
     42  1.1     gwr  * This driver exists simply to provide a tty device that
     43  1.1     gwr  * the indirect console driver can point to.
     44  1.1     gwr  * The kbd driver sends its input here.
     45  1.1     gwr  * Output goes to the screen via PROM printf.
     46  1.1     gwr  */
     47  1.1     gwr 
     48  1.1     gwr #include <sys/param.h>
     49  1.1     gwr #include <sys/proc.h>
     50  1.1     gwr #include <sys/systm.h>
     51  1.1     gwr #include <sys/ioctl.h>
     52  1.1     gwr #include <sys/tty.h>
     53  1.1     gwr #include <sys/file.h>
     54  1.1     gwr #include <sys/conf.h>
     55  1.1     gwr #include <sys/device.h>
     56  1.1     gwr 
     57  1.1     gwr #include <machine/bsd_openprom.h>
     58  1.1     gwr #include <machine/eeprom.h>
     59  1.1     gwr #include <machine/psl.h>
     60  1.1     gwr #include <machine/cpu.h>
     61  1.1     gwr #include <machine/kbd.h>
     62  1.1     gwr #if defined(SUN4)
     63  1.1     gwr #include <machine/oldmon.h>
     64  1.1     gwr #endif
     65  1.1     gwr #include <machine/autoconf.h>
     66  1.1     gwr #include <machine/conf.h>
     67  1.1     gwr 
     68  1.1     gwr #ifdef RASTERCONSOLE
     69  1.1     gwr #include <machine/fbio.h>
     70  1.1     gwr #include <machine/fbvar.h>
     71  1.1     gwr #endif
     72  1.1     gwr 
     73  1.1     gwr 
     74  1.1     gwr #include <dev/cons.h>
     75  1.1     gwr #include <dev/sun/kbd_xlate.h>
     76  1.1     gwr #include <sparc/dev/cons.h>
     77  1.1     gwr 
     78  1.1     gwr extern void fb_unblank __P((void)); /* XXX */
     79  1.1     gwr struct	tty *fbconstty = 0;	/* tty structure for frame buffer console */
     80  1.2  mjacob int cnrom __P((void));
     81  1.2  mjacob void cnrint __P((void));
     82  1.1     gwr 
     83  1.1     gwr #define	KDMAJOR 1
     84  1.1     gwr #define PUT_WSIZE	64
     85  1.1     gwr 
     86  1.1     gwr struct kd_softc {
     87  1.1     gwr 	struct	device kd_dev;		/* required first: base device */
     88  1.1     gwr 	struct  tty *kd_tty;
     89  1.1     gwr 	int rows, cols;
     90  1.1     gwr };
     91  1.1     gwr 
     92  1.1     gwr /*
     93  1.1     gwr  * There is no point in pretending there might be
     94  1.1     gwr  * more than one keyboard/display device.
     95  1.1     gwr  */
     96  1.1     gwr static struct kd_softc kd_softc;
     97  1.1     gwr static int kd_is_console;
     98  1.1     gwr 
     99  1.1     gwr static int kdparam(struct tty *, struct termios *);
    100  1.1     gwr static void kdstart(struct tty *);
    101  1.1     gwr 
    102  1.1     gwr int	rom_console_input;	/* when set, hardclock calls cnrom() */
    103  1.1     gwr int	cons_ocount;		/* output byte count */
    104  1.1     gwr 
    105  1.1     gwr /* Now talking directly to the zs, so this is not needed. */
    106  1.1     gwr int
    107  1.1     gwr cnrom()
    108  1.1     gwr {
    109  1.1     gwr   return (0);
    110  1.1     gwr }
    111  1.1     gwr void
    112  1.1     gwr cnrint()
    113  1.1     gwr {
    114  1.1     gwr }
    115  1.1     gwr 
    116  1.1     gwr /*
    117  1.1     gwr  * This is called by kbd_attach()
    118  1.1     gwr  * XXX - Make this a proper child of kbd?
    119  1.1     gwr  */
    120  1.1     gwr void
    121  1.1     gwr kd_init(unit)
    122  1.1     gwr 	int unit;
    123  1.1     gwr {
    124  1.1     gwr 	struct kd_softc *kd;
    125  1.1     gwr 	struct tty *tp;
    126  1.1     gwr 
    127  1.1     gwr 	if (unit != 0)
    128  1.1     gwr 		return;
    129  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    130  1.1     gwr 
    131  1.1     gwr 	tp = ttymalloc();
    132  1.1     gwr 	tp->t_oproc = kdstart;
    133  1.1     gwr 	tp->t_param = kdparam;
    134  1.1     gwr 	tp->t_dev = makedev(KDMAJOR, unit);
    135  1.1     gwr 
    136  1.1     gwr #if 1	/* XXX - Why? */
    137  1.1     gwr 	clalloc(&tp->t_rawq, 1024, 1);
    138  1.1     gwr 	clalloc(&tp->t_canq, 1024, 1);
    139  1.1     gwr 	/* output queue doesn't need quoting */
    140  1.1     gwr 	clalloc(&tp->t_outq, 1024, 0);
    141  1.1     gwr #endif
    142  1.1     gwr 
    143  1.1     gwr 	tty_attach(tp);
    144  1.1     gwr 	kd->kd_tty = tp;
    145  1.1     gwr 
    146  1.1     gwr 	/*
    147  1.1     gwr 	 * get the console struct winsize.
    148  1.1     gwr 	 */
    149  1.1     gwr 	if (kd_is_console) {
    150  1.1     gwr 		fbconstty = tp;
    151  1.1     gwr #ifdef RASTERCONSOLE
    152  1.1     gwr 		kd->rows = fbrcons_rows();
    153  1.1     gwr 		kd->cols = fbrcons_cols();
    154  1.1     gwr #endif
    155  1.1     gwr 	}
    156  1.1     gwr 
    157  1.1     gwr 	if (CPU_ISSUN4COR4M) {
    158  1.1     gwr 		int i;
    159  1.1     gwr 		char *prop;
    160  1.1     gwr 
    161  1.1     gwr 		if (kd->rows == 0 &&
    162  1.1     gwr 		    (prop = getpropstring(optionsnode, "screen-#rows"))) {
    163  1.1     gwr 			i = 0;
    164  1.1     gwr 			while (*prop != '\0')
    165  1.1     gwr 				i = i * 10 + *prop++ - '0';
    166  1.1     gwr 			kd->rows = (unsigned short)i;
    167  1.1     gwr 		}
    168  1.1     gwr 		if (kd->cols == 0 &&
    169  1.1     gwr 		    (prop = getpropstring(optionsnode, "screen-#columns"))) {
    170  1.1     gwr 			i = 0;
    171  1.1     gwr 			while (*prop != '\0')
    172  1.1     gwr 				i = i * 10 + *prop++ - '0';
    173  1.1     gwr 			kd->cols = (unsigned short)i;
    174  1.1     gwr 		}
    175  1.1     gwr 	}
    176  1.1     gwr 	if (CPU_ISSUN4) {
    177  1.1     gwr 		struct eeprom *ep = (struct eeprom *)eeprom_va;
    178  1.1     gwr 
    179  1.1     gwr 		if (ep) {
    180  1.1     gwr 			if (kd->rows == 0)
    181  1.1     gwr 				kd->rows = (u_short)ep->eeTtyRows;
    182  1.1     gwr 			if (kd->cols == 0)
    183  1.1     gwr 				kd->cols = (u_short)ep->eeTtyCols;
    184  1.1     gwr 		}
    185  1.1     gwr 	}
    186  1.1     gwr 
    187  1.1     gwr 	return;
    188  1.1     gwr }
    189  1.1     gwr 
    190  1.1     gwr struct tty *
    191  1.1     gwr kdtty(dev)
    192  1.1     gwr 	dev_t dev;
    193  1.1     gwr {
    194  1.1     gwr 	struct kd_softc *kd;
    195  1.1     gwr 
    196  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    197  1.1     gwr 	return (kd->kd_tty);
    198  1.1     gwr }
    199  1.1     gwr 
    200  1.1     gwr int
    201  1.1     gwr kdopen(dev, flag, mode, p)
    202  1.1     gwr 	dev_t dev;
    203  1.1     gwr 	int flag, mode;
    204  1.1     gwr 	struct proc *p;
    205  1.1     gwr {
    206  1.1     gwr 	struct kd_softc *kd;
    207  1.1     gwr 	int error, s, unit;
    208  1.1     gwr 	struct tty *tp;
    209  1.1     gwr 
    210  1.1     gwr 	unit = minor(dev);
    211  1.1     gwr 	if (unit != 0)
    212  1.1     gwr 		return ENXIO;
    213  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    214  1.1     gwr 	tp = kd->kd_tty;
    215  1.1     gwr 
    216  1.1     gwr 	if ((error = kbd_iopen(unit)) != 0) {
    217  1.1     gwr #ifdef	DIAGNOSTIC
    218  1.1     gwr 		printf("kd: kbd_iopen, error=%d\n", error);
    219  1.1     gwr #endif
    220  1.1     gwr 		return (error);
    221  1.1     gwr 	}
    222  1.1     gwr 
    223  1.1     gwr 	/* It's simpler to do this up here. */
    224  1.1     gwr 	if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
    225  1.1     gwr 	     ==             (TS_ISOPEN | TS_XCLUDE))
    226  1.1     gwr 	    && (p->p_ucred->cr_uid != 0) )
    227  1.1     gwr 	{
    228  1.1     gwr 		return (EBUSY);
    229  1.1     gwr 	}
    230  1.1     gwr 
    231  1.1     gwr 	s = spltty();
    232  1.1     gwr 
    233  1.1     gwr 	if ((tp->t_state & TS_ISOPEN) == 0) {
    234  1.1     gwr 		/* First open. */
    235  1.1     gwr 		ttychars(tp);
    236  1.1     gwr 		tp->t_iflag = TTYDEF_IFLAG;
    237  1.1     gwr 		tp->t_oflag = TTYDEF_OFLAG;
    238  1.1     gwr 		tp->t_cflag = TTYDEF_CFLAG;
    239  1.1     gwr 		tp->t_lflag = TTYDEF_LFLAG;
    240  1.1     gwr 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    241  1.1     gwr 		(void) kdparam(tp, &tp->t_termios);
    242  1.1     gwr 		ttsetwater(tp);
    243  1.1     gwr 		tp->t_winsize.ws_row = kd->rows;
    244  1.1     gwr 		tp->t_winsize.ws_col = kd->cols;
    245  1.1     gwr 		/* Flush pending input?  Clear translator? */
    246  1.1     gwr 		/* This (pseudo)device always has SOFTCAR */
    247  1.1     gwr 		tp->t_state |= TS_CARR_ON;
    248  1.1     gwr 	}
    249  1.1     gwr 
    250  1.1     gwr 	splx(s);
    251  1.1     gwr 
    252  1.1     gwr 	return ((*linesw[tp->t_line].l_open)(dev, tp));
    253  1.1     gwr }
    254  1.1     gwr 
    255  1.1     gwr int
    256  1.1     gwr kdclose(dev, flag, mode, p)
    257  1.1     gwr 	dev_t dev;
    258  1.1     gwr 	int flag, mode;
    259  1.1     gwr 	struct proc *p;
    260  1.1     gwr {
    261  1.1     gwr 	struct kd_softc *kd;
    262  1.1     gwr 	struct tty *tp;
    263  1.1     gwr 
    264  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    265  1.1     gwr 	tp = kd->kd_tty;
    266  1.1     gwr 
    267  1.1     gwr 	/* XXX This is for cons.c. */
    268  1.1     gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    269  1.1     gwr 		return 0;
    270  1.1     gwr 
    271  1.1     gwr 	(*linesw[tp->t_line].l_close)(tp, flag);
    272  1.1     gwr 	ttyclose(tp);
    273  1.1     gwr 	return (0);
    274  1.1     gwr }
    275  1.1     gwr 
    276  1.1     gwr int
    277  1.1     gwr kdread(dev, uio, flag)
    278  1.1     gwr 	dev_t dev;
    279  1.1     gwr 	struct uio *uio;
    280  1.1     gwr 	int flag;
    281  1.1     gwr {
    282  1.1     gwr 	struct kd_softc *kd;
    283  1.1     gwr 	struct tty *tp;
    284  1.1     gwr 
    285  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    286  1.1     gwr 	tp = kd->kd_tty;
    287  1.1     gwr 
    288  1.1     gwr 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    289  1.1     gwr }
    290  1.1     gwr 
    291  1.1     gwr int
    292  1.1     gwr kdwrite(dev, uio, flag)
    293  1.1     gwr 	dev_t dev;
    294  1.1     gwr 	struct uio *uio;
    295  1.1     gwr 	int flag;
    296  1.1     gwr {
    297  1.1     gwr 	struct kd_softc *kd;
    298  1.1     gwr 	struct tty *tp;
    299  1.1     gwr 
    300  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    301  1.1     gwr 	tp = kd->kd_tty;
    302  1.1     gwr 
    303  1.1     gwr 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    304  1.1     gwr }
    305  1.1     gwr 
    306  1.1     gwr int
    307  1.1     gwr kdioctl(dev, cmd, data, flag, p)
    308  1.1     gwr 	dev_t dev;
    309  1.1     gwr 	u_long cmd;
    310  1.1     gwr 	caddr_t data;
    311  1.1     gwr 	int flag;
    312  1.1     gwr 	struct proc *p;
    313  1.1     gwr {
    314  1.1     gwr 	struct kd_softc *kd;
    315  1.1     gwr 	struct tty *tp;
    316  1.1     gwr 	int error;
    317  1.1     gwr 
    318  1.1     gwr 	kd = &kd_softc; 	/* XXX */
    319  1.1     gwr 	tp = kd->kd_tty;
    320  1.1     gwr 
    321  1.1     gwr 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    322  1.1     gwr 	if (error >= 0)
    323  1.1     gwr 		return error;
    324  1.1     gwr 	error = ttioctl(tp, cmd, data, flag, p);
    325  1.1     gwr 	if (error >= 0)
    326  1.1     gwr 		return error;
    327  1.1     gwr 
    328  1.1     gwr 	/* Handle any ioctl commands specific to kbd/display. */
    329  1.1     gwr 	/* XXX - Send KB* ioctls to kbd module? */
    330  1.1     gwr 	/* XXX - Send FB* ioctls to fb module?  */
    331  1.1     gwr 
    332  1.1     gwr 	return ENOTTY;
    333  1.1     gwr }
    334  1.1     gwr 
    335  1.1     gwr void
    336  1.1     gwr kdstop(tp, flag)
    337  1.1     gwr 	struct tty *tp;
    338  1.1     gwr 	int flag;
    339  1.1     gwr {
    340  1.1     gwr 
    341  1.1     gwr }
    342  1.1     gwr 
    343  1.1     gwr 
    344  1.1     gwr static int
    345  1.1     gwr kdparam(tp, t)
    346  1.1     gwr 	struct tty *tp;
    347  1.1     gwr 	struct termios *t;
    348  1.1     gwr {
    349  1.1     gwr 	/* XXX - These are ignored... */
    350  1.1     gwr 	tp->t_ispeed = t->c_ispeed;
    351  1.1     gwr 	tp->t_ospeed = t->c_ospeed;
    352  1.1     gwr 	tp->t_cflag = t->c_cflag;
    353  1.1     gwr 	return 0;
    354  1.1     gwr }
    355  1.1     gwr 
    356  1.1     gwr 
    357  1.1     gwr static void kd_later(void*);
    358  1.1     gwr static void kd_putfb(struct tty *);
    359  1.1     gwr 
    360  1.1     gwr static void
    361  1.1     gwr kdstart(tp)
    362  1.1     gwr 	struct tty *tp;
    363  1.1     gwr {
    364  1.1     gwr 	struct clist *cl;
    365  1.1     gwr 	register int s;
    366  1.1     gwr 
    367  1.1     gwr 	s = spltty();
    368  1.1     gwr 	if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
    369  1.1     gwr 		goto out;
    370  1.1     gwr 
    371  1.1     gwr 	cl = &tp->t_outq;
    372  1.1     gwr 	if (cl->c_cc) {
    373  1.1     gwr 		if (kd_is_console) {
    374  1.1     gwr 			tp->t_state |= TS_BUSY;
    375  1.1     gwr 			if ((s & PSR_PIL) == 0) {
    376  1.1     gwr 				/* called at level zero - update screen now. */
    377  1.1     gwr 				(void) splsoftclock();
    378  1.1     gwr 				kd_putfb(tp);
    379  1.1     gwr 				(void) spltty();
    380  1.1     gwr 				tp->t_state &= ~TS_BUSY;
    381  1.1     gwr 			} else {
    382  1.1     gwr 				/* called at interrupt level - do it later */
    383  1.1     gwr 				timeout(kd_later, (void*)tp, 0);
    384  1.1     gwr 			}
    385  1.1     gwr 		} else {
    386  1.1     gwr 			/*
    387  1.1     gwr 			 * This driver uses the PROM for writing the screen,
    388  1.1     gwr 			 * and that only works if this is the console device.
    389  1.1     gwr 			 * If this is not the console, just flush the output.
    390  1.1     gwr 			 * Sorry.  (In that case, use xdm instead of getty.)
    391  1.1     gwr 			 */
    392  1.1     gwr 			ndflush(cl, cl->c_cc);
    393  1.1     gwr 		}
    394  1.1     gwr 	}
    395  1.1     gwr 	if (cl->c_cc <= tp->t_lowat) {
    396  1.1     gwr 		if (tp->t_state & TS_ASLEEP) {
    397  1.1     gwr 			tp->t_state &= ~TS_ASLEEP;
    398  1.1     gwr 			wakeup((caddr_t)cl);
    399  1.1     gwr 		}
    400  1.1     gwr 		selwakeup(&tp->t_wsel);
    401  1.1     gwr 	}
    402  1.1     gwr out:
    403  1.1     gwr 	splx(s);
    404  1.1     gwr }
    405  1.1     gwr 
    406  1.1     gwr /*
    407  1.1     gwr  * Timeout function to do delayed writes to the screen.
    408  1.1     gwr  * Called at splsoftclock when requested by kdstart.
    409  1.1     gwr  */
    410  1.1     gwr static void
    411  1.1     gwr kd_later(tpaddr)
    412  1.1     gwr 	void *tpaddr;
    413  1.1     gwr {
    414  1.1     gwr 	struct tty *tp = tpaddr;
    415  1.1     gwr 	register int s;
    416  1.1     gwr 
    417  1.1     gwr 	kd_putfb(tp);
    418  1.1     gwr 
    419  1.1     gwr 	s = spltty();
    420  1.1     gwr 	tp->t_state &= ~TS_BUSY;
    421  1.1     gwr 	(*linesw[tp->t_line].l_start)(tp);
    422  1.1     gwr 	splx(s);
    423  1.1     gwr }
    424  1.1     gwr 
    425  1.1     gwr /*
    426  1.1     gwr  * Put text on the screen using the PROM monitor.
    427  1.1     gwr  * This can take a while, so to avoid missing
    428  1.1     gwr  * interrupts, this is called at splsoftclock.
    429  1.1     gwr  */
    430  1.1     gwr static void
    431  1.1     gwr kd_putfb(tp)
    432  1.1     gwr 	struct tty *tp;
    433  1.1     gwr {
    434  1.1     gwr 	char buf[PUT_WSIZE];
    435  1.1     gwr 	struct clist *cl = &tp->t_outq;
    436  1.1     gwr 	char *p, *end;
    437  1.1     gwr 	int len;
    438  1.1     gwr 
    439  1.1     gwr 	while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
    440  1.1     gwr 		/* PROM will barf if high bits are set. */
    441  1.1     gwr 		p = buf;
    442  1.1     gwr 		end = buf + len;
    443  1.1     gwr 		while (p < end)
    444  1.1     gwr 			*p++ &= 0x7f;
    445  1.1     gwr 		/* Now let the PROM print it. */
    446  1.1     gwr 		if (promvec->pv_romvec_vers > 2) {
    447  1.1     gwr 			(*promvec->pv_v2devops.v2_write)
    448  1.1     gwr 				(*promvec->pv_v2bootargs.v2_fd1, buf, len);
    449  1.1     gwr 		} else
    450  1.1     gwr 			(*promvec->pv_putstr)(buf, len);
    451  1.1     gwr 	}
    452  1.1     gwr }
    453  1.1     gwr 
    454  1.1     gwr /*
    455  1.1     gwr  * Our "interrupt" routine for input. This is called by
    456  1.1     gwr  * the keyboard driver (dev/sun/kbd.c) at spltty.
    457  1.1     gwr  */
    458  1.1     gwr void
    459  1.1     gwr kd_input(c)
    460  1.1     gwr 	int c;
    461  1.1     gwr {
    462  1.1     gwr 	struct kd_softc *kd = &kd_softc;
    463  1.1     gwr 	struct tty *tp;
    464  1.1     gwr 
    465  1.1     gwr 	/* XXX: Make sure the device is open. */
    466  1.1     gwr 	tp = kd->kd_tty;
    467  1.1     gwr 	if (tp == NULL)
    468  1.1     gwr 		return;
    469  1.1     gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    470  1.1     gwr 		return;
    471  1.1     gwr 
    472  1.1     gwr 	(*linesw[tp->t_line].l_rint)(c, tp);
    473  1.1     gwr }
    474  1.1     gwr 
    475  1.1     gwr 
    476  1.1     gwr /****************************************************************
    477  1.1     gwr  * kd console support
    478  1.1     gwr  ****************************************************************/
    479  1.1     gwr 
    480  1.1     gwr /* The debugger gets its own key translation state. */
    481  1.1     gwr static struct kbd_state kdcn_state;
    482  1.1     gwr 
    483  1.1     gwr static void kdcnprobe __P((struct consdev *));
    484  1.1     gwr static void kdcninit __P((struct consdev *));
    485  1.1     gwr static int  kdcngetc __P((dev_t));
    486  1.1     gwr static void kdcnputc __P((dev_t, int));
    487  1.1     gwr static void kdcnpollc __P((dev_t, int));
    488  1.1     gwr 
    489  1.1     gwr struct consdev consdev_kd = {
    490  1.1     gwr 	kdcnprobe,
    491  1.1     gwr 	kdcninit,
    492  1.1     gwr 	kdcngetc,
    493  1.1     gwr 	kdcnputc,
    494  1.1     gwr 	kdcnpollc,
    495  1.1     gwr };
    496  1.1     gwr 
    497  1.1     gwr /* We never call this. */
    498  1.1     gwr static void
    499  1.1     gwr kdcnprobe(cn)
    500  1.1     gwr 	struct consdev *cn;
    501  1.1     gwr {
    502  1.1     gwr }
    503  1.1     gwr 
    504  1.1     gwr static void
    505  1.1     gwr kdcninit(cn)
    506  1.1     gwr 	struct consdev *cn;
    507  1.1     gwr {
    508  1.1     gwr 	struct kbd_state *ks = &kdcn_state;
    509  1.1     gwr 
    510  1.1     gwr 	cn->cn_dev = makedev(KDMAJOR, 0);
    511  1.1     gwr 	cn->cn_pri = CN_INTERNAL;
    512  1.1     gwr 
    513  1.1     gwr 	/* This prepares kbd_translate() */
    514  1.1     gwr 	ks->kbd_id = KBD_MIN_TYPE;
    515  1.1     gwr 	kbd_xlate_init(ks);
    516  1.1     gwr 
    517  1.1     gwr 	/* Indicate that it is OK to use the PROM fbwrite */
    518  1.1     gwr 	kd_is_console = 1;
    519  1.1     gwr }
    520  1.1     gwr 
    521  1.1     gwr static int
    522  1.1     gwr kdcngetc(dev)
    523  1.1     gwr 	dev_t dev;
    524  1.1     gwr {
    525  1.1     gwr 	struct kbd_state *ks = &kdcn_state;
    526  1.1     gwr 	int code, class, data, keysym;
    527  1.1     gwr 
    528  1.1     gwr 	for (;;) {
    529  1.1     gwr 		code = zs_getc(zs_conschan);
    530  1.1     gwr 		keysym = kbd_code_to_keysym(ks, code);
    531  1.1     gwr 		class = KEYSYM_CLASS(keysym);
    532  1.1     gwr 
    533  1.1     gwr 		switch (class) {
    534  1.1     gwr 		case KEYSYM_ASCII:
    535  1.1     gwr 			goto out;
    536  1.1     gwr 
    537  1.1     gwr 		case KEYSYM_CLRMOD:
    538  1.1     gwr 		case KEYSYM_SETMOD:
    539  1.1     gwr 			data = (keysym & 0x1F);
    540  1.1     gwr 			/* Only allow ctrl or shift. */
    541  1.1     gwr 			if (data > KBMOD_SHIFT_R)
    542  1.1     gwr 				break;
    543  1.1     gwr 			data = 1 << data;
    544  1.1     gwr 			if (class == KEYSYM_SETMOD)
    545  1.1     gwr 				ks->kbd_modbits |= data;
    546  1.1     gwr 			else
    547  1.1     gwr 				ks->kbd_modbits &= ~data;
    548  1.1     gwr 			break;
    549  1.1     gwr 
    550  1.1     gwr 		case KEYSYM_ALL_UP:
    551  1.1     gwr 			/* No toggle keys here. */
    552  1.1     gwr 			ks->kbd_modbits = 0;
    553  1.1     gwr 			break;
    554  1.1     gwr 
    555  1.1     gwr 		default:	/* ignore all other keysyms */
    556  1.1     gwr 			break;
    557  1.1     gwr 		}
    558  1.1     gwr 	}
    559  1.1     gwr out:
    560  1.1     gwr 	return (keysym);
    561  1.1     gwr }
    562  1.1     gwr 
    563  1.1     gwr static void
    564  1.1     gwr kdcnputc(dev, c)
    565  1.1     gwr 	dev_t dev;
    566  1.1     gwr 	int c;
    567  1.1     gwr {
    568  1.1     gwr 	char c0 = (c & 0x7f);
    569  1.1     gwr 
    570  1.1     gwr 	if (promvec->pv_romvec_vers > 2)
    571  1.1     gwr 		(*promvec->pv_v2devops.v2_write)
    572  1.1     gwr 			(*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
    573  1.1     gwr 	else
    574  1.1     gwr 		(*promvec->pv_putchar)(c);
    575  1.1     gwr }
    576  1.1     gwr 
    577  1.1     gwr static void
    578  1.1     gwr kdcnpollc(dev, on)
    579  1.1     gwr 	dev_t dev;
    580  1.1     gwr 	int on;
    581  1.1     gwr {
    582  1.1     gwr 	struct kbd_state *ks = &kdcn_state;
    583  1.1     gwr 
    584  1.1     gwr 	if (on) {
    585  1.1     gwr 		/* Entering debugger. */
    586  1.1     gwr 		fb_unblank();
    587  1.1     gwr 		/* Clear shift keys too. */
    588  1.1     gwr 		ks->kbd_modbits = 0;
    589  1.1     gwr 	} else {
    590  1.1     gwr 		/* Resuming kernel. */
    591  1.1     gwr 	}
    592  1.1     gwr }
    593  1.1     gwr 
    594