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