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