wsdisplay.c revision 1.95 1 /* $NetBSD: wsdisplay.c,v 1.95 2006/04/12 20:13:21 macallan Exp $ */
2
3 /*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.95 2006/04/12 20:13:21 macallan Exp $");
35
36 #include "opt_wsdisplay_compat.h"
37 #include "opt_wsmsgattrs.h"
38 #include "opt_compat_netbsd.h"
39 #include "wskbd.h"
40 #include "wsmux.h"
41 #include "wsdisplay.h"
42
43 #include <sys/param.h>
44 #include <sys/conf.h>
45 #include <sys/device.h>
46 #include <sys/ioctl.h>
47 #include <sys/poll.h>
48 #include <sys/kernel.h>
49 #include <sys/proc.h>
50 #include <sys/malloc.h>
51 #include <sys/syslog.h>
52 #include <sys/systm.h>
53 #include <sys/tty.h>
54 #include <sys/signalvar.h>
55 #include <sys/errno.h>
56 #include <sys/fcntl.h>
57 #include <sys/vnode.h>
58
59 #include <dev/wscons/wseventvar.h>
60 #include <dev/wscons/wsmuxvar.h>
61 #include <dev/wscons/wsconsio.h>
62 #include <dev/wscons/wsdisplayvar.h>
63 #include <dev/wscons/wsksymvar.h>
64 #include <dev/wscons/wsksymdef.h>
65 #include <dev/wscons/wsemulvar.h>
66 #include <dev/wscons/wscons_callbacks.h>
67 #include <dev/cons.h>
68
69 struct wsscreen_internal {
70 const struct wsdisplay_emulops *emulops;
71 void *emulcookie;
72
73 const struct wsscreen_descr *scrdata;
74
75 const struct wsemul_ops *wsemul;
76 void *wsemulcookie;
77 };
78
79 struct wsscreen {
80 struct wsscreen_internal *scr_dconf;
81
82 struct tty *scr_tty;
83 int scr_hold_screen; /* hold tty output */
84
85 int scr_flags;
86 #define SCR_OPEN 1 /* is it open? */
87 #define SCR_WAITACTIVE 2 /* someone waiting on activation */
88 #define SCR_GRAPHICS 4 /* graphics mode, no text (emulation) output */
89 #define SCR_DUMBFB 8 /* in use as a dumb fb (iff SCR_GRAPHICS) */
90 const struct wscons_syncops *scr_syncops;
91 void *scr_synccookie;
92
93 #ifdef WSDISPLAY_COMPAT_RAWKBD
94 int scr_rawkbd;
95 #endif
96
97 struct wsdisplay_softc *sc;
98 };
99
100 struct wsscreen *wsscreen_attach(struct wsdisplay_softc *, int,
101 const char *,
102 const struct wsscreen_descr *, void *,
103 int, int, long);
104 void wsscreen_detach(struct wsscreen *);
105 int wsdisplay_addscreen(struct wsdisplay_softc *, int, const char *, const char *);
106 static void wsdisplay_shutdownhook(void *);
107 static void wsdisplay_addscreen_print(struct wsdisplay_softc *, int, int);
108 static void wsdisplay_closescreen(struct wsdisplay_softc *, struct wsscreen *);
109 int wsdisplay_delscreen(struct wsdisplay_softc *, int, int);
110
111 #define WSDISPLAY_MAXSCREEN 8
112
113 struct wsdisplay_softc {
114 struct device sc_dv;
115
116 const struct wsdisplay_accessops *sc_accessops;
117 void *sc_accesscookie;
118
119 const struct wsscreen_list *sc_scrdata;
120 #ifdef WSDISPLAY_SCROLLSUPPORT
121 struct wsdisplay_scroll_data sc_scroll_values;
122 #endif
123
124 struct wsscreen *sc_scr[WSDISPLAY_MAXSCREEN];
125 int sc_focusidx; /* available only if sc_focus isn't null */
126 struct wsscreen *sc_focus;
127
128 struct wseventvar evar;
129
130 int sc_isconsole;
131
132 int sc_flags;
133 #define SC_SWITCHPENDING 1
134 int sc_screenwanted, sc_oldscreen; /* valid with SC_SWITCHPENDING */
135
136 #if NWSKBD > 0
137 struct wsevsrc *sc_input;
138 #ifdef WSDISPLAY_COMPAT_RAWKBD
139 int sc_rawkbd;
140 #endif
141 #endif /* NWSKBD > 0 */
142 };
143
144 #ifdef WSDISPLAY_SCROLLSUPPORT
145
146 struct wsdisplay_scroll_data wsdisplay_default_scroll_values = {
147 WSDISPLAY_SCROLL_DOALL,
148 25,
149 2,
150 };
151 #endif
152
153 extern struct cfdriver wsdisplay_cd;
154
155 /* Autoconfiguration definitions. */
156 static int wsdisplay_emul_match(struct device *, struct cfdata *, void *);
157 static void wsdisplay_emul_attach(struct device *, struct device *, void *);
158 static int wsdisplay_noemul_match(struct device *, struct cfdata *, void *);
159 static void wsdisplay_noemul_attach(struct device *, struct device *, void *);
160
161 CFATTACH_DECL(wsdisplay_emul, sizeof (struct wsdisplay_softc),
162 wsdisplay_emul_match, wsdisplay_emul_attach, NULL, NULL);
163
164 CFATTACH_DECL(wsdisplay_noemul, sizeof (struct wsdisplay_softc),
165 wsdisplay_noemul_match, wsdisplay_noemul_attach, NULL, NULL);
166
167 dev_type_open(wsdisplayopen);
168 dev_type_close(wsdisplayclose);
169 dev_type_read(wsdisplayread);
170 dev_type_write(wsdisplaywrite);
171 dev_type_ioctl(wsdisplayioctl);
172 dev_type_stop(wsdisplaystop);
173 dev_type_tty(wsdisplaytty);
174 dev_type_poll(wsdisplaypoll);
175 dev_type_mmap(wsdisplaymmap);
176 dev_type_kqfilter(wsdisplaykqfilter);
177
178 const struct cdevsw wsdisplay_cdevsw = {
179 wsdisplayopen, wsdisplayclose, wsdisplayread, wsdisplaywrite,
180 wsdisplayioctl, wsdisplaystop, wsdisplaytty, wsdisplaypoll,
181 wsdisplaymmap, wsdisplaykqfilter, D_TTY
182 };
183
184 static void wsdisplaystart(struct tty *);
185 static int wsdisplayparam(struct tty *, struct termios *);
186
187
188 #define WSDISPLAYUNIT(dev) (minor(dev) >> 8)
189 #define WSDISPLAYSCREEN(dev) (minor(dev) & 0xff)
190 #define ISWSDISPLAYSTAT(dev) (WSDISPLAYSCREEN(dev) == 254)
191 #define ISWSDISPLAYCTL(dev) (WSDISPLAYSCREEN(dev) == 255)
192 #define WSDISPLAYMINOR(unit, screen) (((unit) << 8) | (screen))
193
194 #define WSSCREEN_HAS_EMULATOR(scr) ((scr)->scr_dconf->wsemul != NULL)
195 #define WSSCREEN_HAS_TTY(scr) ((scr)->scr_tty != NULL)
196
197 static void wsdisplay_common_attach(struct wsdisplay_softc *sc,
198 int console, int kbdmux, const struct wsscreen_list *,
199 const struct wsdisplay_accessops *accessops,
200 void *accesscookie);
201
202 #ifdef WSDISPLAY_COMPAT_RAWKBD
203 int wsdisplay_update_rawkbd(struct wsdisplay_softc *,
204 struct wsscreen *);
205 #endif
206
207 static int wsdisplay_console_initted;
208 static int wsdisplay_console_attached;
209 static struct wsdisplay_softc *wsdisplay_console_device;
210 static struct wsscreen_internal wsdisplay_console_conf;
211
212 static int wsdisplay_getc_dummy(dev_t);
213 static void wsdisplay_pollc(dev_t, int);
214
215 static int wsdisplay_cons_pollmode;
216 static void (*wsdisplay_cons_kbd_pollc)(dev_t, int);
217
218 static struct consdev wsdisplay_cons = {
219 NULL, NULL, wsdisplay_getc_dummy, wsdisplay_cnputc,
220 wsdisplay_pollc, NULL, NULL, NULL, NODEV, CN_NORMAL
221 };
222
223 #ifndef WSDISPLAY_DEFAULTSCREENS
224 # define WSDISPLAY_DEFAULTSCREENS 0
225 #endif
226 int wsdisplay_defaultscreens = WSDISPLAY_DEFAULTSCREENS;
227
228 int wsdisplay_switch1(void *, int, int);
229 int wsdisplay_switch2(void *, int, int);
230 int wsdisplay_switch3(void *, int, int);
231
232 int wsdisplay_clearonclose;
233
234 struct wsscreen *
235 wsscreen_attach(struct wsdisplay_softc *sc, int console, const char *emul,
236 const struct wsscreen_descr *type, void *cookie, int ccol,
237 int crow, long defattr)
238 {
239 struct wsscreen_internal *dconf;
240 struct wsscreen *scr;
241
242 scr = malloc(sizeof(struct wsscreen), M_DEVBUF, M_WAITOK);
243 if (!scr)
244 return (NULL);
245
246 if (console) {
247 dconf = &wsdisplay_console_conf;
248 /*
249 * If there's an emulation, tell it about the callback argument.
250 * The other stuff is already there.
251 */
252 if (dconf->wsemul != NULL)
253 (*dconf->wsemul->attach)(1, 0, 0, 0, 0, scr, 0);
254 } else { /* not console */
255 dconf = malloc(sizeof(struct wsscreen_internal),
256 M_DEVBUF, M_NOWAIT);
257 dconf->emulops = type->textops;
258 dconf->emulcookie = cookie;
259 if (dconf->emulops) {
260 dconf->wsemul = wsemul_pick(emul);
261 if (dconf->wsemul == NULL) {
262 free(dconf, M_DEVBUF);
263 free(scr, M_DEVBUF);
264 return (NULL);
265 }
266 dconf->wsemulcookie =
267 (*dconf->wsemul->attach)(0, type, cookie,
268 ccol, crow, scr, defattr);
269 } else
270 dconf->wsemul = NULL;
271 dconf->scrdata = type;
272 }
273
274 scr->scr_dconf = dconf;
275
276 scr->scr_tty = ttymalloc();
277 tty_attach(scr->scr_tty);
278 scr->scr_hold_screen = 0;
279 if (WSSCREEN_HAS_EMULATOR(scr))
280 scr->scr_flags = 0;
281 else
282 scr->scr_flags = SCR_GRAPHICS;
283
284 scr->scr_syncops = 0;
285 scr->sc = sc;
286 #ifdef WSDISPLAY_COMPAT_RAWKBD
287 scr->scr_rawkbd = 0;
288 #endif
289 return (scr);
290 }
291
292 void
293 wsscreen_detach(struct wsscreen *scr)
294 {
295 u_int ccol, crow; /* XXX */
296
297 if (WSSCREEN_HAS_TTY(scr)) {
298 tty_detach(scr->scr_tty);
299 ttyfree(scr->scr_tty);
300 }
301 if (WSSCREEN_HAS_EMULATOR(scr))
302 (*scr->scr_dconf->wsemul->detach)(scr->scr_dconf->wsemulcookie,
303 &ccol, &crow);
304 free(scr->scr_dconf, M_DEVBUF);
305 free(scr, M_DEVBUF);
306 }
307
308 const struct wsscreen_descr *
309 wsdisplay_screentype_pick(const struct wsscreen_list *scrdata, const char *name)
310 {
311 int i;
312 const struct wsscreen_descr *scr;
313
314 KASSERT(scrdata->nscreens > 0);
315
316 if (name == NULL)
317 return (scrdata->screens[0]);
318
319 for (i = 0; i < scrdata->nscreens; i++) {
320 scr = scrdata->screens[i];
321 if (!strcmp(name, scr->name))
322 return (scr);
323 }
324
325 return (0);
326 }
327
328 /*
329 * print info about attached screen
330 */
331 static void
332 wsdisplay_addscreen_print(struct wsdisplay_softc *sc, int idx, int count)
333 {
334 printf("%s: screen %d", sc->sc_dv.dv_xname, idx);
335 if (count > 1)
336 printf("-%d", idx + (count-1));
337 printf(" added (%s", sc->sc_scr[idx]->scr_dconf->scrdata->name);
338 if (WSSCREEN_HAS_EMULATOR(sc->sc_scr[idx])) {
339 printf(", %s emulation",
340 sc->sc_scr[idx]->scr_dconf->wsemul->name);
341 }
342 printf(")\n");
343 }
344
345 int
346 wsdisplay_addscreen(struct wsdisplay_softc *sc, int idx,
347 const char *screentype, const char *emul)
348 {
349 const struct wsscreen_descr *scrdesc;
350 int error;
351 void *cookie;
352 int ccol, crow;
353 long defattr;
354 struct wsscreen *scr;
355 int s;
356
357 if (idx < 0 || idx >= WSDISPLAY_MAXSCREEN)
358 return (EINVAL);
359 if (sc->sc_scr[idx] != NULL)
360 return (EBUSY);
361
362 scrdesc = wsdisplay_screentype_pick(sc->sc_scrdata, screentype);
363 if (!scrdesc)
364 return (ENXIO);
365 error = (*sc->sc_accessops->alloc_screen)(sc->sc_accesscookie,
366 scrdesc, &cookie, &ccol, &crow, &defattr);
367 if (error)
368 return (error);
369
370 scr = wsscreen_attach(sc, 0, emul, scrdesc,
371 cookie, ccol, crow, defattr);
372 if (scr == NULL) {
373 (*sc->sc_accessops->free_screen)(sc->sc_accesscookie,
374 cookie);
375 return (ENXIO);
376 }
377
378 sc->sc_scr[idx] = scr;
379
380 /* if no screen has focus yet, activate the first we get */
381 s = spltty();
382 if (!sc->sc_focus) {
383 (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
384 scr->scr_dconf->emulcookie,
385 0, 0, 0);
386 sc->sc_focusidx = idx;
387 sc->sc_focus = scr;
388 }
389 splx(s);
390 return (0);
391 }
392
393 static void
394 wsdisplay_closescreen(struct wsdisplay_softc *sc, struct wsscreen *scr)
395 {
396 int maj, mn, idx;
397
398 /* hangup */
399 if (WSSCREEN_HAS_TTY(scr)) {
400 struct tty *tp = scr->scr_tty;
401 (*tp->t_linesw->l_modem)(tp, 0);
402 }
403
404 /* locate the major number */
405 maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
406 /* locate the screen index */
407 for (idx = 0; idx < WSDISPLAY_MAXSCREEN; idx++)
408 if (scr == sc->sc_scr[idx])
409 break;
410 #ifdef DIAGNOSTIC
411 if (idx == WSDISPLAY_MAXSCREEN)
412 panic("wsdisplay_forceclose: bad screen");
413 #endif
414
415 /* nuke the vnodes */
416 mn = WSDISPLAYMINOR(device_unit(&sc->sc_dv), idx);
417 vdevgone(maj, mn, mn, VCHR);
418 }
419
420 #ifdef WSDISPLAY_SCROLLSUPPORT
421 void
422 wsdisplay_scroll(void *arg, int op)
423 {
424 struct wsdisplay_softc *sc = arg;
425 int lines;
426
427 if (op == WSDISPLAY_SCROLL_RESET)
428 lines = 0;
429 else {
430 lines = (op & WSDISPLAY_SCROLL_LOW) ?
431 sc->sc_scroll_values.slowlines :
432 sc->sc_scroll_values.fastlines;
433 if (op & WSDISPLAY_SCROLL_BACKWARD)
434 lines = -(lines);
435 }
436
437 if (sc->sc_accessops->scroll) {
438 (*sc->sc_accessops->scroll)(sc->sc_accesscookie,
439 sc->sc_focus->scr_dconf->emulcookie, lines);
440 }
441 }
442 #endif
443
444 int
445 wsdisplay_delscreen(struct wsdisplay_softc *sc, int idx, int flags)
446 {
447 struct wsscreen *scr;
448 int s;
449 void *cookie;
450
451 if (idx < 0 || idx >= WSDISPLAY_MAXSCREEN)
452 return (EINVAL);
453 if ((scr = sc->sc_scr[idx]) == NULL)
454 return (ENXIO);
455
456 if (scr->scr_dconf == &wsdisplay_console_conf ||
457 scr->scr_syncops ||
458 ((scr->scr_flags & SCR_OPEN) && !(flags & WSDISPLAY_DELSCR_FORCE)))
459 return(EBUSY);
460
461 wsdisplay_closescreen(sc, scr);
462
463 /*
464 * delete pointers, so neither device entries
465 * nor keyboard input can reference it anymore
466 */
467 s = spltty();
468 if (sc->sc_focus == scr) {
469 sc->sc_focus = 0;
470 #ifdef WSDISPLAY_COMPAT_RAWKBD
471 wsdisplay_update_rawkbd(sc, 0);
472 #endif
473 }
474 sc->sc_scr[idx] = 0;
475 splx(s);
476
477 /*
478 * Wake up processes waiting for the screen to
479 * be activated. Sleepers must check whether
480 * the screen still exists.
481 */
482 if (scr->scr_flags & SCR_WAITACTIVE)
483 wakeup(scr);
484
485 /* save a reference to the graphics screen */
486 cookie = scr->scr_dconf->emulcookie;
487
488 wsscreen_detach(scr);
489
490 (*sc->sc_accessops->free_screen)(sc->sc_accesscookie,
491 cookie);
492
493 printf("%s: screen %d deleted\n", sc->sc_dv.dv_xname, idx);
494 return (0);
495 }
496
497 /*
498 * Autoconfiguration functions.
499 */
500 int
501 wsdisplay_emul_match(struct device *parent, struct cfdata *match, void *aux)
502 {
503 struct wsemuldisplaydev_attach_args *ap = aux;
504
505 if (match->wsemuldisplaydevcf_console !=
506 WSEMULDISPLAYDEVCF_CONSOLE_UNK) {
507 /*
508 * If console-ness of device specified, either match
509 * exactly (at high priority), or fail.
510 */
511 if (match->wsemuldisplaydevcf_console != 0 &&
512 ap->console != 0)
513 return (10);
514 else
515 return (0);
516 }
517
518 /* If console-ness unspecified, it wins. */
519 return (1);
520 }
521
522 void
523 wsdisplay_emul_attach(struct device *parent, struct device *self, void *aux)
524 {
525 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)self;
526 struct wsemuldisplaydev_attach_args *ap = aux;
527
528 /* Don't allow more than one console to attach */
529 if (wsdisplay_console_attached && ap->console)
530 ap->console = 0;
531
532 wsdisplay_common_attach(sc, ap->console,
533 device_cfdata(&sc->sc_dv)->wsemuldisplaydevcf_kbdmux, ap->scrdata,
534 ap->accessops, ap->accesscookie);
535
536 if (ap->console) {
537 int maj;
538
539 /* locate the major number */
540 maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
541
542 cn_tab->cn_dev = makedev(maj, WSDISPLAYMINOR(device_unit(self),
543 0));
544 }
545 }
546
547 /* Print function (for parent devices). */
548 int
549 wsemuldisplaydevprint(void *aux, const char *pnp)
550 {
551 #if 0 /* -Wunused */
552 struct wsemuldisplaydev_attach_args *ap = aux;
553 #endif
554
555 if (pnp)
556 aprint_normal("wsdisplay at %s", pnp);
557 #if 0 /* don't bother; it's ugly */
558 aprint_normal(" console %d", ap->console);
559 #endif
560
561 return (UNCONF);
562 }
563
564 int
565 wsdisplay_noemul_match(struct device *parent, struct cfdata *match, void *aux)
566 {
567 #if 0 /* -Wunused */
568 struct wsdisplaydev_attach_args *ap = aux;
569 #endif
570
571 /* Always match. */
572 return (1);
573 }
574
575 void
576 wsdisplay_noemul_attach(struct device *parent, struct device *self, void *aux)
577 {
578 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)self;
579 struct wsdisplaydev_attach_args *ap = aux;
580
581 wsdisplay_common_attach(sc, 0,
582 device_cfdata(&sc->sc_dv)->wsemuldisplaydevcf_kbdmux, NULL,
583 ap->accessops, ap->accesscookie);
584 }
585
586 /* Print function (for parent devices). */
587 int
588 wsdisplaydevprint(void *aux, const char *pnp)
589 {
590 #if 0 /* -Wunused */
591 struct wsdisplaydev_attach_args *ap = aux;
592 #endif
593
594 if (pnp)
595 aprint_normal("wsdisplay at %s", pnp);
596
597 return (UNCONF);
598 }
599
600 static void
601 wsdisplay_common_attach(struct wsdisplay_softc *sc, int console, int kbdmux,
602 const struct wsscreen_list *scrdata,
603 const struct wsdisplay_accessops *accessops,
604 void *accesscookie)
605 {
606 static int hookset;
607 int i, start=0;
608 #if NWSKBD > 0
609 struct wsevsrc *kme;
610 #if NWSMUX > 0
611 struct wsmux_softc *mux;
612
613 if (kbdmux >= 0)
614 mux = wsmux_getmux(kbdmux);
615 else
616 mux = wsmux_create("dmux", device_unit(&sc->sc_dv));
617 /* XXX panic()ing isn't nice, but attach cannot fail */
618 if (mux == NULL)
619 panic("wsdisplay_common_attach: no memory");
620 sc->sc_input = &mux->sc_base;
621 mux->sc_base.me_dispdv = &sc->sc_dv;
622 printf(" kbdmux %d", kbdmux);
623 #else
624 if (kbdmux >= 0)
625 printf(" (kbdmux ignored)");
626 #endif
627 #endif
628
629 sc->sc_isconsole = console;
630
631 if (console) {
632 KASSERT(wsdisplay_console_initted);
633 KASSERT(wsdisplay_console_device == NULL);
634
635 sc->sc_scr[0] = wsscreen_attach(sc, 1, 0, 0, 0, 0, 0, 0);
636 wsdisplay_console_device = sc;
637
638 printf(": console (%s, %s emulation)",
639 wsdisplay_console_conf.scrdata->name,
640 wsdisplay_console_conf.wsemul->name);
641
642 #if NWSKBD > 0
643 kme = wskbd_set_console_display(&sc->sc_dv, sc->sc_input);
644 if (kme != NULL)
645 printf(", using %s", kme->me_dv.dv_xname);
646 #if NWSMUX == 0
647 sc->sc_input = kme;
648 #endif
649 #endif
650
651 sc->sc_focusidx = 0;
652 sc->sc_focus = sc->sc_scr[0];
653 start = 1;
654
655 wsdisplay_console_attached = 1;
656 }
657 printf("\n");
658
659 #if NWSKBD > 0 && NWSMUX > 0
660 wsmux_set_display(mux, &sc->sc_dv);
661 #endif
662
663 sc->sc_accessops = accessops;
664 sc->sc_accesscookie = accesscookie;
665 sc->sc_scrdata = scrdata;
666
667 #ifdef WSDISPLAY_SCROLLSUPPORT
668 sc->sc_scroll_values = wsdisplay_default_scroll_values;
669 #endif
670
671 /*
672 * Set up a number of virtual screens if wanted. The
673 * WSDISPLAYIO_ADDSCREEN ioctl is more flexible, so this code
674 * is for special cases like installation kernels.
675 */
676 for (i = start; i < wsdisplay_defaultscreens; i++) {
677 if (wsdisplay_addscreen(sc, i, 0, 0))
678 break;
679 }
680
681 if (i > start)
682 wsdisplay_addscreen_print(sc, start, i-start);
683
684 if (hookset == 0)
685 shutdownhook_establish(wsdisplay_shutdownhook, NULL);
686 hookset = 1;
687 }
688
689 void
690 wsdisplay_cnattach(const struct wsscreen_descr *type, void *cookie,
691 int ccol, int crow, long defattr)
692 {
693 const struct wsemul_ops *wsemul;
694
695 KASSERT(!wsdisplay_console_initted);
696 KASSERT(type->nrows > 0);
697 KASSERT(type->ncols > 0);
698 KASSERT(crow < type->nrows);
699 KASSERT(ccol < type->ncols);
700
701 wsdisplay_console_conf.emulops = type->textops;
702 wsdisplay_console_conf.emulcookie = cookie;
703 wsdisplay_console_conf.scrdata = type;
704
705 wsemul = wsemul_pick(0); /* default */
706 wsdisplay_console_conf.wsemul = wsemul;
707 wsdisplay_console_conf.wsemulcookie = (*wsemul->cnattach)(type, cookie,
708 ccol, crow,
709 defattr);
710
711 cn_tab = &wsdisplay_cons;
712 wsdisplay_console_initted = 1;
713 }
714
715 /*
716 * Tty and cdevsw functions.
717 */
718 int
719 wsdisplayopen(dev_t dev, int flag, int mode, struct lwp *l)
720 {
721 struct wsdisplay_softc *sc;
722 struct tty *tp;
723 int newopen, error;
724 struct wsscreen *scr;
725
726 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
727 if (sc == NULL) /* make sure it was attached */
728 return (ENXIO);
729
730 if (ISWSDISPLAYSTAT(dev)) {
731 wsevent_init(&sc->evar, l->l_proc);
732 return (0);
733 }
734
735 if (ISWSDISPLAYCTL(dev))
736 return (0);
737
738 if (WSDISPLAYSCREEN(dev) >= WSDISPLAY_MAXSCREEN)
739 return (ENXIO);
740 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
741 return (ENXIO);
742
743 if (WSSCREEN_HAS_TTY(scr)) {
744 tp = scr->scr_tty;
745 tp->t_oproc = wsdisplaystart;
746 tp->t_param = wsdisplayparam;
747 tp->t_dev = dev;
748 newopen = (tp->t_state & TS_ISOPEN) == 0;
749 if (newopen) {
750 ttychars(tp);
751 tp->t_iflag = TTYDEF_IFLAG;
752 tp->t_oflag = TTYDEF_OFLAG;
753 tp->t_cflag = TTYDEF_CFLAG;
754 tp->t_lflag = TTYDEF_LFLAG;
755 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
756 wsdisplayparam(tp, &tp->t_termios);
757 ttsetwater(tp);
758 } else if ((tp->t_state & TS_XCLUDE) != 0 &&
759 suser(l->l_proc->p_ucred, &l->l_proc->p_acflag) != 0)
760 return EBUSY;
761 tp->t_state |= TS_CARR_ON;
762
763 error = ((*tp->t_linesw->l_open)(dev, tp));
764 if (error)
765 return (error);
766
767 if (newopen && WSSCREEN_HAS_EMULATOR(scr)) {
768 /* set window sizes as appropriate, and reset
769 the emulation */
770 tp->t_winsize.ws_row = scr->scr_dconf->scrdata->nrows;
771 tp->t_winsize.ws_col = scr->scr_dconf->scrdata->ncols;
772
773 /* wsdisplay_set_emulation() */
774 }
775 }
776
777 scr->scr_flags |= SCR_OPEN;
778 return (0);
779 }
780
781 int
782 wsdisplayclose(dev_t dev, int flag, int mode, struct lwp *l)
783 {
784 struct wsdisplay_softc *sc;
785 struct tty *tp;
786 struct wsscreen *scr;
787
788 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
789
790 if (ISWSDISPLAYSTAT(dev)) {
791 wsevent_fini(&sc->evar);
792 return (0);
793 }
794
795 if (ISWSDISPLAYCTL(dev))
796 return (0);
797
798 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
799 return (0);
800
801 if (WSSCREEN_HAS_TTY(scr)) {
802 if (scr->scr_hold_screen) {
803 int s;
804
805 /* XXX RESET KEYBOARD LEDS, etc. */
806 s = spltty(); /* avoid conflict with keyboard */
807 wsdisplay_kbdholdscreen((struct device *)sc, 0);
808 splx(s);
809 }
810 tp = scr->scr_tty;
811 (*tp->t_linesw->l_close)(tp, flag);
812 ttyclose(tp);
813 }
814
815 if (scr->scr_syncops)
816 (*scr->scr_syncops->destroy)(scr->scr_synccookie);
817
818 if (WSSCREEN_HAS_EMULATOR(scr)) {
819 scr->scr_flags &= ~SCR_GRAPHICS;
820 (*scr->scr_dconf->wsemul->reset)(scr->scr_dconf->wsemulcookie,
821 WSEMUL_RESET);
822 if (wsdisplay_clearonclose)
823 (*scr->scr_dconf->wsemul->reset)
824 (scr->scr_dconf->wsemulcookie,
825 WSEMUL_CLEARSCREEN);
826 }
827
828 #ifdef WSDISPLAY_COMPAT_RAWKBD
829 if (scr->scr_rawkbd) {
830 int kbmode = WSKBD_TRANSLATED;
831 (void)wsdisplay_internal_ioctl(sc, scr, WSKBDIO_SETMODE,
832 (caddr_t)&kbmode, 0, l);
833 }
834 #endif
835
836 scr->scr_flags &= ~SCR_OPEN;
837
838 return (0);
839 }
840
841 int
842 wsdisplayread(dev_t dev, struct uio *uio, int flag)
843 {
844 struct wsdisplay_softc *sc;
845 struct tty *tp;
846 struct wsscreen *scr;
847 int error;
848
849 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
850
851 if (ISWSDISPLAYSTAT(dev)) {
852 error = wsevent_read(&sc->evar, uio, flag);
853 return (error);
854 }
855
856 if (ISWSDISPLAYCTL(dev))
857 return (0);
858
859 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
860 return (ENXIO);
861
862 if (!WSSCREEN_HAS_TTY(scr))
863 return (ENODEV);
864
865 tp = scr->scr_tty;
866 return ((*tp->t_linesw->l_read)(tp, uio, flag));
867 }
868
869 int
870 wsdisplaywrite(dev_t dev, struct uio *uio, int flag)
871 {
872 struct wsdisplay_softc *sc;
873 struct tty *tp;
874 struct wsscreen *scr;
875
876 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
877
878 if (ISWSDISPLAYSTAT(dev)) {
879 return (0);
880 }
881
882 if (ISWSDISPLAYCTL(dev))
883 return (0);
884
885 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
886 return (ENXIO);
887
888 if (!WSSCREEN_HAS_TTY(scr))
889 return (ENODEV);
890
891 tp = scr->scr_tty;
892 return ((*tp->t_linesw->l_write)(tp, uio, flag));
893 }
894
895 int
896 wsdisplaypoll(dev_t dev, int events, struct lwp *l)
897 {
898 struct wsdisplay_softc *sc;
899 struct tty *tp;
900 struct wsscreen *scr;
901
902 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
903
904 if (ISWSDISPLAYSTAT(dev))
905 return (wsevent_poll(&sc->evar, events, l));
906
907 if (ISWSDISPLAYCTL(dev))
908 return (0);
909
910 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
911 return (POLLHUP);
912
913 if (!WSSCREEN_HAS_TTY(scr))
914 return (POLLERR);
915
916 tp = scr->scr_tty;
917 return ((*tp->t_linesw->l_poll)(tp, events, l));
918 }
919
920 int
921 wsdisplaykqfilter(dev, kn)
922 dev_t dev;
923 struct knote *kn;
924 {
925 struct wsdisplay_softc *sc =
926 device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
927 struct wsscreen *scr;
928
929 if (ISWSDISPLAYCTL(dev))
930 return (1);
931
932 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
933 return (1);
934
935
936 if (WSSCREEN_HAS_TTY(scr))
937 return (ttykqfilter(dev, kn));
938 else
939 return (1);
940 }
941
942 struct tty *
943 wsdisplaytty(dev_t dev)
944 {
945 struct wsdisplay_softc *sc;
946 struct wsscreen *scr;
947
948 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
949
950 if (ISWSDISPLAYSTAT(dev))
951 panic("wsdisplaytty() on status device");
952
953 if (ISWSDISPLAYCTL(dev))
954 panic("wsdisplaytty() on ctl device");
955
956 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
957 return NULL;
958
959 return (scr->scr_tty);
960 }
961
962 int
963 wsdisplayioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
964 {
965 struct wsdisplay_softc *sc;
966 struct tty *tp;
967 int error;
968 struct wsscreen *scr;
969
970 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
971
972 #ifdef WSDISPLAY_COMPAT_USL
973 error = wsdisplay_usl_ioctl1(sc, cmd, data, flag, l);
974 if (error != EPASSTHROUGH)
975 return (error);
976 #endif
977
978 if (ISWSDISPLAYSTAT(dev))
979 return (wsdisplay_stat_ioctl(sc, cmd, data, flag, l));
980
981 if (ISWSDISPLAYCTL(dev))
982 return (wsdisplay_cfg_ioctl(sc, cmd, data, flag, l));
983
984 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
985 return (ENXIO);
986
987 if (WSSCREEN_HAS_TTY(scr)) {
988 tp = scr->scr_tty;
989
990 /* printf("disc\n"); */
991 /* do the line discipline ioctls first */
992 error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
993 if (error != EPASSTHROUGH)
994 return (error);
995
996 /* printf("tty\n"); */
997 /* then the tty ioctls */
998 error = ttioctl(tp, cmd, data, flag, l);
999 if (error != EPASSTHROUGH)
1000 return (error);
1001 }
1002
1003 #ifdef WSDISPLAY_COMPAT_USL
1004 error = wsdisplay_usl_ioctl2(sc, scr, cmd, data, flag, l);
1005 if (error != EPASSTHROUGH)
1006 return (error);
1007 #endif
1008
1009 return (wsdisplay_internal_ioctl(sc, scr, cmd, data, flag, l));
1010 }
1011
1012 int
1013 wsdisplay_param(struct device *dev, u_long cmd, struct wsdisplay_param *dp)
1014 {
1015 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1016 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, sc->sc_focus,
1017 cmd, (caddr_t)dp, 0, NULL));
1018 }
1019
1020 int
1021 wsdisplay_internal_ioctl(struct wsdisplay_softc *sc, struct wsscreen *scr,
1022 u_long cmd, caddr_t data, int flag, struct lwp *l)
1023 {
1024 int error;
1025 char namebuf[16];
1026 struct wsdisplay_font fd;
1027 #ifdef WSDISPLAY_SCROLLSUPPORT
1028 struct wsdisplay_scroll_data *ksdp, *usdp;
1029 #endif
1030
1031 #if NWSKBD > 0
1032 struct wsevsrc *inp;
1033
1034 #ifdef WSDISPLAY_COMPAT_RAWKBD
1035 switch (cmd) {
1036 case WSKBDIO_SETMODE:
1037 scr->scr_rawkbd = (*(int *)data == WSKBD_RAW);
1038 return (wsdisplay_update_rawkbd(sc, scr));
1039 case WSKBDIO_GETMODE:
1040 *(int *)data = (scr->scr_rawkbd ?
1041 WSKBD_RAW : WSKBD_TRANSLATED);
1042 return (0);
1043 }
1044 #endif
1045 inp = sc->sc_input;
1046 if (inp == NULL)
1047 return (ENXIO);
1048 error = wsevsrc_display_ioctl(inp, cmd, data, flag, l);
1049 if (error != EPASSTHROUGH)
1050 return (error);
1051 #endif /* NWSKBD > 0 */
1052
1053 switch (cmd) {
1054 case WSDISPLAYIO_GMODE:
1055 if (scr->scr_flags & SCR_GRAPHICS) {
1056 if (scr->scr_flags & SCR_DUMBFB)
1057 *(u_int *)data = WSDISPLAYIO_MODE_DUMBFB;
1058 else
1059 *(u_int *)data = WSDISPLAYIO_MODE_MAPPED;
1060 } else
1061 *(u_int *)data = WSDISPLAYIO_MODE_EMUL;
1062 return (0);
1063
1064 case WSDISPLAYIO_SMODE:
1065 #define d (*(int *)data)
1066 if (d != WSDISPLAYIO_MODE_EMUL &&
1067 d != WSDISPLAYIO_MODE_MAPPED &&
1068 d != WSDISPLAYIO_MODE_DUMBFB)
1069 return (EINVAL);
1070
1071 if (WSSCREEN_HAS_EMULATOR(scr)) {
1072 scr->scr_flags &= ~SCR_GRAPHICS;
1073 if (d == WSDISPLAYIO_MODE_MAPPED ||
1074 d == WSDISPLAYIO_MODE_DUMBFB)
1075 scr->scr_flags |= SCR_GRAPHICS |
1076 ((d == WSDISPLAYIO_MODE_DUMBFB) ? SCR_DUMBFB : 0);
1077 } else if (d == WSDISPLAYIO_MODE_EMUL)
1078 return (EINVAL);
1079
1080 (void)(*sc->sc_accessops->ioctl)(sc->sc_accesscookie, scr, cmd,
1081 data, flag, l);
1082
1083 return (0);
1084 #undef d
1085
1086 #ifdef WSDISPLAY_SCROLLSUPPORT
1087 #define SETSCROLLLINES(dstp, srcp, dfltp) \
1088 do { \
1089 (dstp)->fastlines = ((srcp)->which & \
1090 WSDISPLAY_SCROLL_DOFASTLINES) ? \
1091 (srcp)->fastlines : (dfltp)->fastlines; \
1092 (dstp)->slowlines = ((srcp)->which & \
1093 WSDISPLAY_SCROLL_DOSLOWLINES) ? \
1094 (srcp)->slowlines : (dfltp)->slowlines; \
1095 (dstp)->which = WSDISPLAY_SCROLL_DOALL; \
1096 } while (0)
1097
1098
1099 case WSDISPLAYIO_DSSCROLL:
1100 usdp = (struct wsdisplay_scroll_data *)data;
1101 ksdp = &sc->sc_scroll_values;
1102 SETSCROLLLINES(ksdp, usdp, ksdp);
1103 return (0);
1104
1105 case WSDISPLAYIO_DGSCROLL:
1106 usdp = (struct wsdisplay_scroll_data *)data;
1107 ksdp = &sc->sc_scroll_values;
1108 SETSCROLLLINES(usdp, ksdp, ksdp);
1109 return (0);
1110 #else
1111 case WSDISPLAYIO_DSSCROLL:
1112 case WSDISPLAYIO_DGSCROLL:
1113 return ENODEV;
1114 #endif
1115
1116 case WSDISPLAYIO_SFONT:
1117 #define d ((struct wsdisplay_usefontdata *)data)
1118 if (!sc->sc_accessops->load_font)
1119 return (EINVAL);
1120 if (d->name) {
1121 error = copyinstr(d->name, namebuf, sizeof(namebuf), 0);
1122 if (error)
1123 return (error);
1124 fd.name = namebuf;
1125 } else
1126 fd.name = 0;
1127 fd.data = 0;
1128 error = (*sc->sc_accessops->load_font)(sc->sc_accesscookie,
1129 scr->scr_dconf->emulcookie, &fd);
1130 if (!error && WSSCREEN_HAS_EMULATOR(scr))
1131 (*scr->scr_dconf->wsemul->reset)
1132 (scr->scr_dconf->wsemulcookie, WSEMUL_SYNCFONT);
1133 return (error);
1134 #undef d
1135
1136 #if defined(WSDISPLAY_CHARFUNCS)
1137 case WSDISPLAYIO_GETWSCHAR:
1138 #define d ((struct wsdisplay_char *)data)
1139 if (!sc->sc_accessops->getwschar)
1140 return (EINVAL);
1141 return ((*sc->sc_accessops->getwschar)
1142 (scr->scr_dconf->emulcookie, d));
1143 #undef d
1144
1145 case WSDISPLAYIO_PUTWSCHAR:
1146 #define d ((struct wsdisplay_char *)data)
1147 if (!sc->sc_accessops->putwschar)
1148 return (EINVAL);
1149 return ((*sc->sc_accessops->putwschar)
1150 (scr->scr_dconf->emulcookie, d));
1151 #undef d
1152 #else
1153 case WSDISPLAYIO_PUTWSCHAR:
1154 case WSDISPLAYIO_GETWSCHAR:
1155 return ENODEV;
1156 #endif /* WSDISPLAY_CHARFUNCS */
1157
1158 #ifdef WSDISPLAY_CUSTOM_OUTPUT
1159 case WSDISPLAYIO_GMSGATTRS:
1160 #define d ((struct wsdisplay_msgattrs *)data)
1161 (*scr->scr_dconf->wsemul->getmsgattrs)
1162 (scr->scr_dconf->wsemulcookie, d);
1163 return (0);
1164 #undef d
1165
1166 case WSDISPLAYIO_SMSGATTRS: {
1167 #define d ((struct wsdisplay_msgattrs *)data)
1168 int i;
1169 for (i = 0; i < WSDISPLAY_MAXSCREEN; i++)
1170 if (sc->sc_scr[i] != NULL)
1171 (*sc->sc_scr[i]->scr_dconf->wsemul->setmsgattrs)
1172 (sc->sc_scr[i]->scr_dconf->wsemulcookie,
1173 sc->sc_scr[i]->scr_dconf->scrdata,
1174 d);
1175 }
1176 return (0);
1177 #undef d
1178 #else
1179 case WSDISPLAYIO_GMSGATTRS:
1180 case WSDISPLAYIO_SMSGATTRS:
1181 return (ENODEV);
1182 #endif
1183 }
1184
1185 /* check ioctls for display */
1186 return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie, scr, cmd, data,
1187 flag, l));
1188 }
1189
1190 int
1191 wsdisplay_stat_ioctl(struct wsdisplay_softc *sc, u_long cmd, caddr_t data,
1192 int flag, struct lwp *l)
1193 {
1194 switch (cmd) {
1195 case WSDISPLAYIO_GETACTIVESCREEN:
1196 *(int*)data = wsdisplay_getactivescreen(sc);
1197 return (0);
1198 }
1199
1200 return (EPASSTHROUGH);
1201 }
1202
1203 int
1204 wsdisplay_cfg_ioctl(struct wsdisplay_softc *sc, u_long cmd, caddr_t data,
1205 int flag, struct lwp *l)
1206 {
1207 int error;
1208 char *type, typebuf[16], *emul, emulbuf[16];
1209 void *tbuf;
1210 u_int fontsz;
1211 #if defined(COMPAT_14) && NWSKBD > 0
1212 struct wsmux_device wsmuxdata;
1213 #endif
1214 #if NWSKBD > 0
1215 struct wsevsrc *inp;
1216 #endif
1217
1218 switch (cmd) {
1219 case WSDISPLAYIO_ADDSCREEN:
1220 #define d ((struct wsdisplay_addscreendata *)data)
1221 if (d->screentype) {
1222 error = copyinstr(d->screentype, typebuf,
1223 sizeof(typebuf), 0);
1224 if (error)
1225 return (error);
1226 type = typebuf;
1227 } else
1228 type = 0;
1229 if (d->emul) {
1230 error = copyinstr(d->emul, emulbuf, sizeof(emulbuf),0);
1231 if (error)
1232 return (error);
1233 emul = emulbuf;
1234 } else
1235 emul = 0;
1236
1237 if ((error = wsdisplay_addscreen(sc, d->idx, type, emul)) == 0)
1238 wsdisplay_addscreen_print(sc, d->idx, 0);
1239 return (error);
1240 #undef d
1241 case WSDISPLAYIO_DELSCREEN:
1242 #define d ((struct wsdisplay_delscreendata *)data)
1243 return (wsdisplay_delscreen(sc, d->idx, d->flags));
1244 #undef d
1245 case WSDISPLAYIO_LDFONT:
1246 #define d ((struct wsdisplay_font *)data)
1247 if (!sc->sc_accessops->load_font)
1248 return (EINVAL);
1249 if (d->name) {
1250 error = copyinstr(d->name, typebuf, sizeof(typebuf), 0);
1251 if (error)
1252 return (error);
1253 d->name = typebuf;
1254 } else
1255 d->name = "loaded"; /* ??? */
1256 fontsz = d->fontheight * d->stride * d->numchars;
1257 if (fontsz > WSDISPLAY_MAXFONTSZ)
1258 return (EINVAL);
1259
1260 tbuf = malloc(fontsz, M_DEVBUF, M_WAITOK);
1261 error = copyin(d->data, tbuf, fontsz);
1262 if (error) {
1263 free(tbuf, M_DEVBUF);
1264 return (error);
1265 }
1266 d->data = tbuf;
1267 error =
1268 (*sc->sc_accessops->load_font)(sc->sc_accesscookie, 0, d);
1269 free(tbuf, M_DEVBUF);
1270 #undef d
1271 return (error);
1272
1273 #if NWSKBD > 0
1274 #ifdef COMPAT_14
1275 case _O_WSDISPLAYIO_SETKEYBOARD:
1276 #define d ((struct wsdisplay_kbddata *)data)
1277 inp = sc->sc_input;
1278 if (inp == NULL)
1279 return (ENXIO);
1280 switch (d->op) {
1281 case _O_WSDISPLAY_KBD_ADD:
1282 if (d->idx == -1) {
1283 d->idx = wskbd_pickfree();
1284 if (d->idx == -1)
1285 return (ENXIO);
1286 }
1287 wsmuxdata.type = WSMUX_KBD;
1288 wsmuxdata.idx = d->idx;
1289 return (wsevsrc_ioctl(inp, WSMUX_ADD_DEVICE,
1290 &wsmuxdata, flag, l));
1291 case _O_WSDISPLAY_KBD_DEL:
1292 wsmuxdata.type = WSMUX_KBD;
1293 wsmuxdata.idx = d->idx;
1294 return (wsevsrc_ioctl(inp, WSMUX_REMOVE_DEVICE,
1295 &wsmuxdata, flag, l));
1296 default:
1297 return (EINVAL);
1298 }
1299 #undef d
1300 #endif
1301
1302 case WSMUXIO_ADD_DEVICE:
1303 #define d ((struct wsmux_device *)data)
1304 if (d->idx == -1 && d->type == WSMUX_KBD)
1305 d->idx = wskbd_pickfree();
1306 #undef d
1307 /* fall into */
1308 case WSMUXIO_INJECTEVENT:
1309 case WSMUXIO_REMOVE_DEVICE:
1310 case WSMUXIO_LIST_DEVICES:
1311 inp = sc->sc_input;
1312 if (inp == NULL)
1313 return (ENXIO);
1314 return (wsevsrc_ioctl(inp, cmd, data, flag, l));
1315 #endif /* NWSKBD > 0 */
1316
1317 }
1318 return (EPASSTHROUGH);
1319 }
1320
1321 int
1322 wsdisplay_stat_inject(struct device *dev, u_int type, int value)
1323 {
1324 struct wsdisplay_softc *sc = (struct wsdisplay_softc *) dev;
1325 struct wseventvar *evar;
1326 struct wscons_event event;
1327
1328 evar = &sc->evar;
1329
1330 if (evar == NULL)
1331 return (0);
1332
1333 if (evar->q == NULL)
1334 return (1);
1335
1336 event.type = type;
1337 event.value = value;
1338 if (wsevent_inject(evar, &event, 1) != 0) {
1339 log(LOG_WARNING, "wsdisplay: event queue overflow\n");
1340 return (1);
1341 }
1342
1343 return (0);
1344 }
1345
1346 paddr_t
1347 wsdisplaymmap(dev_t dev, off_t offset, int prot)
1348 {
1349 struct wsdisplay_softc *sc =
1350 device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev));
1351 struct wsscreen *scr;
1352
1353 if (ISWSDISPLAYSTAT(dev))
1354 return (-1);
1355
1356 if (ISWSDISPLAYCTL(dev))
1357 return (-1);
1358
1359 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
1360 return (-1);
1361
1362 if (!(scr->scr_flags & SCR_GRAPHICS))
1363 return (-1);
1364
1365 /* pass mmap to display */
1366 return ((*sc->sc_accessops->mmap)(sc->sc_accesscookie, scr,
1367 offset, prot));
1368 }
1369
1370 void
1371 wsdisplaystart(struct tty *tp)
1372 {
1373 struct wsdisplay_softc *sc;
1374 struct wsscreen *scr;
1375 int s, n;
1376 u_char *tbuf;
1377
1378 s = spltty();
1379 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
1380 splx(s);
1381 return;
1382 }
1383 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(tp->t_dev));
1384 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) {
1385 splx(s);
1386 return;
1387 }
1388
1389 if (scr->scr_hold_screen) {
1390 tp->t_state |= TS_TIMEOUT;
1391 splx(s);
1392 return;
1393 }
1394 tp->t_state |= TS_BUSY;
1395 splx(s);
1396
1397 /*
1398 * Drain output from ring buffer.
1399 * The output will normally be in one contiguous chunk, but when the
1400 * ring wraps, it will be in two pieces.. one at the end of the ring,
1401 * the other at the start. For performance, rather than loop here,
1402 * we output one chunk, see if there's another one, and if so, output
1403 * it too.
1404 */
1405
1406 n = ndqb(&tp->t_outq, 0);
1407 tbuf = tp->t_outq.c_cf;
1408
1409 if (!(scr->scr_flags & SCR_GRAPHICS)) {
1410 KASSERT(WSSCREEN_HAS_EMULATOR(scr));
1411 (*scr->scr_dconf->wsemul->output)(scr->scr_dconf->wsemulcookie,
1412 tbuf, n, 0);
1413 }
1414 ndflush(&tp->t_outq, n);
1415
1416 if ((n = ndqb(&tp->t_outq, 0)) > 0) {
1417 tbuf = tp->t_outq.c_cf;
1418
1419 if (!(scr->scr_flags & SCR_GRAPHICS)) {
1420 KASSERT(WSSCREEN_HAS_EMULATOR(scr));
1421 (*scr->scr_dconf->wsemul->output)
1422 (scr->scr_dconf->wsemulcookie, tbuf, n, 0);
1423 }
1424 ndflush(&tp->t_outq, n);
1425 }
1426
1427 s = spltty();
1428 tp->t_state &= ~TS_BUSY;
1429 /* Come back if there's more to do */
1430 if (tp->t_outq.c_cc) {
1431 tp->t_state |= TS_TIMEOUT;
1432 callout_reset(&tp->t_rstrt_ch, (hz > 128) ? (hz / 128) : 1,
1433 ttrstrt, tp);
1434 }
1435 if (tp->t_outq.c_cc <= tp->t_lowat) {
1436 if (tp->t_state&TS_ASLEEP) {
1437 tp->t_state &= ~TS_ASLEEP;
1438 wakeup(&tp->t_outq);
1439 }
1440 selwakeup(&tp->t_wsel);
1441 }
1442 splx(s);
1443 }
1444
1445 void
1446 wsdisplaystop(struct tty *tp, int flag)
1447 {
1448 int s;
1449
1450 s = spltty();
1451 if (ISSET(tp->t_state, TS_BUSY))
1452 if (!ISSET(tp->t_state, TS_TTSTOP))
1453 SET(tp->t_state, TS_FLUSH);
1454 splx(s);
1455 }
1456
1457 /* Set line parameters. */
1458 int
1459 wsdisplayparam(struct tty *tp, struct termios *t)
1460 {
1461
1462 tp->t_ispeed = t->c_ispeed;
1463 tp->t_ospeed = t->c_ospeed;
1464 tp->t_cflag = t->c_cflag;
1465 return 0;
1466 }
1467
1468 /*
1469 * Callbacks for the emulation code.
1470 */
1471 void
1472 wsdisplay_emulbell(void *v)
1473 {
1474 struct wsscreen *scr = v;
1475
1476 if (scr == NULL) /* console, before real attach */
1477 return;
1478
1479 if (scr->scr_flags & SCR_GRAPHICS) /* can this happen? */
1480 return;
1481
1482 (void) wsdisplay_internal_ioctl(scr->sc, scr, WSKBDIO_BELL, NULL,
1483 FWRITE, NULL);
1484 }
1485
1486 void
1487 wsdisplay_emulinput(void *v, const u_char *data, u_int count)
1488 {
1489 struct wsscreen *scr = v;
1490 struct tty *tp;
1491
1492 if (v == NULL) /* console, before real attach */
1493 return;
1494
1495 if (scr->scr_flags & SCR_GRAPHICS) /* XXX can't happen */
1496 return;
1497 if (!WSSCREEN_HAS_TTY(scr))
1498 return;
1499
1500 tp = scr->scr_tty;
1501 while (count-- > 0)
1502 (*tp->t_linesw->l_rint)(*data++, tp);
1503 }
1504
1505 /*
1506 * Calls from the keyboard interface.
1507 */
1508 void
1509 wsdisplay_kbdinput(struct device *dev, keysym_t ks)
1510 {
1511 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1512 struct wsscreen *scr;
1513 const char *dp;
1514 int count;
1515 struct tty *tp;
1516
1517 KASSERT(sc != NULL);
1518
1519 scr = sc->sc_focus;
1520
1521 if (!scr || !WSSCREEN_HAS_TTY(scr))
1522 return;
1523
1524 tp = scr->scr_tty;
1525
1526 if (KS_GROUP(ks) == KS_GROUP_Ascii)
1527 (*tp->t_linesw->l_rint)(KS_VALUE(ks), tp);
1528 else if (WSSCREEN_HAS_EMULATOR(scr)) {
1529 count = (*scr->scr_dconf->wsemul->translate)
1530 (scr->scr_dconf->wsemulcookie, ks, &dp);
1531 while (count-- > 0)
1532 (*tp->t_linesw->l_rint)(*dp++, tp);
1533 }
1534 }
1535
1536 #if defined(WSDISPLAY_COMPAT_RAWKBD)
1537 int
1538 wsdisplay_update_rawkbd(struct wsdisplay_softc *sc, struct wsscreen *scr)
1539 {
1540 #if NWSKBD > 0
1541 int s, raw, data, error;
1542 struct wsevsrc *inp;
1543
1544 s = spltty();
1545
1546 raw = (scr ? scr->scr_rawkbd : 0);
1547
1548 if (scr != sc->sc_focus ||
1549 sc->sc_rawkbd == raw) {
1550 splx(s);
1551 return (0);
1552 }
1553
1554 data = raw ? WSKBD_RAW : WSKBD_TRANSLATED;
1555 inp = sc->sc_input;
1556 if (inp == NULL)
1557 return (ENXIO);
1558 error = wsevsrc_display_ioctl(inp, WSKBDIO_SETMODE, &data, 0, 0);
1559 if (!error)
1560 sc->sc_rawkbd = raw;
1561 splx(s);
1562 return (error);
1563 #else
1564 return (0);
1565 #endif
1566 }
1567 #endif
1568
1569 int
1570 wsdisplay_switch3(void *arg, int error, int waitok)
1571 {
1572 struct wsdisplay_softc *sc = arg;
1573 int no;
1574 struct wsscreen *scr;
1575
1576 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1577 printf("wsdisplay_switch3: not switching\n");
1578 return (EINVAL);
1579 }
1580
1581 no = sc->sc_screenwanted;
1582 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1583 panic("wsdisplay_switch3: invalid screen %d", no);
1584 scr = sc->sc_scr[no];
1585 if (!scr) {
1586 printf("wsdisplay_switch3: screen %d disappeared\n", no);
1587 error = ENXIO;
1588 }
1589
1590 if (error) {
1591 /* try to recover, avoid recursion */
1592
1593 if (sc->sc_oldscreen == WSDISPLAY_NULLSCREEN) {
1594 printf("wsdisplay_switch3: giving up\n");
1595 sc->sc_focus = 0;
1596 #ifdef WSDISPLAY_COMPAT_RAWKBD
1597 wsdisplay_update_rawkbd(sc, 0);
1598 #endif
1599 sc->sc_flags &= ~SC_SWITCHPENDING;
1600 return (error);
1601 }
1602
1603 sc->sc_screenwanted = sc->sc_oldscreen;
1604 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1605 return (wsdisplay_switch1(arg, 0, waitok));
1606 }
1607
1608 sc->sc_flags &= ~SC_SWITCHPENDING;
1609
1610 if (!error && (scr->scr_flags & SCR_WAITACTIVE))
1611 wakeup(scr);
1612 return (error);
1613 }
1614
1615 int
1616 wsdisplay_switch2(void *arg, int error, int waitok)
1617 {
1618 struct wsdisplay_softc *sc = arg;
1619 int no;
1620 struct wsscreen *scr;
1621
1622 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1623 printf("wsdisplay_switch2: not switching\n");
1624 return (EINVAL);
1625 }
1626
1627 no = sc->sc_screenwanted;
1628 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1629 panic("wsdisplay_switch2: invalid screen %d", no);
1630 scr = sc->sc_scr[no];
1631 if (!scr) {
1632 printf("wsdisplay_switch2: screen %d disappeared\n", no);
1633 error = ENXIO;
1634 }
1635
1636 if (error) {
1637 /* try to recover, avoid recursion */
1638
1639 if (sc->sc_oldscreen == WSDISPLAY_NULLSCREEN) {
1640 printf("wsdisplay_switch2: giving up\n");
1641 sc->sc_focus = 0;
1642 sc->sc_flags &= ~SC_SWITCHPENDING;
1643 return (error);
1644 }
1645
1646 sc->sc_screenwanted = sc->sc_oldscreen;
1647 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1648 return (wsdisplay_switch1(arg, 0, waitok));
1649 }
1650
1651 sc->sc_focusidx = no;
1652 sc->sc_focus = scr;
1653
1654 #ifdef WSDISPLAY_COMPAT_RAWKBD
1655 (void) wsdisplay_update_rawkbd(sc, scr);
1656 #endif
1657 /* keyboard map??? */
1658
1659 #define wsswitch_cb3 ((void (*)(void *, int, int))wsdisplay_switch3)
1660 if (scr->scr_syncops) {
1661 error = (*scr->scr_syncops->attach)(scr->scr_synccookie, waitok,
1662 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb3, sc);
1663 if (error == EAGAIN) {
1664 /* switch will be done asynchronously */
1665 return (0);
1666 }
1667 }
1668
1669 return (wsdisplay_switch3(sc, error, waitok));
1670 }
1671
1672 int
1673 wsdisplay_switch1(void *arg, int error, int waitok)
1674 {
1675 struct wsdisplay_softc *sc = arg;
1676 int no;
1677 struct wsscreen *scr;
1678
1679 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1680 printf("wsdisplay_switch1: not switching\n");
1681 return (EINVAL);
1682 }
1683
1684 no = sc->sc_screenwanted;
1685 if (no == WSDISPLAY_NULLSCREEN) {
1686 sc->sc_flags &= ~SC_SWITCHPENDING;
1687 if (!error) {
1688 sc->sc_focus = 0;
1689 }
1690 wakeup(sc);
1691 return (error);
1692 }
1693 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1694 panic("wsdisplay_switch1: invalid screen %d", no);
1695 scr = sc->sc_scr[no];
1696 if (!scr) {
1697 printf("wsdisplay_switch1: screen %d disappeared\n", no);
1698 error = ENXIO;
1699 }
1700
1701 if (error) {
1702 sc->sc_flags &= ~SC_SWITCHPENDING;
1703 return (error);
1704 }
1705
1706 #define wsswitch_cb2 ((void (*)(void *, int, int))wsdisplay_switch2)
1707 error = (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
1708 scr->scr_dconf->emulcookie,
1709 waitok,
1710 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb2, sc);
1711 if (error == EAGAIN) {
1712 /* switch will be done asynchronously */
1713 return (0);
1714 }
1715
1716 return (wsdisplay_switch2(sc, error, waitok));
1717 }
1718
1719 int
1720 wsdisplay_switch(struct device *dev, int no, int waitok)
1721 {
1722 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1723 int s, res = 0;
1724 struct wsscreen *scr;
1725
1726 if (no != WSDISPLAY_NULLSCREEN) {
1727 if ((no < 0 || no >= WSDISPLAY_MAXSCREEN))
1728 return (EINVAL);
1729 if (sc->sc_scr[no] == NULL)
1730 return (ENXIO);
1731 }
1732
1733 wsdisplay_stat_inject(dev, WSCONS_EVENT_SCREEN_SWITCH, no);
1734
1735 s = spltty();
1736
1737 if ((sc->sc_focus && no == sc->sc_focusidx) ||
1738 (sc->sc_focus == NULL && no == WSDISPLAY_NULLSCREEN)) {
1739 splx(s);
1740 return (0);
1741 }
1742
1743 if (sc->sc_flags & SC_SWITCHPENDING) {
1744 splx(s);
1745 return (EBUSY);
1746 }
1747
1748 sc->sc_flags |= SC_SWITCHPENDING;
1749 sc->sc_screenwanted = no;
1750
1751 splx(s);
1752
1753 scr = sc->sc_focus;
1754 if (!scr) {
1755 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1756 return (wsdisplay_switch1(sc, 0, waitok));
1757 } else
1758 sc->sc_oldscreen = sc->sc_focusidx;
1759
1760 #define wsswitch_cb1 ((void (*)(void *, int, int))wsdisplay_switch1)
1761 if (scr->scr_syncops) {
1762 res = (*scr->scr_syncops->detach)(scr->scr_synccookie, waitok,
1763 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb1, sc);
1764 if (res == EAGAIN) {
1765 /* switch will be done asynchronously */
1766 return (0);
1767 }
1768 } else if (scr->scr_flags & SCR_GRAPHICS) {
1769 /* no way to save state */
1770 res = EBUSY;
1771 }
1772
1773 return (wsdisplay_switch1(sc, res, waitok));
1774 }
1775
1776 void
1777 wsdisplay_reset(struct device *dev, enum wsdisplay_resetops op)
1778 {
1779 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1780 struct wsscreen *scr;
1781
1782 KASSERT(sc != NULL);
1783 scr = sc->sc_focus;
1784
1785 if (!scr)
1786 return;
1787
1788 switch (op) {
1789 case WSDISPLAY_RESETEMUL:
1790 if (!WSSCREEN_HAS_EMULATOR(scr))
1791 break;
1792 (*scr->scr_dconf->wsemul->reset)(scr->scr_dconf->wsemulcookie,
1793 WSEMUL_RESET);
1794 break;
1795 case WSDISPLAY_RESETCLOSE:
1796 wsdisplay_closescreen(sc, scr);
1797 break;
1798 }
1799 }
1800
1801 /*
1802 * Interface for (external) VT switch / process synchronization code
1803 */
1804 int
1805 wsscreen_attach_sync(struct wsscreen *scr, const struct wscons_syncops *ops,
1806 void *cookie)
1807 {
1808 if (scr->scr_syncops) {
1809 /*
1810 * The screen is already claimed.
1811 * Check if the owner is still alive.
1812 */
1813 if ((*scr->scr_syncops->check)(scr->scr_synccookie))
1814 return (EBUSY);
1815 }
1816 scr->scr_syncops = ops;
1817 scr->scr_synccookie = cookie;
1818 return (0);
1819 }
1820
1821 int
1822 wsscreen_detach_sync(struct wsscreen *scr)
1823 {
1824 if (!scr->scr_syncops)
1825 return (EINVAL);
1826 scr->scr_syncops = 0;
1827 return (0);
1828 }
1829
1830 int
1831 wsscreen_lookup_sync(struct wsscreen *scr,
1832 const struct wscons_syncops *ops, /* used as ID */
1833 void **cookiep)
1834 {
1835 if (!scr->scr_syncops || ops != scr->scr_syncops)
1836 return (EINVAL);
1837 *cookiep = scr->scr_synccookie;
1838 return (0);
1839 }
1840
1841 /*
1842 * Interface to virtual screen stuff
1843 */
1844 int
1845 wsdisplay_maxscreenidx(struct wsdisplay_softc *sc)
1846 {
1847 return (WSDISPLAY_MAXSCREEN - 1);
1848 }
1849
1850 int
1851 wsdisplay_screenstate(struct wsdisplay_softc *sc, int idx)
1852 {
1853 if (idx < 0 || idx >= WSDISPLAY_MAXSCREEN)
1854 return (EINVAL);
1855 if (!sc->sc_scr[idx])
1856 return (ENXIO);
1857 return ((sc->sc_scr[idx]->scr_flags & SCR_OPEN) ? EBUSY : 0);
1858 }
1859
1860 int
1861 wsdisplay_getactivescreen(struct wsdisplay_softc *sc)
1862 {
1863 return (sc->sc_focus ? sc->sc_focusidx : WSDISPLAY_NULLSCREEN);
1864 }
1865
1866 int
1867 wsscreen_switchwait(struct wsdisplay_softc *sc, int no)
1868 {
1869 struct wsscreen *scr;
1870 int s, res = 0;
1871
1872 if (no == WSDISPLAY_NULLSCREEN) {
1873 s = spltty();
1874 while (sc->sc_focus && res == 0) {
1875 res = tsleep(sc, PCATCH, "wswait", 0);
1876 }
1877 splx(s);
1878 return (res);
1879 }
1880
1881 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1882 return (ENXIO);
1883 scr = sc->sc_scr[no];
1884 if (!scr)
1885 return (ENXIO);
1886
1887 s = spltty();
1888 if (scr != sc->sc_focus) {
1889 scr->scr_flags |= SCR_WAITACTIVE;
1890 res = tsleep(scr, PCATCH, "wswait", 0);
1891 if (scr != sc->sc_scr[no])
1892 res = ENXIO; /* disappeared in the meantime */
1893 else
1894 scr->scr_flags &= ~SCR_WAITACTIVE;
1895 }
1896 splx(s);
1897 return (res);
1898 }
1899
1900 void
1901 wsdisplay_kbdholdscreen(struct device *dev, int hold)
1902 {
1903 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1904 struct wsscreen *scr;
1905
1906 scr = sc->sc_focus;
1907
1908 if (hold)
1909 scr->scr_hold_screen = 1;
1910 else {
1911 scr->scr_hold_screen = 0;
1912 callout_reset(&scr->scr_tty->t_rstrt_ch, 0,
1913 ttrstrt, scr->scr_tty); /* "immediate" */
1914 }
1915 }
1916
1917 #if NWSKBD > 0
1918 void
1919 wsdisplay_set_console_kbd(struct wsevsrc *src)
1920 {
1921 if (wsdisplay_console_device == NULL) {
1922 src->me_dispdv = NULL;
1923 return;
1924 }
1925 #if NWSMUX > 0
1926 if (wsmux_attach_sc((struct wsmux_softc *)
1927 wsdisplay_console_device->sc_input, src)) {
1928 src->me_dispdv = NULL;
1929 return;
1930 }
1931 #else
1932 wsdisplay_console_device->sc_input = src;
1933 #endif
1934 src->me_dispdv = &wsdisplay_console_device->sc_dv;
1935 }
1936 #endif /* NWSKBD > 0 */
1937
1938 /*
1939 * Console interface.
1940 */
1941 void
1942 wsdisplay_cnputc(dev_t dev, int i)
1943 {
1944 struct wsscreen_internal *dc;
1945 u_char c = i;
1946
1947 if (!wsdisplay_console_initted)
1948 return;
1949
1950 if ((wsdisplay_console_device != NULL) &&
1951 (wsdisplay_console_device->sc_scr[0] != NULL) &&
1952 (wsdisplay_console_device->sc_scr[0]->scr_flags & SCR_GRAPHICS))
1953 return;
1954
1955 dc = &wsdisplay_console_conf;
1956 (*dc->wsemul->output)(dc->wsemulcookie, &c, 1, 1);
1957 }
1958
1959 static int
1960 wsdisplay_getc_dummy(dev_t dev)
1961 {
1962 /* panic? */
1963 return (0);
1964 }
1965
1966 static void
1967 wsdisplay_pollc(dev_t dev, int on)
1968 {
1969
1970 wsdisplay_cons_pollmode = on;
1971
1972 /* notify to fb drivers */
1973 if (wsdisplay_console_device != NULL &&
1974 wsdisplay_console_device->sc_accessops->pollc != NULL)
1975 (*wsdisplay_console_device->sc_accessops->pollc)
1976 (wsdisplay_console_device->sc_accesscookie, on);
1977
1978 /* notify to kbd drivers */
1979 if (wsdisplay_cons_kbd_pollc)
1980 (*wsdisplay_cons_kbd_pollc)(NODEV, on);
1981 }
1982
1983 void
1984 wsdisplay_set_cons_kbd(int (*get)(dev_t), void (*poll)(dev_t, int),
1985 void (*bell)(dev_t, u_int, u_int, u_int))
1986 {
1987 wsdisplay_cons.cn_getc = get;
1988 wsdisplay_cons.cn_bell = bell;
1989 wsdisplay_cons_kbd_pollc = poll;
1990 }
1991
1992 void
1993 wsdisplay_unset_cons_kbd(void)
1994 {
1995 wsdisplay_cons.cn_getc = wsdisplay_getc_dummy;
1996 wsdisplay_cons.cn_bell = NULL;
1997 wsdisplay_cons_kbd_pollc = 0;
1998 }
1999
2000 /*
2001 * Switch the console display to it's first screen.
2002 */
2003 void
2004 wsdisplay_switchtoconsole(void)
2005 {
2006 struct wsdisplay_softc *sc;
2007 struct wsscreen *scr;
2008
2009 if (wsdisplay_console_device != NULL) {
2010 sc = wsdisplay_console_device;
2011 if ((scr = sc->sc_scr[0]) == NULL)
2012 return;
2013 (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
2014 scr->scr_dconf->emulcookie,
2015 0, NULL, NULL);
2016 }
2017 }
2018
2019 /*
2020 * Switch the console at shutdown.
2021 */
2022 static void
2023 wsdisplay_shutdownhook(void *arg)
2024 {
2025
2026 wsdisplay_switchtoconsole();
2027 }
2028