1 /* $NetBSD: rcons_kern.c,v 1.14 2003/08/07 16:31:21 agc 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.14 2003/08/07 16:31:21 agc 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 __P((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 (tp->t_outq.c_cc) {
105 tp->t_state |= TS_TIMEOUT;
106 callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
107 }
108 if (tp->t_outq.c_cc <= tp->t_lowat) {
109 if (tp->t_state&TS_ASLEEP) {
110 tp->t_state &= ~TS_ASLEEP;
111 wakeup((caddr_t)&tp->t_outq);
112 }
113 selwakeup(&tp->t_wsel);
114 }
115 splx(s);
116 }
117
118 /* Ring the console bell */
119 void
120 rcons_bell(rc)
121 struct rconsole *rc;
122 {
123 int i, s;
124
125 if (rc->rc_bits & FB_VISBELL) {
126 /* invert the screen twice */
127 i = ((rc->rc_bits & FB_INVERT) == 0);
128 rcons_invert(rc, i);
129 rcons_invert(rc, i ^ 1);
130 }
131
132 s = splhigh();
133 if (rc->rc_belldepth++) {
134 if (rc->rc_belldepth > 3)
135 rc->rc_belldepth = 3;
136 splx(s);
137 } else {
138 rc->rc_ringing = 1;
139 splx(s);
140 (*rc->rc_bell)(1);
141 /* XXX Chris doesn't like the following divide */
142 callout_reset(&rc->rc_belltmr_ch, hz / 10,
143 rcons_belltmr, rc);
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 callout_reset(&rc->rc_belltmr_ch, hz / 30,
163 rcons_belltmr, rc);
164 } else {
165 rc->rc_ringing = 1;
166 splx(s);
167 (*rc->rc_bell)(1);
168 callout_reset(&rc->rc_belltmr_ch, hz / 10,
169 rcons_belltmr, rc);
170 }
171 }
172
173 void
174 rcons_init(rc, clear)
175 struct rconsole *rc;
176 int clear;
177 {
178 mydevicep = rc;
179
180 callout_init(&rc->rc_belltmr_ch);
181
182 /* Initialize operations set, clear screen and turn cursor on */
183 rcons_init_ops(rc);
184 if (clear) {
185 rc->rc_col = 0;
186 rc->rc_row = 0;
187 rcons_clear2eop(rc);
188 }
189 rcons_cursor(rc);
190 }
191
192 void
193 rcons_ttyinit(tp)
194 struct tty *tp;
195 {
196 /* XXX this should go away */
197 struct rconsole *rc = mydevicep;
198 struct winsize *ws;
199
200 if (rc == NULL)
201 return;
202
203 /* Let the system know how big the console is */
204 ws = &tp->t_winsize;
205 ws->ws_row = rc->rc_maxrow;
206 ws->ws_col = rc->rc_maxcol;
207 ws->ws_xpixel = rc->rc_width;
208 ws->ws_ypixel = rc->rc_height;
209
210 /* Initialization done; hook us up */
211 tp->t_oproc = rcons_output;
212 /*tp->t_stop = (void (*)()) nullop;*/
213 }
Cache object: a2068d1820f9f3056d8dd2c5ba452806
|