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