wsdisplay.c revision 1.89.2.3 1 /* $NetBSD: wsdisplay.c,v 1.89.2.3 2006/04/11 11:55:29 yamt 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.89.2.3 2006/04/11 11:55:29 yamt 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, cmd,
1017 (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, cmd, data,
1081 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, 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, offset, prot));
1367 }
1368
1369 void
1370 wsdisplaystart(struct tty *tp)
1371 {
1372 struct wsdisplay_softc *sc;
1373 struct wsscreen *scr;
1374 int s, n;
1375 u_char *tbuf;
1376
1377 s = spltty();
1378 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
1379 splx(s);
1380 return;
1381 }
1382 sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(tp->t_dev));
1383 if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) {
1384 splx(s);
1385 return;
1386 }
1387
1388 if (scr->scr_hold_screen) {
1389 tp->t_state |= TS_TIMEOUT;
1390 splx(s);
1391 return;
1392 }
1393 tp->t_state |= TS_BUSY;
1394 splx(s);
1395
1396 /*
1397 * Drain output from ring buffer.
1398 * The output will normally be in one contiguous chunk, but when the
1399 * ring wraps, it will be in two pieces.. one at the end of the ring,
1400 * the other at the start. For performance, rather than loop here,
1401 * we output one chunk, see if there's another one, and if so, output
1402 * it too.
1403 */
1404
1405 n = ndqb(&tp->t_outq, 0);
1406 tbuf = tp->t_outq.c_cf;
1407
1408 if (!(scr->scr_flags & SCR_GRAPHICS)) {
1409 KASSERT(WSSCREEN_HAS_EMULATOR(scr));
1410 (*scr->scr_dconf->wsemul->output)(scr->scr_dconf->wsemulcookie,
1411 tbuf, n, 0);
1412 }
1413 ndflush(&tp->t_outq, n);
1414
1415 if ((n = ndqb(&tp->t_outq, 0)) > 0) {
1416 tbuf = tp->t_outq.c_cf;
1417
1418 if (!(scr->scr_flags & SCR_GRAPHICS)) {
1419 KASSERT(WSSCREEN_HAS_EMULATOR(scr));
1420 (*scr->scr_dconf->wsemul->output)
1421 (scr->scr_dconf->wsemulcookie, tbuf, n, 0);
1422 }
1423 ndflush(&tp->t_outq, n);
1424 }
1425
1426 s = spltty();
1427 tp->t_state &= ~TS_BUSY;
1428 /* Come back if there's more to do */
1429 if (tp->t_outq.c_cc) {
1430 tp->t_state |= TS_TIMEOUT;
1431 callout_reset(&tp->t_rstrt_ch, (hz > 128) ? (hz / 128) : 1,
1432 ttrstrt, tp);
1433 }
1434 if (tp->t_outq.c_cc <= tp->t_lowat) {
1435 if (tp->t_state&TS_ASLEEP) {
1436 tp->t_state &= ~TS_ASLEEP;
1437 wakeup(&tp->t_outq);
1438 }
1439 selwakeup(&tp->t_wsel);
1440 }
1441 splx(s);
1442 }
1443
1444 void
1445 wsdisplaystop(struct tty *tp, int flag)
1446 {
1447 int s;
1448
1449 s = spltty();
1450 if (ISSET(tp->t_state, TS_BUSY))
1451 if (!ISSET(tp->t_state, TS_TTSTOP))
1452 SET(tp->t_state, TS_FLUSH);
1453 splx(s);
1454 }
1455
1456 /* Set line parameters. */
1457 int
1458 wsdisplayparam(struct tty *tp, struct termios *t)
1459 {
1460
1461 tp->t_ispeed = t->c_ispeed;
1462 tp->t_ospeed = t->c_ospeed;
1463 tp->t_cflag = t->c_cflag;
1464 return 0;
1465 }
1466
1467 /*
1468 * Callbacks for the emulation code.
1469 */
1470 void
1471 wsdisplay_emulbell(void *v)
1472 {
1473 struct wsscreen *scr = v;
1474
1475 if (scr == NULL) /* console, before real attach */
1476 return;
1477
1478 if (scr->scr_flags & SCR_GRAPHICS) /* can this happen? */
1479 return;
1480
1481 (void) wsdisplay_internal_ioctl(scr->sc, scr, WSKBDIO_BELL, NULL,
1482 FWRITE, NULL);
1483 }
1484
1485 void
1486 wsdisplay_emulinput(void *v, const u_char *data, u_int count)
1487 {
1488 struct wsscreen *scr = v;
1489 struct tty *tp;
1490
1491 if (v == NULL) /* console, before real attach */
1492 return;
1493
1494 if (scr->scr_flags & SCR_GRAPHICS) /* XXX can't happen */
1495 return;
1496 if (!WSSCREEN_HAS_TTY(scr))
1497 return;
1498
1499 tp = scr->scr_tty;
1500 while (count-- > 0)
1501 (*tp->t_linesw->l_rint)(*data++, tp);
1502 }
1503
1504 /*
1505 * Calls from the keyboard interface.
1506 */
1507 void
1508 wsdisplay_kbdinput(struct device *dev, keysym_t ks)
1509 {
1510 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1511 struct wsscreen *scr;
1512 const char *dp;
1513 int count;
1514 struct tty *tp;
1515
1516 KASSERT(sc != NULL);
1517
1518 scr = sc->sc_focus;
1519
1520 if (!scr || !WSSCREEN_HAS_TTY(scr))
1521 return;
1522
1523 tp = scr->scr_tty;
1524
1525 if (KS_GROUP(ks) == KS_GROUP_Ascii)
1526 (*tp->t_linesw->l_rint)(KS_VALUE(ks), tp);
1527 else if (WSSCREEN_HAS_EMULATOR(scr)) {
1528 count = (*scr->scr_dconf->wsemul->translate)
1529 (scr->scr_dconf->wsemulcookie, ks, &dp);
1530 while (count-- > 0)
1531 (*tp->t_linesw->l_rint)(*dp++, tp);
1532 }
1533 }
1534
1535 #if defined(WSDISPLAY_COMPAT_RAWKBD)
1536 int
1537 wsdisplay_update_rawkbd(struct wsdisplay_softc *sc, struct wsscreen *scr)
1538 {
1539 #if NWSKBD > 0
1540 int s, raw, data, error;
1541 struct wsevsrc *inp;
1542
1543 s = spltty();
1544
1545 raw = (scr ? scr->scr_rawkbd : 0);
1546
1547 if (scr != sc->sc_focus ||
1548 sc->sc_rawkbd == raw) {
1549 splx(s);
1550 return (0);
1551 }
1552
1553 data = raw ? WSKBD_RAW : WSKBD_TRANSLATED;
1554 inp = sc->sc_input;
1555 if (inp == NULL)
1556 return (ENXIO);
1557 error = wsevsrc_display_ioctl(inp, WSKBDIO_SETMODE, &data, 0, 0);
1558 if (!error)
1559 sc->sc_rawkbd = raw;
1560 splx(s);
1561 return (error);
1562 #else
1563 return (0);
1564 #endif
1565 }
1566 #endif
1567
1568 int
1569 wsdisplay_switch3(void *arg, int error, int waitok)
1570 {
1571 struct wsdisplay_softc *sc = arg;
1572 int no;
1573 struct wsscreen *scr;
1574
1575 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1576 printf("wsdisplay_switch3: not switching\n");
1577 return (EINVAL);
1578 }
1579
1580 no = sc->sc_screenwanted;
1581 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1582 panic("wsdisplay_switch3: invalid screen %d", no);
1583 scr = sc->sc_scr[no];
1584 if (!scr) {
1585 printf("wsdisplay_switch3: screen %d disappeared\n", no);
1586 error = ENXIO;
1587 }
1588
1589 if (error) {
1590 /* try to recover, avoid recursion */
1591
1592 if (sc->sc_oldscreen == WSDISPLAY_NULLSCREEN) {
1593 printf("wsdisplay_switch3: giving up\n");
1594 sc->sc_focus = 0;
1595 #ifdef WSDISPLAY_COMPAT_RAWKBD
1596 wsdisplay_update_rawkbd(sc, 0);
1597 #endif
1598 sc->sc_flags &= ~SC_SWITCHPENDING;
1599 return (error);
1600 }
1601
1602 sc->sc_screenwanted = sc->sc_oldscreen;
1603 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1604 return (wsdisplay_switch1(arg, 0, waitok));
1605 }
1606
1607 sc->sc_flags &= ~SC_SWITCHPENDING;
1608
1609 if (!error && (scr->scr_flags & SCR_WAITACTIVE))
1610 wakeup(scr);
1611 return (error);
1612 }
1613
1614 int
1615 wsdisplay_switch2(void *arg, int error, int waitok)
1616 {
1617 struct wsdisplay_softc *sc = arg;
1618 int no;
1619 struct wsscreen *scr;
1620
1621 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1622 printf("wsdisplay_switch2: not switching\n");
1623 return (EINVAL);
1624 }
1625
1626 no = sc->sc_screenwanted;
1627 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1628 panic("wsdisplay_switch2: invalid screen %d", no);
1629 scr = sc->sc_scr[no];
1630 if (!scr) {
1631 printf("wsdisplay_switch2: screen %d disappeared\n", no);
1632 error = ENXIO;
1633 }
1634
1635 if (error) {
1636 /* try to recover, avoid recursion */
1637
1638 if (sc->sc_oldscreen == WSDISPLAY_NULLSCREEN) {
1639 printf("wsdisplay_switch2: giving up\n");
1640 sc->sc_focus = 0;
1641 sc->sc_flags &= ~SC_SWITCHPENDING;
1642 return (error);
1643 }
1644
1645 sc->sc_screenwanted = sc->sc_oldscreen;
1646 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1647 return (wsdisplay_switch1(arg, 0, waitok));
1648 }
1649
1650 sc->sc_focusidx = no;
1651 sc->sc_focus = scr;
1652
1653 #ifdef WSDISPLAY_COMPAT_RAWKBD
1654 (void) wsdisplay_update_rawkbd(sc, scr);
1655 #endif
1656 /* keyboard map??? */
1657
1658 #define wsswitch_cb3 ((void (*)(void *, int, int))wsdisplay_switch3)
1659 if (scr->scr_syncops) {
1660 error = (*scr->scr_syncops->attach)(scr->scr_synccookie, waitok,
1661 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb3, sc);
1662 if (error == EAGAIN) {
1663 /* switch will be done asynchronously */
1664 return (0);
1665 }
1666 }
1667
1668 return (wsdisplay_switch3(sc, error, waitok));
1669 }
1670
1671 int
1672 wsdisplay_switch1(void *arg, int error, int waitok)
1673 {
1674 struct wsdisplay_softc *sc = arg;
1675 int no;
1676 struct wsscreen *scr;
1677
1678 if (!(sc->sc_flags & SC_SWITCHPENDING)) {
1679 printf("wsdisplay_switch1: not switching\n");
1680 return (EINVAL);
1681 }
1682
1683 no = sc->sc_screenwanted;
1684 if (no == WSDISPLAY_NULLSCREEN) {
1685 sc->sc_flags &= ~SC_SWITCHPENDING;
1686 if (!error) {
1687 sc->sc_focus = 0;
1688 }
1689 wakeup(sc);
1690 return (error);
1691 }
1692 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1693 panic("wsdisplay_switch1: invalid screen %d", no);
1694 scr = sc->sc_scr[no];
1695 if (!scr) {
1696 printf("wsdisplay_switch1: screen %d disappeared\n", no);
1697 error = ENXIO;
1698 }
1699
1700 if (error) {
1701 sc->sc_flags &= ~SC_SWITCHPENDING;
1702 return (error);
1703 }
1704
1705 #define wsswitch_cb2 ((void (*)(void *, int, int))wsdisplay_switch2)
1706 error = (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
1707 scr->scr_dconf->emulcookie,
1708 waitok,
1709 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb2, sc);
1710 if (error == EAGAIN) {
1711 /* switch will be done asynchronously */
1712 return (0);
1713 }
1714
1715 return (wsdisplay_switch2(sc, error, waitok));
1716 }
1717
1718 int
1719 wsdisplay_switch(struct device *dev, int no, int waitok)
1720 {
1721 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1722 int s, res = 0;
1723 struct wsscreen *scr;
1724
1725 if (no != WSDISPLAY_NULLSCREEN) {
1726 if ((no < 0 || no >= WSDISPLAY_MAXSCREEN))
1727 return (EINVAL);
1728 if (sc->sc_scr[no] == NULL)
1729 return (ENXIO);
1730 }
1731
1732 wsdisplay_stat_inject(dev, WSCONS_EVENT_SCREEN_SWITCH, no);
1733
1734 s = spltty();
1735
1736 if ((sc->sc_focus && no == sc->sc_focusidx) ||
1737 (sc->sc_focus == NULL && no == WSDISPLAY_NULLSCREEN)) {
1738 splx(s);
1739 return (0);
1740 }
1741
1742 if (sc->sc_flags & SC_SWITCHPENDING) {
1743 splx(s);
1744 return (EBUSY);
1745 }
1746
1747 sc->sc_flags |= SC_SWITCHPENDING;
1748 sc->sc_screenwanted = no;
1749
1750 splx(s);
1751
1752 scr = sc->sc_focus;
1753 if (!scr) {
1754 sc->sc_oldscreen = WSDISPLAY_NULLSCREEN;
1755 return (wsdisplay_switch1(sc, 0, waitok));
1756 } else
1757 sc->sc_oldscreen = sc->sc_focusidx;
1758
1759 #define wsswitch_cb1 ((void (*)(void *, int, int))wsdisplay_switch1)
1760 if (scr->scr_syncops) {
1761 res = (*scr->scr_syncops->detach)(scr->scr_synccookie, waitok,
1762 sc->sc_isconsole && wsdisplay_cons_pollmode ? 0 : wsswitch_cb1, sc);
1763 if (res == EAGAIN) {
1764 /* switch will be done asynchronously */
1765 return (0);
1766 }
1767 } else if (scr->scr_flags & SCR_GRAPHICS) {
1768 /* no way to save state */
1769 res = EBUSY;
1770 }
1771
1772 return (wsdisplay_switch1(sc, res, waitok));
1773 }
1774
1775 void
1776 wsdisplay_reset(struct device *dev, enum wsdisplay_resetops op)
1777 {
1778 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1779 struct wsscreen *scr;
1780
1781 KASSERT(sc != NULL);
1782 scr = sc->sc_focus;
1783
1784 if (!scr)
1785 return;
1786
1787 switch (op) {
1788 case WSDISPLAY_RESETEMUL:
1789 if (!WSSCREEN_HAS_EMULATOR(scr))
1790 break;
1791 (*scr->scr_dconf->wsemul->reset)(scr->scr_dconf->wsemulcookie,
1792 WSEMUL_RESET);
1793 break;
1794 case WSDISPLAY_RESETCLOSE:
1795 wsdisplay_closescreen(sc, scr);
1796 break;
1797 }
1798 }
1799
1800 /*
1801 * Interface for (external) VT switch / process synchronization code
1802 */
1803 int
1804 wsscreen_attach_sync(struct wsscreen *scr, const struct wscons_syncops *ops,
1805 void *cookie)
1806 {
1807 if (scr->scr_syncops) {
1808 /*
1809 * The screen is already claimed.
1810 * Check if the owner is still alive.
1811 */
1812 if ((*scr->scr_syncops->check)(scr->scr_synccookie))
1813 return (EBUSY);
1814 }
1815 scr->scr_syncops = ops;
1816 scr->scr_synccookie = cookie;
1817 return (0);
1818 }
1819
1820 int
1821 wsscreen_detach_sync(struct wsscreen *scr)
1822 {
1823 if (!scr->scr_syncops)
1824 return (EINVAL);
1825 scr->scr_syncops = 0;
1826 return (0);
1827 }
1828
1829 int
1830 wsscreen_lookup_sync(struct wsscreen *scr,
1831 const struct wscons_syncops *ops, /* used as ID */
1832 void **cookiep)
1833 {
1834 if (!scr->scr_syncops || ops != scr->scr_syncops)
1835 return (EINVAL);
1836 *cookiep = scr->scr_synccookie;
1837 return (0);
1838 }
1839
1840 /*
1841 * Interface to virtual screen stuff
1842 */
1843 int
1844 wsdisplay_maxscreenidx(struct wsdisplay_softc *sc)
1845 {
1846 return (WSDISPLAY_MAXSCREEN - 1);
1847 }
1848
1849 int
1850 wsdisplay_screenstate(struct wsdisplay_softc *sc, int idx)
1851 {
1852 if (idx < 0 || idx >= WSDISPLAY_MAXSCREEN)
1853 return (EINVAL);
1854 if (!sc->sc_scr[idx])
1855 return (ENXIO);
1856 return ((sc->sc_scr[idx]->scr_flags & SCR_OPEN) ? EBUSY : 0);
1857 }
1858
1859 int
1860 wsdisplay_getactivescreen(struct wsdisplay_softc *sc)
1861 {
1862 return (sc->sc_focus ? sc->sc_focusidx : WSDISPLAY_NULLSCREEN);
1863 }
1864
1865 int
1866 wsscreen_switchwait(struct wsdisplay_softc *sc, int no)
1867 {
1868 struct wsscreen *scr;
1869 int s, res = 0;
1870
1871 if (no == WSDISPLAY_NULLSCREEN) {
1872 s = spltty();
1873 while (sc->sc_focus && res == 0) {
1874 res = tsleep(sc, PCATCH, "wswait", 0);
1875 }
1876 splx(s);
1877 return (res);
1878 }
1879
1880 if (no < 0 || no >= WSDISPLAY_MAXSCREEN)
1881 return (ENXIO);
1882 scr = sc->sc_scr[no];
1883 if (!scr)
1884 return (ENXIO);
1885
1886 s = spltty();
1887 if (scr != sc->sc_focus) {
1888 scr->scr_flags |= SCR_WAITACTIVE;
1889 res = tsleep(scr, PCATCH, "wswait", 0);
1890 if (scr != sc->sc_scr[no])
1891 res = ENXIO; /* disappeared in the meantime */
1892 else
1893 scr->scr_flags &= ~SCR_WAITACTIVE;
1894 }
1895 splx(s);
1896 return (res);
1897 }
1898
1899 void
1900 wsdisplay_kbdholdscreen(struct device *dev, int hold)
1901 {
1902 struct wsdisplay_softc *sc = (struct wsdisplay_softc *)dev;
1903 struct wsscreen *scr;
1904
1905 scr = sc->sc_focus;
1906
1907 if (hold)
1908 scr->scr_hold_screen = 1;
1909 else {
1910 scr->scr_hold_screen = 0;
1911 callout_reset(&scr->scr_tty->t_rstrt_ch, 0,
1912 ttrstrt, scr->scr_tty); /* "immediate" */
1913 }
1914 }
1915
1916 #if NWSKBD > 0
1917 void
1918 wsdisplay_set_console_kbd(struct wsevsrc *src)
1919 {
1920 if (wsdisplay_console_device == NULL) {
1921 src->me_dispdv = NULL;
1922 return;
1923 }
1924 #if NWSMUX > 0
1925 if (wsmux_attach_sc((struct wsmux_softc *)
1926 wsdisplay_console_device->sc_input, src)) {
1927 src->me_dispdv = NULL;
1928 return;
1929 }
1930 #else
1931 wsdisplay_console_device->sc_input = src;
1932 #endif
1933 src->me_dispdv = &wsdisplay_console_device->sc_dv;
1934 }
1935 #endif /* NWSKBD > 0 */
1936
1937 /*
1938 * Console interface.
1939 */
1940 void
1941 wsdisplay_cnputc(dev_t dev, int i)
1942 {
1943 struct wsscreen_internal *dc;
1944 u_char c = i;
1945
1946 if (!wsdisplay_console_initted)
1947 return;
1948
1949 if ((wsdisplay_console_device != NULL) &&
1950 (wsdisplay_console_device->sc_scr[0] != NULL) &&
1951 (wsdisplay_console_device->sc_scr[0]->scr_flags & SCR_GRAPHICS))
1952 return;
1953
1954 dc = &wsdisplay_console_conf;
1955 (*dc->wsemul->output)(dc->wsemulcookie, &c, 1, 1);
1956 }
1957
1958 static int
1959 wsdisplay_getc_dummy(dev_t dev)
1960 {
1961 /* panic? */
1962 return (0);
1963 }
1964
1965 static void
1966 wsdisplay_pollc(dev_t dev, int on)
1967 {
1968
1969 wsdisplay_cons_pollmode = on;
1970
1971 /* notify to fb drivers */
1972 if (wsdisplay_console_device != NULL &&
1973 wsdisplay_console_device->sc_accessops->pollc != NULL)
1974 (*wsdisplay_console_device->sc_accessops->pollc)
1975 (wsdisplay_console_device->sc_accesscookie, on);
1976
1977 /* notify to kbd drivers */
1978 if (wsdisplay_cons_kbd_pollc)
1979 (*wsdisplay_cons_kbd_pollc)(NODEV, on);
1980 }
1981
1982 void
1983 wsdisplay_set_cons_kbd(int (*get)(dev_t), void (*poll)(dev_t, int),
1984 void (*bell)(dev_t, u_int, u_int, u_int))
1985 {
1986 wsdisplay_cons.cn_getc = get;
1987 wsdisplay_cons.cn_bell = bell;
1988 wsdisplay_cons_kbd_pollc = poll;
1989 }
1990
1991 void
1992 wsdisplay_unset_cons_kbd(void)
1993 {
1994 wsdisplay_cons.cn_getc = wsdisplay_getc_dummy;
1995 wsdisplay_cons.cn_bell = NULL;
1996 wsdisplay_cons_kbd_pollc = 0;
1997 }
1998
1999 /*
2000 * Switch the console display to it's first screen.
2001 */
2002 void
2003 wsdisplay_switchtoconsole(void)
2004 {
2005 struct wsdisplay_softc *sc;
2006 struct wsscreen *scr;
2007
2008 if (wsdisplay_console_device != NULL) {
2009 sc = wsdisplay_console_device;
2010 if ((scr = sc->sc_scr[0]) == NULL)
2011 return;
2012 (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
2013 scr->scr_dconf->emulcookie,
2014 0, NULL, NULL);
2015 }
2016 }
2017
2018 /*
2019 * Switch the console at shutdown.
2020 */
2021 static void
2022 wsdisplay_shutdownhook(void *arg)
2023 {
2024
2025 wsdisplay_switchtoconsole();
2026 }
2027