Home | History | Annotate | Line # | Download | only in rcons
rcons_kern.c revision 1.7
      1 /*	$NetBSD: rcons_kern.c,v 1.7 1999/04/13 18:43:17 ad Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)rcons_kern.c	8.1 (Berkeley) 6/11/93
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/device.h>
     49 #include <sys/kernel.h>
     50 #include <sys/systm.h>
     51 #include <sys/ioctl.h>
     52 #include <sys/tty.h>
     53 #include <sys/proc.h>
     54 
     55 #include <dev/rcons/raster.h>
     56 #include <dev/rcons/rcons.h>
     57 
     58 extern struct tty *fbconstty;
     59 
     60 static void rcons_belltmr(void *);
     61 
     62 static struct rconsole *mydevicep; /* XXX */
     63 static void rcons_output __P((struct tty *));
     64 
     65 void
     66 rcons_cnputc(c)
     67 	int c;
     68 {
     69 	char buf[1];
     70 	long attr;
     71 
     72 	/* Swap in kernel attribute */
     73 	attr = mydevicep->rc_attr;
     74 	mydevicep->rc_attr = mydevicep->rc_kern_attr;
     75 
     76 	if (c == '\n')
     77 		rcons_puts(mydevicep, "\r\n", 2);
     78 	else {
     79 		buf[0] = c;
     80 		rcons_puts(mydevicep, buf, 1);
     81 	}
     82 
     83 	/* Swap out kernel attribute */
     84 	mydevicep->rc_attr = attr;
     85 }
     86 
     87 static void
     88 rcons_output(tp)
     89 	struct tty *tp;
     90 {
     91 	int s, n;
     92 	char buf[OBUFSIZ];
     93 
     94 	s = spltty();
     95 	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
     96 		splx(s);
     97 		return;
     98 	}
     99 	tp->t_state |= TS_BUSY;
    100 	splx(s);
    101 	n = q_to_b(&tp->t_outq, buf, sizeof(buf));
    102 	rcons_puts(mydevicep, buf, n);
    103 
    104 	s = spltty();
    105 	tp->t_state &= ~TS_BUSY;
    106 	/* Come back if there's more to do */
    107 	if (tp->t_outq.c_cc) {
    108 		tp->t_state |= TS_TIMEOUT;
    109 		timeout(ttrstrt, tp, 1);
    110 	}
    111 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    112 		if (tp->t_state&TS_ASLEEP) {
    113 			tp->t_state &= ~TS_ASLEEP;
    114 			wakeup((caddr_t)&tp->t_outq);
    115 		}
    116 		selwakeup(&tp->t_wsel);
    117 	}
    118 	splx(s);
    119 }
    120 
    121 /* Ring the console bell */
    122 void
    123 rcons_bell(rc)
    124 	struct rconsole *rc;
    125 {
    126 	int i, s;
    127 
    128 	if (rc->rc_bits & FB_VISBELL) {
    129 		/* invert the screen twice */
    130 		i = ((rc->rc_bits & FB_INVERT) == 0);
    131 		rcons_invert(rc, i);
    132 		rcons_invert(rc, i ^ 1);
    133 	}
    134 
    135 	s = splhigh();
    136 	if (rc->rc_belldepth++) {
    137 		if (rc->rc_belldepth > 3)
    138 			rc->rc_belldepth = 3;
    139 		splx(s);
    140 	} else {
    141 		rc->rc_ringing = 1;
    142 		splx(s);
    143 		(*rc->rc_bell)(1);
    144 		/* XXX Chris doesn't like the following divide */
    145 		timeout(rcons_belltmr, rc, hz/10);
    146 	}
    147 }
    148 
    149 /* Bell timer service routine */
    150 static void
    151 rcons_belltmr(p)
    152 	void *p;
    153 {
    154 	struct rconsole *rc = p;
    155 	int s = splhigh(), i;
    156 
    157 	if (rc->rc_ringing) {
    158 		rc->rc_ringing = 0;
    159 		i = --rc->rc_belldepth;
    160 		splx(s);
    161 		(*rc->rc_bell)(0);
    162 		if (i != 0)
    163 			/* XXX Chris doesn't like the following divide */
    164 			timeout(rcons_belltmr, rc, hz/30);
    165 	} else {
    166 		rc->rc_ringing = 1;
    167 		splx(s);
    168 		(*rc->rc_bell)(1);
    169 		timeout(rcons_belltmr, rc, hz/10);
    170 	}
    171 }
    172 
    173 void
    174 rcons_init(rc)
    175 	struct rconsole *rc;
    176 {
    177 	/* XXX this should go away */
    178 	struct winsize *ws;
    179 
    180 	mydevicep = rc;
    181 
    182 	/* Let the system know how big the console is */
    183 	ws = &fbconstty->t_winsize;
    184 	ws->ws_row = rc->rc_maxrow;
    185 	ws->ws_col = rc->rc_maxcol;
    186 	ws->ws_xpixel = rc->rc_width;
    187 	ws->ws_ypixel = rc->rc_height;
    188 
    189 	/* Initialize operations set, clear screen and turn cursor on */
    190 	rcons_init_ops(rc);
    191 	rc->rc_col = 0;
    192 	rc->rc_row = 0;
    193 	rcons_clear2eop(rc);
    194 	rcons_cursor(rc);
    195 
    196 	/* Initialization done; hook us up */
    197 	fbconstty->t_oproc = rcons_output;
    198 	/*fbconstty->t_stop = (void (*)()) nullop;*/
    199 }
    200