Home | History | Annotate | Line # | Download | only in dev
kd.c revision 1.1
      1  1.1  gwr /*	$NetBSD: kd.c,v 1.1 1997/10/18 00:00:30 gwr 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.1  gwr 
     81  1.1  gwr #define	KDMAJOR 1
     82  1.1  gwr #define PUT_WSIZE	64
     83  1.1  gwr 
     84  1.1  gwr struct kd_softc {
     85  1.1  gwr 	struct	device kd_dev;		/* required first: base device */
     86  1.1  gwr 	struct  tty *kd_tty;
     87  1.1  gwr 	int rows, cols;
     88  1.1  gwr };
     89  1.1  gwr 
     90  1.1  gwr /*
     91  1.1  gwr  * There is no point in pretending there might be
     92  1.1  gwr  * more than one keyboard/display device.
     93  1.1  gwr  */
     94  1.1  gwr static struct kd_softc kd_softc;
     95  1.1  gwr static int kd_is_console;
     96  1.1  gwr 
     97  1.1  gwr static int kdparam(struct tty *, struct termios *);
     98  1.1  gwr static void kdstart(struct tty *);
     99  1.1  gwr 
    100  1.1  gwr int	rom_console_input;	/* when set, hardclock calls cnrom() */
    101  1.1  gwr int	cons_ocount;		/* output byte count */
    102  1.1  gwr 
    103  1.1  gwr /* Now talking directly to the zs, so this is not needed. */
    104  1.1  gwr int
    105  1.1  gwr cnrom()
    106  1.1  gwr {
    107  1.1  gwr   return (0);
    108  1.1  gwr }
    109  1.1  gwr void
    110  1.1  gwr cnrint()
    111  1.1  gwr {
    112  1.1  gwr }
    113  1.1  gwr 
    114  1.1  gwr /*
    115  1.1  gwr  * This is called by kbd_attach()
    116  1.1  gwr  * XXX - Make this a proper child of kbd?
    117  1.1  gwr  */
    118  1.1  gwr void
    119  1.1  gwr kd_init(unit)
    120  1.1  gwr 	int unit;
    121  1.1  gwr {
    122  1.1  gwr 	struct kd_softc *kd;
    123  1.1  gwr 	struct tty *tp;
    124  1.1  gwr 
    125  1.1  gwr 	if (unit != 0)
    126  1.1  gwr 		return;
    127  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    128  1.1  gwr 
    129  1.1  gwr 	tp = ttymalloc();
    130  1.1  gwr 	tp->t_oproc = kdstart;
    131  1.1  gwr 	tp->t_param = kdparam;
    132  1.1  gwr 	tp->t_dev = makedev(KDMAJOR, unit);
    133  1.1  gwr 
    134  1.1  gwr #if 1	/* XXX - Why? */
    135  1.1  gwr 	clalloc(&tp->t_rawq, 1024, 1);
    136  1.1  gwr 	clalloc(&tp->t_canq, 1024, 1);
    137  1.1  gwr 	/* output queue doesn't need quoting */
    138  1.1  gwr 	clalloc(&tp->t_outq, 1024, 0);
    139  1.1  gwr #endif
    140  1.1  gwr 
    141  1.1  gwr 	tty_attach(tp);
    142  1.1  gwr 	kd->kd_tty = tp;
    143  1.1  gwr 
    144  1.1  gwr 	/*
    145  1.1  gwr 	 * get the console struct winsize.
    146  1.1  gwr 	 */
    147  1.1  gwr 	if (kd_is_console) {
    148  1.1  gwr 		fbconstty = tp;
    149  1.1  gwr #ifdef RASTERCONSOLE
    150  1.1  gwr 		kd->rows = fbrcons_rows();
    151  1.1  gwr 		kd->cols = fbrcons_cols();
    152  1.1  gwr #endif
    153  1.1  gwr 	}
    154  1.1  gwr 
    155  1.1  gwr 	if (CPU_ISSUN4COR4M) {
    156  1.1  gwr 		int i;
    157  1.1  gwr 		char *prop;
    158  1.1  gwr 
    159  1.1  gwr 		if (kd->rows == 0 &&
    160  1.1  gwr 		    (prop = getpropstring(optionsnode, "screen-#rows"))) {
    161  1.1  gwr 			i = 0;
    162  1.1  gwr 			while (*prop != '\0')
    163  1.1  gwr 				i = i * 10 + *prop++ - '0';
    164  1.1  gwr 			kd->rows = (unsigned short)i;
    165  1.1  gwr 		}
    166  1.1  gwr 		if (kd->cols == 0 &&
    167  1.1  gwr 		    (prop = getpropstring(optionsnode, "screen-#columns"))) {
    168  1.1  gwr 			i = 0;
    169  1.1  gwr 			while (*prop != '\0')
    170  1.1  gwr 				i = i * 10 + *prop++ - '0';
    171  1.1  gwr 			kd->cols = (unsigned short)i;
    172  1.1  gwr 		}
    173  1.1  gwr 	}
    174  1.1  gwr 	if (CPU_ISSUN4) {
    175  1.1  gwr 		struct eeprom *ep = (struct eeprom *)eeprom_va;
    176  1.1  gwr 
    177  1.1  gwr 		if (ep) {
    178  1.1  gwr 			if (kd->rows == 0)
    179  1.1  gwr 				kd->rows = (u_short)ep->eeTtyRows;
    180  1.1  gwr 			if (kd->cols == 0)
    181  1.1  gwr 				kd->cols = (u_short)ep->eeTtyCols;
    182  1.1  gwr 		}
    183  1.1  gwr 	}
    184  1.1  gwr 
    185  1.1  gwr 	return;
    186  1.1  gwr }
    187  1.1  gwr 
    188  1.1  gwr struct tty *
    189  1.1  gwr kdtty(dev)
    190  1.1  gwr 	dev_t dev;
    191  1.1  gwr {
    192  1.1  gwr 	struct kd_softc *kd;
    193  1.1  gwr 
    194  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    195  1.1  gwr 	return (kd->kd_tty);
    196  1.1  gwr }
    197  1.1  gwr 
    198  1.1  gwr int
    199  1.1  gwr kdopen(dev, flag, mode, p)
    200  1.1  gwr 	dev_t dev;
    201  1.1  gwr 	int flag, mode;
    202  1.1  gwr 	struct proc *p;
    203  1.1  gwr {
    204  1.1  gwr 	struct kd_softc *kd;
    205  1.1  gwr 	int error, s, unit;
    206  1.1  gwr 	struct tty *tp;
    207  1.1  gwr 
    208  1.1  gwr 	unit = minor(dev);
    209  1.1  gwr 	if (unit != 0)
    210  1.1  gwr 		return ENXIO;
    211  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    212  1.1  gwr 	tp = kd->kd_tty;
    213  1.1  gwr 
    214  1.1  gwr 	if ((error = kbd_iopen(unit)) != 0) {
    215  1.1  gwr #ifdef	DIAGNOSTIC
    216  1.1  gwr 		printf("kd: kbd_iopen, error=%d\n", error);
    217  1.1  gwr #endif
    218  1.1  gwr 		return (error);
    219  1.1  gwr 	}
    220  1.1  gwr 
    221  1.1  gwr 	/* It's simpler to do this up here. */
    222  1.1  gwr 	if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
    223  1.1  gwr 	     ==             (TS_ISOPEN | TS_XCLUDE))
    224  1.1  gwr 	    && (p->p_ucred->cr_uid != 0) )
    225  1.1  gwr 	{
    226  1.1  gwr 		return (EBUSY);
    227  1.1  gwr 	}
    228  1.1  gwr 
    229  1.1  gwr 	s = spltty();
    230  1.1  gwr 
    231  1.1  gwr 	if ((tp->t_state & TS_ISOPEN) == 0) {
    232  1.1  gwr 		/* First open. */
    233  1.1  gwr 		ttychars(tp);
    234  1.1  gwr 		tp->t_iflag = TTYDEF_IFLAG;
    235  1.1  gwr 		tp->t_oflag = TTYDEF_OFLAG;
    236  1.1  gwr 		tp->t_cflag = TTYDEF_CFLAG;
    237  1.1  gwr 		tp->t_lflag = TTYDEF_LFLAG;
    238  1.1  gwr 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    239  1.1  gwr 		(void) kdparam(tp, &tp->t_termios);
    240  1.1  gwr 		ttsetwater(tp);
    241  1.1  gwr 		tp->t_winsize.ws_row = kd->rows;
    242  1.1  gwr 		tp->t_winsize.ws_col = kd->cols;
    243  1.1  gwr 		/* Flush pending input?  Clear translator? */
    244  1.1  gwr 		/* This (pseudo)device always has SOFTCAR */
    245  1.1  gwr 		tp->t_state |= TS_CARR_ON;
    246  1.1  gwr 	}
    247  1.1  gwr 
    248  1.1  gwr 	splx(s);
    249  1.1  gwr 
    250  1.1  gwr 	return ((*linesw[tp->t_line].l_open)(dev, tp));
    251  1.1  gwr }
    252  1.1  gwr 
    253  1.1  gwr int
    254  1.1  gwr kdclose(dev, flag, mode, p)
    255  1.1  gwr 	dev_t dev;
    256  1.1  gwr 	int flag, mode;
    257  1.1  gwr 	struct proc *p;
    258  1.1  gwr {
    259  1.1  gwr 	struct kd_softc *kd;
    260  1.1  gwr 	struct tty *tp;
    261  1.1  gwr 
    262  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    263  1.1  gwr 	tp = kd->kd_tty;
    264  1.1  gwr 
    265  1.1  gwr 	/* XXX This is for cons.c. */
    266  1.1  gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    267  1.1  gwr 		return 0;
    268  1.1  gwr 
    269  1.1  gwr 	(*linesw[tp->t_line].l_close)(tp, flag);
    270  1.1  gwr 	ttyclose(tp);
    271  1.1  gwr 	return (0);
    272  1.1  gwr }
    273  1.1  gwr 
    274  1.1  gwr int
    275  1.1  gwr kdread(dev, uio, flag)
    276  1.1  gwr 	dev_t dev;
    277  1.1  gwr 	struct uio *uio;
    278  1.1  gwr 	int flag;
    279  1.1  gwr {
    280  1.1  gwr 	struct kd_softc *kd;
    281  1.1  gwr 	struct tty *tp;
    282  1.1  gwr 
    283  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    284  1.1  gwr 	tp = kd->kd_tty;
    285  1.1  gwr 
    286  1.1  gwr 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    287  1.1  gwr }
    288  1.1  gwr 
    289  1.1  gwr int
    290  1.1  gwr kdwrite(dev, uio, flag)
    291  1.1  gwr 	dev_t dev;
    292  1.1  gwr 	struct uio *uio;
    293  1.1  gwr 	int flag;
    294  1.1  gwr {
    295  1.1  gwr 	struct kd_softc *kd;
    296  1.1  gwr 	struct tty *tp;
    297  1.1  gwr 
    298  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    299  1.1  gwr 	tp = kd->kd_tty;
    300  1.1  gwr 
    301  1.1  gwr 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    302  1.1  gwr }
    303  1.1  gwr 
    304  1.1  gwr int
    305  1.1  gwr kdioctl(dev, cmd, data, flag, p)
    306  1.1  gwr 	dev_t dev;
    307  1.1  gwr 	u_long cmd;
    308  1.1  gwr 	caddr_t data;
    309  1.1  gwr 	int flag;
    310  1.1  gwr 	struct proc *p;
    311  1.1  gwr {
    312  1.1  gwr 	struct kd_softc *kd;
    313  1.1  gwr 	struct tty *tp;
    314  1.1  gwr 	int error;
    315  1.1  gwr 
    316  1.1  gwr 	kd = &kd_softc; 	/* XXX */
    317  1.1  gwr 	tp = kd->kd_tty;
    318  1.1  gwr 
    319  1.1  gwr 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    320  1.1  gwr 	if (error >= 0)
    321  1.1  gwr 		return error;
    322  1.1  gwr 	error = ttioctl(tp, cmd, data, flag, p);
    323  1.1  gwr 	if (error >= 0)
    324  1.1  gwr 		return error;
    325  1.1  gwr 
    326  1.1  gwr 	/* Handle any ioctl commands specific to kbd/display. */
    327  1.1  gwr 	/* XXX - Send KB* ioctls to kbd module? */
    328  1.1  gwr 	/* XXX - Send FB* ioctls to fb module?  */
    329  1.1  gwr 
    330  1.1  gwr 	return ENOTTY;
    331  1.1  gwr }
    332  1.1  gwr 
    333  1.1  gwr void
    334  1.1  gwr kdstop(tp, flag)
    335  1.1  gwr 	struct tty *tp;
    336  1.1  gwr 	int flag;
    337  1.1  gwr {
    338  1.1  gwr 
    339  1.1  gwr }
    340  1.1  gwr 
    341  1.1  gwr 
    342  1.1  gwr static int
    343  1.1  gwr kdparam(tp, t)
    344  1.1  gwr 	struct tty *tp;
    345  1.1  gwr 	struct termios *t;
    346  1.1  gwr {
    347  1.1  gwr 	/* XXX - These are ignored... */
    348  1.1  gwr 	tp->t_ispeed = t->c_ispeed;
    349  1.1  gwr 	tp->t_ospeed = t->c_ospeed;
    350  1.1  gwr 	tp->t_cflag = t->c_cflag;
    351  1.1  gwr 	return 0;
    352  1.1  gwr }
    353  1.1  gwr 
    354  1.1  gwr 
    355  1.1  gwr static void kd_later(void*);
    356  1.1  gwr static void kd_putfb(struct tty *);
    357  1.1  gwr 
    358  1.1  gwr static void
    359  1.1  gwr kdstart(tp)
    360  1.1  gwr 	struct tty *tp;
    361  1.1  gwr {
    362  1.1  gwr 	struct clist *cl;
    363  1.1  gwr 	register int s;
    364  1.1  gwr 
    365  1.1  gwr 	s = spltty();
    366  1.1  gwr 	if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
    367  1.1  gwr 		goto out;
    368  1.1  gwr 
    369  1.1  gwr 	cl = &tp->t_outq;
    370  1.1  gwr 	if (cl->c_cc) {
    371  1.1  gwr 		if (kd_is_console) {
    372  1.1  gwr 			tp->t_state |= TS_BUSY;
    373  1.1  gwr 			if ((s & PSR_PIL) == 0) {
    374  1.1  gwr 				/* called at level zero - update screen now. */
    375  1.1  gwr 				(void) splsoftclock();
    376  1.1  gwr 				kd_putfb(tp);
    377  1.1  gwr 				(void) spltty();
    378  1.1  gwr 				tp->t_state &= ~TS_BUSY;
    379  1.1  gwr 			} else {
    380  1.1  gwr 				/* called at interrupt level - do it later */
    381  1.1  gwr 				timeout(kd_later, (void*)tp, 0);
    382  1.1  gwr 			}
    383  1.1  gwr 		} else {
    384  1.1  gwr 			/*
    385  1.1  gwr 			 * This driver uses the PROM for writing the screen,
    386  1.1  gwr 			 * and that only works if this is the console device.
    387  1.1  gwr 			 * If this is not the console, just flush the output.
    388  1.1  gwr 			 * Sorry.  (In that case, use xdm instead of getty.)
    389  1.1  gwr 			 */
    390  1.1  gwr 			ndflush(cl, cl->c_cc);
    391  1.1  gwr 		}
    392  1.1  gwr 	}
    393  1.1  gwr 	if (cl->c_cc <= tp->t_lowat) {
    394  1.1  gwr 		if (tp->t_state & TS_ASLEEP) {
    395  1.1  gwr 			tp->t_state &= ~TS_ASLEEP;
    396  1.1  gwr 			wakeup((caddr_t)cl);
    397  1.1  gwr 		}
    398  1.1  gwr 		selwakeup(&tp->t_wsel);
    399  1.1  gwr 	}
    400  1.1  gwr out:
    401  1.1  gwr 	splx(s);
    402  1.1  gwr }
    403  1.1  gwr 
    404  1.1  gwr /*
    405  1.1  gwr  * Timeout function to do delayed writes to the screen.
    406  1.1  gwr  * Called at splsoftclock when requested by kdstart.
    407  1.1  gwr  */
    408  1.1  gwr static void
    409  1.1  gwr kd_later(tpaddr)
    410  1.1  gwr 	void *tpaddr;
    411  1.1  gwr {
    412  1.1  gwr 	struct tty *tp = tpaddr;
    413  1.1  gwr 	register int s;
    414  1.1  gwr 
    415  1.1  gwr 	kd_putfb(tp);
    416  1.1  gwr 
    417  1.1  gwr 	s = spltty();
    418  1.1  gwr 	tp->t_state &= ~TS_BUSY;
    419  1.1  gwr 	(*linesw[tp->t_line].l_start)(tp);
    420  1.1  gwr 	splx(s);
    421  1.1  gwr }
    422  1.1  gwr 
    423  1.1  gwr /*
    424  1.1  gwr  * Put text on the screen using the PROM monitor.
    425  1.1  gwr  * This can take a while, so to avoid missing
    426  1.1  gwr  * interrupts, this is called at splsoftclock.
    427  1.1  gwr  */
    428  1.1  gwr static void
    429  1.1  gwr kd_putfb(tp)
    430  1.1  gwr 	struct tty *tp;
    431  1.1  gwr {
    432  1.1  gwr 	char buf[PUT_WSIZE];
    433  1.1  gwr 	struct clist *cl = &tp->t_outq;
    434  1.1  gwr 	char *p, *end;
    435  1.1  gwr 	int len;
    436  1.1  gwr 
    437  1.1  gwr 	while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
    438  1.1  gwr 		/* PROM will barf if high bits are set. */
    439  1.1  gwr 		p = buf;
    440  1.1  gwr 		end = buf + len;
    441  1.1  gwr 		while (p < end)
    442  1.1  gwr 			*p++ &= 0x7f;
    443  1.1  gwr 		/* Now let the PROM print it. */
    444  1.1  gwr 		if (promvec->pv_romvec_vers > 2) {
    445  1.1  gwr 			(*promvec->pv_v2devops.v2_write)
    446  1.1  gwr 				(*promvec->pv_v2bootargs.v2_fd1, buf, len);
    447  1.1  gwr 		} else
    448  1.1  gwr 			(*promvec->pv_putstr)(buf, len);
    449  1.1  gwr 	}
    450  1.1  gwr }
    451  1.1  gwr 
    452  1.1  gwr /*
    453  1.1  gwr  * Our "interrupt" routine for input. This is called by
    454  1.1  gwr  * the keyboard driver (dev/sun/kbd.c) at spltty.
    455  1.1  gwr  */
    456  1.1  gwr void
    457  1.1  gwr kd_input(c)
    458  1.1  gwr 	int c;
    459  1.1  gwr {
    460  1.1  gwr 	struct kd_softc *kd = &kd_softc;
    461  1.1  gwr 	struct tty *tp;
    462  1.1  gwr 
    463  1.1  gwr 	/* XXX: Make sure the device is open. */
    464  1.1  gwr 	tp = kd->kd_tty;
    465  1.1  gwr 	if (tp == NULL)
    466  1.1  gwr 		return;
    467  1.1  gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    468  1.1  gwr 		return;
    469  1.1  gwr 
    470  1.1  gwr 	(*linesw[tp->t_line].l_rint)(c, tp);
    471  1.1  gwr }
    472  1.1  gwr 
    473  1.1  gwr 
    474  1.1  gwr /****************************************************************
    475  1.1  gwr  * kd console support
    476  1.1  gwr  ****************************************************************/
    477  1.1  gwr 
    478  1.1  gwr /* The debugger gets its own key translation state. */
    479  1.1  gwr static struct kbd_state kdcn_state;
    480  1.1  gwr 
    481  1.1  gwr static void kdcnprobe __P((struct consdev *));
    482  1.1  gwr static void kdcninit __P((struct consdev *));
    483  1.1  gwr static int  kdcngetc __P((dev_t));
    484  1.1  gwr static void kdcnputc __P((dev_t, int));
    485  1.1  gwr static void kdcnpollc __P((dev_t, int));
    486  1.1  gwr 
    487  1.1  gwr struct consdev consdev_kd = {
    488  1.1  gwr 	kdcnprobe,
    489  1.1  gwr 	kdcninit,
    490  1.1  gwr 	kdcngetc,
    491  1.1  gwr 	kdcnputc,
    492  1.1  gwr 	kdcnpollc,
    493  1.1  gwr };
    494  1.1  gwr 
    495  1.1  gwr /* We never call this. */
    496  1.1  gwr static void
    497  1.1  gwr kdcnprobe(cn)
    498  1.1  gwr 	struct consdev *cn;
    499  1.1  gwr {
    500  1.1  gwr }
    501  1.1  gwr 
    502  1.1  gwr static void
    503  1.1  gwr kdcninit(cn)
    504  1.1  gwr 	struct consdev *cn;
    505  1.1  gwr {
    506  1.1  gwr 	struct kbd_state *ks = &kdcn_state;
    507  1.1  gwr 
    508  1.1  gwr 	cn->cn_dev = makedev(KDMAJOR, 0);
    509  1.1  gwr 	cn->cn_pri = CN_INTERNAL;
    510  1.1  gwr 
    511  1.1  gwr 	/* This prepares kbd_translate() */
    512  1.1  gwr 	ks->kbd_id = KBD_MIN_TYPE;
    513  1.1  gwr 	kbd_xlate_init(ks);
    514  1.1  gwr 
    515  1.1  gwr 	/* Indicate that it is OK to use the PROM fbwrite */
    516  1.1  gwr 	kd_is_console = 1;
    517  1.1  gwr }
    518  1.1  gwr 
    519  1.1  gwr static int
    520  1.1  gwr kdcngetc(dev)
    521  1.1  gwr 	dev_t dev;
    522  1.1  gwr {
    523  1.1  gwr 	struct kbd_state *ks = &kdcn_state;
    524  1.1  gwr 	int code, class, data, keysym;
    525  1.1  gwr 
    526  1.1  gwr 	for (;;) {
    527  1.1  gwr 		code = zs_getc(zs_conschan);
    528  1.1  gwr 		keysym = kbd_code_to_keysym(ks, code);
    529  1.1  gwr 		class = KEYSYM_CLASS(keysym);
    530  1.1  gwr 
    531  1.1  gwr 		switch (class) {
    532  1.1  gwr 		case KEYSYM_ASCII:
    533  1.1  gwr 			goto out;
    534  1.1  gwr 
    535  1.1  gwr 		case KEYSYM_CLRMOD:
    536  1.1  gwr 		case KEYSYM_SETMOD:
    537  1.1  gwr 			data = (keysym & 0x1F);
    538  1.1  gwr 			/* Only allow ctrl or shift. */
    539  1.1  gwr 			if (data > KBMOD_SHIFT_R)
    540  1.1  gwr 				break;
    541  1.1  gwr 			data = 1 << data;
    542  1.1  gwr 			if (class == KEYSYM_SETMOD)
    543  1.1  gwr 				ks->kbd_modbits |= data;
    544  1.1  gwr 			else
    545  1.1  gwr 				ks->kbd_modbits &= ~data;
    546  1.1  gwr 			break;
    547  1.1  gwr 
    548  1.1  gwr 		case KEYSYM_ALL_UP:
    549  1.1  gwr 			/* No toggle keys here. */
    550  1.1  gwr 			ks->kbd_modbits = 0;
    551  1.1  gwr 			break;
    552  1.1  gwr 
    553  1.1  gwr 		default:	/* ignore all other keysyms */
    554  1.1  gwr 			break;
    555  1.1  gwr 		}
    556  1.1  gwr 	}
    557  1.1  gwr out:
    558  1.1  gwr 	return (keysym);
    559  1.1  gwr }
    560  1.1  gwr 
    561  1.1  gwr static void
    562  1.1  gwr kdcnputc(dev, c)
    563  1.1  gwr 	dev_t dev;
    564  1.1  gwr 	int c;
    565  1.1  gwr {
    566  1.1  gwr 	char c0 = (c & 0x7f);
    567  1.1  gwr 
    568  1.1  gwr 	if (promvec->pv_romvec_vers > 2)
    569  1.1  gwr 		(*promvec->pv_v2devops.v2_write)
    570  1.1  gwr 			(*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
    571  1.1  gwr 	else
    572  1.1  gwr 		(*promvec->pv_putchar)(c);
    573  1.1  gwr }
    574  1.1  gwr 
    575  1.1  gwr static void
    576  1.1  gwr kdcnpollc(dev, on)
    577  1.1  gwr 	dev_t dev;
    578  1.1  gwr 	int on;
    579  1.1  gwr {
    580  1.1  gwr 	struct kbd_state *ks = &kdcn_state;
    581  1.1  gwr 
    582  1.1  gwr 	if (on) {
    583  1.1  gwr 		/* Entering debugger. */
    584  1.1  gwr 		fb_unblank();
    585  1.1  gwr 		/* Clear shift keys too. */
    586  1.1  gwr 		ks->kbd_modbits = 0;
    587  1.1  gwr 	} else {
    588  1.1  gwr 		/* Resuming kernel. */
    589  1.1  gwr 	}
    590  1.1  gwr }
    591  1.1  gwr 
    592