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