Home | History | Annotate | Line # | Download | only in wscons
wsmouse.c revision 1.6.4.1
      1  1.6.4.1   thorpej /* $NetBSD: wsmouse.c,v 1.6.4.1 1999/07/01 23:41:21 thorpej Exp $ */
      2      1.1  drochner 
      3      1.1  drochner /*
      4      1.1  drochner  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      5      1.1  drochner  *
      6      1.1  drochner  * Redistribution and use in source and binary forms, with or without
      7      1.1  drochner  * modification, are permitted provided that the following conditions
      8      1.1  drochner  * are met:
      9      1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     10      1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     11      1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  drochner  *    documentation and/or other materials provided with the distribution.
     14      1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     15      1.1  drochner  *    must display the following acknowledgement:
     16      1.1  drochner  *      This product includes software developed by Christopher G. Demetriou
     17      1.1  drochner  *	for the NetBSD Project.
     18      1.1  drochner  * 4. The name of the author may not be used to endorse or promote products
     19      1.1  drochner  *    derived from this software without specific prior written permission
     20      1.1  drochner  *
     21      1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  drochner  */
     32      1.1  drochner 
     33      1.1  drochner static const char _copyright[] __attribute__ ((unused)) =
     34      1.1  drochner     "Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.";
     35      1.1  drochner static const char _rcsid[] __attribute__ ((unused)) =
     36  1.6.4.1   thorpej     "$NetBSD: wsmouse.c,v 1.6.4.1 1999/07/01 23:41:21 thorpej Exp $";
     37      1.1  drochner 
     38      1.1  drochner /*
     39      1.1  drochner  * Copyright (c) 1992, 1993
     40      1.1  drochner  *	The Regents of the University of California.  All rights reserved.
     41      1.1  drochner  *
     42      1.1  drochner  * This software was developed by the Computer Systems Engineering group
     43      1.1  drochner  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     44      1.1  drochner  * contributed to Berkeley.
     45      1.1  drochner  *
     46      1.1  drochner  * All advertising materials mentioning features or use of this software
     47      1.1  drochner  * must display the following acknowledgement:
     48      1.1  drochner  *	This product includes software developed by the University of
     49      1.1  drochner  *	California, Lawrence Berkeley Laboratory.
     50      1.1  drochner  *
     51      1.1  drochner  * Redistribution and use in source and binary forms, with or without
     52      1.1  drochner  * modification, are permitted provided that the following conditions
     53      1.1  drochner  * are met:
     54      1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     55      1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     56      1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     57      1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     58      1.1  drochner  *    documentation and/or other materials provided with the distribution.
     59      1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     60      1.1  drochner  *    must display the following acknowledgement:
     61      1.1  drochner  *	This product includes software developed by the University of
     62      1.1  drochner  *	California, Berkeley and its contributors.
     63      1.1  drochner  * 4. Neither the name of the University nor the names of its contributors
     64      1.1  drochner  *    may be used to endorse or promote products derived from this software
     65      1.1  drochner  *    without specific prior written permission.
     66      1.1  drochner  *
     67      1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     68      1.1  drochner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     69      1.1  drochner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     70      1.1  drochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     71      1.1  drochner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     72      1.1  drochner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     73      1.1  drochner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     74      1.1  drochner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     75      1.1  drochner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     76      1.1  drochner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     77      1.1  drochner  * SUCH DAMAGE.
     78      1.1  drochner  *
     79      1.1  drochner  *	@(#)ms.c	8.1 (Berkeley) 6/11/93
     80      1.1  drochner  */
     81      1.1  drochner 
     82      1.1  drochner /*
     83      1.1  drochner  * Mouse driver.
     84      1.1  drochner  */
     85      1.1  drochner 
     86      1.1  drochner #include <sys/param.h>
     87      1.1  drochner #include <sys/conf.h>
     88      1.1  drochner #include <sys/ioctl.h>
     89      1.5  augustss #include <sys/fcntl.h>
     90      1.1  drochner #include <sys/kernel.h>
     91      1.1  drochner #include <sys/proc.h>
     92      1.1  drochner #include <sys/syslog.h>
     93      1.1  drochner #include <sys/systm.h>
     94      1.1  drochner #include <sys/tty.h>
     95      1.1  drochner #include <sys/signalvar.h>
     96      1.1  drochner #include <sys/device.h>
     97  1.6.4.1   thorpej #include <sys/vnode.h>
     98      1.1  drochner 
     99      1.1  drochner #include <dev/wscons/wsconsio.h>
    100      1.1  drochner #include <dev/wscons/wsmousevar.h>
    101      1.1  drochner #include <dev/wscons/wseventvar.h>
    102      1.1  drochner 
    103      1.3  augustss #include "wsmouse.h"
    104      1.3  augustss 
    105      1.1  drochner struct wsmouse_softc {
    106      1.1  drochner 	struct device	sc_dv;
    107      1.1  drochner 
    108      1.1  drochner 	const struct wsmouse_accessops *sc_accessops;
    109      1.1  drochner 	void		*sc_accesscookie;
    110      1.1  drochner 
    111      1.1  drochner 	int		sc_ready;	/* accepting events */
    112      1.1  drochner 	struct wseventvar sc_events;	/* event queue state */
    113      1.1  drochner 
    114      1.1  drochner 	u_int		sc_mb;		/* mouse button state */
    115      1.1  drochner 	u_int		sc_ub;		/* user button state */
    116      1.1  drochner 	int		sc_dx;		/* delta-x */
    117      1.1  drochner 	int		sc_dy;		/* delta-y */
    118      1.4  drochner 	int		sc_dz;		/* delta-z */
    119  1.6.4.1   thorpej 
    120  1.6.4.1   thorpej 	int		sc_refcnt;
    121  1.6.4.1   thorpej 	u_char		sc_dying;	/* device is being detached */
    122  1.6.4.1   thorpej 
    123      1.1  drochner };
    124      1.1  drochner 
    125      1.1  drochner int	wsmouse_match __P((struct device *, struct cfdata *, void *));
    126      1.1  drochner void	wsmouse_attach __P((struct device *, struct device *, void *));
    127  1.6.4.1   thorpej int	wsmouse_detach __P((struct device *, int));
    128  1.6.4.1   thorpej int	wsmouse_activate __P((struct device *, enum devact));
    129  1.6.4.1   thorpej 
    130  1.6.4.1   thorpej int	wsmouse_do_ioctl __P((struct wsmouse_softc *, u_long, caddr_t,
    131  1.6.4.1   thorpej 			      int, struct proc *));
    132      1.1  drochner 
    133      1.1  drochner struct cfattach wsmouse_ca = {
    134      1.1  drochner 	sizeof (struct wsmouse_softc), wsmouse_match, wsmouse_attach,
    135  1.6.4.1   thorpej 	wsmouse_detach, wsmouse_activate
    136      1.1  drochner };
    137      1.1  drochner 
    138      1.3  augustss #if NWSMOUSE > 0
    139      1.1  drochner extern struct cfdriver wsmouse_cd;
    140      1.3  augustss #endif /* NWSMOUSE > 0 */
    141      1.1  drochner 
    142      1.1  drochner cdev_decl(wsmouse);
    143      1.1  drochner 
    144      1.1  drochner /*
    145      1.1  drochner  * Print function (for parent devices).
    146      1.1  drochner  */
    147      1.1  drochner int
    148      1.1  drochner wsmousedevprint(aux, pnp)
    149      1.1  drochner 	void *aux;
    150      1.1  drochner 	const char *pnp;
    151      1.1  drochner {
    152      1.1  drochner 
    153      1.1  drochner 	if (pnp)
    154      1.1  drochner 		printf("wsmouse at %s", pnp);
    155      1.1  drochner 	return (UNCONF);
    156      1.1  drochner }
    157      1.1  drochner 
    158      1.1  drochner int
    159      1.1  drochner wsmouse_match(parent, match, aux)
    160      1.1  drochner 	struct device *parent;
    161      1.1  drochner 	struct cfdata *match;
    162      1.1  drochner 	void *aux;
    163      1.1  drochner {
    164      1.1  drochner 	return (1);
    165      1.1  drochner }
    166      1.1  drochner 
    167      1.1  drochner void
    168      1.1  drochner wsmouse_attach(parent, self, aux)
    169      1.1  drochner         struct device *parent, *self;
    170      1.1  drochner 	void *aux;
    171      1.1  drochner {
    172      1.1  drochner         struct wsmouse_softc *sc = (struct wsmouse_softc *)self;
    173      1.1  drochner 	struct wsmousedev_attach_args *ap = aux;
    174      1.1  drochner 
    175      1.1  drochner 	sc->sc_accessops = ap->accessops;
    176      1.1  drochner 	sc->sc_accesscookie = ap->accesscookie;
    177      1.1  drochner 	sc->sc_ready = 0;				/* sanity */
    178  1.6.4.1   thorpej 
    179  1.6.4.1   thorpej 	printf("\n");
    180  1.6.4.1   thorpej }
    181  1.6.4.1   thorpej 
    182  1.6.4.1   thorpej int
    183  1.6.4.1   thorpej wsmouse_activate(self, act)
    184  1.6.4.1   thorpej 	struct device *self;
    185  1.6.4.1   thorpej 	enum devact act;
    186  1.6.4.1   thorpej {
    187  1.6.4.1   thorpej 	/* XXX should we do something more? */
    188  1.6.4.1   thorpej 	return (0);
    189  1.6.4.1   thorpej }
    190  1.6.4.1   thorpej 
    191  1.6.4.1   thorpej /*
    192  1.6.4.1   thorpej  * Detach a mouse.  To keep track of users of the softc we keep
    193  1.6.4.1   thorpej  * a reference count that's incremented while inside, e.g., read.
    194  1.6.4.1   thorpej  * If the mouse is active and the reference count is > 0 (0 is the
    195  1.6.4.1   thorpej  * normal state) we post an event and then wait for the process
    196  1.6.4.1   thorpej  * that had the reference to wake us up again.  Then we blow away the
    197  1.6.4.1   thorpej  * vnode and return (which will deallocate the softc).
    198  1.6.4.1   thorpej  */
    199  1.6.4.1   thorpej int
    200  1.6.4.1   thorpej wsmouse_detach(self, flags)
    201  1.6.4.1   thorpej 	struct device  *self;
    202  1.6.4.1   thorpej 	int flags;
    203  1.6.4.1   thorpej {
    204  1.6.4.1   thorpej 	struct wsmouse_softc *sc = (struct wsmouse_softc *)self;
    205  1.6.4.1   thorpej 	struct wseventvar *evar;
    206  1.6.4.1   thorpej 	int maj, mn;
    207  1.6.4.1   thorpej 	int s;
    208  1.6.4.1   thorpej 
    209  1.6.4.1   thorpej 	sc->sc_dying = 1;
    210  1.6.4.1   thorpej 
    211  1.6.4.1   thorpej 	evar = &sc->sc_events;
    212  1.6.4.1   thorpej 	if (evar->io) {
    213  1.6.4.1   thorpej 		s = spltty();
    214  1.6.4.1   thorpej 		if (--sc->sc_refcnt >= 0) {
    215  1.6.4.1   thorpej 			/* Wake everyone by generating a dummy event. */
    216  1.6.4.1   thorpej 			if (++evar->put >= WSEVENT_QSIZE)
    217  1.6.4.1   thorpej 				evar->put = 0;
    218  1.6.4.1   thorpej 			WSEVENT_WAKEUP(evar);
    219  1.6.4.1   thorpej 			/* Wait for processes to go away. */
    220  1.6.4.1   thorpej 			if (tsleep(sc, PZERO, "wsmdet", hz * 60))
    221  1.6.4.1   thorpej 				printf("wsmouse_detach: %s didn't detach\n",
    222  1.6.4.1   thorpej 				       sc->sc_dv.dv_xname);
    223  1.6.4.1   thorpej 		}
    224  1.6.4.1   thorpej 		splx(s);
    225  1.6.4.1   thorpej 	}
    226  1.6.4.1   thorpej 
    227  1.6.4.1   thorpej 	/* locate the major number */
    228  1.6.4.1   thorpej 	for (maj = 0; maj < nchrdev; maj++)
    229  1.6.4.1   thorpej 		if (cdevsw[maj].d_open == wsmouseopen)
    230  1.6.4.1   thorpej 			break;
    231  1.6.4.1   thorpej 
    232  1.6.4.1   thorpej 	/* Nuke the vnodes for any open instances (calls close). */
    233  1.6.4.1   thorpej 	mn = self->dv_unit;
    234  1.6.4.1   thorpej 	vdevgone(maj, mn, mn, VCHR);
    235  1.6.4.1   thorpej 
    236  1.6.4.1   thorpej 	return (0);
    237      1.1  drochner }
    238      1.1  drochner 
    239      1.1  drochner void
    240      1.4  drochner wsmouse_input(wsmousedev, btns, dx, dy, dz)
    241      1.1  drochner 	struct device *wsmousedev;
    242      1.1  drochner 	u_int btns;			/* 0 is up */
    243      1.4  drochner 	int dx, dy, dz;
    244      1.1  drochner {
    245      1.1  drochner 	struct wsmouse_softc *sc = (struct wsmouse_softc *)wsmousedev;
    246      1.1  drochner 	struct wscons_event *ev;
    247  1.6.4.1   thorpej 	struct wseventvar *evar;
    248      1.1  drochner 	int mb, ub, d, get, put, any;
    249      1.1  drochner 
    250      1.1  drochner         /*
    251      1.1  drochner          * Discard input if not ready.
    252      1.1  drochner          */
    253      1.1  drochner 	if (sc->sc_ready == 0)
    254      1.1  drochner 		return;
    255      1.1  drochner 
    256  1.6.4.1   thorpej 	evar = &sc->sc_events;
    257  1.6.4.1   thorpej 
    258      1.1  drochner 	sc->sc_mb = btns;
    259      1.1  drochner 	sc->sc_dx += dx;
    260      1.1  drochner 	sc->sc_dy += dy;
    261      1.4  drochner 	sc->sc_dz += dz;
    262      1.1  drochner 
    263      1.1  drochner 	/*
    264      1.1  drochner 	 * We have at least one event (mouse button, delta-X, or
    265      1.1  drochner 	 * delta-Y; possibly all three, and possibly three separate
    266      1.1  drochner 	 * button events).  Deliver these events until we are out
    267      1.1  drochner 	 * of changes or out of room.  As events get delivered,
    268      1.1  drochner 	 * mark them `unchanged'.
    269      1.1  drochner 	 */
    270      1.1  drochner 	any = 0;
    271  1.6.4.1   thorpej 	get = evar->get;
    272  1.6.4.1   thorpej 	put = evar->put;
    273  1.6.4.1   thorpej 	ev = &evar->q[put];
    274      1.1  drochner 
    275      1.1  drochner 	/* NEXT prepares to put the next event, backing off if necessary */
    276      1.1  drochner #define	NEXT								\
    277      1.1  drochner 	if ((++put) % WSEVENT_QSIZE == get) {				\
    278      1.1  drochner 		put--;							\
    279      1.1  drochner 		goto out;						\
    280      1.1  drochner 	}
    281      1.1  drochner 	/* ADVANCE completes the `put' of the event */
    282      1.1  drochner #define	ADVANCE								\
    283      1.1  drochner 	ev++;								\
    284      1.1  drochner 	if (put >= WSEVENT_QSIZE) {					\
    285      1.1  drochner 		put = 0;						\
    286  1.6.4.1   thorpej 		ev = &evar->q[0];				\
    287      1.1  drochner 	}								\
    288      1.1  drochner 	any = 1
    289      1.1  drochner 	/* TIMESTAMP sets `time' field of the event to the current time */
    290      1.1  drochner #define TIMESTAMP							\
    291      1.1  drochner 	do {								\
    292      1.1  drochner 		int s;							\
    293      1.1  drochner 		s = splhigh();						\
    294      1.1  drochner 		TIMEVAL_TO_TIMESPEC(&time, &ev->time);			\
    295      1.1  drochner 		splx(s);						\
    296      1.1  drochner 	} while (0)
    297      1.1  drochner 
    298      1.1  drochner 	mb = sc->sc_mb;
    299      1.1  drochner 	ub = sc->sc_ub;
    300      1.1  drochner 	while ((d = mb ^ ub) != 0) {
    301      1.1  drochner 		/*
    302      1.1  drochner 		 * Mouse button change.  Find the first change and drop
    303      1.1  drochner 		 * it into the event queue.
    304      1.1  drochner 		 */
    305      1.1  drochner 		NEXT;
    306      1.1  drochner 		ev->value = ffs(d) - 1;
    307      1.1  drochner 
    308      1.1  drochner 		KASSERT(ev->value >= 0);
    309      1.1  drochner 
    310      1.1  drochner 		d = 1 << ev->value;
    311      1.1  drochner 		ev->type =
    312      1.1  drochner 		    (mb & d) ? WSCONS_EVENT_MOUSE_DOWN : WSCONS_EVENT_MOUSE_UP;
    313      1.1  drochner 		TIMESTAMP;
    314      1.1  drochner 		ADVANCE;
    315      1.1  drochner 		ub ^= d;
    316      1.1  drochner 	}
    317      1.1  drochner 	if (sc->sc_dx) {
    318      1.1  drochner 		NEXT;
    319      1.1  drochner 		ev->type = WSCONS_EVENT_MOUSE_DELTA_X;
    320      1.1  drochner 		ev->value = sc->sc_dx;
    321      1.1  drochner 		TIMESTAMP;
    322      1.1  drochner 		ADVANCE;
    323      1.1  drochner 		sc->sc_dx = 0;
    324      1.1  drochner 	}
    325      1.1  drochner 	if (sc->sc_dy) {
    326      1.1  drochner 		NEXT;
    327      1.1  drochner 		ev->type = WSCONS_EVENT_MOUSE_DELTA_Y;
    328      1.1  drochner 		ev->value = sc->sc_dy;
    329      1.1  drochner 		TIMESTAMP;
    330      1.1  drochner 		ADVANCE;
    331      1.1  drochner 		sc->sc_dy = 0;
    332      1.4  drochner 	}
    333      1.4  drochner 	if (sc->sc_dz) {
    334      1.4  drochner 		NEXT;
    335      1.4  drochner 		ev->type = WSCONS_EVENT_MOUSE_DELTA_Z;
    336      1.4  drochner 		ev->value = sc->sc_dz;
    337      1.4  drochner 		TIMESTAMP;
    338      1.4  drochner 		ADVANCE;
    339      1.4  drochner 		sc->sc_dz = 0;
    340      1.1  drochner 	}
    341      1.1  drochner out:
    342      1.1  drochner 	if (any) {
    343      1.1  drochner 		sc->sc_ub = ub;
    344  1.6.4.1   thorpej 		evar->put = put;
    345  1.6.4.1   thorpej 		WSEVENT_WAKEUP(evar);
    346      1.1  drochner 	}
    347      1.1  drochner }
    348      1.1  drochner 
    349      1.1  drochner int
    350      1.1  drochner wsmouseopen(dev, flags, mode, p)
    351      1.1  drochner 	dev_t dev;
    352      1.1  drochner 	int flags, mode;
    353      1.1  drochner 	struct proc *p;
    354      1.1  drochner {
    355      1.3  augustss #if NWSMOUSE > 0
    356      1.1  drochner 	struct wsmouse_softc *sc;
    357      1.1  drochner 	int error, unit;
    358      1.1  drochner 
    359      1.1  drochner 	unit = minor(dev);
    360      1.1  drochner 	if (unit >= wsmouse_cd.cd_ndevs ||	/* make sure it was attached */
    361      1.1  drochner 	    (sc = wsmouse_cd.cd_devs[unit]) == NULL)
    362      1.1  drochner 		return (ENXIO);
    363      1.1  drochner 
    364  1.6.4.1   thorpej 	if (sc->sc_dying)
    365  1.6.4.1   thorpej 		return (EIO);
    366  1.6.4.1   thorpej 
    367      1.5  augustss 	if ((flags & (FREAD | FWRITE)) == FWRITE)
    368      1.5  augustss 		return (0);			/* always allow open for write
    369      1.5  augustss 						   so ioctl() is possible. */
    370      1.5  augustss 
    371      1.1  drochner 	if (sc->sc_events.io)			/* and that it's not in use */
    372      1.1  drochner 		return (EBUSY);
    373      1.1  drochner 
    374      1.1  drochner 	sc->sc_events.io = p;
    375      1.1  drochner 	wsevent_init(&sc->sc_events);		/* may cause sleep */
    376      1.1  drochner 
    377      1.1  drochner 	sc->sc_ready = 1;			/* start accepting events */
    378      1.1  drochner 
    379      1.1  drochner 	/* enable the device, and punt if that's not possible */
    380      1.1  drochner 	error = (*sc->sc_accessops->enable)(sc->sc_accesscookie);
    381      1.1  drochner 	if (error) {
    382      1.1  drochner 		sc->sc_ready = 0;		/* stop accepting events */
    383      1.1  drochner 		wsevent_fini(&sc->sc_events);
    384      1.1  drochner 		sc->sc_events.io = NULL;
    385      1.1  drochner 		return (error);
    386      1.1  drochner 	}
    387      1.1  drochner 
    388      1.1  drochner 	return (0);
    389      1.3  augustss #else
    390      1.3  augustss 	return (ENXIO);
    391      1.3  augustss #endif /* NWSMOUSE > 0 */
    392      1.1  drochner }
    393      1.1  drochner 
    394      1.1  drochner int
    395      1.1  drochner wsmouseclose(dev, flags, mode, p)
    396      1.1  drochner 	dev_t dev;
    397      1.1  drochner 	int flags, mode;
    398      1.1  drochner 	struct proc *p;
    399      1.1  drochner {
    400      1.3  augustss #if NWSMOUSE > 0
    401      1.6  augustss 	struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
    402      1.5  augustss 
    403      1.5  augustss 	if ((flags & (FREAD | FWRITE)) == FWRITE)
    404      1.5  augustss 		return (0);			/* see wsmouseopen() */
    405      1.1  drochner 
    406      1.1  drochner 	(*sc->sc_accessops->disable)(sc->sc_accesscookie);
    407      1.1  drochner 
    408      1.1  drochner 	sc->sc_ready = 0;			/* stop accepting events */
    409      1.1  drochner 	wsevent_fini(&sc->sc_events);
    410      1.1  drochner 	sc->sc_events.io = NULL;
    411      1.1  drochner 	return (0);
    412      1.3  augustss #else
    413      1.3  augustss 	return (ENXIO);
    414      1.3  augustss #endif /* NWSMOUSE > 0 */
    415      1.1  drochner }
    416      1.1  drochner 
    417      1.1  drochner int
    418      1.1  drochner wsmouseread(dev, uio, flags)
    419      1.1  drochner 	dev_t dev;
    420      1.1  drochner 	struct uio *uio;
    421      1.1  drochner 	int flags;
    422      1.1  drochner {
    423      1.3  augustss #if NWSMOUSE > 0
    424      1.6  augustss 	struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
    425  1.6.4.1   thorpej 	int error;
    426      1.1  drochner 
    427  1.6.4.1   thorpej 	if (sc->sc_dying)
    428  1.6.4.1   thorpej 		return (EIO);
    429  1.6.4.1   thorpej 
    430  1.6.4.1   thorpej 	sc->sc_refcnt++;
    431  1.6.4.1   thorpej 	error = wsevent_read(&sc->sc_events, uio, flags);
    432  1.6.4.1   thorpej 	if (--sc->sc_refcnt < 0) {
    433  1.6.4.1   thorpej 		wakeup(sc);
    434  1.6.4.1   thorpej 		error = EIO;
    435  1.6.4.1   thorpej 	}
    436  1.6.4.1   thorpej 	return (error);
    437      1.3  augustss #else
    438      1.3  augustss 	return (ENXIO);
    439      1.3  augustss #endif /* NWSMOUSE > 0 */
    440      1.1  drochner }
    441      1.1  drochner 
    442      1.1  drochner int
    443      1.1  drochner wsmouseioctl(dev, cmd, data, flag, p)
    444      1.1  drochner 	dev_t dev;
    445      1.1  drochner 	u_long cmd;
    446      1.1  drochner 	caddr_t data;
    447      1.1  drochner 	int flag;
    448      1.1  drochner 	struct proc *p;
    449      1.1  drochner {
    450      1.3  augustss #if NWSMOUSE > 0
    451      1.6  augustss 	struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
    452      1.6  augustss 	int error;
    453      1.1  drochner 
    454  1.6.4.1   thorpej 	sc->sc_refcnt++;
    455  1.6.4.1   thorpej 	error = wsmouse_do_ioctl(sc, cmd, data, flag, p);
    456  1.6.4.1   thorpej 	if (--sc->sc_refcnt < 0)
    457  1.6.4.1   thorpej 		wakeup(sc);
    458  1.6.4.1   thorpej 	return (error);
    459  1.6.4.1   thorpej #else
    460  1.6.4.1   thorpej 	return (ENXIO);
    461  1.6.4.1   thorpej #endif /* NWSMOUSE > 0 */
    462  1.6.4.1   thorpej }
    463  1.6.4.1   thorpej 
    464  1.6.4.1   thorpej #if NWSMOUSE > 0
    465  1.6.4.1   thorpej int
    466  1.6.4.1   thorpej wsmouse_do_ioctl(sc, cmd, data, flag, p)
    467  1.6.4.1   thorpej 	struct wsmouse_softc *sc;
    468  1.6.4.1   thorpej 	u_long cmd;
    469  1.6.4.1   thorpej 	caddr_t data;
    470  1.6.4.1   thorpej 	int flag;
    471  1.6.4.1   thorpej 	struct proc *p;
    472  1.6.4.1   thorpej {
    473  1.6.4.1   thorpej 	int error;
    474  1.6.4.1   thorpej 
    475  1.6.4.1   thorpej 	if (sc->sc_dying)
    476  1.6.4.1   thorpej 		return (EIO);
    477  1.6.4.1   thorpej 
    478      1.1  drochner 	/*
    479      1.1  drochner 	 * Try the generic ioctls that the wsmouse interface supports.
    480      1.1  drochner 	 */
    481      1.1  drochner 	switch (cmd) {
    482      1.1  drochner 	case FIONBIO:		/* we will remove this someday (soon???) */
    483      1.1  drochner 		return (0);
    484      1.1  drochner 
    485      1.1  drochner 	case FIOASYNC:
    486      1.1  drochner 		sc->sc_events.async = *(int *)data != 0;
    487      1.1  drochner 		return (0);
    488      1.1  drochner 
    489      1.1  drochner 	case TIOCSPGRP:
    490      1.1  drochner 		if (*(int *)data != sc->sc_events.io->p_pgid)
    491      1.1  drochner 			return (EPERM);
    492      1.1  drochner 		return (0);
    493      1.1  drochner 	}
    494      1.1  drochner 
    495      1.1  drochner 	/*
    496      1.1  drochner 	 * Try the mouse driver for WSMOUSEIO ioctls.  It returns -1
    497      1.1  drochner 	 * if it didn't recognize the request.
    498      1.1  drochner 	 */
    499      1.1  drochner 	error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd,
    500      1.1  drochner 	    data, flag, p);
    501      1.1  drochner 	return (error != -1 ? error : ENOTTY);
    502      1.1  drochner }
    503  1.6.4.1   thorpej #endif /* NWSMOUSE > 0 */
    504      1.1  drochner 
    505      1.1  drochner int
    506      1.1  drochner wsmousepoll(dev, events, p)
    507      1.1  drochner 	dev_t dev;
    508      1.1  drochner 	int events;
    509      1.1  drochner 	struct proc *p;
    510      1.1  drochner {
    511      1.3  augustss #if NWSMOUSE > 0
    512      1.1  drochner 	struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)];
    513      1.1  drochner 
    514      1.1  drochner 	return (wsevent_poll(&sc->sc_events, events, p));
    515      1.3  augustss #else
    516      1.3  augustss 	return (0);
    517      1.3  augustss #endif /* NWSMOUSE > 0 */
    518      1.1  drochner }
    519  1.6.4.1   thorpej 
    520