1999-08-04 15:26:04 +04:00
|
|
|
/* $NetBSD: wsmouse.c,v 1.9 1999/08/04 11:26:04 augustss Exp $ */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Christopher G. Demetriou
|
|
|
|
* for the NetBSD Project.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char _copyright[] __attribute__ ((unused)) =
|
|
|
|
"Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.";
|
|
|
|
static const char _rcsid[] __attribute__ ((unused)) =
|
1999-08-04 15:26:04 +04:00
|
|
|
"$NetBSD: wsmouse.c,v 1.9 1999/08/04 11:26:04 augustss Exp $";
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* 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 University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* @(#)ms.c 8.1 (Berkeley) 6/11/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mouse driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
1998-12-30 17:02:18 +03:00
|
|
|
#include <sys/fcntl.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/device.h>
|
1999-06-30 10:21:21 +04:00
|
|
|
#include <sys/vnode.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsmousevar.h>
|
|
|
|
#include <dev/wscons/wseventvar.h>
|
|
|
|
|
1998-07-26 00:02:20 +04:00
|
|
|
#include "wsmouse.h"
|
1999-07-29 22:20:02 +04:00
|
|
|
#include "wsmux.h"
|
|
|
|
#include "wsdisplay.h"
|
|
|
|
#include "wskbd.h"
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
#include <dev/wscons/wsmuxvar.h>
|
|
|
|
#endif
|
1998-07-26 00:02:20 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsmouse_softc {
|
|
|
|
struct device sc_dv;
|
|
|
|
|
|
|
|
const struct wsmouse_accessops *sc_accessops;
|
|
|
|
void *sc_accesscookie;
|
|
|
|
|
|
|
|
int sc_ready; /* accepting events */
|
|
|
|
struct wseventvar sc_events; /* event queue state */
|
|
|
|
|
|
|
|
u_int sc_mb; /* mouse button state */
|
|
|
|
u_int sc_ub; /* user button state */
|
|
|
|
int sc_dx; /* delta-x */
|
|
|
|
int sc_dy; /* delta-y */
|
1998-07-28 02:33:22 +04:00
|
|
|
int sc_dz; /* delta-z */
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
int sc_refcnt;
|
|
|
|
u_char sc_dying; /* device is being detached */
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wsmux_softc *sc_mux;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int wsmouse_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
void wsmouse_attach __P((struct device *, struct device *, void *));
|
1999-06-30 10:21:21 +04:00
|
|
|
int wsmouse_detach __P((struct device *, int));
|
|
|
|
int wsmouse_activate __P((struct device *, enum devact));
|
|
|
|
|
|
|
|
int wsmouse_do_ioctl __P((struct wsmouse_softc *, u_long, caddr_t,
|
|
|
|
int, struct proc *));
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
int wsmousedoclose __P((struct device *, int, int, struct proc *));
|
|
|
|
int wsmousedoioctl __P((struct device *, u_long, caddr_t, int,
|
|
|
|
struct proc *));
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
struct cfattach wsmouse_ca = {
|
|
|
|
sizeof (struct wsmouse_softc), wsmouse_match, wsmouse_attach,
|
1999-06-30 10:21:21 +04:00
|
|
|
wsmouse_detach, wsmouse_activate
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
extern struct cfdriver wsmouse_cd;
|
1998-07-26 00:02:20 +04:00
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
cdev_decl(wsmouse);
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wsmuxops wsmouse_muxops = {
|
|
|
|
wsmouseopen, wsmousedoclose, wsmousedoioctl, 0, 0
|
|
|
|
};
|
1999-08-04 15:26:04 +04:00
|
|
|
#endif
|
1999-07-29 22:20:02 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* Print function (for parent devices).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wsmousedevprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (pnp)
|
|
|
|
printf("wsmouse at %s", pnp);
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouse_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wsmouse_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)self;
|
|
|
|
struct wsmousedev_attach_args *ap = aux;
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
int mux;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
sc->sc_accessops = ap->accessops;
|
|
|
|
sc->sc_accesscookie = ap->accesscookie;
|
|
|
|
sc->sc_ready = 0; /* sanity */
|
1999-06-30 10:21:21 +04:00
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
mux = sc->sc_dv.dv_cfdata->wsmousedevcf_mux;
|
|
|
|
if (mux != WSMOUSEDEVCF_MUX_DEFAULT) {
|
|
|
|
wsmux_attach(mux, WSMUX_MOUSE, &sc->sc_dv, &sc->sc_events,
|
|
|
|
&sc->sc_mux, &wsmouse_muxops);
|
|
|
|
printf(" mux %d", mux);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouse_activate(self, act)
|
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
|
|
|
/* XXX should we do something more? */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach a mouse. To keep track of users of the softc we keep
|
|
|
|
* a reference count that's incremented while inside, e.g., read.
|
|
|
|
* If the mouse is active and the reference count is > 0 (0 is the
|
|
|
|
* normal state) we post an event and then wait for the process
|
|
|
|
* that had the reference to wake us up again. Then we blow away the
|
|
|
|
* vnode and return (which will deallocate the softc).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wsmouse_detach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)self;
|
|
|
|
struct wseventvar *evar;
|
|
|
|
int maj, mn;
|
|
|
|
int s;
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
int mux;
|
|
|
|
#endif
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
sc->sc_dying = 1;
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
mux = sc->sc_dv.dv_cfdata->wsmousedevcf_mux;
|
|
|
|
if (mux != WSMOUSEDEVCF_MUX_DEFAULT)
|
|
|
|
wsmux_detach(mux, &sc->sc_dv);
|
|
|
|
#endif
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
evar = &sc->sc_events;
|
|
|
|
if (evar->io) {
|
|
|
|
s = spltty();
|
|
|
|
if (--sc->sc_refcnt >= 0) {
|
|
|
|
/* Wake everyone by generating a dummy event. */
|
|
|
|
if (++evar->put >= WSEVENT_QSIZE)
|
|
|
|
evar->put = 0;
|
|
|
|
WSEVENT_WAKEUP(evar);
|
|
|
|
/* Wait for processes to go away. */
|
|
|
|
if (tsleep(sc, PZERO, "wsmdet", hz * 60))
|
|
|
|
printf("wsmouse_detach: %s didn't detach\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* locate the major number */
|
|
|
|
for (maj = 0; maj < nchrdev; maj++)
|
|
|
|
if (cdevsw[maj].d_open == wsmouseopen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances (calls close). */
|
|
|
|
mn = self->dv_unit;
|
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
return (0);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-07-28 02:33:22 +04:00
|
|
|
wsmouse_input(wsmousedev, btns, dx, dy, dz)
|
1998-03-22 17:24:02 +03:00
|
|
|
struct device *wsmousedev;
|
|
|
|
u_int btns; /* 0 is up */
|
1998-07-28 02:33:22 +04:00
|
|
|
int dx, dy, dz;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)wsmousedev;
|
|
|
|
struct wscons_event *ev;
|
1999-06-30 10:21:21 +04:00
|
|
|
struct wseventvar *evar;
|
1998-03-22 17:24:02 +03:00
|
|
|
int mb, ub, d, get, put, any;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard input if not ready.
|
|
|
|
*/
|
|
|
|
if (sc->sc_ready == 0)
|
|
|
|
return;
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
if (sc->sc_mux)
|
|
|
|
evar = &sc->sc_mux->sc_events;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
evar = &sc->sc_events;
|
1999-06-30 10:21:21 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_mb = btns;
|
|
|
|
sc->sc_dx += dx;
|
|
|
|
sc->sc_dy += dy;
|
1998-07-28 02:33:22 +04:00
|
|
|
sc->sc_dz += dz;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have at least one event (mouse button, delta-X, or
|
|
|
|
* delta-Y; possibly all three, and possibly three separate
|
|
|
|
* button events). Deliver these events until we are out
|
|
|
|
* of changes or out of room. As events get delivered,
|
|
|
|
* mark them `unchanged'.
|
|
|
|
*/
|
|
|
|
any = 0;
|
1999-06-30 10:21:21 +04:00
|
|
|
get = evar->get;
|
|
|
|
put = evar->put;
|
|
|
|
ev = &evar->q[put];
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/* NEXT prepares to put the next event, backing off if necessary */
|
|
|
|
#define NEXT \
|
|
|
|
if ((++put) % WSEVENT_QSIZE == get) { \
|
|
|
|
put--; \
|
|
|
|
goto out; \
|
|
|
|
}
|
|
|
|
/* ADVANCE completes the `put' of the event */
|
|
|
|
#define ADVANCE \
|
|
|
|
ev++; \
|
|
|
|
if (put >= WSEVENT_QSIZE) { \
|
|
|
|
put = 0; \
|
1999-06-30 10:21:21 +04:00
|
|
|
ev = &evar->q[0]; \
|
1998-03-22 17:24:02 +03:00
|
|
|
} \
|
|
|
|
any = 1
|
|
|
|
/* TIMESTAMP sets `time' field of the event to the current time */
|
|
|
|
#define TIMESTAMP \
|
|
|
|
do { \
|
|
|
|
int s; \
|
|
|
|
s = splhigh(); \
|
|
|
|
TIMEVAL_TO_TIMESPEC(&time, &ev->time); \
|
|
|
|
splx(s); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
mb = sc->sc_mb;
|
|
|
|
ub = sc->sc_ub;
|
|
|
|
while ((d = mb ^ ub) != 0) {
|
|
|
|
/*
|
|
|
|
* Mouse button change. Find the first change and drop
|
|
|
|
* it into the event queue.
|
|
|
|
*/
|
|
|
|
NEXT;
|
|
|
|
ev->value = ffs(d) - 1;
|
|
|
|
|
|
|
|
KASSERT(ev->value >= 0);
|
|
|
|
|
|
|
|
d = 1 << ev->value;
|
|
|
|
ev->type =
|
|
|
|
(mb & d) ? WSCONS_EVENT_MOUSE_DOWN : WSCONS_EVENT_MOUSE_UP;
|
|
|
|
TIMESTAMP;
|
|
|
|
ADVANCE;
|
|
|
|
ub ^= d;
|
|
|
|
}
|
|
|
|
if (sc->sc_dx) {
|
|
|
|
NEXT;
|
|
|
|
ev->type = WSCONS_EVENT_MOUSE_DELTA_X;
|
|
|
|
ev->value = sc->sc_dx;
|
|
|
|
TIMESTAMP;
|
|
|
|
ADVANCE;
|
|
|
|
sc->sc_dx = 0;
|
|
|
|
}
|
|
|
|
if (sc->sc_dy) {
|
|
|
|
NEXT;
|
|
|
|
ev->type = WSCONS_EVENT_MOUSE_DELTA_Y;
|
|
|
|
ev->value = sc->sc_dy;
|
|
|
|
TIMESTAMP;
|
|
|
|
ADVANCE;
|
|
|
|
sc->sc_dy = 0;
|
|
|
|
}
|
1998-07-28 02:33:22 +04:00
|
|
|
if (sc->sc_dz) {
|
|
|
|
NEXT;
|
|
|
|
ev->type = WSCONS_EVENT_MOUSE_DELTA_Z;
|
|
|
|
ev->value = sc->sc_dz;
|
|
|
|
TIMESTAMP;
|
|
|
|
ADVANCE;
|
|
|
|
sc->sc_dz = 0;
|
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
out:
|
|
|
|
if (any) {
|
|
|
|
sc->sc_ub = ub;
|
1999-06-30 10:21:21 +04:00
|
|
|
evar->put = put;
|
|
|
|
WSEVENT_WAKEUP(evar);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouseopen(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsmouse_softc *sc;
|
|
|
|
int error, unit;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
if (unit >= wsmouse_cd.cd_ndevs || /* make sure it was attached */
|
|
|
|
(sc = wsmouse_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1998-12-30 17:02:18 +03:00
|
|
|
if ((flags & (FREAD | FWRITE)) == FWRITE)
|
|
|
|
return (0); /* always allow open for write
|
|
|
|
so ioctl() is possible. */
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
if (sc->sc_mux)
|
|
|
|
return (EBUSY);
|
|
|
|
#endif
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
if (sc->sc_events.io) /* and that it's not in use */
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
sc->sc_events.io = p;
|
|
|
|
wsevent_init(&sc->sc_events); /* may cause sleep */
|
|
|
|
|
|
|
|
sc->sc_ready = 1; /* start accepting events */
|
|
|
|
|
|
|
|
/* enable the device, and punt if that's not possible */
|
|
|
|
error = (*sc->sc_accessops->enable)(sc->sc_accesscookie);
|
|
|
|
if (error) {
|
|
|
|
sc->sc_ready = 0; /* stop accepting events */
|
|
|
|
wsevent_fini(&sc->sc_events);
|
|
|
|
sc->sc_events.io = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
1998-07-26 00:02:20 +04:00
|
|
|
#else
|
|
|
|
return (ENXIO);
|
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouseclose(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
return (wsmousedoclose(wsmouse_cd.cd_devs[minor(dev)],
|
|
|
|
flags, mode, p));
|
|
|
|
#else
|
|
|
|
return (ENXIO);
|
|
|
|
#endif /* NWSMOUSE > 0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NWSMOUSE > 0
|
|
|
|
int
|
|
|
|
wsmousedoclose(dv, flags, mode, p)
|
|
|
|
struct device *dv;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)dv;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1998-12-30 17:02:18 +03:00
|
|
|
if ((flags & (FREAD | FWRITE)) == FWRITE)
|
|
|
|
return (0); /* see wsmouseopen() */
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
(*sc->sc_accessops->disable)(sc->sc_accesscookie);
|
|
|
|
|
|
|
|
sc->sc_ready = 0; /* stop accepting events */
|
|
|
|
wsevent_fini(&sc->sc_events);
|
|
|
|
sc->sc_events.io = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
wsmouseread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
|
|
|
{
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1999-01-10 21:22:14 +03:00
|
|
|
struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
|
1999-06-30 10:21:21 +04:00
|
|
|
int error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
sc->sc_refcnt++;
|
|
|
|
error = wsevent_read(&sc->sc_events, uio, flags);
|
|
|
|
if (--sc->sc_refcnt < 0) {
|
|
|
|
wakeup(sc);
|
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
return (error);
|
1998-07-26 00:02:20 +04:00
|
|
|
#else
|
|
|
|
return (ENXIO);
|
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouseioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
return (wsmousedoioctl(wsmouse_cd.cd_devs[minor(dev)],
|
|
|
|
cmd, data, flag, p));
|
|
|
|
#else
|
|
|
|
return (ENXIO);
|
|
|
|
#endif /* NWSMOUSE > 0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NWSMOUSE > 0
|
|
|
|
/* A wrapper around the ioctl() workhorse to make reference counting easy. */
|
|
|
|
int
|
|
|
|
wsmousedoioctl(dv, cmd, data, flag, p)
|
|
|
|
struct device *dv;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)dv;
|
1999-01-10 21:22:14 +03:00
|
|
|
int error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
sc->sc_refcnt++;
|
|
|
|
error = wsmouse_do_ioctl(sc, cmd, data, flag, p);
|
|
|
|
if (--sc->sc_refcnt < 0)
|
|
|
|
wakeup(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouse_do_ioctl(sc, cmd, data, flag, p)
|
|
|
|
struct wsmouse_softc *sc;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* Try the generic ioctls that the wsmouse interface supports.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO: /* we will remove this someday (soon???) */
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try the mouse driver for WSMOUSEIO ioctls. It returns -1
|
|
|
|
* if it didn't recognize the request.
|
|
|
|
*/
|
|
|
|
error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd,
|
|
|
|
data, flag, p);
|
|
|
|
return (error != -1 ? error : ENOTTY);
|
|
|
|
}
|
1999-06-30 10:21:21 +04:00
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
wsmousepoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-07-26 00:02:20 +04:00
|
|
|
#if NWSMOUSE > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
|
|
|
|
|
|
|
|
return (wsevent_poll(&sc->sc_events, events, p));
|
1998-07-26 00:02:20 +04:00
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif /* NWSMOUSE > 0 */
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
1999-06-30 10:21:21 +04:00
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
|
|
|
wsmouse_add_mux(unit, muxsc)
|
|
|
|
int unit;
|
|
|
|
struct wsmux_softc *muxsc;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc;
|
|
|
|
|
|
|
|
if (unit < 0 || unit >= wsmouse_cd.cd_ndevs ||
|
|
|
|
(sc = wsmouse_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (sc->sc_mux || sc->sc_events.io)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
return (wsmux_attach_sc(muxsc, WSMUX_KBD, &sc->sc_dv, &sc->sc_events,
|
|
|
|
&sc->sc_mux, &wsmouse_muxops));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouse_rem_mux(unit, muxsc)
|
|
|
|
int unit;
|
|
|
|
struct wsmux_softc *muxsc;
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc;
|
|
|
|
|
|
|
|
if (unit < 0 || unit >= wsmouse_cd.cd_ndevs ||
|
|
|
|
(sc = wsmouse_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
return (wsmux_detach_sc(muxsc, &sc->sc_dv));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|