Home | History | Annotate | Line # | Download | only in dev
kd.c revision 1.27.2.1
      1  1.27.2.1    bouyer /*	$NetBSD: kd.c,v 1.27.2.1 2000/11/20 20:27:52 bouyer Exp $	*/
      2       1.4       cgd 
      3      1.21       gwr /*-
      4      1.21       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5       1.1       gwr  * All rights reserved.
      6       1.1       gwr  *
      7      1.21       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8      1.21       gwr  * by Gordon W. Ross.
      9      1.21       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.21       gwr  * 3. All advertising materials mentioning features or use of this software
     19      1.11       gwr  *    must display the following acknowledgement:
     20      1.21       gwr  *        This product includes software developed by the NetBSD
     21      1.21       gwr  *        Foundation, Inc. and its contributors.
     22      1.21       gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.21       gwr  *    contributors may be used to endorse or promote products derived
     24      1.21       gwr  *    from this software without specific prior written permission.
     25       1.1       gwr  *
     26      1.21       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.21       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.21       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.23       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.23       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.21       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.21       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.21       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.21       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.21       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.21       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.20  christos  * 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/autoconf.h>
     58       1.1       gwr #include <machine/mon.h>
     59      1.11       gwr #include <machine/psl.h>
     60       1.1       gwr 
     61       1.1       gwr #include <dev/cons.h>
     62  1.27.2.1    bouyer #include <dev/sun/event_var.h>
     63      1.14       gwr #include <dev/sun/kbd_xlate.h>
     64  1.27.2.1    bouyer #include <dev/sun/kbdvar.h>
     65      1.22       gwr #include <sun3/dev/zs_cons.h>
     66      1.22       gwr 
     67      1.26       gwr #include "fb.h"
     68      1.26       gwr 
     69      1.22       gwr extern void fb_unblank __P((void)); /* XXX */
     70       1.1       gwr 
     71      1.14       gwr #define	KDMAJOR 1
     72      1.14       gwr #define PUT_WSIZE	64
     73      1.14       gwr 
     74      1.14       gwr cdev_decl(kd);	/* open, close, read, write, ioctl, stop, ... */
     75      1.14       gwr 
     76      1.14       gwr struct kd_softc {
     77      1.14       gwr 	struct	device kd_dev;		/* required first: base device */
     78      1.14       gwr 	struct  tty *kd_tty;
     79  1.27.2.1    bouyer 
     80  1.27.2.1    bouyer 	/* Console input hook */
     81  1.27.2.1    bouyer 	struct cons_channel *kd_in;
     82      1.14       gwr };
     83       1.1       gwr 
     84      1.13       gwr /*
     85      1.13       gwr  * There is no point in pretending there might be
     86      1.13       gwr  * more than one keyboard/display device.
     87      1.13       gwr  */
     88      1.25       gwr static struct kd_softc kd_softc;
     89      1.25       gwr static int kd_is_console;
     90       1.1       gwr 
     91       1.1       gwr static int kdparam(struct tty *, struct termios *);
     92       1.1       gwr static void kdstart(struct tty *);
     93  1.27.2.1    bouyer static void kd_init __P((struct kd_softc *));
     94  1.27.2.1    bouyer static void kd_cons_input __P((int));
     95       1.1       gwr 
     96      1.10       gwr 
     97      1.14       gwr /*
     98  1.27.2.1    bouyer  * Prepare the console tty; called on first open of /dev/console
     99      1.14       gwr  */
    100       1.7       gwr void
    101  1.27.2.1    bouyer kd_init(kd)
    102      1.14       gwr 	struct kd_softc *kd;
    103  1.27.2.1    bouyer {
    104      1.14       gwr 	struct tty *tp;
    105      1.14       gwr 
    106      1.14       gwr 	tp = ttymalloc();
    107      1.14       gwr 	tp->t_oproc = kdstart;
    108      1.14       gwr 	tp->t_param = kdparam;
    109  1.27.2.1    bouyer 	tp->t_dev = makedev(KDMAJOR, 0);
    110      1.17       gwr 
    111  1.27.2.1    bouyer 	tty_attach(tp);
    112      1.17       gwr 	kd->kd_tty = tp;
    113      1.14       gwr 
    114      1.14       gwr 	return;
    115      1.13       gwr }
    116      1.13       gwr 
    117      1.13       gwr struct tty *
    118      1.13       gwr kdtty(dev)
    119      1.13       gwr 	dev_t dev;
    120      1.13       gwr {
    121      1.14       gwr 	struct kd_softc *kd;
    122      1.14       gwr 
    123      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    124      1.14       gwr 	return (kd->kd_tty);
    125       1.1       gwr }
    126       1.1       gwr 
    127       1.1       gwr int
    128       1.1       gwr kdopen(dev, flag, mode, p)
    129       1.1       gwr 	dev_t dev;
    130       1.1       gwr 	int flag, mode;
    131       1.1       gwr 	struct proc *p;
    132       1.1       gwr {
    133      1.14       gwr 	struct kd_softc *kd;
    134      1.14       gwr 	int error, s, unit;
    135       1.1       gwr 	struct tty *tp;
    136  1.27.2.1    bouyer static	int firstopen = 1;
    137       1.1       gwr 
    138       1.1       gwr 	unit = minor(dev);
    139      1.14       gwr 	if (unit != 0)
    140       1.1       gwr 		return ENXIO;
    141      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    142  1.27.2.1    bouyer 	if (firstopen) {
    143  1.27.2.1    bouyer 		kd_init(kd);
    144  1.27.2.1    bouyer 		firstopen = 0;
    145       1.8       gwr 	}
    146  1.27.2.1    bouyer 	tp = kd->kd_tty;
    147       1.1       gwr 
    148      1.14       gwr 	/* It's simpler to do this up here. */
    149      1.14       gwr 	if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
    150      1.14       gwr 	     ==             (TS_ISOPEN | TS_XCLUDE))
    151      1.14       gwr 	    && (p->p_ucred->cr_uid != 0) )
    152      1.14       gwr 	{
    153      1.14       gwr 		return (EBUSY);
    154      1.14       gwr 	}
    155      1.14       gwr 
    156      1.14       gwr 	s = spltty();
    157      1.14       gwr 
    158       1.1       gwr 	if ((tp->t_state & TS_ISOPEN) == 0) {
    159      1.14       gwr 		/* First open. */
    160  1.27.2.1    bouyer 
    161  1.27.2.1    bouyer 		/* Notify the input device that serves us */
    162  1.27.2.1    bouyer 		struct cons_channel *cc = kd->kd_in;
    163  1.27.2.1    bouyer 		if (cc != NULL &&
    164  1.27.2.1    bouyer 		    (error = (*cc->cc_iopen)(cc)) != 0) {
    165  1.27.2.1    bouyer 			return (error);
    166  1.27.2.1    bouyer 		}
    167  1.27.2.1    bouyer 
    168       1.1       gwr 		ttychars(tp);
    169       1.1       gwr 		tp->t_iflag = TTYDEF_IFLAG;
    170       1.1       gwr 		tp->t_oflag = TTYDEF_OFLAG;
    171       1.1       gwr 		tp->t_cflag = TTYDEF_CFLAG;
    172       1.1       gwr 		tp->t_lflag = TTYDEF_LFLAG;
    173       1.1       gwr 		tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    174      1.14       gwr 		(void) kdparam(tp, &tp->t_termios);
    175       1.1       gwr 		ttsetwater(tp);
    176      1.14       gwr 		/* Flush pending input?  Clear translator? */
    177      1.14       gwr 		/* This (pseudo)device always has SOFTCAR */
    178      1.14       gwr 		tp->t_state |= TS_CARR_ON;
    179      1.14       gwr 	}
    180      1.14       gwr 
    181      1.14       gwr 	splx(s);
    182       1.1       gwr 
    183       1.1       gwr 	return ((*linesw[tp->t_line].l_open)(dev, tp));
    184       1.1       gwr }
    185       1.1       gwr 
    186       1.1       gwr int
    187       1.1       gwr kdclose(dev, flag, mode, p)
    188       1.1       gwr 	dev_t dev;
    189       1.1       gwr 	int flag, mode;
    190       1.1       gwr 	struct proc *p;
    191       1.1       gwr {
    192      1.14       gwr 	struct kd_softc *kd;
    193      1.14       gwr 	struct tty *tp;
    194  1.27.2.1    bouyer 	struct cons_channel *cc;
    195      1.14       gwr 
    196      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    197      1.14       gwr 	tp = kd->kd_tty;
    198      1.14       gwr 
    199      1.14       gwr 	/* XXX This is for cons.c. */
    200      1.14       gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    201      1.14       gwr 		return 0;
    202       1.1       gwr 
    203       1.1       gwr 	(*linesw[tp->t_line].l_close)(tp, flag);
    204       1.1       gwr 	ttyclose(tp);
    205  1.27.2.1    bouyer 	if ((cc = kd->kd_in) != NULL)
    206  1.27.2.1    bouyer 		(void)(*cc->cc_iclose)(cc->cc_dev);
    207       1.1       gwr 	return (0);
    208       1.1       gwr }
    209       1.1       gwr 
    210       1.1       gwr int
    211       1.1       gwr kdread(dev, uio, flag)
    212       1.1       gwr 	dev_t dev;
    213       1.1       gwr 	struct uio *uio;
    214       1.1       gwr 	int flag;
    215       1.1       gwr {
    216      1.14       gwr 	struct kd_softc *kd;
    217      1.14       gwr 	struct tty *tp;
    218      1.14       gwr 
    219      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    220      1.14       gwr 	tp = kd->kd_tty;
    221       1.1       gwr 
    222       1.1       gwr 	return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
    223       1.1       gwr }
    224       1.1       gwr 
    225       1.1       gwr int
    226       1.1       gwr kdwrite(dev, uio, flag)
    227       1.1       gwr 	dev_t dev;
    228       1.1       gwr 	struct uio *uio;
    229       1.1       gwr 	int flag;
    230       1.1       gwr {
    231      1.14       gwr 	struct kd_softc *kd;
    232      1.14       gwr 	struct tty *tp;
    233      1.14       gwr 
    234      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    235      1.14       gwr 	tp = kd->kd_tty;
    236       1.1       gwr 
    237       1.1       gwr 	return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
    238      1.12   mycroft }
    239      1.12   mycroft 
    240      1.12   mycroft int
    241       1.1       gwr kdioctl(dev, cmd, data, flag, p)
    242       1.1       gwr 	dev_t dev;
    243      1.14       gwr 	u_long cmd;
    244       1.1       gwr 	caddr_t data;
    245       1.1       gwr 	int flag;
    246       1.1       gwr 	struct proc *p;
    247       1.1       gwr {
    248      1.14       gwr 	struct kd_softc *kd;
    249      1.14       gwr 	struct tty *tp;
    250       1.1       gwr 	int error;
    251      1.14       gwr 
    252      1.14       gwr 	kd = &kd_softc; 	/* XXX */
    253      1.14       gwr 	tp = kd->kd_tty;
    254       1.1       gwr 
    255       1.1       gwr 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
    256       1.1       gwr 	if (error >= 0)
    257       1.1       gwr 		return error;
    258       1.1       gwr 	error = ttioctl(tp, cmd, data, flag, p);
    259       1.1       gwr 	if (error >= 0)
    260       1.1       gwr 		return error;
    261       1.1       gwr 
    262       1.1       gwr 	/* Handle any ioctl commands specific to kbd/display. */
    263       1.1       gwr 	/* XXX - Send KB* ioctls to kbd module? */
    264       1.1       gwr 	/* XXX - Send FB* ioctls to fb module?  */
    265       1.1       gwr 
    266       1.1       gwr 	return ENOTTY;
    267       1.1       gwr }
    268       1.1       gwr 
    269      1.25       gwr void
    270      1.25       gwr kdstop(tp, flag)
    271      1.25       gwr 	struct tty *tp;
    272      1.25       gwr 	int flag;
    273      1.25       gwr {
    274      1.25       gwr 
    275      1.25       gwr }
    276      1.25       gwr 
    277      1.14       gwr 
    278      1.14       gwr static int
    279      1.14       gwr kdparam(tp, t)
    280      1.14       gwr 	struct tty *tp;
    281      1.14       gwr 	struct termios *t;
    282      1.14       gwr {
    283      1.14       gwr 	/* XXX - These are ignored... */
    284      1.14       gwr 	tp->t_ispeed = t->c_ispeed;
    285      1.14       gwr 	tp->t_ospeed = t->c_ospeed;
    286      1.14       gwr 	tp->t_cflag = t->c_cflag;
    287      1.14       gwr 	return 0;
    288      1.14       gwr }
    289      1.14       gwr 
    290      1.14       gwr 
    291      1.11       gwr static void kd_later(void*);
    292      1.11       gwr static void kd_putfb(struct tty *);
    293      1.11       gwr 
    294      1.25       gwr static void
    295       1.1       gwr kdstart(tp)
    296       1.1       gwr 	struct tty *tp;
    297       1.1       gwr {
    298       1.1       gwr 	struct clist *cl;
    299      1.11       gwr 	register int s;
    300       1.1       gwr 
    301       1.1       gwr 	s = spltty();
    302       1.1       gwr 	if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
    303       1.1       gwr 		goto out;
    304      1.11       gwr 
    305       1.1       gwr 	cl = &tp->t_outq;
    306      1.11       gwr 	if (cl->c_cc) {
    307      1.10       gwr 		if (kd_is_console) {
    308      1.11       gwr 			tp->t_state |= TS_BUSY;
    309      1.11       gwr 			if ((s & PSL_IPL) == 0) {
    310      1.11       gwr 				/* called at level zero - update screen now. */
    311      1.27   thorpej 				(void) spllowersoftclock();
    312      1.11       gwr 				kd_putfb(tp);
    313      1.11       gwr 				(void) spltty();
    314      1.11       gwr 				tp->t_state &= ~TS_BUSY;
    315      1.11       gwr 			} else {
    316      1.11       gwr 				/* called at interrupt level - do it later */
    317  1.27.2.1    bouyer 				callout_reset(&tp->t_rstrt_ch, 0,
    318  1.27.2.1    bouyer 				    kd_later, tp);
    319      1.11       gwr 			}
    320      1.11       gwr 		} else {
    321      1.11       gwr 			/*
    322      1.11       gwr 			 * This driver uses the PROM for writing the screen,
    323      1.11       gwr 			 * and that only works if this is the console device.
    324      1.11       gwr 			 * If this is not the console, just flush the output.
    325      1.11       gwr 			 * Sorry.  (In that case, use xdm instead of getty.)
    326      1.11       gwr 			 */
    327      1.11       gwr 			ndflush(cl, cl->c_cc);
    328      1.11       gwr 		}
    329      1.11       gwr 	}
    330      1.11       gwr 	if (cl->c_cc <= tp->t_lowat) {
    331      1.11       gwr 		if (tp->t_state & TS_ASLEEP) {
    332      1.11       gwr 			tp->t_state &= ~TS_ASLEEP;
    333      1.11       gwr 			wakeup((caddr_t)cl);
    334      1.10       gwr 		}
    335      1.11       gwr 		selwakeup(&tp->t_wsel);
    336       1.1       gwr 	}
    337      1.11       gwr out:
    338      1.11       gwr 	splx(s);
    339      1.11       gwr }
    340      1.11       gwr 
    341      1.11       gwr /*
    342      1.11       gwr  * Timeout function to do delayed writes to the screen.
    343      1.11       gwr  * Called at splsoftclock when requested by kdstart.
    344      1.11       gwr  */
    345      1.11       gwr static void
    346      1.11       gwr kd_later(tpaddr)
    347      1.11       gwr 	void *tpaddr;
    348      1.11       gwr {
    349      1.11       gwr 	struct tty *tp = tpaddr;
    350      1.11       gwr 	register int s;
    351       1.1       gwr 
    352      1.11       gwr 	kd_putfb(tp);
    353      1.11       gwr 
    354      1.11       gwr 	s = spltty();
    355       1.1       gwr 	tp->t_state &= ~TS_BUSY;
    356      1.16       gwr 	(*linesw[tp->t_line].l_start)(tp);
    357      1.11       gwr 	splx(s);
    358      1.11       gwr }
    359      1.11       gwr 
    360      1.11       gwr /*
    361      1.11       gwr  * Put text on the screen using the PROM monitor.
    362      1.11       gwr  * This can take a while, so to avoid missing
    363      1.11       gwr  * interrupts, this is called at splsoftclock.
    364      1.11       gwr  */
    365      1.25       gwr static void
    366      1.25       gwr kd_putfb(tp)
    367      1.11       gwr 	struct tty *tp;
    368      1.11       gwr {
    369      1.14       gwr 	char buf[PUT_WSIZE];
    370      1.11       gwr 	struct clist *cl = &tp->t_outq;
    371      1.11       gwr 	char *p, *end;
    372      1.11       gwr 	int len;
    373      1.11       gwr 
    374      1.14       gwr 	while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
    375      1.11       gwr 		/* PROM will barf if high bits are set. */
    376      1.11       gwr 		p = buf;
    377      1.11       gwr 		end = buf + len;
    378      1.11       gwr 		while (p < end)
    379      1.11       gwr 			*p++ &= 0x7f;
    380      1.11       gwr 		(romVectorPtr->fbWriteStr)(buf, len);
    381       1.1       gwr 	}
    382       1.1       gwr }
    383       1.1       gwr 
    384  1.27.2.1    bouyer void
    385  1.27.2.1    bouyer cons_attach_input(cc, cn)
    386  1.27.2.1    bouyer 	struct cons_channel *cc;
    387  1.27.2.1    bouyer 	struct consdev *cn;
    388  1.27.2.1    bouyer {
    389  1.27.2.1    bouyer 	struct kd_softc *kd = &kd_softc;
    390  1.27.2.1    bouyer 
    391  1.27.2.1    bouyer 	kd->kd_in = cc;
    392  1.27.2.1    bouyer 	cc->cc_upstream = kd_cons_input;
    393  1.27.2.1    bouyer }
    394  1.27.2.1    bouyer 
    395  1.27.2.1    bouyer /*
    396  1.27.2.1    bouyer  * Default PROM-based console input stream
    397  1.27.2.1    bouyer  */
    398  1.27.2.1    bouyer static int kd_rom_iopen __P((struct cons_channel *));
    399  1.27.2.1    bouyer static int kd_rom_iclose __P((struct cons_channel *));
    400  1.27.2.1    bouyer 
    401  1.27.2.1    bouyer static struct cons_channel prom_cons_channel;
    402  1.27.2.1    bouyer 
    403  1.27.2.1    bouyer int
    404  1.27.2.1    bouyer kd_rom_iopen(cc)
    405  1.27.2.1    bouyer 	struct cons_channel *cc;
    406  1.27.2.1    bouyer {
    407  1.27.2.1    bouyer 	/* No-op */
    408  1.27.2.1    bouyer 	return (0);
    409  1.27.2.1    bouyer }
    410  1.27.2.1    bouyer 
    411  1.27.2.1    bouyer int
    412  1.27.2.1    bouyer kd_rom_iclose(cc)
    413  1.27.2.1    bouyer 	struct cons_channel *cc;
    414  1.27.2.1    bouyer {
    415  1.27.2.1    bouyer 	/* No-op */
    416  1.27.2.1    bouyer 	return (0);
    417  1.27.2.1    bouyer }
    418  1.27.2.1    bouyer 
    419      1.14       gwr /*
    420      1.15       gwr  * Our "interrupt" routine for input. This is called by
    421      1.15       gwr  * the keyboard driver (dev/sun/kbd.c) at spltty.
    422      1.14       gwr  */
    423      1.14       gwr void
    424  1.27.2.1    bouyer kd_cons_input(c)
    425      1.14       gwr 	int c;
    426      1.14       gwr {
    427      1.14       gwr 	struct kd_softc *kd = &kd_softc;
    428      1.14       gwr 	struct tty *tp;
    429      1.14       gwr 
    430      1.14       gwr 	/* XXX: Make sure the device is open. */
    431      1.14       gwr 	tp = kd->kd_tty;
    432      1.14       gwr 	if (tp == NULL)
    433      1.14       gwr 		return;
    434      1.25       gwr 	if ((tp->t_state & TS_ISOPEN) == 0)
    435      1.14       gwr 		return;
    436      1.11       gwr 
    437      1.16       gwr 	(*linesw[tp->t_line].l_rint)(c, tp);
    438       1.1       gwr }
    439       1.1       gwr 
    440       1.1       gwr 
    441      1.14       gwr /****************************************************************
    442       1.1       gwr  * kd console support
    443      1.14       gwr  ****************************************************************/
    444       1.1       gwr 
    445      1.14       gwr /* The debugger gets its own key translation state. */
    446      1.14       gwr static struct kbd_state kdcn_state;
    447       1.1       gwr 
    448      1.25       gwr static void kdcnprobe __P((struct consdev *));
    449      1.25       gwr static void kdcninit __P((struct consdev *));
    450      1.25       gwr static int  kdcngetc __P((dev_t));
    451      1.25       gwr static void kdcnputc __P((dev_t, int));
    452      1.25       gwr static void kdcnpollc __P((dev_t, int));
    453      1.25       gwr 
    454      1.25       gwr struct consdev consdev_kd = {
    455      1.25       gwr 	kdcnprobe,
    456      1.25       gwr 	kdcninit,
    457      1.25       gwr 	kdcngetc,
    458      1.25       gwr 	kdcnputc,
    459      1.25       gwr 	kdcnpollc,
    460  1.27.2.1    bouyer 	NULL,
    461      1.25       gwr };
    462      1.25       gwr 
    463      1.25       gwr /* We never call this. */
    464      1.25       gwr static void
    465      1.25       gwr kdcnprobe(cn)
    466      1.25       gwr 	struct consdev *cn;
    467      1.25       gwr {
    468      1.25       gwr }
    469      1.25       gwr 
    470      1.25       gwr static void
    471      1.14       gwr kdcninit(cn)
    472      1.14       gwr 	struct consdev *cn;
    473       1.1       gwr {
    474      1.14       gwr 	struct kbd_state *ks = &kdcn_state;
    475       1.8       gwr 
    476      1.24       gwr 	cn->cn_dev = makedev(KDMAJOR, 0);
    477      1.24       gwr 	cn->cn_pri = CN_INTERNAL;
    478       1.8       gwr 
    479       1.8       gwr 	/* This prepares kbd_translate() */
    480      1.14       gwr 	ks->kbd_id = KBD_MIN_TYPE;
    481      1.14       gwr 	kbd_xlate_init(ks);
    482  1.27.2.1    bouyer 
    483  1.27.2.1    bouyer 	/* Set up initial PROM input channel for /dev/console */
    484  1.27.2.1    bouyer 	prom_cons_channel.cc_dev = NULL;
    485  1.27.2.1    bouyer 	prom_cons_channel.cc_iopen = kd_rom_iopen;
    486  1.27.2.1    bouyer 	prom_cons_channel.cc_iclose = kd_rom_iclose;
    487  1.27.2.1    bouyer 	cons_attach_input(&prom_cons_channel, cn);
    488      1.10       gwr 
    489      1.10       gwr 	/* Indicate that it is OK to use the PROM fbwrite */
    490      1.10       gwr 	kd_is_console = 1;
    491       1.1       gwr }
    492       1.1       gwr 
    493      1.25       gwr static int
    494       1.1       gwr kdcngetc(dev)
    495       1.1       gwr 	dev_t dev;
    496       1.1       gwr {
    497      1.14       gwr 	struct kbd_state *ks = &kdcn_state;
    498      1.14       gwr 	int code, class, data, keysym;
    499      1.14       gwr 
    500      1.14       gwr 	for (;;) {
    501      1.14       gwr 		code = zs_getc(zs_conschan);
    502      1.14       gwr 		keysym = kbd_code_to_keysym(ks, code);
    503      1.14       gwr 		class = KEYSYM_CLASS(keysym);
    504      1.14       gwr 
    505      1.14       gwr 		switch (class) {
    506      1.14       gwr 		case KEYSYM_ASCII:
    507      1.14       gwr 			goto out;
    508      1.14       gwr 
    509      1.14       gwr 		case KEYSYM_CLRMOD:
    510      1.14       gwr 		case KEYSYM_SETMOD:
    511      1.14       gwr 			data = (keysym & 0x1F);
    512      1.14       gwr 			/* Only allow ctrl or shift. */
    513      1.14       gwr 			if (data > KBMOD_SHIFT_R)
    514      1.14       gwr 				break;
    515      1.14       gwr 			data = 1 << data;
    516      1.14       gwr 			if (class == KEYSYM_SETMOD)
    517      1.14       gwr 				ks->kbd_modbits |= data;
    518      1.14       gwr 			else
    519      1.14       gwr 				ks->kbd_modbits &= ~data;
    520      1.14       gwr 			break;
    521       1.1       gwr 
    522      1.14       gwr 		case KEYSYM_ALL_UP:
    523      1.14       gwr 			/* No toggle keys here. */
    524      1.14       gwr 			ks->kbd_modbits = 0;
    525      1.14       gwr 			break;
    526       1.1       gwr 
    527      1.14       gwr 		default:	/* ignore all other keysyms */
    528      1.14       gwr 			break;
    529      1.14       gwr 		}
    530      1.14       gwr 	}
    531      1.14       gwr out:
    532      1.14       gwr 	return (keysym);
    533       1.1       gwr }
    534       1.1       gwr 
    535      1.25       gwr static void
    536       1.1       gwr kdcnputc(dev, c)
    537       1.1       gwr 	dev_t dev;
    538       1.1       gwr 	int c;
    539       1.1       gwr {
    540      1.11       gwr 	(romVectorPtr->fbWriteChar)(c & 0x7f);
    541       1.9       gwr }
    542       1.9       gwr 
    543      1.25       gwr static void
    544      1.25       gwr kdcnpollc(dev, on)
    545       1.9       gwr 	dev_t dev;
    546       1.9       gwr 	int on;
    547       1.9       gwr {
    548      1.14       gwr 	struct kbd_state *ks = &kdcn_state;
    549      1.14       gwr 
    550      1.14       gwr 	if (on) {
    551      1.14       gwr 		/* Entering debugger. */
    552      1.26       gwr #if NFB > 0
    553       1.9       gwr 		fb_unblank();
    554      1.26       gwr #endif
    555      1.14       gwr 		/* Clear shift keys too. */
    556      1.14       gwr 		ks->kbd_modbits = 0;
    557      1.14       gwr 	} else {
    558      1.14       gwr 		/* Resuming kernel. */
    559      1.14       gwr 	}
    560       1.1       gwr }
    561      1.14       gwr 
    562