2003-09-23 13:16:07 +04:00
|
|
|
/* $NetBSD: wsmux.c,v 1.35 2003/09/23 09:16:07 simonb Exp $ */
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:17:46 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-09-23 13:16:07 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.35 2003/09/23 09:16:07 simonb Exp $");
|
2001-11-13 09:17:46 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#include "wsdisplay.h"
|
|
|
|
#include "wsmux.h"
|
|
|
|
#include "wskbd.h"
|
|
|
|
#include "wsmouse.h"
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
#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 "opt_wsdisplay_compat.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
|
2001-10-25 18:46:41 +04:00
|
|
|
#define DPRINTFN(n,x) if (wsmuxdebug > (n)) printf x
|
1999-07-29 22:20:02 +04:00
|
|
|
int wsmuxdebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
2001-10-25 18:46:41 +04:00
|
|
|
#define DPRINTFN(n,x)
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* The wsmux pseudo device is used to multiplex events from several wsmouse,
|
|
|
|
* wskbd, and/or wsmux devices together.
|
|
|
|
* The devices connected together form a tree with muxes in the interior
|
|
|
|
* and real devices (mouse and kbd) at the leaves. The special case of
|
|
|
|
* a tree with one node (mux or other) is supported as well.
|
|
|
|
* Only the device at the root of the tree can be opened (if a non-root
|
|
|
|
* device is opened the subtree rooted at that point is severed from the
|
|
|
|
* containing tree). When the root is opened it allocates a wseventvar
|
|
|
|
* struct which all the nodes in the tree will send their events too.
|
|
|
|
* An ioctl() performed on the root is propagated to all the nodes.
|
|
|
|
* There are also ioctl() operations to add and remove nodes from a tree.
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
static int wsmux_mux_open(struct wsevsrc *, struct wseventvar *);
|
|
|
|
static int wsmux_mux_close(struct wsevsrc *);
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
static void wsmux_do_open(struct wsmux_softc *, struct wseventvar *);
|
|
|
|
|
|
|
|
static void wsmux_do_close(struct wsmux_softc *);
|
|
|
|
#if NWSDISPLAY > 0
|
2002-03-02 11:22:26 +03:00
|
|
|
static int wsmux_evsrc_set_display(struct device *, struct wsevsrc *);
|
2001-10-24 18:07:31 +04:00
|
|
|
#else
|
2002-03-02 11:22:26 +03:00
|
|
|
#define wsmux_evsrc_set_display NULL
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int wsmux_do_displayioctl(struct device *dev, u_long cmd,
|
2003-06-30 02:28:00 +04:00
|
|
|
caddr_t data, int flag, struct proc *p);
|
|
|
|
static int wsmux_do_ioctl(struct device *, u_long, caddr_t,int,struct proc *);
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
static int wsmux_add_mux(int, struct wsmux_softc *);
|
|
|
|
|
|
|
|
void wsmuxattach(int);
|
2001-10-14 00:03:38 +04:00
|
|
|
|
|
|
|
#define WSMUXDEV(n) ((n) & 0x7f)
|
|
|
|
#define WSMUXCTL(n) ((n) & 0x80)
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(wsmuxopen);
|
|
|
|
dev_type_close(wsmuxclose);
|
|
|
|
dev_type_read(wsmuxread);
|
|
|
|
dev_type_ioctl(wsmuxioctl);
|
|
|
|
dev_type_poll(wsmuxpoll);
|
2002-10-23 13:10:23 +04:00
|
|
|
dev_type_kqfilter(wsmuxkqfilter);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct cdevsw wsmux_cdevsw = {
|
|
|
|
wsmuxopen, wsmuxclose, wsmuxread, nowrite, wsmuxioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, wsmuxpoll, nommap, wsmuxkqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wssrcops wsmux_srcops = {
|
|
|
|
WSMUX_MUX,
|
|
|
|
wsmux_mux_open, wsmux_mux_close, wsmux_do_ioctl, wsmux_do_displayioctl,
|
2002-03-02 11:22:26 +03:00
|
|
|
wsmux_evsrc_set_display
|
1999-07-29 22:20:02 +04:00
|
|
|
};
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* From upper level */
|
|
|
|
void
|
|
|
|
wsmuxattach(int n)
|
|
|
|
{
|
|
|
|
}
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Keep track of all muxes that have been allocated */
|
|
|
|
static int nwsmux = 0;
|
|
|
|
static struct wsmux_softc **wsmuxdevs;
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Return mux n, create if necessary */
|
|
|
|
struct wsmux_softc *
|
|
|
|
wsmux_getmux(int n)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsmux_softc *sc;
|
1999-07-31 00:52:27 +04:00
|
|
|
int i;
|
2001-10-24 18:07:31 +04:00
|
|
|
void *new;
|
|
|
|
|
|
|
|
n = WSMUXDEV(n); /* limit range */
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Make sure there is room for mux n in the table */
|
1999-07-31 00:52:27 +04:00
|
|
|
if (n >= nwsmux) {
|
|
|
|
i = nwsmux;
|
|
|
|
nwsmux = n + 1;
|
2001-10-13 17:35:59 +04:00
|
|
|
if (i != 0)
|
2001-10-24 18:07:31 +04:00
|
|
|
new = realloc(wsmuxdevs, nwsmux * sizeof (*wsmuxdevs),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
1999-07-31 00:52:27 +04:00
|
|
|
else
|
2001-10-24 18:07:31 +04:00
|
|
|
new = malloc(nwsmux * sizeof (*wsmuxdevs),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (new == NULL) {
|
|
|
|
printf("wsmux_getmux: no memory for mux %d\n", n);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
wsmuxdevs = new;
|
1999-07-31 00:52:27 +04:00
|
|
|
for (; i < nwsmux; i++)
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmuxdevs[i] = NULL;
|
1999-07-31 00:52:27 +04:00
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-13 17:35:59 +04:00
|
|
|
sc = wsmuxdevs[n];
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc == NULL) {
|
2001-10-13 17:35:59 +04:00
|
|
|
sc = wsmux_create("wsmux", n);
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc == NULL)
|
2001-10-13 17:35:59 +04:00
|
|
|
printf("wsmux: attach out of memory\n");
|
|
|
|
wsmuxdevs[n] = sc;
|
|
|
|
}
|
|
|
|
return (sc);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* open() of the pseudo device from device table.
|
|
|
|
*/
|
1999-07-31 00:52:27 +04:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
wsmuxopen(dev_t dev, int flags, int mode, struct proc *p)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
|
|
|
struct wsmux_softc *sc;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wseventvar *evar;
|
|
|
|
int minr, unit;
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
minr = minor(dev);
|
|
|
|
unit = WSMUXDEV(minr);
|
2001-10-14 00:03:38 +04:00
|
|
|
sc = wsmux_getmux(unit);
|
|
|
|
if (sc == NULL)
|
1999-07-31 00:52:27 +04:00
|
|
|
return (ENXIO);
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("wsmuxopen: %s: sc=%p p=%p\n", sc->sc_base.me_dv.dv_xname,
|
|
|
|
sc, p));
|
|
|
|
|
|
|
|
if (WSMUXCTL(minr)) {
|
2001-10-14 00:03:38 +04:00
|
|
|
/* This is the control device which does not allow reads. */
|
|
|
|
if (flags & FREAD)
|
|
|
|
return (EINVAL);
|
1999-07-31 00:52:27 +04:00
|
|
|
return (0);
|
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
if ((flags & (FREAD | FWRITE)) == FWRITE)
|
|
|
|
/* Allow write only open */
|
|
|
|
return (0);
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_parent != NULL) {
|
2001-10-14 00:03:38 +04:00
|
|
|
/* Grab the mux out of the greedy hands of the parent mux. */
|
2001-11-02 16:02:20 +03:00
|
|
|
DPRINTF(("wsmuxopen: detach\n"));
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_detach_sc(&sc->sc_base);
|
2001-10-14 00:03:38 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp != NULL)
|
|
|
|
/* Already open. */
|
1999-07-31 00:52:27 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
2001-10-25 18:46:41 +04:00
|
|
|
evar = &sc->sc_base.me_evar;
|
|
|
|
wsevent_init(evar);
|
2003-06-30 02:28:00 +04:00
|
|
|
evar->io = p;
|
2001-10-25 17:19:41 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_rawkbd = 0;
|
2001-10-25 17:19:41 +04:00
|
|
|
#endif
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_do_open(sc, evar);
|
1999-07-31 00:52:27 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* Open of a mux via the parent mux.
|
|
|
|
*/
|
1999-07-31 00:52:27 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_mux_open(struct wsevsrc *me, struct wseventvar *evar)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsmux_softc *sc = (struct wsmux_softc *)me;
|
2001-10-14 00:03:38 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sc->sc_base.me_evp != NULL) {
|
|
|
|
printf("wsmux_mux_open: busy\n");
|
|
|
|
return (EBUSY);
|
2001-10-14 00:03:38 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_parent == NULL) {
|
|
|
|
printf("wsmux_mux_open: no parent\n");
|
2001-10-14 00:03:38 +04:00
|
|
|
return (EINVAL);
|
2001-10-24 18:07:31 +04:00
|
|
|
}
|
|
|
|
#endif
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_do_open(sc, evar);
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
return (0);
|
1999-07-31 00:52:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Common part of opening a mux. */
|
|
|
|
void
|
|
|
|
wsmux_do_open(struct wsmux_softc *sc, struct wseventvar *evar)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsevsrc *me;
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_evp = evar; /* remember event variable, mark as open */
|
2001-10-14 00:03:38 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Open all children. */
|
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
DPRINTF(("wsmuxopen: %s: m=%p dev=%s\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, me, me->me_dv.dv_xname));
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (me->me_evp != NULL) {
|
|
|
|
printf("wsmuxopen: dev already in use\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (me->me_parent != sc) {
|
|
|
|
printf("wsmux_do_open: bad child=%p\n", me);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
{
|
2001-10-27 04:39:29 +04:00
|
|
|
int error = wsevsrc_open(me, evar);
|
2001-10-24 18:07:31 +04:00
|
|
|
if (error) {
|
|
|
|
DPRINTF(("wsmuxopen: open failed %d\n", error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* ignore errors, failing children will not be marked open */
|
2001-10-27 04:39:29 +04:00
|
|
|
(void)wsevsrc_open(me, evar);
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
2001-10-14 00:03:38 +04:00
|
|
|
}
|
1999-07-31 00:52:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* close() of the pseudo device from device table.
|
|
|
|
*/
|
1999-07-31 00:52:27 +04:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
wsmuxclose(dev_t dev, int flags, int mode, struct proc *p)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
int minr = minor(dev);
|
|
|
|
struct wsmux_softc *sc = wsmuxdevs[WSMUXDEV(minr)];
|
|
|
|
struct wseventvar *evar = sc->sc_base.me_evp;
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (WSMUXCTL(minr))
|
|
|
|
/* control device */
|
|
|
|
return (0);
|
|
|
|
if (evar == NULL)
|
|
|
|
/* Not open for read */
|
|
|
|
return (0);
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-11-22 03:54:23 +03:00
|
|
|
wsmux_do_close(sc);
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_evp = NULL;
|
2001-10-25 18:46:41 +04:00
|
|
|
wsevent_fini(evar);
|
2001-10-24 18:07:31 +04:00
|
|
|
return (0);
|
1999-07-31 00:52:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* Close of a mux via the parent mux.
|
|
|
|
*/
|
1999-07-31 00:52:27 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_mux_close(struct wsevsrc *me)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
me->me_evp = NULL;
|
|
|
|
wsmux_do_close((struct wsmux_softc *)me);
|
|
|
|
return (0);
|
1999-07-31 00:52:27 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Common part of closing a mux. */
|
|
|
|
void
|
|
|
|
wsmux_do_close(struct wsmux_softc *sc)
|
1999-07-31 00:52:27 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsevsrc *me;
|
1999-07-31 00:52:27 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("wsmuxclose: %s: sc=%p\n", sc->sc_base.me_dv.dv_xname, sc));
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Close all the children. */
|
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
DPRINTF(("wsmuxclose %s: m=%p dev=%s\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, me, me->me_dv.dv_xname));
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (me->me_parent != sc) {
|
|
|
|
printf("wsmuxclose: bad child=%p\n", me);
|
|
|
|
continue;
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
2001-10-27 04:39:29 +04:00
|
|
|
(void)wsevsrc_close(me);
|
2001-10-24 18:07:31 +04:00
|
|
|
me->me_evp = NULL;
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* read() of the pseudo device from device table.
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmuxread(dev_t dev, struct uio *uio, int flags)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
int minr = minor(dev);
|
|
|
|
struct wsmux_softc *sc = wsmuxdevs[WSMUXDEV(minr)];
|
2001-10-25 18:46:41 +04:00
|
|
|
struct wseventvar *evar;
|
|
|
|
int error;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (WSMUXCTL(minr)) {
|
|
|
|
/* control device */
|
|
|
|
return (EINVAL);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-10-25 18:46:41 +04:00
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar == NULL) {
|
1999-07-29 22:20:02 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2001-10-24 18:07:31 +04:00
|
|
|
/* XXX can we get here? */
|
|
|
|
printf("wsmuxread: not open\n");
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
2001-10-24 18:07:31 +04:00
|
|
|
return (EINVAL);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-10-25 18:46:41 +04:00
|
|
|
DPRINTFN(5,("wsmuxread: %s event read evar=%p\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, evar));
|
|
|
|
error = wsevent_read(evar, uio, flags);
|
|
|
|
DPRINTFN(5,("wsmuxread: %s event read ==> error=%d\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, error));
|
|
|
|
return (error);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* ioctl of the pseudo device from device table.
|
|
|
|
*/
|
2001-10-13 17:35:59 +04:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
wsmuxioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
int u = WSMUXDEV(minor(dev));
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return wsmux_do_ioctl(&wsmuxdevs[u]->sc_base.me_dv, cmd, data, flag, p);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* ioctl of a mux via the parent mux, continuation of wsmuxioctl().
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_do_ioctl(struct device *dv, u_long cmd, caddr_t data, int flag,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
|
|
|
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsevsrc *me;
|
1999-07-29 22:20:02 +04:00
|
|
|
int error, ok;
|
|
|
|
int s, put, get, n;
|
|
|
|
struct wseventvar *evar;
|
|
|
|
struct wscons_event *ev;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct timeval thistime;
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wsmux_device_list *l;
|
|
|
|
|
2001-10-25 18:46:41 +04:00
|
|
|
DPRINTF(("wsmux_do_ioctl: %s: enter sc=%p, cmd=%08lx\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_dv.dv_xname, sc, cmd));
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
2001-10-24 18:07:31 +04:00
|
|
|
case WSMUXIO_INJECTEVENT:
|
1999-07-29 22:20:02 +04:00
|
|
|
/* Inject an event, e.g., from moused. */
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("%s: inject\n", sc->sc_base.me_dv.dv_xname));
|
|
|
|
|
|
|
|
evar = sc->sc_base.me_evp;
|
2001-11-19 03:37:22 +03:00
|
|
|
if (evar == NULL) {
|
|
|
|
/* No event sink, so ignore it. */
|
|
|
|
DPRINTF(("wsmux_do_ioctl: event ignored\n"));
|
|
|
|
return (0);
|
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
get = evar->get;
|
|
|
|
put = evar->put;
|
2001-10-29 04:02:11 +03:00
|
|
|
ev = &evar->q[put];
|
1999-07-29 22:20:02 +04:00
|
|
|
if (++put % WSEVENT_QSIZE == get) {
|
|
|
|
put--;
|
|
|
|
splx(s);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
|
|
|
if (put >= WSEVENT_QSIZE)
|
|
|
|
put = 0;
|
|
|
|
*ev = *(struct wscons_event *)data;
|
2001-10-24 18:07:31 +04:00
|
|
|
microtime(&thistime);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&thistime, &ev->time);
|
1999-07-29 22:20:02 +04:00
|
|
|
evar->put = put;
|
|
|
|
WSEVENT_WAKEUP(evar);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
2001-10-24 18:07:31 +04:00
|
|
|
case WSMUXIO_ADD_DEVICE:
|
1999-07-29 22:20:02 +04:00
|
|
|
#define d ((struct wsmux_device *)data)
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("%s: add type=%d, no=%d\n", sc->sc_base.me_dv.dv_xname,
|
|
|
|
d->type, d->idx));
|
1999-07-29 22:20:02 +04:00
|
|
|
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
|
|
|
|
case WSMUX_MUX:
|
|
|
|
return (wsmux_add_mux(d->idx, sc));
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
case WSMUXIO_REMOVE_DEVICE:
|
|
|
|
DPRINTF(("%s: rem type=%d, no=%d\n", sc->sc_base.me_dv.dv_xname,
|
|
|
|
d->type, d->idx));
|
|
|
|
/* Locate the device */
|
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
if (me->me_ops->type == d->type &&
|
|
|
|
me->me_dv.dv_unit == d->idx) {
|
2001-11-02 16:02:20 +03:00
|
|
|
DPRINTF(("wsmux_do_ioctl: detach\n"));
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_detach_sc(me);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
return (EINVAL);
|
1999-07-29 22:20:02 +04:00
|
|
|
#undef d
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
case WSMUXIO_LIST_DEVICES:
|
|
|
|
DPRINTF(("%s: list\n", sc->sc_base.me_dv.dv_xname));
|
1999-07-29 22:20:02 +04:00
|
|
|
l = (struct wsmux_device_list *)data;
|
2001-10-24 18:07:31 +04:00
|
|
|
n = 0;
|
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
if (n >= WSMUX_MAXDEV)
|
|
|
|
break;
|
|
|
|
l->devices[n].type = me->me_ops->type;
|
|
|
|
l->devices[n].idx = me->me_dv.dv_unit;
|
1999-07-29 22:20:02 +04:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
l->ndevices = n;
|
|
|
|
return (0);
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
case WSKBDIO_SETMODE:
|
|
|
|
sc->sc_rawkbd = *(int *)data;
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("wsmux_do_ioctl: save rawkbd = %d\n", sc->sc_rawkbd));
|
1999-07-29 22:20:02 +04:00
|
|
|
break;
|
|
|
|
#endif
|
2001-10-25 18:46:41 +04:00
|
|
|
case FIONBIO:
|
|
|
|
DPRINTF(("%s: FIONBIO\n", sc->sc_base.me_dv.dv_xname));
|
|
|
|
return (0);
|
|
|
|
|
2000-05-28 14:33:14 +04:00
|
|
|
case FIOASYNC:
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("%s: FIOASYNC\n", sc->sc_base.me_dv.dv_xname));
|
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
evar->async = *(int *)data != 0;
|
2000-05-28 14:33:14 +04:00
|
|
|
return (0);
|
2003-09-21 23:16:48 +04:00
|
|
|
case FIOSETOWN:
|
|
|
|
DPRINTF(("%s: FIOSETOWN\n", sc->sc_base.me_dv.dv_xname));
|
2003-09-23 13:16:07 +04:00
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar == NULL)
|
2003-09-21 23:16:48 +04:00
|
|
|
return (EINVAL);
|
|
|
|
if (-*(int *)data != evar->io->p_pgid
|
|
|
|
&& *(int *)data != evar->io->p_pid)
|
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
2000-05-28 14:33:14 +04:00
|
|
|
case TIOCSPGRP:
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("%s: TIOCSPGRP\n", sc->sc_base.me_dv.dv_xname));
|
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (*(int *)data != evar->io->p_pgid)
|
2000-05-28 14:33:14 +04:00
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
1999-07-29 22:20:02 +04:00
|
|
|
default:
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("%s: unknown\n", sc->sc_base.me_dv.dv_xname));
|
1999-07-29 22:20:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp == NULL
|
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
&& sc->sc_base.me_dispdv == NULL
|
|
|
|
#endif
|
|
|
|
)
|
1999-07-29 22:20:02 +04:00
|
|
|
return (EACCES);
|
|
|
|
|
|
|
|
/* Return 0 if any of the ioctl() succeeds, otherwise the last error */
|
1999-11-04 01:48:38 +03:00
|
|
|
error = 0;
|
1999-07-29 22:20:02 +04:00
|
|
|
ok = 0;
|
2001-10-24 18:07:31 +04:00
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* XXX check evp? */
|
|
|
|
if (me->me_parent != sc) {
|
|
|
|
printf("wsmux_do_ioctl: bad child %p\n", me);
|
|
|
|
continue;
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
2003-06-30 02:28:00 +04:00
|
|
|
error = wsevsrc_ioctl(me, cmd, data, flag, p);
|
2001-10-25 18:46:41 +04:00
|
|
|
DPRINTF(("wsmux_do_ioctl: %s: me=%p dev=%s ==> %d\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, me, me->me_dv.dv_xname,
|
|
|
|
error));
|
2001-10-24 18:07:31 +04:00
|
|
|
if (!error)
|
|
|
|
ok = 1;
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* poll() of the pseudo device from device table.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
wsmuxpoll(dev_t dev, int events, struct proc *p)
|
2001-10-24 18:07:31 +04:00
|
|
|
{
|
|
|
|
int minr = minor(dev);
|
|
|
|
struct wsmux_softc *sc = wsmuxdevs[WSMUXDEV(minr)];
|
|
|
|
|
|
|
|
if (WSMUXCTL(minr)) {
|
|
|
|
/* control device */
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_base.me_evp == NULL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("wsmuxpoll: not open\n");
|
|
|
|
#endif
|
|
|
|
return (EACCES);
|
|
|
|
}
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return (wsevent_poll(sc->sc_base.me_evp, events, p));
|
2001-10-24 18:07:31 +04:00
|
|
|
}
|
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
/*
|
|
|
|
* kqfilter() of the pseudo device from device table.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wsmuxkqfilter(dev_t dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
int minr = minor(dev);
|
|
|
|
struct wsmux_softc *sc = wsmuxdevs[WSMUXDEV(minr)];
|
|
|
|
|
|
|
|
if (WSMUXCTL(minr)) {
|
|
|
|
/* control device */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_base.me_evp == NULL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("wsmuxkqfilter: not open\n");
|
|
|
|
#endif
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (wsevent_kqfilter(sc->sc_base.me_evp, kn));
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/*
|
|
|
|
* Add mux unit as a child to muxsc.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wsmux_add_mux(int unit, struct wsmux_softc *muxsc)
|
|
|
|
{
|
|
|
|
struct wsmux_softc *sc, *m;
|
|
|
|
|
|
|
|
sc = wsmux_getmux(unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
DPRINTF(("wsmux_add_mux: %s(%p) to %s(%p)\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, sc, muxsc->sc_base.me_dv.dv_xname,
|
|
|
|
muxsc));
|
|
|
|
|
|
|
|
if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
/* The mux we are adding must not be an ancestor of itself. */
|
|
|
|
for (m = muxsc; m != NULL ; m = m->sc_base.me_parent)
|
|
|
|
if (m == sc)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
return (wsmux_attach_sc(muxsc, &sc->sc_base));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new mux softc. */
|
|
|
|
struct wsmux_softc *
|
|
|
|
wsmux_create(const char *name, int unit)
|
|
|
|
{
|
|
|
|
struct wsmux_softc *sc;
|
|
|
|
|
|
|
|
DPRINTF(("wsmux_create: allocating\n"));
|
2002-01-12 19:41:02 +03:00
|
|
|
sc = malloc(sizeof *sc, M_DEVBUF, M_NOWAIT|M_ZERO);
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc == NULL)
|
|
|
|
return (NULL);
|
|
|
|
CIRCLEQ_INIT(&sc->sc_cld);
|
|
|
|
snprintf(sc->sc_base.me_dv.dv_xname, sizeof sc->sc_base.me_dv.dv_xname,
|
|
|
|
"%s%d", name, unit);
|
|
|
|
sc->sc_base.me_dv.dv_unit = unit;
|
|
|
|
sc->sc_base.me_ops = &wsmux_srcops;
|
|
|
|
return (sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach me as a child to sc. */
|
|
|
|
int
|
|
|
|
wsmux_attach_sc(struct wsmux_softc *sc, struct wsevsrc *me)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2001-11-02 16:02:20 +03:00
|
|
|
DPRINTF(("wsmux_attach_sc: %s(%p): type=%d\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, sc, me->me_ops->type));
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (me->me_parent != NULL) {
|
|
|
|
printf("wsmux_attach_sc: busy\n");
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
me->me_parent = sc;
|
|
|
|
CIRCLEQ_INSERT_TAIL(&sc->sc_cld, me, me_next);
|
|
|
|
|
2001-10-27 04:34:57 +04:00
|
|
|
error = 0;
|
2001-10-24 18:07:31 +04:00
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
if (sc->sc_base.me_dispdv != NULL) {
|
|
|
|
/* This is a display mux, so attach the new device to it. */
|
|
|
|
DPRINTF(("wsmux_attach_sc: %s: set display %p\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, sc->sc_base.me_dispdv));
|
|
|
|
if (me->me_ops->dsetdisplay != NULL) {
|
|
|
|
error = wsevsrc_set_display(me, &sc->sc_base);
|
|
|
|
/* Ignore that the console already has a display. */
|
|
|
|
if (error == EBUSY)
|
|
|
|
error = 0;
|
|
|
|
if (!error) {
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
2001-10-27 00:35:55 +04:00
|
|
|
DPRINTF(("wsmux_attach_sc: %s set rawkbd=%d\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
me->me_dv.dv_xname, sc->sc_rawkbd));
|
|
|
|
(void)wsevsrc_ioctl(me, WSKBDIO_SETMODE,
|
|
|
|
&sc->sc_rawkbd, 0, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2001-10-27 04:34:57 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
2001-10-27 04:34:57 +04:00
|
|
|
if (sc->sc_base.me_evp != NULL) {
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Mux is open, so open the new subdevice */
|
|
|
|
DPRINTF(("wsmux_attach_sc: %s: calling open of %s\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, me->me_dv.dv_xname));
|
2001-10-27 04:39:29 +04:00
|
|
|
error = wsevsrc_open(me, sc->sc_base.me_evp);
|
2001-10-24 18:07:31 +04:00
|
|
|
} else {
|
|
|
|
DPRINTF(("wsmux_attach_sc: %s not open\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
me->me_parent = NULL;
|
|
|
|
CIRCLEQ_REMOVE(&sc->sc_cld, me, me_next);
|
|
|
|
}
|
|
|
|
|
2001-11-02 16:02:20 +03:00
|
|
|
DPRINTF(("wsmux_attach_sc: %s(%p) done, error=%d\n",
|
|
|
|
sc->sc_base.me_dv.dv_xname, sc, error));
|
2001-10-24 18:07:31 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove me from the parent. */
|
|
|
|
void
|
|
|
|
wsmux_detach_sc(struct wsevsrc *me)
|
|
|
|
{
|
|
|
|
struct wsmux_softc *sc = me->me_parent;
|
|
|
|
|
2001-11-02 16:02:20 +03:00
|
|
|
DPRINTF(("wsmux_detach_sc: %s(%p) parent=%p\n",
|
|
|
|
me->me_dv.dv_xname, me, sc));
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sc == NULL) {
|
2001-11-07 06:26:06 +03:00
|
|
|
printf("wsmux_detach_sc: %s has no parent\n",
|
|
|
|
me->me_dv.dv_xname);
|
2001-10-24 18:07:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
if (sc->sc_base.me_dispdv != NULL) {
|
|
|
|
if (me->me_ops->dsetdisplay != NULL)
|
|
|
|
/* ignore error, there's nothing we can do */
|
|
|
|
(void)wsevsrc_set_display(me, NULL);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (me->me_evp != NULL) {
|
|
|
|
DPRINTF(("wsmux_detach_sc: close\n"));
|
|
|
|
/* mux device is open, so close multiplexee */
|
2001-10-27 04:39:29 +04:00
|
|
|
(void)wsevsrc_close(me);
|
2001-10-24 18:07:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CIRCLEQ_REMOVE(&sc->sc_cld, me, me_next);
|
|
|
|
me->me_parent = NULL;
|
|
|
|
|
|
|
|
DPRINTF(("wsmux_detach_sc: done sc=%p\n", sc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display ioctl() of a mux via the parent mux.
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_do_displayioctl(struct device *dv, u_long cmd, caddr_t data, int flag,
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
|
|
|
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsevsrc *me;
|
1999-07-29 22:20:02 +04:00
|
|
|
int error, ok;
|
|
|
|
|
|
|
|
DPRINTF(("wsmux_displayioctl: %s: sc=%p, cmd=%08lx\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_dv.dv_xname, sc, cmd));
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
if (cmd == WSKBDIO_SETMODE) {
|
|
|
|
sc->sc_rawkbd = *(int *)data;
|
|
|
|
DPRINTF(("wsmux_displayioctl: rawkbd = %d\n", sc->sc_rawkbd));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-11-08 13:10:25 +03:00
|
|
|
/*
|
|
|
|
* Return 0 if any of the ioctl() succeeds, otherwise the last error.
|
2002-03-17 22:40:26 +03:00
|
|
|
* Return EPASSTHROUGH if no mux component accepts the ioctl.
|
1999-11-08 13:10:25 +03:00
|
|
|
*/
|
2002-03-17 22:40:26 +03:00
|
|
|
error = EPASSTHROUGH;
|
1999-07-29 22:20:02 +04:00
|
|
|
ok = 0;
|
2001-10-24 18:07:31 +04:00
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld, me_next) {
|
|
|
|
DPRINTF(("wsmux_displayioctl: me=%p\n", me));
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (me->me_parent != sc) {
|
|
|
|
printf("wsmux_displayioctl: bad child %p\n", me);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (me->me_ops->ddispioctl != NULL) {
|
2003-06-30 02:28:00 +04:00
|
|
|
error = wsevsrc_display_ioctl(me, cmd, data, flag, p);
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("wsmux_displayioctl: me=%p dev=%s ==> %d\n",
|
|
|
|
me, me->me_dv.dv_xname, error));
|
1999-07-29 22:20:02 +04:00
|
|
|
if (!error)
|
|
|
|
ok = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
/*
|
|
|
|
* Set display of a mux via the parent mux.
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
2002-03-02 11:22:26 +03:00
|
|
|
wsmux_evsrc_set_display(struct device *dv, struct wsevsrc *ame)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsmux_softc *muxsc = (struct wsmux_softc *)ame;
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wsmux_softc *sc = (struct wsmux_softc *)dv;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct device *displaydv = muxsc ? muxsc->sc_base.me_dispdv : NULL;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
DPRINTF(("wsmux_set_display: %s: displaydv=%p\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_dv.dv_xname, displaydv));
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (displaydv != NULL) {
|
|
|
|
if (sc->sc_base.me_dispdv != NULL)
|
1999-07-29 22:20:02 +04:00
|
|
|
return (EBUSY);
|
|
|
|
} else {
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_dispdv == NULL)
|
1999-07-29 22:20:02 +04:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2002-03-02 11:22:26 +03:00
|
|
|
return wsmux_set_display(sc, displaydv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmux_set_display(struct wsmux_softc *sc, struct device *displaydv)
|
|
|
|
{
|
|
|
|
struct device *odisplaydv;
|
|
|
|
struct wsevsrc *me;
|
|
|
|
struct wsmux_softc *nsc = displaydv ? sc : NULL;
|
|
|
|
int error, ok;
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
odisplaydv = sc->sc_base.me_dispdv;
|
|
|
|
sc->sc_base.me_dispdv = displaydv;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
if (displaydv)
|
|
|
|
printf("%s: connecting to %s\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_dv.dv_xname, displaydv->dv_xname);
|
1999-07-29 22:20:02 +04:00
|
|
|
ok = 0;
|
|
|
|
error = 0;
|
2001-10-24 18:07:31 +04:00
|
|
|
CIRCLEQ_FOREACH(me, &sc->sc_cld,me_next) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (me->me_parent != sc) {
|
|
|
|
printf("wsmux_set_display: bad child parent %p\n", me);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (me->me_ops->dsetdisplay != NULL) {
|
|
|
|
error = wsevsrc_set_display(me, &nsc->sc_base);
|
1999-07-29 22:20:02 +04:00
|
|
|
DPRINTF(("wsmux_set_display: m=%p dev=%s error=%d\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
me, me->me_dv.dv_xname, error));
|
1999-07-29 22:20:02 +04:00
|
|
|
if (!error) {
|
|
|
|
ok = 1;
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
2001-10-27 04:39:29 +04:00
|
|
|
DPRINTF(("wsmux_set_display: %s set rawkbd=%d\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
me->me_dv.dv_xname, sc->sc_rawkbd));
|
|
|
|
(void)wsevsrc_ioctl(me, WSKBDIO_SETMODE,
|
|
|
|
&sc->sc_rawkbd, 0, 0);
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (displaydv == NULL)
|
|
|
|
printf("%s: disconnecting from %s\n",
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_dv.dv_xname, odisplaydv->dv_xname);
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif /* NWSDISPLAY > 0 */
|