Home | History | Annotate | Line # | Download | only in rcons
rcons_kern.c revision 1.11
      1 /*	$NetBSD: rcons_kern.c,v 1.11 2000/03/20 11:24:46 pk 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 static void rcons_belltmr(void *);
     59 
     60 static struct rconsole *mydevicep; /* XXX */
     61 static void rcons_output __P((struct tty *));
     62 
     63 void
     64 rcons_cnputc(c)
     65 	int c;
     66 {
     67 	char buf[1];
     68 	long attr;
     69 
     70 	/* Swap in kernel attribute */
     71 	attr = mydevicep->rc_attr;
     72 	mydevicep->rc_attr = mydevicep->rc_kern_attr;
     73 
     74 	if (c == '\n')
     75 		rcons_puts(mydevicep, "\r\n", 2);
     76 	else {
     77 		buf[0] = c;
     78 		rcons_puts(mydevicep, buf, 1);
     79 	}
     80 
     81 	/* Swap out kernel attribute */
     82 	mydevicep->rc_attr = attr;
     83 }
     84 
     85 static void
     86 rcons_output(tp)
     87 	struct tty *tp;
     88 {
     89 	int s, n;
     90 	char buf[OBUFSIZ];
     91 
     92 	s = spltty();
     93 	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
     94 		splx(s);
     95 		return;
     96 	}
     97 	tp->t_state |= TS_BUSY;
     98 	splx(s);
     99 	n = q_to_b(&tp->t_outq, buf, sizeof(buf));
    100 	rcons_puts(mydevicep, buf, n);
    101 
    102 	s = spltty();
    103 	tp->t_state &= ~TS_BUSY;
    104 	/* Come back if there's more to do */
    105 	if (tp->t_outq.c_cc) {
    106 		tp->t_state |= TS_TIMEOUT;
    107 		timeout(ttrstrt, tp, 1);
    108 	}
    109 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    110 		if (tp->t_state&TS_ASLEEP) {
    111 			tp->t_state &= ~TS_ASLEEP;
    112 			wakeup((caddr_t)&tp->t_outq);
    113 		}
    114 		selwakeup(&tp->t_wsel);
    115 	}
    116 	splx(s);
    117 }
    118 
    119 /* Ring the console bell */
    120 void
    121 rcons_bell(rc)
    122 	struct rconsole *rc;
    123 {
    124 	int i, s;
    125 
    126 	if (rc->rc_bits & FB_VISBELL) {
    127 		/* invert the screen twice */
    128 		i = ((rc->rc_bits & FB_INVERT) == 0);
    129 		rcons_invert(rc, i);
    130 		rcons_invert(rc, i ^ 1);
    131 	}
    132 
    133 	s = splhigh();
    134 	if (rc->rc_belldepth++) {
    135 		if (rc->rc_belldepth > 3)
    136 			rc->rc_belldepth = 3;
    137 		splx(s);
    138 	} else {
    139 		rc->rc_ringing = 1;
    140 		splx(s);
    141 		(*rc->rc_bell)(1);
    142 		/* XXX Chris doesn't like the following divide */
    143 		timeout(rcons_belltmr, rc, hz/10);
    144 	}
    145 }
    146 
    147 /* Bell timer service routine */
    148 static void
    149 rcons_belltmr(p)
    150 	void *p;
    151 {
    152 	struct rconsole *rc = p;
    153 	int s = splhigh(), i;
    154 
    155 	if (rc->rc_ringing) {
    156 		rc->rc_ringing = 0;
    157 		i = --rc->rc_belldepth;
    158 		splx(s);
    159 		(*rc->rc_bell)(0);
    160 		if (i != 0)
    161 			/* XXX Chris doesn't like the following divide */
    162 			timeout(rcons_belltmr, rc, hz/30);
    163 	} else {
    164 		rc->rc_ringing = 1;
    165 		splx(s);
    166 		(*rc->rc_bell)(1);
    167 		timeout(rcons_belltmr, rc, hz/10);
    168 	}
    169 }
    170 
    171 void
    172 rcons_init(rc, clear)
    173 	struct rconsole *rc;
    174 	int clear;
    175 {
    176 	mydevicep = rc;
    177 
    178 	/* Initialize operations set, clear screen and turn cursor on */
    179 	rcons_init_ops(rc);
    180 	if (clear) {
    181 		rc->rc_col = 0;
    182 		rc->rc_row = 0;
    183 		rcons_clear2eop(rc);
    184 	}
    185 	rcons_cursor(rc);
    186 }
    187 
    188 void
    189 rcons_ttyinit(tp)
    190 	struct tty *tp;
    191 {
    192 	/* XXX this should go away */
    193 	struct rconsole *rc = mydevicep;
    194 	struct winsize *ws;
    195 
    196 	if (rc == NULL)
    197 		return;
    198 
    199 	/* Let the system know how big the console is */
    200 	ws = &tp->t_winsize;
    201 	ws->ws_row = rc->rc_maxrow;
    202 	ws->ws_col = rc->rc_maxcol;
    203 	ws->ws_xpixel = rc->rc_width;
    204 	ws->ws_ypixel = rc->rc_height;
    205 
    206 	/* Initialization done; hook us up */
    207 	tp->t_oproc = rcons_output;
    208 	/*tp->t_stop = (void (*)()) nullop;*/
    209 }
    210