rcons_kern.c revision 1.19.8.2 1 /* $NetBSD: rcons_kern.c,v 1.19.8.2 2008/01/09 01:54:26 matt 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. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)rcons_kern.c 8.1 (Berkeley) 6/11/93
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: rcons_kern.c,v 1.19.8.2 2008/01/09 01:54:26 matt Exp $");
45
46 #include <sys/param.h>
47 #include <sys/device.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/ioctl.h>
51 #include <sys/tty.h>
52 #include <sys/proc.h>
53
54 #include <dev/rcons/raster.h>
55 #include <dev/rcons/rcons.h>
56
57 static void rcons_belltmr(void *);
58
59 static struct rconsole *mydevicep; /* XXX */
60 static void rcons_output(struct tty *);
61
62 void
63 rcons_cnputc(c)
64 int c;
65 {
66 char buf[1];
67 long attr;
68
69 /* Swap in kernel attribute */
70 attr = mydevicep->rc_attr;
71 mydevicep->rc_attr = mydevicep->rc_kern_attr;
72
73 if (c == '\n')
74 rcons_puts(mydevicep, "\r\n", 2);
75 else {
76 buf[0] = c;
77 rcons_puts(mydevicep, buf, 1);
78 }
79
80 /* Swap out kernel attribute */
81 mydevicep->rc_attr = attr;
82 }
83
84 static void
85 rcons_output(tp)
86 struct tty *tp;
87 {
88 int s, n;
89 char buf[OBUFSIZ];
90
91 s = spltty();
92 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
93 splx(s);
94 return;
95 }
96 tp->t_state |= TS_BUSY;
97 splx(s);
98 n = q_to_b(&tp->t_outq, buf, sizeof(buf));
99 rcons_puts(mydevicep, buf, n);
100
101 s = spltty();
102 tp->t_state &= ~TS_BUSY;
103 /* Come back if there's more to do */
104 if (ttypull(tp)) {
105 tp->t_state |= TS_TIMEOUT;
106 callout_schedule(&tp->t_rstrt_ch, 1);
107 }
108 splx(s);
109 }
110
111 /* Ring the console bell */
112 void
113 rcons_bell(rc)
114 struct rconsole *rc;
115 {
116 int i, s;
117
118 if (rc->rc_bits & FB_VISBELL) {
119 /* invert the screen twice */
120 i = ((rc->rc_bits & FB_INVERT) == 0);
121 rcons_invert(rc, i);
122 rcons_invert(rc, i ^ 1);
123 }
124
125 s = splhigh();
126 if (rc->rc_belldepth++) {
127 if (rc->rc_belldepth > 3)
128 rc->rc_belldepth = 3;
129 splx(s);
130 } else {
131 rc->rc_ringing = 1;
132 splx(s);
133 (*rc->rc_bell)(1);
134 /* XXX Chris doesn't like the following divide */
135 callout_reset(&rc->rc_belltmr_ch, hz / 10,
136 rcons_belltmr, rc);
137 }
138 }
139
140 /* Bell timer service routine */
141 static void
142 rcons_belltmr(p)
143 void *p;
144 {
145 struct rconsole *rc = p;
146 int s = splhigh(), i;
147
148 if (rc->rc_ringing) {
149 rc->rc_ringing = 0;
150 i = --rc->rc_belldepth;
151 splx(s);
152 (*rc->rc_bell)(0);
153 if (i != 0)
154 /* XXX Chris doesn't like the following divide */
155 callout_reset(&rc->rc_belltmr_ch, hz / 30,
156 rcons_belltmr, rc);
157 } else {
158 rc->rc_ringing = 1;
159 splx(s);
160 (*rc->rc_bell)(1);
161 callout_reset(&rc->rc_belltmr_ch, hz / 10,
162 rcons_belltmr, rc);
163 }
164 }
165
166 void
167 rcons_init(rc, clear)
168 struct rconsole *rc;
169 int clear;
170 {
171 mydevicep = rc;
172
173 callout_init(&rc->rc_belltmr_ch, 0);
174
175 /* Initialize operations set, clear screen and turn cursor on */
176 rcons_init_ops(rc);
177 if (clear) {
178 rc->rc_col = 0;
179 rc->rc_row = 0;
180 rcons_clear2eop(rc);
181 }
182 rcons_cursor(rc);
183 }
184
185 void
186 rcons_ttyinit(tp)
187 struct tty *tp;
188 {
189 /* XXX this should go away */
190 struct rconsole *rc = mydevicep;
191 struct winsize *ws;
192
193 if (rc == NULL)
194 return;
195
196 /* Let the system know how big the console is */
197 ws = &tp->t_winsize;
198 ws->ws_row = rc->rc_maxrow;
199 ws->ws_col = rc->rc_maxcol;
200 ws->ws_xpixel = rc->rc_width;
201 ws->ws_ypixel = rc->rc_height;
202
203 /* Initialization done; hook us up */
204 tp->t_oproc = rcons_output;
205 /*tp->t_stop = (void (*)()) nullop;*/
206 }
207