Home | History | Annotate | Line # | Download | only in wscons
wseventvar.h revision 1.9
      1 /* $NetBSD: wseventvar.h,v 1.9 2005/12/11 12:24:12 christos Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Christopher G. Demetriou
     17  *	for the NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1992, 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * This software was developed by the Computer Systems Engineering group
     38  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     39  * contributed to Berkeley.
     40  *
     41  * All advertising materials mentioning features or use of this software
     42  * must display the following acknowledgement:
     43  *	This product includes software developed by the University of
     44  *	California, Lawrence Berkeley Laboratory.
     45  *
     46  * Redistribution and use in source and binary forms, with or without
     47  * modification, are permitted provided that the following conditions
     48  * are met:
     49  * 1. Redistributions of source code must retain the above copyright
     50  *    notice, this list of conditions and the following disclaimer.
     51  * 2. Redistributions in binary form must reproduce the above copyright
     52  *    notice, this list of conditions and the following disclaimer in the
     53  *    documentation and/or other materials provided with the distribution.
     54  * 3. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  *
     70  *	@(#)event_var.h	8.1 (Berkeley) 6/11/93
     71  */
     72 
     73 /*
     74  * Internal "wscons_event" queue interface for the keyboard and mouse drivers.
     75  * The drivers are expected not to place events in the queue above spltty(),
     76  * i.e., are expected to run off serial ports or similar devices.
     77  */
     78 
     79 /* WSEVENT_QSIZE should be a power of two so that `%' is fast */
     80 #define	WSEVENT_QSIZE	256	/* may need tuning; this uses 2k */
     81 
     82 struct wseventvar {
     83 	u_int	get;		/* get (read) index (modified synchronously) */
     84 	volatile u_int put;	/* put (write) index (modified by interrupt) */
     85 	struct selinfo sel;	/* process selecting */
     86 	struct proc *io;	/* process that opened queue (can get SIGIO) */
     87 	int	wanted;		/* wake up on input ready */
     88 	int	async;		/* send SIGIO on input ready */
     89 	struct wscons_event *q;	/* circular buffer (queue) of events */
     90 };
     91 
     92 #define	splwsevent()	spltty()
     93 
     94 #define	WSEVENT_WAKEUP(ev) { \
     95 	selnotify(&(ev)->sel, 0); \
     96 	if ((ev)->wanted) { \
     97 		(ev)->wanted = 0; \
     98 		wakeup((ev)); \
     99 	} \
    100 	if ((ev)->async) \
    101 		psignal((ev)->io, SIGIO); \
    102 }
    103 
    104 void	wsevent_init(struct wseventvar *);
    105 void	wsevent_fini(struct wseventvar *);
    106 int	wsevent_read(struct wseventvar *, struct uio *, int);
    107 int	wsevent_poll(struct wseventvar *, int, struct lwp *);
    108 int	wsevent_kqfilter(struct wseventvar *ev, struct knote *kn);
    109 
    110 /*
    111  * PWSEVENT is set just above PSOCK, which is just above TTIPRI, on the
    112  * theory that mouse and keyboard `user' input should be quick.
    113  */
    114 #define	PWSEVENT	23
    115