1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
|
/* $OpenBSD: wsmux.c,v 1.10 2002/10/12 01:09:44 krw Exp $ */
/* $NetBSD: wsmux.c,v 1.9 2000/05/28 10:33:14 takemura Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Author: Lennart Augustsson <augustss@carlstedt.se>
* Carlstedt Research & Technology
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "wsmux.h"
#include "wsdisplay.h"
#include "wskbd.h"
#if NWSMUX > 0 || (NWSDISPLAY > 0 && NWSKBD > 0)
/*
* wscons mux device.
*
* The mux device is a collection of real mice and keyboards and acts as
* a merge point for all the events from the different real devices.
*/
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/signalvar.h>
#include <sys/device.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wseventvar.h>
#include <dev/wscons/wscons_callbacks.h>
#include <dev/wscons/wsmuxvar.h>
#ifdef WSMUX_DEBUG
#define DPRINTF(x) if (wsmuxdebug) printf x
int wsmuxdebug = 0;
#else
#define DPRINTF(x)
#endif
struct wsplink {
LIST_ENTRY(wsplink) next;
int type;
struct wsmux_softc *mux; /* our mux device */
/* The rest of the fields reflect a value in the multiplexee. */
struct device *sc; /* softc */
struct wseventvar *sc_mevents; /* event var */
struct wsmux_softc **sc_muxp; /* pointer to us */
struct wsmuxops *sc_ops;
};
int wsmuxdoclose(struct device *, int, int, struct proc *);
int wsmux_set_display(struct device *, struct wsmux_softc *);
int wsmux_isset_display(struct device *);
#if NWSMUX > 0
void wsmuxattach(int);
struct wsmuxops wsmux_muxops = {
wsmuxopen, wsmuxdoclose, wsmuxdoioctl, wsmux_displayioctl,
wsmux_set_display, wsmux_isset_display
};
void wsmux_setmax(int n);
int nwsmux = 0;
struct wsmux_softc **wsmuxdevs = NULL;
void
wsmux_setmax(n)
int n;
{
int i;
struct wsmux_softc **wsmuxdevs_tmp = NULL;
if (n >= nwsmux) {
if (wsmuxdevs != NULL) {
wsmuxdevs_tmp = malloc(nwsmux * sizeof(*wsmuxdevs_tmp),
M_DEVBUF, M_NOWAIT);
if (wsmuxdevs_tmp == 0)
panic("wsmux_setmax: no mem");
for (i = 0; i < nwsmux; i++)
wsmuxdevs_tmp[i] = wsmuxdevs[i];
free(wsmuxdevs, M_DEVBUF);
}
wsmuxdevs = malloc((n + 1) * sizeof(*wsmuxdevs),
M_DEVBUF, M_NOWAIT);
if (wsmuxdevs == NULL)
panic("wsmux_setmax: no memory");
memset(wsmuxdevs, 0, (n + 1) * sizeof(*wsmuxdevs));
if (wsmuxdevs_tmp != NULL) {
for (i = 0; i < nwsmux; i++)
wsmuxdevs[i] = wsmuxdevs_tmp[i];
free(wsmuxdevs_tmp, M_DEVBUF);
}
nwsmux = n + 1;
}
}
/* From upper level */
void
wsmuxattach(n)
int n;
{
int i;
wsmux_setmax(n); /* Make sure we have room for all muxes. */
/* Make sure all muxes are there. */
for (i = 0; i < nwsmux; i++)
if (wsmuxdevs[i] == NULL)
wsmuxdevs[i] = wsmux_create("wsmux", i);
}
/* From mouse or keyboard. */
void
wsmux_attach(n, type, dsc, ev, psp, ops)
int n;
int type;
struct device *dsc;
struct wseventvar *ev;
struct wsmux_softc **psp;
struct wsmuxops *ops;
{
struct wsmux_softc *sc;
int error;
DPRINTF(("wsmux_attach: n=%d\n", n));
wsmux_setmax(n);
sc = wsmuxdevs[n];
if (sc == 0) {
sc = wsmux_create("wsmux", n);
if (sc == 0) {
printf("wsmux: attach out of memory\n");
return;
}
wsmuxdevs[n] = sc;
}
error = wsmux_attach_sc(sc, type, dsc, ev, psp, ops);
if (error)
printf("wsmux_attach: error=%d\n", error);
}
/* From mouse or keyboard. */
void
wsmux_detach(n, dsc)
int n;
struct device *dsc;
{
#ifdef DIAGNOSTIC
int error;
if (n >= nwsmux || n < 0) {
printf("wsmux_detach: detach is out of range\n");
return;
}
if ((error = wsmux_detach_sc(wsmuxdevs[n], dsc)))
printf("wsmux_detach: error=%d\n", error);
#else
(void)wsmux_detach_sc(wsmuxdevs[n], dsc);
#endif
}
int
wsmuxopen(dev, flags, mode, p)
dev_t dev;
int flags, mode;
struct proc *p;
{
struct wsmux_softc *sc;
struct wsplink *m;
int unit, error, nopen, lasterror;
unit = minor(dev);
if (unit >= nwsmux || /* make sure it was attached */
(sc = wsmuxdevs[unit]) == NULL)
return (ENXIO);
DPRINTF(("wsmuxopen: %s: sc=%p\n", sc->sc_dv.dv_xname, sc));
if (!(flags & FREAD)) {
/* Not opening for read, only ioctl is available. */
return (0);
}
if (sc->sc_events.io)
return (EBUSY);
sc->sc_events.io = p;
sc->sc_flags = flags;
sc->sc_mode = mode;
sc->sc_p = p;
wsevent_init(&sc->sc_events); /* may cause sleep */
nopen = 0;
lasterror = 0;
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
if (!m->sc_mevents->io && !*m->sc_muxp) {
DPRINTF(("wsmuxopen: %s: m=%p dev=%s\n",
sc->sc_dv.dv_xname, m, m->sc->dv_xname));
error = m->sc_ops->dopen(makedev(0, m->sc->dv_unit),
flags, mode, p);
if (error) {
/* Ignore opens that fail */
lasterror = error;
DPRINTF(("wsmuxopen: open failed %d\n",
error));
} else {
nopen++;
*m->sc_muxp = sc;
}
}
}
if (nopen == 0 && lasterror != 0) {
wsevent_fini(&sc->sc_events);
sc->sc_events.io = NULL;
return (lasterror);
}
return (0);
}
int
wsmuxclose(dev, flags, mode, p)
dev_t dev;
int flags, mode;
struct proc *p;
{
return wsmuxdoclose(&wsmuxdevs[minor(dev)]->sc_dv, flags, mode, p);
}
int
wsmuxread(dev, uio, flags)
dev_t dev;
struct uio *uio;
int flags;
{
struct wsmux_softc *sc = wsmuxdevs[minor(dev)];
if (!sc->sc_events.io)
return (EACCES);
return (wsevent_read(&sc->sc_events, uio, flags));
}
int
wsmuxioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
return wsmuxdoioctl(&wsmuxdevs[minor(dev)]->sc_dv, cmd, data, flag, p);
}
int
wsmuxselect(dev, events, p)
dev_t dev;
int events;
struct proc *p;
{
struct wsmux_softc *sc = wsmuxdevs[minor(dev)];
if (!sc->sc_events.io)
return (EACCES);
return (wsevent_poll(&sc->sc_events, events, p));
}
int
wsmux_add_mux(unit, muxsc)
int unit;
struct wsmux_softc *muxsc;
{
struct wsmux_softc *sc, *m;
if (unit < 0 || unit >= nwsmux || (sc = wsmuxdevs[unit]) == NULL)
return (ENXIO);
DPRINTF(("wsmux_add_mux: %s to %s\n", sc->sc_dv.dv_xname,
muxsc->sc_dv.dv_xname));
if (sc->sc_mux || sc->sc_events.io)
return (EBUSY);
/* The mux we are adding must not be an ancestor of it. */
for (m = muxsc->sc_mux; m; m = m->sc_mux)
if (m == sc)
return (EINVAL);
return (wsmux_attach_sc(muxsc, WSMUX_MUX, &sc->sc_dv, &sc->sc_events,
&sc->sc_mux, &wsmux_muxops));
}
int
wsmux_rem_mux(unit, muxsc)
int unit;
struct wsmux_softc *muxsc;
{
struct wsmux_softc *sc;
if (unit < 0 || unit >= nwsmux || (sc = wsmuxdevs[unit]) == NULL)
return (ENXIO);
DPRINTF(("wsmux_rem_mux: %s from %s\n", sc->sc_dv.dv_xname,
muxsc->sc_dv.dv_xname));
return (wsmux_detach_sc(muxsc, &sc->sc_dv));
}
#endif /* NWSMUX > 0 */
struct wsmux_softc *
wsmux_create(name, unit)
const char *name;
int unit;
{
struct wsmux_softc *sc;
DPRINTF(("wsmux_create: allocating\n"));
sc = malloc(sizeof *sc, M_DEVBUF, M_NOWAIT);
if (!sc)
return (0);
memset(sc, 0, sizeof *sc);
LIST_INIT(&sc->sc_reals);
snprintf(sc->sc_dv.dv_xname, sizeof sc->sc_dv.dv_xname,
"%s%d", name, unit);
sc->sc_dv.dv_unit = unit;
return (sc);
}
int
wsmux_attach_sc(sc, type, dsc, ev, psp, ops)
struct wsmux_softc *sc;
int type;
struct device *dsc;
struct wseventvar *ev;
struct wsmux_softc **psp;
struct wsmuxops *ops;
{
struct wsplink *m;
int error;
DPRINTF(("wsmux_attach_sc: %s: type=%d dsc=%p, *psp=%p\n",
sc->sc_dv.dv_xname, type, dsc, *psp));
m = malloc(sizeof *m, M_DEVBUF, M_NOWAIT);
if (m == 0)
return (ENOMEM);
m->type = type;
m->mux = sc;
m->sc = dsc;
m->sc_mevents = ev;
m->sc_muxp = psp;
m->sc_ops = ops;
LIST_INSERT_HEAD(&sc->sc_reals, m, next);
if (sc->sc_displaydv) {
/* This is a display mux, so attach the new device to it. */
DPRINTF(("wsmux_attach_sc: %s: set display %p\n",
sc->sc_dv.dv_xname, sc->sc_displaydv));
error = 0;
if (m->sc_ops->dsetdisplay) {
error = m->sc_ops->dsetdisplay(m->sc, sc);
/* Ignore that the console already has a display. */
if (error == EBUSY)
error = 0;
if (!error) {
*m->sc_muxp = sc;
#ifdef WSDISPLAY_COMPAT_RAWKBD
DPRINTF(("wsmux_attach_sc: on %s set rawkbd=%d\n",
m->sc->dv_xname, sc->sc_rawkbd));
(void)m->sc_ops->dioctl(m->sc,
WSKBDIO_SETMODE,
(caddr_t)&sc->sc_rawkbd,
0, 0);
#endif
}
}
} else if (sc->sc_events.io) {
/* Mux is open, so open the new subdevice */
DPRINTF(("wsmux_attach_sc: %s: calling open of %s\n",
sc->sc_dv.dv_xname, m->sc->dv_xname));
/* mux already open, join in */
error = m->sc_ops->dopen(makedev(0, m->sc->dv_unit),
sc->sc_flags, sc->sc_mode, sc->sc_p);
if (!error)
*m->sc_muxp = sc;
} else {
DPRINTF(("wsmux_attach_sc: %s not open\n",
sc->sc_dv.dv_xname));
error = 0;
}
DPRINTF(("wsmux_attach_sc: done sc=%p psp=%p *psp=%p\n",
sc, psp, *psp));
return (error);
}
int
wsmux_detach_sc(sc, dsc)
struct wsmux_softc *sc;
struct device *dsc;
{
struct wsplink *m;
int error = 0;
DPRINTF(("wsmux_detach_sc: %s: dsc=%p\n", sc->sc_dv.dv_xname, dsc));
#ifdef DIAGNOSTIC
if (sc == 0) {
printf("wsmux_detach_sc: not allocated\n");
return (ENXIO);
}
#endif
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
if (m->sc == dsc)
break;
}
#ifdef DIAGNOSTIC
if (!m) {
printf("wsmux_detach_sc: not found\n");
return (ENXIO);
}
#endif
if (sc->sc_displaydv ||
(m->sc_ops->dissetdisplay && m->sc_ops->dissetdisplay(m->sc))) {
if (m->sc_ops->dsetdisplay)
error = m->sc_ops->dsetdisplay(m->sc, 0);
if (error)
return (error);
*m->sc_muxp = 0;
} else if (*m->sc_muxp) {
DPRINTF(("wsmux_detach_sc: close\n"));
/* mux device is open, so close multiplexee */
m->sc_ops->dclose(m->sc, FREAD, 0, 0);
*m->sc_muxp = 0;
}
LIST_REMOVE(m, next);
free(m, M_DEVBUF);
DPRINTF(("wsmux_detach_sc: done sc=%p\n", sc));
return (0);
}
int wsmuxdoclose(dv, flags, mode, p)
struct device *dv;
int flags, mode;
struct proc *p;
{
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
struct wsplink *m;
DPRINTF(("wsmuxclose: %s: sc=%p\n", sc->sc_dv.dv_xname, sc));
if (!(flags & FREAD)) {
/* Nothing to do, because open didn't do anything. */
return (0);
}
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
if (*m->sc_muxp == sc) {
DPRINTF(("wsmuxclose %s: m=%p dev=%s\n",
sc->sc_dv.dv_xname, m, m->sc->dv_xname));
m->sc_ops->dclose(m->sc, flags, mode, p);
*m->sc_muxp = 0;
}
}
wsevent_fini(&sc->sc_events);
sc->sc_events.io = NULL;
return (0);
}
int
wsmuxdoioctl(dv, cmd, data, flag, p)
struct device *dv;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
struct wsplink *m;
int error, ok;
int s, put, get, n;
struct wseventvar *evar;
struct wscons_event *ev;
struct timeval xxxtime;
struct wsmux_device_list *l;
DPRINTF(("wsmuxdoioctl: %s: sc=%p, cmd=%08lx\n",
sc->sc_dv.dv_xname, sc, cmd));
switch (cmd) {
case WSMUX_INJECTEVENT:
/* Inject an event, e.g., from moused. */
if (!sc->sc_events.io)
return (EACCES);
evar = &sc->sc_events;
s = spltty();
get = evar->get;
put = evar->put;
if (++put % WSEVENT_QSIZE == get) {
put--;
splx(s);
return (ENOSPC);
}
if (put >= WSEVENT_QSIZE)
put = 0;
ev = &evar->q[put];
*ev = *(struct wscons_event *)data;
microtime(&xxxtime);
TIMEVAL_TO_TIMESPEC(&xxxtime, &ev->time);
evar->put = put;
WSEVENT_WAKEUP(evar);
splx(s);
return (0);
case WSMUX_ADD_DEVICE:
#define d ((struct wsmux_device *)data)
switch (d->type) {
#if NWSMOUSE > 0
case WSMUX_MOUSE:
return (wsmouse_add_mux(d->idx, sc));
#endif
#if NWSKBD > 0
case WSMUX_KBD:
return (wskbd_add_mux(d->idx, sc));
#endif
#if NWSMUX > 0
case WSMUX_MUX:
return (wsmux_add_mux(d->idx, sc));
#endif
default:
return (EINVAL);
}
case WSMUX_REMOVE_DEVICE:
switch (d->type) {
#if NWSMOUSE > 0
case WSMUX_MOUSE:
return (wsmouse_rem_mux(d->idx, sc));
#endif
#if NWSKBD > 0
case WSMUX_KBD:
return (wskbd_rem_mux(d->idx, sc));
#endif
#if NWSMUX > 0
case WSMUX_MUX:
return (wsmux_rem_mux(d->idx, sc));
#endif
default:
return (EINVAL);
}
#undef d
case WSMUX_LIST_DEVICES:
l = (struct wsmux_device_list *)data;
for (n = 0, m = LIST_FIRST(&sc->sc_reals);
n < WSMUX_MAXDEV && m != NULL;
m = LIST_NEXT(m, next)) {
l->devices[n].type = m->type;
l->devices[n].idx = m->sc->dv_unit;
n++;
}
l->ndevices = n;
return (0);
#ifdef WSDISPLAY_COMPAT_RAWKBD
case WSKBDIO_SETMODE:
sc->sc_rawkbd = *(int *)data;
DPRINTF(("wsmuxdoioctl: save rawkbd = %d\n", sc->sc_rawkbd));
break;
#endif
case FIOASYNC:
sc->sc_events.async = *(int *)data != 0;
return (0);
case TIOCSPGRP:
if (*(int *)data != sc->sc_events.io->p_pgid)
return (EPERM);
return (0);
default:
break;
}
if (sc->sc_events.io == NULL && sc->sc_displaydv == NULL)
return (EACCES);
/* Return 0 if any of the ioctl() succeeds, otherwise the last error */
error = 0;
ok = 0;
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
DPRINTF(("wsmuxdoioctl: m=%p *m->sc_muxp=%p sc=%p\n",
m, *m->sc_muxp, sc));
if (*m->sc_muxp == sc) {
DPRINTF(("wsmuxdoioctl: %s: m=%p dev=%s\n",
sc->sc_dv.dv_xname, m, m->sc->dv_xname));
error = m->sc_ops->dioctl(m->sc, cmd, data, flag, p);
if (!error)
ok = 1;
}
}
if (ok)
error = 0;
return (error);
}
int
wsmux_displayioctl(dv, cmd, data, flag, p)
struct device *dv;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
struct wsplink *m;
int error, ok;
DPRINTF(("wsmux_displayioctl: %s: sc=%p, cmd=%08lx\n",
sc->sc_dv.dv_xname, sc, cmd));
#ifdef WSDISPLAY_COMPAT_RAWKBD
if (cmd == WSKBDIO_SETMODE) {
sc->sc_rawkbd = *(int *)data;
DPRINTF(("wsmux_displayioctl: rawkbd = %d\n", sc->sc_rawkbd));
}
#endif
/*
* Return 0 if any of the ioctl() succeeds, otherwise the last error.
* Return -1 if no mux component accepts the ioctl.
*/
error = -1;
ok = 0;
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
DPRINTF(("wsmux_displayioctl: m=%p sc=%p sc_muxp=%p\n",
m, sc, *m->sc_muxp));
if (m->sc_ops->ddispioctl && *m->sc_muxp == sc) {
error = m->sc_ops->ddispioctl(m->sc, cmd, data,
flag, p);
DPRINTF(("wsmux_displayioctl: m=%p dev=%s ==> %d\n",
m, m->sc->dv_xname, error));
if (!error)
ok = 1;
}
}
if (ok)
error = 0;
return (error);
}
int
wsmux_set_display(dv, muxsc)
struct device *dv;
struct wsmux_softc *muxsc;
{
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
struct wsmux_softc *nsc = muxsc ? sc : 0;
struct device *displaydv = muxsc ? muxsc->sc_displaydv : 0;
struct device *odisplaydv;
struct wsplink *m;
int error, ok;
DPRINTF(("wsmux_set_display: %s: displaydv=%p\n",
sc->sc_dv.dv_xname, displaydv));
if (displaydv) {
if (sc->sc_displaydv)
return (EBUSY);
} else {
if (sc->sc_displaydv == NULL)
return (ENXIO);
}
odisplaydv = sc->sc_displaydv;
sc->sc_displaydv = displaydv;
if (displaydv)
printf("%s: connecting to %s\n",
sc->sc_dv.dv_xname, displaydv->dv_xname);
ok = 0;
error = 0;
for (m = LIST_FIRST(&sc->sc_reals); m; m = LIST_NEXT(m, next)) {
if (m->sc_ops->dsetdisplay &&
(nsc ? m->sc_mevents->io == 0 && *m->sc_muxp == 0 :
*m->sc_muxp == sc)) {
error = m->sc_ops->dsetdisplay(m->sc, nsc);
DPRINTF(("wsmux_set_display: m=%p dev=%s error=%d\n",
m, m->sc->dv_xname, error));
if (!error) {
ok = 1;
*m->sc_muxp = nsc;
#ifdef WSDISPLAY_COMPAT_RAWKBD
DPRINTF(("wsmux_set_display: on %s set rawkbd=%d\n",
m->sc->dv_xname, sc->sc_rawkbd));
(void)m->sc_ops->dioctl(m->sc,
WSKBDIO_SETMODE,
(caddr_t)&sc->sc_rawkbd,
0, 0);
#endif
}
}
}
if (ok)
error = 0;
if (displaydv == NULL)
printf("%s: disconnecting from %s\n",
sc->sc_dv.dv_xname, odisplaydv->dv_xname);
return (error);
}
int
wsmux_isset_display(dv)
struct device *dv;
{
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
if (sc->sc_displaydv != NULL)
return (1);
return (0);
}
#endif /* NWSMUX > 0 || (NWSDISPLAY > 0 && NWSKBD > 0) */
|