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