kd.c revision 1.1.4.5 1 1.1.4.5 nathanw /* $NetBSD: kd.c,v 1.1.4.5 2002/11/11 22:05:03 nathanw Exp $ */
2 1.1.4.2 nathanw
3 1.1.4.2 nathanw /*-
4 1.1.4.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1.4.2 nathanw * All rights reserved.
6 1.1.4.2 nathanw *
7 1.1.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 nathanw * by Gordon W. Ross.
9 1.1.4.2 nathanw *
10 1.1.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.4.2 nathanw * are met:
13 1.1.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.4.2 nathanw * must display the following acknowledgement:
20 1.1.4.2 nathanw * This product includes software developed by the NetBSD
21 1.1.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.4.2 nathanw * from this software without specific prior written permission.
25 1.1.4.2 nathanw *
26 1.1.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.4.2 nathanw */
38 1.1.4.2 nathanw
39 1.1.4.2 nathanw /*
40 1.1.4.2 nathanw * Keyboard/Display device.
41 1.1.4.2 nathanw *
42 1.1.4.2 nathanw * This driver exists simply to provide a tty device that
43 1.1.4.2 nathanw * the indirect console driver can point to.
44 1.1.4.2 nathanw * The kbd driver sends its input here.
45 1.1.4.2 nathanw * Output goes to the screen via PROM printf.
46 1.1.4.2 nathanw */
47 1.1.4.2 nathanw
48 1.1.4.2 nathanw #include <sys/param.h>
49 1.1.4.2 nathanw #include <sys/proc.h>
50 1.1.4.2 nathanw #include <sys/systm.h>
51 1.1.4.2 nathanw #include <sys/ioctl.h>
52 1.1.4.2 nathanw #include <sys/tty.h>
53 1.1.4.2 nathanw #include <sys/file.h>
54 1.1.4.2 nathanw #include <sys/conf.h>
55 1.1.4.2 nathanw #include <sys/device.h>
56 1.1.4.2 nathanw
57 1.1.4.2 nathanw #include <machine/promlib.h>
58 1.1.4.2 nathanw #include <machine/eeprom.h>
59 1.1.4.2 nathanw #include <machine/psl.h>
60 1.1.4.2 nathanw #include <machine/cpu.h>
61 1.1.4.2 nathanw #include <machine/kbd.h>
62 1.1.4.2 nathanw #include <machine/autoconf.h>
63 1.1.4.2 nathanw
64 1.1.4.2 nathanw #ifdef RASTERCONSOLE
65 1.1.4.2 nathanw #include <dev/sun/fbio.h>
66 1.1.4.2 nathanw #include <machine/fbvar.h>
67 1.1.4.2 nathanw #endif
68 1.1.4.2 nathanw
69 1.1.4.2 nathanw
70 1.1.4.2 nathanw #include <dev/cons.h>
71 1.1.4.2 nathanw #include <dev/sun/event_var.h>
72 1.1.4.2 nathanw #include <dev/sun/kbd_xlate.h>
73 1.1.4.2 nathanw #include <dev/sun/kbdvar.h>
74 1.1.4.2 nathanw #include <sun2/dev/cons.h>
75 1.1.4.2 nathanw
76 1.1.4.2 nathanw struct tty *fbconstty = 0; /* tty structure for frame buffer console */
77 1.1.4.2 nathanw
78 1.1.4.2 nathanw #define PUT_WSIZE 64
79 1.1.4.2 nathanw
80 1.1.4.2 nathanw struct kd_softc {
81 1.1.4.2 nathanw struct device kd_dev; /* required first: base device */
82 1.1.4.2 nathanw struct tty *kd_tty;
83 1.1.4.2 nathanw int rows, cols;
84 1.1.4.2 nathanw
85 1.1.4.2 nathanw /* Console input hook */
86 1.1.4.2 nathanw struct cons_channel *kd_in;
87 1.1.4.2 nathanw };
88 1.1.4.2 nathanw
89 1.1.4.2 nathanw /*
90 1.1.4.2 nathanw * There is no point in pretending there might be
91 1.1.4.2 nathanw * more than one keyboard/display device.
92 1.1.4.2 nathanw */
93 1.1.4.2 nathanw static struct kd_softc kd_softc;
94 1.1.4.2 nathanw static int kd_is_console;
95 1.1.4.2 nathanw
96 1.1.4.2 nathanw static int kdparam(struct tty *, struct termios *);
97 1.1.4.2 nathanw static void kdstart(struct tty *);
98 1.1.4.2 nathanw static void kd_init __P((struct kd_softc *));
99 1.1.4.2 nathanw static void kd_cons_input __P((int));
100 1.1.4.2 nathanw static int kdcngetc __P((dev_t));
101 1.1.4.2 nathanw
102 1.1.4.3 nathanw dev_type_open(kdopen);
103 1.1.4.3 nathanw dev_type_close(kdclose);
104 1.1.4.3 nathanw dev_type_read(kdread);
105 1.1.4.3 nathanw dev_type_write(kdwrite);
106 1.1.4.3 nathanw dev_type_ioctl(kdioctl);
107 1.1.4.3 nathanw dev_type_tty(kdtty);
108 1.1.4.3 nathanw dev_type_poll(kdpoll);
109 1.1.4.3 nathanw
110 1.1.4.3 nathanw const struct cdevsw kd_cdevsw = {
111 1.1.4.3 nathanw kdopen, kdclose, kdread, kdwrite, kdioctl,
112 1.1.4.5 nathanw nostop, kdtty, kdpoll, nommap, ttykqfilter, D_TTY
113 1.1.4.3 nathanw };
114 1.1.4.3 nathanw
115 1.1.4.2 nathanw /*
116 1.1.4.2 nathanw * This is called by kbd_attach()
117 1.1.4.2 nathanw * XXX - Make this a proper child of kbd?
118 1.1.4.2 nathanw */
119 1.1.4.2 nathanw void
120 1.1.4.2 nathanw kd_init(kd)
121 1.1.4.2 nathanw struct kd_softc *kd;
122 1.1.4.2 nathanw {
123 1.1.4.2 nathanw struct tty *tp;
124 1.1.4.2 nathanw #ifdef PROM_OLDMON
125 1.1.4.2 nathanw struct eeprom *ep;
126 1.1.4.2 nathanw #endif
127 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
128 1.1.4.2 nathanw int i;
129 1.1.4.2 nathanw char *prop;
130 1.1.4.2 nathanw #endif
131 1.1.4.2 nathanw
132 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
133 1.1.4.2 nathanw
134 1.1.4.2 nathanw tp = ttymalloc();
135 1.1.4.2 nathanw tp->t_oproc = kdstart;
136 1.1.4.2 nathanw tp->t_param = kdparam;
137 1.1.4.3 nathanw tp->t_dev = makedev(cdevsw_lookup_major(&kd_cdevsw), 0);
138 1.1.4.2 nathanw
139 1.1.4.2 nathanw tty_attach(tp);
140 1.1.4.2 nathanw kd->kd_tty = tp;
141 1.1.4.2 nathanw
142 1.1.4.2 nathanw /*
143 1.1.4.2 nathanw * get the console struct winsize.
144 1.1.4.2 nathanw */
145 1.1.4.2 nathanw if (kd_is_console) {
146 1.1.4.2 nathanw fbconstty = tp;
147 1.1.4.2 nathanw #ifdef RASTERCONSOLE
148 1.1.4.2 nathanw kd->rows = fbrcons_rows();
149 1.1.4.2 nathanw kd->cols = fbrcons_cols();
150 1.1.4.2 nathanw rcons_ttyinit(tp);
151 1.1.4.2 nathanw #endif
152 1.1.4.2 nathanw }
153 1.1.4.2 nathanw
154 1.1.4.2 nathanw /* else, consult the PROM */
155 1.1.4.2 nathanw switch (prom_version()) {
156 1.1.4.2 nathanw #ifdef PROM_OLDMON
157 1.1.4.2 nathanw case PROM_OLDMON:
158 1.1.4.2 nathanw if ((ep = (struct eeprom *)eeprom_va) == NULL)
159 1.1.4.2 nathanw break;
160 1.1.4.2 nathanw if (kd->rows == 0)
161 1.1.4.2 nathanw kd->rows = (u_short)ep->eeTtyRows;
162 1.1.4.2 nathanw if (kd->cols == 0)
163 1.1.4.2 nathanw kd->cols = (u_short)ep->eeTtyCols;
164 1.1.4.2 nathanw break;
165 1.1.4.2 nathanw #endif /* PROM_OLDMON */
166 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
167 1.1.4.2 nathanw case PROM_OBP_V0:
168 1.1.4.2 nathanw case PROM_OBP_V2:
169 1.1.4.2 nathanw case PROM_OBP_V3:
170 1.1.4.2 nathanw case PROM_OPENFIRM:
171 1.1.4.2 nathanw
172 1.1.4.2 nathanw if (kd->rows == 0 &&
173 1.1.4.2 nathanw (prop = PROM_getpropstring(optionsnode, "screen-#rows"))) {
174 1.1.4.2 nathanw i = 0;
175 1.1.4.2 nathanw while (*prop != '\0')
176 1.1.4.2 nathanw i = i * 10 + *prop++ - '0';
177 1.1.4.2 nathanw kd->rows = (unsigned short)i;
178 1.1.4.2 nathanw }
179 1.1.4.2 nathanw if (kd->cols == 0 &&
180 1.1.4.2 nathanw (prop = PROM_getpropstring(optionsnode, "screen-#columns"))) {
181 1.1.4.2 nathanw i = 0;
182 1.1.4.2 nathanw while (*prop != '\0')
183 1.1.4.2 nathanw i = i * 10 + *prop++ - '0';
184 1.1.4.2 nathanw kd->cols = (unsigned short)i;
185 1.1.4.2 nathanw }
186 1.1.4.2 nathanw break;
187 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
188 1.1.4.2 nathanw }
189 1.1.4.2 nathanw return;
190 1.1.4.2 nathanw }
191 1.1.4.2 nathanw
192 1.1.4.2 nathanw struct tty *
193 1.1.4.2 nathanw kdtty(dev)
194 1.1.4.2 nathanw dev_t dev;
195 1.1.4.2 nathanw {
196 1.1.4.2 nathanw struct kd_softc *kd;
197 1.1.4.2 nathanw
198 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
199 1.1.4.2 nathanw return (kd->kd_tty);
200 1.1.4.2 nathanw }
201 1.1.4.2 nathanw
202 1.1.4.2 nathanw int
203 1.1.4.2 nathanw kdopen(dev, flag, mode, p)
204 1.1.4.2 nathanw dev_t dev;
205 1.1.4.2 nathanw int flag, mode;
206 1.1.4.2 nathanw struct proc *p;
207 1.1.4.2 nathanw {
208 1.1.4.2 nathanw struct kd_softc *kd;
209 1.1.4.2 nathanw int error, s, unit;
210 1.1.4.2 nathanw struct tty *tp;
211 1.1.4.2 nathanw static int firstopen = 1;
212 1.1.4.2 nathanw
213 1.1.4.2 nathanw unit = minor(dev);
214 1.1.4.2 nathanw if (unit != 0)
215 1.1.4.2 nathanw return ENXIO;
216 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
217 1.1.4.2 nathanw
218 1.1.4.2 nathanw if (firstopen) {
219 1.1.4.2 nathanw kd_init(kd);
220 1.1.4.2 nathanw firstopen = 0;
221 1.1.4.2 nathanw }
222 1.1.4.2 nathanw tp = kd->kd_tty;
223 1.1.4.2 nathanw
224 1.1.4.2 nathanw /* It's simpler to do this up here. */
225 1.1.4.2 nathanw if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
226 1.1.4.2 nathanw == (TS_ISOPEN | TS_XCLUDE))
227 1.1.4.2 nathanw && (p->p_ucred->cr_uid != 0) )
228 1.1.4.2 nathanw {
229 1.1.4.2 nathanw return (EBUSY);
230 1.1.4.2 nathanw }
231 1.1.4.2 nathanw
232 1.1.4.2 nathanw s = spltty();
233 1.1.4.2 nathanw
234 1.1.4.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0) {
235 1.1.4.2 nathanw /* First open. */
236 1.1.4.2 nathanw
237 1.1.4.2 nathanw /* Notify the input device that serves us */
238 1.1.4.2 nathanw struct cons_channel *cc = kd->kd_in;
239 1.1.4.2 nathanw if (cc != NULL &&
240 1.1.4.2 nathanw (error = (*cc->cc_iopen)(cc)) != 0) {
241 1.1.4.2 nathanw splx(s);
242 1.1.4.2 nathanw return (error);
243 1.1.4.2 nathanw }
244 1.1.4.2 nathanw
245 1.1.4.2 nathanw ttychars(tp);
246 1.1.4.2 nathanw tp->t_iflag = TTYDEF_IFLAG;
247 1.1.4.2 nathanw tp->t_oflag = TTYDEF_OFLAG;
248 1.1.4.2 nathanw tp->t_cflag = TTYDEF_CFLAG;
249 1.1.4.2 nathanw tp->t_lflag = TTYDEF_LFLAG;
250 1.1.4.2 nathanw tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
251 1.1.4.2 nathanw (void) kdparam(tp, &tp->t_termios);
252 1.1.4.2 nathanw ttsetwater(tp);
253 1.1.4.2 nathanw tp->t_winsize.ws_row = kd->rows;
254 1.1.4.2 nathanw tp->t_winsize.ws_col = kd->cols;
255 1.1.4.2 nathanw /* Flush pending input? Clear translator? */
256 1.1.4.2 nathanw /* This (pseudo)device always has SOFTCAR */
257 1.1.4.2 nathanw tp->t_state |= TS_CARR_ON;
258 1.1.4.2 nathanw }
259 1.1.4.2 nathanw
260 1.1.4.2 nathanw splx(s);
261 1.1.4.2 nathanw
262 1.1.4.2 nathanw return ((*tp->t_linesw->l_open)(dev, tp));
263 1.1.4.2 nathanw }
264 1.1.4.2 nathanw
265 1.1.4.2 nathanw int
266 1.1.4.2 nathanw kdclose(dev, flag, mode, p)
267 1.1.4.2 nathanw dev_t dev;
268 1.1.4.2 nathanw int flag, mode;
269 1.1.4.2 nathanw struct proc *p;
270 1.1.4.2 nathanw {
271 1.1.4.2 nathanw struct kd_softc *kd;
272 1.1.4.2 nathanw struct tty *tp;
273 1.1.4.2 nathanw struct cons_channel *cc;
274 1.1.4.2 nathanw
275 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
276 1.1.4.2 nathanw tp = kd->kd_tty;
277 1.1.4.2 nathanw
278 1.1.4.2 nathanw /* XXX This is for cons.c. */
279 1.1.4.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0)
280 1.1.4.2 nathanw return 0;
281 1.1.4.2 nathanw
282 1.1.4.2 nathanw (*tp->t_linesw->l_close)(tp, flag);
283 1.1.4.2 nathanw ttyclose(tp);
284 1.1.4.2 nathanw
285 1.1.4.2 nathanw if ((cc = kd->kd_in) != NULL)
286 1.1.4.4 nathanw (void)(*cc->cc_iclose)(cc);
287 1.1.4.2 nathanw
288 1.1.4.2 nathanw return (0);
289 1.1.4.2 nathanw }
290 1.1.4.2 nathanw
291 1.1.4.2 nathanw int
292 1.1.4.2 nathanw kdread(dev, uio, flag)
293 1.1.4.2 nathanw dev_t dev;
294 1.1.4.2 nathanw struct uio *uio;
295 1.1.4.2 nathanw int flag;
296 1.1.4.2 nathanw {
297 1.1.4.2 nathanw struct kd_softc *kd;
298 1.1.4.2 nathanw struct tty *tp;
299 1.1.4.2 nathanw
300 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
301 1.1.4.2 nathanw tp = kd->kd_tty;
302 1.1.4.2 nathanw
303 1.1.4.2 nathanw return ((*tp->t_linesw->l_read)(tp, uio, flag));
304 1.1.4.2 nathanw }
305 1.1.4.2 nathanw
306 1.1.4.2 nathanw int
307 1.1.4.2 nathanw kdwrite(dev, uio, flag)
308 1.1.4.2 nathanw dev_t dev;
309 1.1.4.2 nathanw struct uio *uio;
310 1.1.4.2 nathanw int flag;
311 1.1.4.2 nathanw {
312 1.1.4.2 nathanw struct kd_softc *kd;
313 1.1.4.2 nathanw struct tty *tp;
314 1.1.4.2 nathanw
315 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
316 1.1.4.2 nathanw tp = kd->kd_tty;
317 1.1.4.2 nathanw
318 1.1.4.2 nathanw return ((*tp->t_linesw->l_write)(tp, uio, flag));
319 1.1.4.2 nathanw }
320 1.1.4.2 nathanw
321 1.1.4.2 nathanw int
322 1.1.4.2 nathanw kdpoll(dev, events, p)
323 1.1.4.2 nathanw dev_t dev;
324 1.1.4.2 nathanw int events;
325 1.1.4.2 nathanw struct proc *p;
326 1.1.4.2 nathanw {
327 1.1.4.2 nathanw struct kd_softc *kd;
328 1.1.4.2 nathanw struct tty *tp;
329 1.1.4.2 nathanw
330 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
331 1.1.4.2 nathanw tp = kd->kd_tty;
332 1.1.4.2 nathanw
333 1.1.4.2 nathanw return ((*tp->t_linesw->l_poll)(tp, events, p));
334 1.1.4.2 nathanw }
335 1.1.4.2 nathanw
336 1.1.4.2 nathanw int
337 1.1.4.2 nathanw kdioctl(dev, cmd, data, flag, p)
338 1.1.4.2 nathanw dev_t dev;
339 1.1.4.2 nathanw u_long cmd;
340 1.1.4.2 nathanw caddr_t data;
341 1.1.4.2 nathanw int flag;
342 1.1.4.2 nathanw struct proc *p;
343 1.1.4.2 nathanw {
344 1.1.4.2 nathanw struct kd_softc *kd;
345 1.1.4.2 nathanw struct tty *tp;
346 1.1.4.2 nathanw int error;
347 1.1.4.2 nathanw
348 1.1.4.2 nathanw kd = &kd_softc; /* XXX */
349 1.1.4.2 nathanw tp = kd->kd_tty;
350 1.1.4.2 nathanw
351 1.1.4.2 nathanw error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
352 1.1.4.2 nathanw if (error != EPASSTHROUGH)
353 1.1.4.2 nathanw return error;
354 1.1.4.2 nathanw
355 1.1.4.2 nathanw error = ttioctl(tp, cmd, data, flag, p);
356 1.1.4.2 nathanw if (error != EPASSTHROUGH)
357 1.1.4.2 nathanw return error;
358 1.1.4.2 nathanw
359 1.1.4.2 nathanw /* Handle any ioctl commands specific to kbd/display. */
360 1.1.4.2 nathanw /* XXX - Send KB* ioctls to kbd module? */
361 1.1.4.2 nathanw /* XXX - Send FB* ioctls to fb module? */
362 1.1.4.2 nathanw
363 1.1.4.2 nathanw return EPASSTHROUGH;
364 1.1.4.2 nathanw }
365 1.1.4.2 nathanw
366 1.1.4.2 nathanw static int
367 1.1.4.2 nathanw kdparam(tp, t)
368 1.1.4.2 nathanw struct tty *tp;
369 1.1.4.2 nathanw struct termios *t;
370 1.1.4.2 nathanw {
371 1.1.4.2 nathanw /* XXX - These are ignored... */
372 1.1.4.2 nathanw tp->t_ispeed = t->c_ispeed;
373 1.1.4.2 nathanw tp->t_ospeed = t->c_ospeed;
374 1.1.4.2 nathanw tp->t_cflag = t->c_cflag;
375 1.1.4.2 nathanw return 0;
376 1.1.4.2 nathanw }
377 1.1.4.2 nathanw
378 1.1.4.2 nathanw
379 1.1.4.2 nathanw static void kd_later(void*);
380 1.1.4.2 nathanw static void kd_putfb(struct tty *);
381 1.1.4.2 nathanw
382 1.1.4.2 nathanw static void
383 1.1.4.2 nathanw kdstart(tp)
384 1.1.4.2 nathanw struct tty *tp;
385 1.1.4.2 nathanw {
386 1.1.4.2 nathanw struct clist *cl;
387 1.1.4.2 nathanw register int s;
388 1.1.4.2 nathanw
389 1.1.4.2 nathanw s = spltty();
390 1.1.4.2 nathanw if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
391 1.1.4.2 nathanw goto out;
392 1.1.4.2 nathanw
393 1.1.4.2 nathanw cl = &tp->t_outq;
394 1.1.4.2 nathanw if (cl->c_cc) {
395 1.1.4.2 nathanw if (kd_is_console) {
396 1.1.4.2 nathanw tp->t_state |= TS_BUSY;
397 1.1.4.2 nathanw if (is_spl0(s)) {
398 1.1.4.2 nathanw /* called at level zero - update screen now. */
399 1.1.4.2 nathanw (void) spllowersoftclock();
400 1.1.4.2 nathanw kd_putfb(tp);
401 1.1.4.2 nathanw (void) spltty();
402 1.1.4.2 nathanw tp->t_state &= ~TS_BUSY;
403 1.1.4.2 nathanw } else {
404 1.1.4.2 nathanw /* called at interrupt level - do it later */
405 1.1.4.2 nathanw callout_reset(&tp->t_rstrt_ch, 0,
406 1.1.4.2 nathanw kd_later, tp);
407 1.1.4.2 nathanw }
408 1.1.4.2 nathanw } else {
409 1.1.4.2 nathanw /*
410 1.1.4.2 nathanw * This driver uses the PROM for writing the screen,
411 1.1.4.2 nathanw * and that only works if this is the console device.
412 1.1.4.2 nathanw * If this is not the console, just flush the output.
413 1.1.4.2 nathanw * Sorry. (In that case, use xdm instead of getty.)
414 1.1.4.2 nathanw */
415 1.1.4.2 nathanw ndflush(cl, cl->c_cc);
416 1.1.4.2 nathanw }
417 1.1.4.2 nathanw }
418 1.1.4.2 nathanw if (cl->c_cc <= tp->t_lowat) {
419 1.1.4.2 nathanw if (tp->t_state & TS_ASLEEP) {
420 1.1.4.2 nathanw tp->t_state &= ~TS_ASLEEP;
421 1.1.4.2 nathanw wakeup((caddr_t)cl);
422 1.1.4.2 nathanw }
423 1.1.4.2 nathanw selwakeup(&tp->t_wsel);
424 1.1.4.2 nathanw }
425 1.1.4.2 nathanw out:
426 1.1.4.2 nathanw splx(s);
427 1.1.4.2 nathanw }
428 1.1.4.2 nathanw
429 1.1.4.2 nathanw /*
430 1.1.4.2 nathanw * Timeout function to do delayed writes to the screen.
431 1.1.4.2 nathanw * Called at splsoftclock when requested by kdstart.
432 1.1.4.2 nathanw */
433 1.1.4.2 nathanw static void
434 1.1.4.2 nathanw kd_later(tpaddr)
435 1.1.4.2 nathanw void *tpaddr;
436 1.1.4.2 nathanw {
437 1.1.4.2 nathanw struct tty *tp = tpaddr;
438 1.1.4.2 nathanw register int s;
439 1.1.4.2 nathanw
440 1.1.4.2 nathanw kd_putfb(tp);
441 1.1.4.2 nathanw
442 1.1.4.2 nathanw s = spltty();
443 1.1.4.2 nathanw tp->t_state &= ~TS_BUSY;
444 1.1.4.2 nathanw (*tp->t_linesw->l_start)(tp);
445 1.1.4.2 nathanw splx(s);
446 1.1.4.2 nathanw }
447 1.1.4.2 nathanw
448 1.1.4.2 nathanw /*
449 1.1.4.2 nathanw * Put text on the screen using the PROM monitor.
450 1.1.4.2 nathanw * This can take a while, so to avoid missing
451 1.1.4.2 nathanw * interrupts, this is called at splsoftclock.
452 1.1.4.2 nathanw */
453 1.1.4.2 nathanw static void
454 1.1.4.2 nathanw kd_putfb(tp)
455 1.1.4.2 nathanw struct tty *tp;
456 1.1.4.2 nathanw {
457 1.1.4.2 nathanw char buf[PUT_WSIZE];
458 1.1.4.2 nathanw struct clist *cl = &tp->t_outq;
459 1.1.4.2 nathanw char *p, *end;
460 1.1.4.2 nathanw int len;
461 1.1.4.2 nathanw
462 1.1.4.2 nathanw while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
463 1.1.4.2 nathanw /* PROM will barf if high bits are set. */
464 1.1.4.2 nathanw p = buf;
465 1.1.4.2 nathanw end = buf + len;
466 1.1.4.2 nathanw while (p < end)
467 1.1.4.2 nathanw *p++ &= 0x7f;
468 1.1.4.2 nathanw /* Now let the PROM print it. */
469 1.1.4.2 nathanw prom_putstr(buf, len);
470 1.1.4.2 nathanw }
471 1.1.4.2 nathanw }
472 1.1.4.2 nathanw
473 1.1.4.2 nathanw /*
474 1.1.4.2 nathanw * Default PROM-based console input stream
475 1.1.4.2 nathanw */
476 1.1.4.2 nathanw static int kd_rom_iopen __P((struct cons_channel *));
477 1.1.4.2 nathanw static int kd_rom_iclose __P((struct cons_channel *));
478 1.1.4.2 nathanw
479 1.1.4.2 nathanw static struct cons_channel prom_cons_channel;
480 1.1.4.2 nathanw
481 1.1.4.2 nathanw int
482 1.1.4.2 nathanw kd_rom_iopen(cc)
483 1.1.4.2 nathanw struct cons_channel *cc;
484 1.1.4.2 nathanw {
485 1.1.4.2 nathanw return (0);
486 1.1.4.2 nathanw }
487 1.1.4.2 nathanw
488 1.1.4.2 nathanw int
489 1.1.4.2 nathanw kd_rom_iclose(cc)
490 1.1.4.2 nathanw struct cons_channel *cc;
491 1.1.4.2 nathanw {
492 1.1.4.2 nathanw return (0);
493 1.1.4.2 nathanw }
494 1.1.4.2 nathanw
495 1.1.4.2 nathanw /*
496 1.1.4.2 nathanw * Our "interrupt" routine for input. This is called by
497 1.1.4.2 nathanw * the keyboard driver (dev/sun/kbd.c) at spltty.
498 1.1.4.2 nathanw */
499 1.1.4.2 nathanw void
500 1.1.4.2 nathanw kd_cons_input(c)
501 1.1.4.2 nathanw int c;
502 1.1.4.2 nathanw {
503 1.1.4.2 nathanw struct kd_softc *kd = &kd_softc;
504 1.1.4.2 nathanw struct tty *tp;
505 1.1.4.2 nathanw
506 1.1.4.2 nathanw /* XXX: Make sure the device is open. */
507 1.1.4.2 nathanw tp = kd->kd_tty;
508 1.1.4.2 nathanw if (tp == NULL)
509 1.1.4.2 nathanw return;
510 1.1.4.2 nathanw if ((tp->t_state & TS_ISOPEN) == 0)
511 1.1.4.2 nathanw return;
512 1.1.4.2 nathanw
513 1.1.4.2 nathanw (*tp->t_linesw->l_rint)(c, tp);
514 1.1.4.2 nathanw }
515 1.1.4.2 nathanw
516 1.1.4.2 nathanw
517 1.1.4.2 nathanw /****************************************************************
518 1.1.4.2 nathanw * kd console support
519 1.1.4.2 nathanw ****************************************************************/
520 1.1.4.2 nathanw
521 1.1.4.2 nathanw /* The debugger gets its own key translation state. */
522 1.1.4.2 nathanw static struct kbd_state *kdcn_state;
523 1.1.4.2 nathanw
524 1.1.4.2 nathanw static void kdcnprobe __P((struct consdev *));
525 1.1.4.2 nathanw static void kdcninit __P((struct consdev *));
526 1.1.4.2 nathanw static void kdcnputc __P((dev_t, int));
527 1.1.4.2 nathanw static void kdcnpollc __P((dev_t, int));
528 1.1.4.2 nathanw
529 1.1.4.2 nathanw /* The keyboard driver uses cn_hw to access the real console driver */
530 1.1.4.2 nathanw extern struct consdev consdev_prom;
531 1.1.4.2 nathanw struct consdev consdev_kd = {
532 1.1.4.2 nathanw kdcnprobe,
533 1.1.4.2 nathanw kdcninit,
534 1.1.4.2 nathanw kdcngetc,
535 1.1.4.2 nathanw kdcnputc,
536 1.1.4.2 nathanw kdcnpollc,
537 1.1.4.2 nathanw NULL,
538 1.1.4.2 nathanw };
539 1.1.4.2 nathanw struct consdev *cn_hw = &consdev_kd;
540 1.1.4.2 nathanw
541 1.1.4.2 nathanw void
542 1.1.4.2 nathanw cons_attach_input(cc, cn)
543 1.1.4.2 nathanw struct cons_channel *cc;
544 1.1.4.2 nathanw struct consdev *cn;
545 1.1.4.2 nathanw {
546 1.1.4.2 nathanw struct kd_softc *kd = &kd_softc;
547 1.1.4.2 nathanw struct kbd_softc *kds = cc->cc_dev;
548 1.1.4.2 nathanw struct kbd_state *ks;
549 1.1.4.2 nathanw
550 1.1.4.2 nathanw /* Share the keyboard state */
551 1.1.4.2 nathanw kdcn_state = ks = &kds->k_state;
552 1.1.4.2 nathanw
553 1.1.4.2 nathanw kd->kd_in = cc;
554 1.1.4.2 nathanw cc->cc_upstream = kd_cons_input;
555 1.1.4.2 nathanw
556 1.1.4.2 nathanw /* Attach lower level. */
557 1.1.4.2 nathanw cn_hw->cn_dev = cn->cn_dev;
558 1.1.4.2 nathanw cn_hw->cn_pollc = cn->cn_pollc;
559 1.1.4.2 nathanw cn_hw->cn_getc = cn->cn_getc;
560 1.1.4.2 nathanw
561 1.1.4.2 nathanw /* Attach us as console. */
562 1.1.4.3 nathanw cn_tab->cn_dev = makedev(cdevsw_lookup_major(&kd_cdevsw), 0);
563 1.1.4.2 nathanw cn_tab->cn_probe = kdcnprobe;
564 1.1.4.2 nathanw cn_tab->cn_init = kdcninit;
565 1.1.4.2 nathanw cn_tab->cn_getc = kdcngetc;
566 1.1.4.2 nathanw cn_tab->cn_pollc = kdcnpollc;
567 1.1.4.2 nathanw cn_tab->cn_pri = CN_INTERNAL;
568 1.1.4.2 nathanw
569 1.1.4.2 nathanw /* Set up initial PROM input channel for /dev/console */
570 1.1.4.2 nathanw prom_cons_channel.cc_dev = NULL;
571 1.1.4.2 nathanw prom_cons_channel.cc_iopen = kd_rom_iopen;
572 1.1.4.2 nathanw prom_cons_channel.cc_iclose = kd_rom_iclose;
573 1.1.4.2 nathanw
574 1.1.4.2 nathanw /* Indicate that it is OK to use the PROM fbwrite */
575 1.1.4.2 nathanw kd_is_console = 1;
576 1.1.4.2 nathanw }
577 1.1.4.2 nathanw
578 1.1.4.2 nathanw
579 1.1.4.2 nathanw void kd_attach_input(struct cons_channel *);
580 1.1.4.2 nathanw void
581 1.1.4.2 nathanw kd_attach_input(cc)
582 1.1.4.2 nathanw struct cons_channel *cc;
583 1.1.4.2 nathanw {
584 1.1.4.2 nathanw struct kd_softc *kd = &kd_softc;
585 1.1.4.2 nathanw
586 1.1.4.2 nathanw kd->kd_in = cc;
587 1.1.4.2 nathanw cc->cc_upstream = kd_cons_input;
588 1.1.4.2 nathanw }
589 1.1.4.2 nathanw
590 1.1.4.2 nathanw
591 1.1.4.2 nathanw /* We never call this. */
592 1.1.4.2 nathanw static void
593 1.1.4.2 nathanw kdcnprobe(cn)
594 1.1.4.2 nathanw struct consdev *cn;
595 1.1.4.2 nathanw {
596 1.1.4.2 nathanw }
597 1.1.4.2 nathanw
598 1.1.4.2 nathanw static void
599 1.1.4.2 nathanw kdcninit(cn)
600 1.1.4.2 nathanw struct consdev *cn;
601 1.1.4.2 nathanw {
602 1.1.4.2 nathanw #if 0
603 1.1.4.2 nathanw struct kbd_state *ks = kdcn_state;
604 1.1.4.2 nathanw
605 1.1.4.3 nathanw cn->cn_dev = makedev(cdevsw_lookup_major(&kd_cdevsw), 0);
606 1.1.4.2 nathanw cn->cn_pri = CN_INTERNAL;
607 1.1.4.2 nathanw
608 1.1.4.2 nathanw /* This prepares kbd_translate() */
609 1.1.4.2 nathanw ks->kbd_id = KBD_MIN_TYPE;
610 1.1.4.2 nathanw kbd_xlate_init(ks);
611 1.1.4.2 nathanw
612 1.1.4.2 nathanw /* Set up initial PROM input channel for /dev/console */
613 1.1.4.2 nathanw prom_cons_channel.cc_dev = NULL;
614 1.1.4.2 nathanw prom_cons_channel.cc_iopen = kd_rom_iopen;
615 1.1.4.2 nathanw prom_cons_channel.cc_iclose = kd_rom_iclose;
616 1.1.4.2 nathanw cons_attach_input(&prom_cons_channel);
617 1.1.4.2 nathanw
618 1.1.4.2 nathanw /* Indicate that it is OK to use the PROM fbwrite */
619 1.1.4.2 nathanw kd_is_console = 1;
620 1.1.4.2 nathanw #endif
621 1.1.4.2 nathanw }
622 1.1.4.2 nathanw
623 1.1.4.2 nathanw static int
624 1.1.4.2 nathanw kdcngetc(dev)
625 1.1.4.2 nathanw dev_t dev;
626 1.1.4.2 nathanw {
627 1.1.4.2 nathanw struct kbd_state *ks = kdcn_state;
628 1.1.4.2 nathanw int code, class, data, keysym;
629 1.1.4.2 nathanw extern int prom_cngetc __P((dev_t));
630 1.1.4.2 nathanw
631 1.1.4.2 nathanw
632 1.1.4.2 nathanw if (cn_hw->cn_getc == prom_cngetc) return (*cn_hw->cn_getc)(dev);
633 1.1.4.2 nathanw for (;;) {
634 1.1.4.2 nathanw code = (*cn_hw->cn_getc)(dev);
635 1.1.4.2 nathanw keysym = kbd_code_to_keysym(ks, code);
636 1.1.4.2 nathanw class = KEYSYM_CLASS(keysym);
637 1.1.4.2 nathanw
638 1.1.4.2 nathanw switch (class) {
639 1.1.4.2 nathanw case KEYSYM_ASCII:
640 1.1.4.2 nathanw goto out;
641 1.1.4.2 nathanw
642 1.1.4.2 nathanw case KEYSYM_CLRMOD:
643 1.1.4.2 nathanw case KEYSYM_SETMOD:
644 1.1.4.2 nathanw data = (keysym & 0x1F);
645 1.1.4.2 nathanw /* Only allow ctrl or shift. */
646 1.1.4.2 nathanw if (data > KBMOD_SHIFT_R)
647 1.1.4.2 nathanw break;
648 1.1.4.2 nathanw data = 1 << data;
649 1.1.4.2 nathanw if (class == KEYSYM_SETMOD)
650 1.1.4.2 nathanw ks->kbd_modbits |= data;
651 1.1.4.2 nathanw else
652 1.1.4.2 nathanw ks->kbd_modbits &= ~data;
653 1.1.4.2 nathanw break;
654 1.1.4.2 nathanw
655 1.1.4.2 nathanw case KEYSYM_ALL_UP:
656 1.1.4.2 nathanw /* No toggle keys here. */
657 1.1.4.2 nathanw ks->kbd_modbits = 0;
658 1.1.4.2 nathanw break;
659 1.1.4.2 nathanw
660 1.1.4.2 nathanw default: /* ignore all other keysyms */
661 1.1.4.2 nathanw break;
662 1.1.4.2 nathanw }
663 1.1.4.2 nathanw }
664 1.1.4.2 nathanw out:
665 1.1.4.2 nathanw return (keysym);
666 1.1.4.2 nathanw }
667 1.1.4.2 nathanw
668 1.1.4.2 nathanw static void
669 1.1.4.2 nathanw kdcnputc(dev, c)
670 1.1.4.2 nathanw dev_t dev;
671 1.1.4.2 nathanw int c;
672 1.1.4.2 nathanw {
673 1.1.4.2 nathanw int s;
674 1.1.4.2 nathanw
675 1.1.4.2 nathanw s = splhigh();
676 1.1.4.2 nathanw prom_putchar(c);
677 1.1.4.2 nathanw splx(s);
678 1.1.4.2 nathanw }
679 1.1.4.2 nathanw
680 1.1.4.2 nathanw static void
681 1.1.4.2 nathanw kdcnpollc(dev, on)
682 1.1.4.2 nathanw dev_t dev;
683 1.1.4.2 nathanw int on;
684 1.1.4.2 nathanw {
685 1.1.4.2 nathanw struct kbd_state *ks = kdcn_state;
686 1.1.4.2 nathanw
687 1.1.4.2 nathanw if (on) {
688 1.1.4.2 nathanw /* Entering debugger. */
689 1.1.4.2 nathanw #if NFB > 0
690 1.1.4.2 nathanw fb_unblank();
691 1.1.4.2 nathanw #endif
692 1.1.4.2 nathanw /* Clear shift keys too. */
693 1.1.4.2 nathanw ks->kbd_modbits = 0;
694 1.1.4.2 nathanw } else {
695 1.1.4.2 nathanw /* Resuming kernel. */
696 1.1.4.2 nathanw }
697 1.1.4.2 nathanw (*cn_hw->cn_pollc)(dev, on);
698 1.1.4.2 nathanw }
699