2009-01-15 07:22:11 +03:00
|
|
|
/* $NetBSD: wsmouse.c,v 1.62 2009/01/15 04:22:11 yamt Exp $ */
|
2006-02-05 20:38:33 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Julio M. Merino Vidal.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1998-03-22 17:24:02 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:17:46 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-01-15 07:22:11 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wsmouse.c,v 1.62 2009/01/15 04:22:11 yamt Exp $");
|
2001-11-13 09:17:46 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#include "wsmouse.h"
|
|
|
|
#include "wsdisplay.h"
|
|
|
|
#include "wsmux.h"
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
2005-06-21 18:01:11 +04:00
|
|
|
#include <sys/poll.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>
|
2006-02-05 20:38:33 +03:00
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsmousevar.h>
|
|
|
|
#include <dev/wscons/wseventvar.h>
|
1999-07-29 22:20:02 +04:00
|
|
|
#include <dev/wscons/wsmuxvar.h>
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
#if defined(WSMUX_DEBUG) && NWSMUX > 0
|
|
|
|
#define DPRINTF(x) if (wsmuxdebug) printf x
|
|
|
|
#define DPRINTFN(n,x) if (wsmuxdebug > (n)) printf x
|
|
|
|
extern int wsmuxdebug;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
1998-07-26 00:02:20 +04:00
|
|
|
|
2000-01-08 05:57:22 +03:00
|
|
|
#define INVALID_X INT_MAX
|
|
|
|
#define INVALID_Y INT_MAX
|
|
|
|
#define INVALID_Z INT_MAX
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsmouse_softc {
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsevsrc sc_base;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
const struct wsmouse_accessops *sc_accessops;
|
|
|
|
void *sc_accesscookie;
|
|
|
|
|
|
|
|
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 */
|
2005-11-23 12:38:02 +03:00
|
|
|
int sc_dw; /* delta-w */
|
2000-01-08 05:57:22 +03:00
|
|
|
int sc_x; /* absolute-x */
|
|
|
|
int sc_y; /* absolute-y */
|
|
|
|
int sc_z; /* absolute-z */
|
2005-11-23 12:38:02 +03:00
|
|
|
int sc_w; /* absolute-w */
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
int sc_refcnt;
|
|
|
|
u_char sc_dying; /* device is being detached */
|
2006-02-05 20:38:33 +03:00
|
|
|
|
|
|
|
struct wsmouse_repeat sc_repeat;
|
|
|
|
int sc_repeat_button;
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_t sc_repeat_callout;
|
2006-02-05 20:38:33 +03:00
|
|
|
unsigned int sc_repeat_delay;
|
2001-10-24 18:07:31 +04:00
|
|
|
};
|
|
|
|
|
2008-03-25 03:49:19 +03:00
|
|
|
static int wsmouse_match(device_t, cfdata_t, void *);
|
|
|
|
static void wsmouse_attach(device_t, device_t, void *);
|
|
|
|
static int wsmouse_detach(device_t, int);
|
|
|
|
static int wsmouse_activate(device_t, enum devact);
|
2001-10-24 18:07:31 +04:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
static int wsmouse_do_ioctl(struct wsmouse_softc *, u_long, void *,
|
2005-12-11 15:16:03 +03:00
|
|
|
int, struct lwp *);
|
1999-06-30 10:21:21 +04:00
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
static int wsmouse_mux_open(struct wsevsrc *, struct wseventvar *);
|
|
|
|
static int wsmouse_mux_close(struct wsevsrc *);
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
1999-06-30 10:21:21 +04:00
|
|
|
|
2008-03-25 03:49:19 +03:00
|
|
|
static int wsmousedoioctl(device_t, u_long, void *, int, struct lwp *);
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
static int wsmousedoopen(struct wsmouse_softc *, struct wseventvar *);
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2008-03-25 03:49:19 +03:00
|
|
|
CFATTACH_DECL_NEW(wsmouse, sizeof (struct wsmouse_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
wsmouse_match, wsmouse_attach, wsmouse_detach, wsmouse_activate);
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2006-02-05 20:38:33 +03:00
|
|
|
static void wsmouse_repeat(void *v);
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
extern struct cfdriver wsmouse_cd;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(wsmouseopen);
|
|
|
|
dev_type_close(wsmouseclose);
|
|
|
|
dev_type_read(wsmouseread);
|
|
|
|
dev_type_ioctl(wsmouseioctl);
|
|
|
|
dev_type_poll(wsmousepoll);
|
2002-10-23 13:10:23 +04:00
|
|
|
dev_type_kqfilter(wsmousekqfilter);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct cdevsw wsmouse_cdevsw = {
|
|
|
|
wsmouseopen, wsmouseclose, wsmouseread, nowrite, wsmouseioctl,
|
2006-08-29 01:33:16 +04:00
|
|
|
nostop, notty, wsmousepoll, nommap, wsmousekqfilter, D_OTHER
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wssrcops wsmouse_srcops = {
|
|
|
|
WSMUX_MOUSE,
|
|
|
|
wsmouse_mux_open, wsmouse_mux_close, wsmousedoioctl, NULL, NULL
|
1999-07-29 22:20:02 +04:00
|
|
|
};
|
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
|
2006-11-16 04:32:37 +03:00
|
|
|
wsmousedevprint(void *aux, const char *pnp)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (pnp)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("wsmouse at %s", pnp);
|
1998-03-22 17:24:02 +03:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmouse_match(device_t parent, cfdata_t match, void *aux)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmouse_attach(device_t parent, device_t self, void *aux)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc = device_private(self);
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wsmousedev_attach_args *ap = aux;
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
int mux, error;
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2008-03-25 03:49:19 +03:00
|
|
|
sc->sc_base.me_dv = self;
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_accessops = ap->accessops;
|
|
|
|
sc->sc_accesscookie = ap->accesscookie;
|
1999-06-30 10:21:21 +04:00
|
|
|
|
2006-02-05 20:38:33 +03:00
|
|
|
/* Initialize button repeating. */
|
|
|
|
memset(&sc->sc_repeat, 0, sizeof(sc->sc_repeat));
|
|
|
|
sc->sc_repeat_button = -1;
|
|
|
|
sc->sc_repeat_delay = 0;
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_repeat_callout, 0);
|
2007-10-17 01:06:09 +04:00
|
|
|
callout_setfunc(&sc->sc_repeat_callout, wsmouse_repeat, sc);
|
2006-02-05 20:38:33 +03:00
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_ops = &wsmouse_srcops;
|
2008-03-25 03:49:19 +03:00
|
|
|
mux = device_cfdata(self)->wsmousedevcf_mux;
|
2001-10-24 18:07:31 +04:00
|
|
|
if (mux >= 0) {
|
|
|
|
error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base);
|
|
|
|
if (error)
|
2007-12-01 07:50:50 +03:00
|
|
|
aprint_error(" attach error=%d", error);
|
2001-10-24 18:07:31 +04:00
|
|
|
else
|
2007-12-01 07:50:50 +03:00
|
|
|
aprint_normal(" mux %d", mux);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
#else
|
2008-03-25 03:49:19 +03:00
|
|
|
if (device_cfdata(self)->wsmousedevcf_mux >= 0)
|
2007-12-01 07:50:50 +03:00
|
|
|
aprint_normal(" (mux ignored)");
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
|
|
|
|
2007-12-01 07:50:50 +03:00
|
|
|
aprint_naive("\n");
|
|
|
|
aprint_normal("\n");
|
2007-12-09 23:27:42 +03:00
|
|
|
|
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
1999-06-30 10:21:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmouse_activate(device_t self, enum devact act)
|
1999-06-30 10:21:21 +04:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc = device_private(self);
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
if (act == DVACT_DEACTIVATE)
|
|
|
|
sc->sc_dying = 1;
|
1999-06-30 10:21:21 +04:00
|
|
|
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
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmouse_detach(device_t self, int flags)
|
1999-06-30 10:21:21 +04:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc = device_private(self);
|
1999-06-30 10:21:21 +04:00
|
|
|
struct wseventvar *evar;
|
|
|
|
int maj, mn;
|
|
|
|
int s;
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
/* Tell parent mux we're leaving. */
|
2001-11-02 16:02:20 +03:00
|
|
|
if (sc->sc_base.me_parent != NULL) {
|
|
|
|
DPRINTF(("wsmouse_detach:\n"));
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmux_detach_sc(&sc->sc_base);
|
2001-11-02 16:02:20 +03:00
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* If we're open ... */
|
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar != NULL && evar->io != NULL) {
|
1999-06-30 10:21:21 +04:00
|
|
|
s = spltty();
|
|
|
|
if (--sc->sc_refcnt >= 0) {
|
2006-02-07 12:13:02 +03:00
|
|
|
struct wscons_event event;
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
/* Wake everyone by generating a dummy event. */
|
2006-02-07 12:13:02 +03:00
|
|
|
event.type = 0;
|
|
|
|
event.value = 0;
|
|
|
|
if (wsevent_inject(evar, &event, 1) != 0)
|
|
|
|
wsevent_wakeup(evar);
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
/* Wait for processes to go away. */
|
|
|
|
if (tsleep(sc, PZERO, "wsmdet", hz * 60))
|
|
|
|
printf("wsmouse_detach: %s didn't detach\n",
|
2008-03-25 03:49:19 +03:00
|
|
|
device_xname(self));
|
1999-06-30 10:21:21 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* locate the major number */
|
2002-09-06 17:18:43 +04:00
|
|
|
maj = cdevsw_lookup_major(&wsmouse_cdevsw);
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances (calls close). */
|
2006-03-28 21:38:24 +04:00
|
|
|
mn = device_unit(self);
|
1999-06-30 10:21:21 +04:00
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
return (0);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmouse_input(device_t wsmousedev, u_int btns /* 0 is up */,
|
2005-11-23 12:38:02 +03:00
|
|
|
int x, int y, int z, int w, u_int flags)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc = device_private(wsmousedev);
|
1999-06-30 10:21:21 +04:00
|
|
|
struct wseventvar *evar;
|
2006-02-07 12:13:02 +03:00
|
|
|
int mb, ub, d, nevents;
|
2006-02-10 20:33:01 +03:00
|
|
|
/* one for each dimension (4) + a bit for each button */
|
2006-02-07 12:13:02 +03:00
|
|
|
struct wscons_event events[4 + sizeof(d) * 8];
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
2001-10-24 18:07:31 +04:00
|
|
|
* Discard input if not open.
|
1998-03-22 17:24:02 +03:00
|
|
|
*/
|
2001-10-24 18:07:31 +04:00
|
|
|
evar = sc->sc_base.me_evp;
|
|
|
|
if (evar == NULL)
|
1998-03-22 17:24:02 +03:00
|
|
|
return;
|
|
|
|
|
2001-11-22 03:57:14 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (evar->q == NULL) {
|
|
|
|
printf("wsmouse_input: evar->q=NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTFN(5,("wsmouse_input: %s mux=%p, evar=%p\n",
|
2008-03-25 03:49:19 +03:00
|
|
|
device_xname(sc->sc_base.me_dv),
|
|
|
|
sc->sc_base.me_parent, evar));
|
1999-07-29 22:20:02 +04:00
|
|
|
#endif
|
1999-06-30 10:21:21 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_mb = btns;
|
2000-01-08 05:57:22 +03:00
|
|
|
if (!(flags & WSMOUSE_INPUT_ABSOLUTE_X))
|
|
|
|
sc->sc_dx += x;
|
|
|
|
if (!(flags & WSMOUSE_INPUT_ABSOLUTE_Y))
|
|
|
|
sc->sc_dy += y;
|
|
|
|
if (!(flags & WSMOUSE_INPUT_ABSOLUTE_Z))
|
|
|
|
sc->sc_dz += z;
|
2005-11-23 12:38:02 +03:00
|
|
|
if (!(flags & WSMOUSE_INPUT_ABSOLUTE_W))
|
|
|
|
sc->sc_dw += w;
|
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'.
|
|
|
|
*/
|
2001-02-13 04:14:45 +03:00
|
|
|
ub = sc->sc_ub;
|
2006-02-07 12:13:02 +03:00
|
|
|
nevents = 0;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2000-01-08 05:57:22 +03:00
|
|
|
if (flags & WSMOUSE_INPUT_ABSOLUTE_X) {
|
|
|
|
if (sc->sc_x != x) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_ABSOLUTE_X;
|
|
|
|
events[nevents].value = x;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_dx) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_DELTA_X;
|
|
|
|
events[nevents].value = sc->sc_dx;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
2000-01-08 05:57:22 +03:00
|
|
|
if (flags & WSMOUSE_INPUT_ABSOLUTE_Y) {
|
|
|
|
if (sc->sc_y != y) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_ABSOLUTE_Y;
|
|
|
|
events[nevents].value = y;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_dy) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_DELTA_Y;
|
|
|
|
events[nevents].value = sc->sc_dy;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
2000-01-08 05:57:22 +03:00
|
|
|
if (flags & WSMOUSE_INPUT_ABSOLUTE_Z) {
|
|
|
|
if (sc->sc_z != z) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_ABSOLUTE_Z;
|
|
|
|
events[nevents].value = z;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_dz) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_DELTA_Z;
|
|
|
|
events[nevents].value = sc->sc_dz;
|
|
|
|
nevents++;
|
2000-01-08 05:57:22 +03:00
|
|
|
}
|
1998-07-28 02:33:22 +04:00
|
|
|
}
|
2005-11-23 12:38:02 +03:00
|
|
|
if (flags & WSMOUSE_INPUT_ABSOLUTE_W) {
|
|
|
|
if (sc->sc_w != w) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_ABSOLUTE_W;
|
|
|
|
events[nevents].value = w;
|
|
|
|
nevents++;
|
2005-11-23 12:38:02 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_dw) {
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type = WSCONS_EVENT_MOUSE_DELTA_W;
|
|
|
|
events[nevents].value = sc->sc_dw;
|
|
|
|
nevents++;
|
2005-11-23 12:38:02 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-01 11:36:58 +04:00
|
|
|
|
|
|
|
mb = sc->sc_mb;
|
|
|
|
while ((d = mb ^ ub) != 0) {
|
2006-02-05 20:38:33 +03:00
|
|
|
int btnno;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel button repeating if button status changed.
|
|
|
|
*/
|
|
|
|
if (sc->sc_repeat_button != -1) {
|
|
|
|
KASSERT(sc->sc_repeat_button >= 0);
|
|
|
|
KASSERT(sc->sc_repeat.wr_buttons &
|
|
|
|
(1 << sc->sc_repeat_button));
|
|
|
|
ub &= ~(1 << sc->sc_repeat_button);
|
|
|
|
sc->sc_repeat_button = -1;
|
|
|
|
callout_stop(&sc->sc_repeat_callout);
|
|
|
|
}
|
|
|
|
|
2000-05-01 11:36:58 +04:00
|
|
|
/*
|
|
|
|
* Mouse button change. Find the first change and drop
|
|
|
|
* it into the event queue.
|
|
|
|
*/
|
2006-02-05 20:38:33 +03:00
|
|
|
btnno = ffs(d) - 1;
|
|
|
|
KASSERT(btnno >= 0);
|
2000-05-01 11:36:58 +04:00
|
|
|
|
2006-02-10 23:38:54 +03:00
|
|
|
if (nevents >= sizeof(events) / sizeof(events[0])) {
|
2008-03-25 03:49:19 +03:00
|
|
|
aprint_error_dev(sc->sc_base.me_dv,
|
|
|
|
"Event queue full (button status mb=0x%x"
|
|
|
|
" ub=0x%x)\n", mb, ub);
|
2006-02-10 20:33:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].type =
|
2000-05-01 11:36:58 +04:00
|
|
|
(mb & d) ? WSCONS_EVENT_MOUSE_DOWN : WSCONS_EVENT_MOUSE_UP;
|
2006-02-07 12:13:02 +03:00
|
|
|
events[nevents].value = btnno;
|
|
|
|
nevents++;
|
|
|
|
|
|
|
|
ub ^= (1 << btnno);
|
2006-02-05 20:38:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Program button repeating if configured for this button.
|
|
|
|
*/
|
|
|
|
if ((mb & d) && (sc->sc_repeat.wr_buttons & (1 << btnno)) &&
|
|
|
|
sc->sc_repeat.wr_delay_first > 0) {
|
|
|
|
sc->sc_repeat_button = btnno;
|
|
|
|
sc->sc_repeat_delay = sc->sc_repeat.wr_delay_first;
|
2007-10-17 01:06:09 +04:00
|
|
|
callout_schedule(&sc->sc_repeat_callout,
|
|
|
|
mstohz(sc->sc_repeat_delay));
|
2006-02-05 20:38:33 +03:00
|
|
|
}
|
2000-05-01 11:36:58 +04:00
|
|
|
}
|
2006-02-07 12:13:02 +03:00
|
|
|
|
2006-02-10 20:33:01 +03:00
|
|
|
if (nevents == 0 || wsevent_inject(evar, events, nevents) == 0) {
|
2006-02-07 12:13:02 +03:00
|
|
|
/* All events were correctly injected into the queue.
|
|
|
|
* Synchronize the mouse's status with what the user
|
|
|
|
* has received. */
|
|
|
|
sc->sc_x = x; sc->sc_dx = 0;
|
|
|
|
sc->sc_y = y; sc->sc_dy = 0;
|
|
|
|
sc->sc_z = z; sc->sc_dz = 0;
|
|
|
|
sc->sc_w = w; sc->sc_dw = 0;
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_ub = ub;
|
2001-10-25 18:46:41 +04:00
|
|
|
#if NWSMUX > 0
|
|
|
|
DPRINTFN(5,("wsmouse_input: %s wakeup evar=%p\n",
|
2008-03-25 03:49:19 +03:00
|
|
|
device_xname(sc->sc_base.me_dv), evar));
|
2001-10-25 18:46:41 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-05 20:38:33 +03:00
|
|
|
static void
|
|
|
|
wsmouse_repeat(void *v)
|
|
|
|
{
|
|
|
|
int oldspl;
|
|
|
|
unsigned int newdelay;
|
|
|
|
struct wsmouse_softc *sc;
|
2006-02-07 12:13:02 +03:00
|
|
|
struct wscons_event events[2];
|
2006-02-05 20:38:33 +03:00
|
|
|
|
|
|
|
oldspl = spltty();
|
|
|
|
sc = (struct wsmouse_softc *)v;
|
|
|
|
|
|
|
|
if (sc->sc_repeat_button == -1) {
|
|
|
|
/* Race condition: a "button up" event came in when
|
|
|
|
* this function was already called but did not do
|
|
|
|
* spltty() yet. */
|
|
|
|
splx(oldspl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KASSERT(sc->sc_repeat_button >= 0);
|
|
|
|
|
|
|
|
KASSERT(sc->sc_repeat.wr_buttons & (1 << sc->sc_repeat_button));
|
|
|
|
|
|
|
|
newdelay = sc->sc_repeat_delay;
|
|
|
|
|
2006-02-07 12:13:02 +03:00
|
|
|
events[0].type = WSCONS_EVENT_MOUSE_UP;
|
|
|
|
events[0].value = sc->sc_repeat_button;
|
|
|
|
events[1].type = WSCONS_EVENT_MOUSE_DOWN;
|
|
|
|
events[1].value = sc->sc_repeat_button;
|
2006-02-05 20:38:33 +03:00
|
|
|
|
2006-02-07 12:13:02 +03:00
|
|
|
if (wsevent_inject(sc->sc_base.me_evp, events, 2) == 0) {
|
2006-02-05 20:38:33 +03:00
|
|
|
sc->sc_ub = 1 << sc->sc_repeat_button;
|
|
|
|
|
|
|
|
if (newdelay - sc->sc_repeat.wr_delay_decrement <
|
|
|
|
sc->sc_repeat.wr_delay_minimum)
|
|
|
|
newdelay = sc->sc_repeat.wr_delay_minimum;
|
|
|
|
else if (newdelay > sc->sc_repeat.wr_delay_minimum)
|
|
|
|
newdelay -= sc->sc_repeat.wr_delay_decrement;
|
|
|
|
KASSERT(newdelay >= sc->sc_repeat.wr_delay_minimum &&
|
|
|
|
newdelay <= sc->sc_repeat.wr_delay_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reprogram the repeating event.
|
|
|
|
*/
|
|
|
|
sc->sc_repeat_delay = newdelay;
|
2007-10-17 01:06:09 +04:00
|
|
|
callout_schedule(&sc->sc_repeat_callout, mstohz(newdelay));
|
2006-02-05 20:38:33 +03:00
|
|
|
|
|
|
|
splx(oldspl);
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
wsmouseopen(dev_t dev, int flags, int mode, struct lwp *l)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc;
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wseventvar *evar;
|
2008-06-13 03:04:37 +04:00
|
|
|
int error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2008-06-13 03:04:37 +04:00
|
|
|
sc = device_lookup_private(&wsmouse_cd, minor(dev));
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENXIO;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#if NWSMUX > 0
|
2008-04-30 18:07:13 +04:00
|
|
|
DPRINTF(("wsmouseopen: %s mux=%p p=%p\n", device_xname(sc->sc_base.me_dv),
|
2005-12-11 15:16:03 +03:00
|
|
|
sc->sc_base.me_parent, l));
|
2001-10-24 18:07:31 +04:00
|
|
|
#endif
|
|
|
|
|
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. */
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp != NULL)
|
1998-03-22 17:24:02 +03:00
|
|
|
return (EBUSY);
|
|
|
|
|
2001-10-25 18:46:41 +04:00
|
|
|
evar = &sc->sc_base.me_evar;
|
2006-02-07 12:13:02 +03:00
|
|
|
wsevent_init(evar, l->l_proc);
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_evp = evar;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
error = wsmousedoopen(sc, evar);
|
1998-03-22 17:24:02 +03:00
|
|
|
if (error) {
|
2001-10-24 18:07:31 +04:00
|
|
|
DPRINTF(("wsmouseopen: %s open failed\n",
|
2008-04-30 18:07:13 +04:00
|
|
|
device_xname(sc->sc_base.me_dv)));
|
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);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
2001-10-24 18:07:31 +04:00
|
|
|
return (error);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
wsmouseclose(dev_t dev, int flags, int mode,
|
|
|
|
struct lwp *l)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsmouse_softc *sc =
|
2008-06-13 03:04:37 +04:00
|
|
|
device_lookup_private(&wsmouse_cd, minor(dev));
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wseventvar *evar = sc->sc_base.me_evp;
|
|
|
|
|
|
|
|
if (evar == NULL)
|
|
|
|
/* not open for read */
|
|
|
|
return (0);
|
|
|
|
sc->sc_base.me_evp = NULL;
|
|
|
|
(*sc->sc_accessops->disable)(sc->sc_accesscookie);
|
2001-10-25 18:46:41 +04:00
|
|
|
wsevent_fini(evar);
|
2001-10-24 18:07:31 +04:00
|
|
|
|
|
|
|
return (0);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmousedoopen(struct wsmouse_softc *sc, struct wseventvar *evp)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
sc->sc_base.me_evp = evp;
|
|
|
|
sc->sc_x = INVALID_X;
|
|
|
|
sc->sc_y = INVALID_Y;
|
|
|
|
sc->sc_z = INVALID_Z;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2006-02-05 20:38:33 +03:00
|
|
|
/* Stop button repeating when messing with the device. */
|
|
|
|
if (sc->sc_repeat_button != -1) {
|
|
|
|
KASSERT(sc->sc_repeat_button >= 0);
|
|
|
|
sc->sc_repeat_button = -1;
|
|
|
|
callout_stop(&sc->sc_repeat_callout);
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
/* enable the device, and punt if that's not possible */
|
|
|
|
return (*sc->sc_accessops->enable)(sc->sc_accesscookie);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-13 19:56:15 +04:00
|
|
|
wsmouseread(dev_t dev, struct uio *uio, int flags)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc =
|
2008-06-13 03:04:37 +04:00
|
|
|
device_lookup_private(&wsmouse_cd, 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);
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sc->sc_base.me_evp == NULL) {
|
|
|
|
printf("wsmouseread: evp == NULL\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
sc->sc_refcnt++;
|
2001-10-24 18:07:31 +04:00
|
|
|
error = wsevent_read(sc->sc_base.me_evp, uio, flags);
|
1999-06-30 10:21:21 +04:00
|
|
|
if (--sc->sc_refcnt < 0) {
|
|
|
|
wakeup(sc);
|
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
return (error);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
wsmouseioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2008-06-13 03:04:37 +04:00
|
|
|
return (wsmousedoioctl(device_lookup(&wsmouse_cd, minor(dev)),
|
2005-12-11 15:16:03 +03:00
|
|
|
cmd, data, flag, l));
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A wrapper around the ioctl() workhorse to make reference counting easy. */
|
|
|
|
int
|
2008-03-25 03:49:19 +03:00
|
|
|
wsmousedoioctl(device_t dv, u_long cmd, void *data, int flag,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc = device_private(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++;
|
2005-12-11 15:16:03 +03:00
|
|
|
error = wsmouse_do_ioctl(sc, cmd, data, flag, l);
|
1999-06-30 10:21:21 +04:00
|
|
|
if (--sc->sc_refcnt < 0)
|
|
|
|
wakeup(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
wsmouse_do_ioctl(struct wsmouse_softc *sc, u_long cmd, void *data,
|
2005-12-11 15:16:03 +03:00
|
|
|
int flag, struct lwp *l)
|
1999-06-30 10:21:21 +04:00
|
|
|
{
|
|
|
|
int error;
|
2006-02-05 20:38:33 +03:00
|
|
|
struct wsmouse_repeat *wr;
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
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:
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
sc->sc_base.me_evp->async = *(int *)data != 0;
|
1998-03-22 17:24:02 +03:00
|
|
|
return (0);
|
|
|
|
|
2003-09-21 23:16:48 +04:00
|
|
|
case FIOSETOWN:
|
|
|
|
if (sc->sc_base.me_evp == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (-*(int *)data != sc->sc_base.me_evp->io->p_pgid
|
|
|
|
&& *(int *)data != sc->sc_base.me_evp->io->p_pid)
|
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
case TIOCSPGRP:
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (*(int *)data != sc->sc_base.me_evp->io->p_pgid)
|
1998-03-22 17:24:02 +03:00
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-02-05 20:38:33 +03:00
|
|
|
/*
|
|
|
|
* Try the wsmouse specific ioctls.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case WSMOUSEIO_GETREPEAT:
|
|
|
|
wr = (struct wsmouse_repeat *)data;
|
|
|
|
memcpy(wr, &sc->sc_repeat, sizeof(sc->sc_repeat));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WSMOUSEIO_SETREPEAT:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EACCES;
|
|
|
|
|
|
|
|
/* Validate input data. */
|
|
|
|
wr = (struct wsmouse_repeat *)data;
|
|
|
|
if (wr->wr_delay_first != 0 &&
|
|
|
|
(wr->wr_delay_first < wr->wr_delay_decrement ||
|
|
|
|
wr->wr_delay_first < wr->wr_delay_minimum ||
|
|
|
|
wr->wr_delay_first < wr->wr_delay_minimum +
|
|
|
|
wr->wr_delay_decrement))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Stop current repeating and set new data. */
|
|
|
|
sc->sc_repeat_button = -1;
|
|
|
|
callout_stop(&sc->sc_repeat_callout);
|
|
|
|
memcpy(&sc->sc_repeat, wr, sizeof(sc->sc_repeat));
|
|
|
|
|
|
|
|
return 0;
|
2009-01-13 21:05:55 +03:00
|
|
|
|
|
|
|
case WSMOUSEIO_SETVERSION:
|
|
|
|
return wsevent_setversion(sc->sc_base.me_evp, *(int *)data);
|
2006-02-05 20:38:33 +03:00
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* 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,
|
2005-12-11 15:16:03 +03:00
|
|
|
data, flag, l);
|
2003-11-28 16:19:46 +03:00
|
|
|
return (error); /* may be EPASSTHROUGH */
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
wsmousepoll(dev_t dev, int events, struct lwp *l)
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc =
|
2008-06-13 03:04:37 +04:00
|
|
|
device_lookup_private(&wsmouse_cd, minor(dev));
|
1998-03-22 17:24:02 +03:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp == NULL)
|
2005-06-21 18:01:11 +04:00
|
|
|
return (POLLERR);
|
2005-12-11 15:16:03 +03:00
|
|
|
return (wsevent_poll(sc->sc_base.me_evp, events, l));
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
1999-06-30 10:21:21 +04:00
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
int
|
|
|
|
wsmousekqfilter(dev_t dev, struct knote *kn)
|
|
|
|
{
|
2008-03-25 03:49:19 +03:00
|
|
|
struct wsmouse_softc *sc =
|
2008-06-13 03:04:37 +04:00
|
|
|
device_lookup_private(&wsmouse_cd, minor(dev));
|
2002-10-23 13:10:23 +04:00
|
|
|
|
|
|
|
if (sc->sc_base.me_evp == NULL)
|
|
|
|
return (1);
|
|
|
|
return (wsevent_kqfilter(sc->sc_base.me_evp, kn));
|
|
|
|
}
|
|
|
|
|
1999-08-04 15:26:04 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmouse_mux_open(struct wsevsrc *me, struct wseventvar *evp)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
2001-10-24 18:07:31 +04:00
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)me;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_evp != NULL)
|
1999-07-29 22:20:02 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
return wsmousedoopen(sc, evp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wsmouse_mux_close(struct wsevsrc *me)
|
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc = (struct wsmouse_softc *)me;
|
|
|
|
|
|
|
|
sc->sc_base.me_evp = NULL;
|
|
|
|
(*sc->sc_accessops->disable)(sc->sc_accesscookie);
|
|
|
|
|
|
|
|
return (0);
|
1999-07-29 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-24 18:07:31 +04:00
|
|
|
wsmouse_add_mux(int unit, struct wsmux_softc *muxsc)
|
1999-07-29 22:20:02 +04:00
|
|
|
{
|
|
|
|
struct wsmouse_softc *sc;
|
|
|
|
|
2008-06-13 03:04:37 +04:00
|
|
|
sc = device_lookup_private(&wsmouse_cd, unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENXIO;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL)
|
|
|
|
return (EBUSY);
|
1999-07-29 22:20:02 +04:00
|
|
|
|
2001-10-24 18:07:31 +04:00
|
|
|
return (wsmux_attach_sc(muxsc, &sc->sc_base));
|
|
|
|
}
|
|
|
|
#endif /* NWSMUX > 0 */
|