event_var.h revision 1.4
11.4Sagc/*	$NetBSD: event_var.h,v 1.4 2003/08/07 16:26:58 agc Exp $	*/
21.1Sleo
31.1Sleo/*
41.1Sleo * Copyright (c) 1992, 1993
51.1Sleo *	The Regents of the University of California.  All rights reserved.
61.1Sleo *
71.1Sleo * This software was developed by the Computer Systems Engineering group
81.1Sleo * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
91.1Sleo * contributed to Berkeley.
101.1Sleo *
111.1Sleo * All advertising materials mentioning features or use of this software
121.1Sleo * must display the following acknowledgement:
131.1Sleo *	This product includes software developed by the University of
141.1Sleo *	California, Lawrence Berkeley Laboratory.
151.1Sleo *
161.1Sleo * Redistribution and use in source and binary forms, with or without
171.1Sleo * modification, are permitted provided that the following conditions
181.1Sleo * are met:
191.1Sleo * 1. Redistributions of source code must retain the above copyright
201.1Sleo *    notice, this list of conditions and the following disclaimer.
211.1Sleo * 2. Redistributions in binary form must reproduce the above copyright
221.1Sleo *    notice, this list of conditions and the following disclaimer in the
231.1Sleo *    documentation and/or other materials provided with the distribution.
241.4Sagc * 3. Neither the name of the University nor the names of its contributors
251.1Sleo *    may be used to endorse or promote products derived from this software
261.1Sleo *    without specific prior written permission.
271.1Sleo *
281.1Sleo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
291.1Sleo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
301.1Sleo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
311.1Sleo * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
321.1Sleo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
331.1Sleo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
341.1Sleo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
351.1Sleo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
361.1Sleo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
371.1Sleo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
381.1Sleo * SUCH DAMAGE.
391.1Sleo *
401.1Sleo *	@(#)event_var.h	8.1 (Berkeley) 6/11/93
411.1Sleo *
421.1Sleo * from: Header: event_var.h,v 1.5 92/11/26 01:11:51 torek Exp  (LBL)
431.1Sleo */
441.1Sleo
451.1Sleo/*
461.1Sleo * Internal `Firm_event' interface for the keyboard and mouse drivers.
471.1Sleo * The drivers are expected not to place events in the queue above spltty(),
481.1Sleo * i.e., are expected to run off serial ports.
491.1Sleo */
501.1Sleo
511.1Sleo/* EV_QSIZE should be a power of two so that `%' is fast */
521.1Sleo#define	EV_QSIZE	256	/* may need tuning; this uses 2k */
531.1Sleo
541.1Sleostruct evvar {
551.1Sleo	u_int	ev_get;		/* get (read) index (modified synchronously) */
561.1Sleo	volatile u_int ev_put;	/* put (write) index (modified by interrupt) */
571.1Sleo	struct	selinfo ev_sel;	/* process selecting */
581.1Sleo	struct	proc *ev_io;	/* process that opened queue (can get SIGIO) */
591.1Sleo	char	ev_wanted;	/* wake up on input ready */
601.1Sleo	char	ev_async;	/* send SIGIO on input ready */
611.1Sleo	struct	firm_event *ev_q;/* circular buffer (queue) of events */
621.1Sleo};
631.1Sleo
641.1Sleo#define	splev()	spltty()
651.1Sleo
661.1Sleo#define	EV_WAKEUP(ev) { \
671.3Sjdolecek	selnotify(&(ev)->ev_sel, 0); \
681.1Sleo	if ((ev)->ev_wanted) { \
691.1Sleo		(ev)->ev_wanted = 0; \
701.1Sleo		wakeup((caddr_t)(ev)); \
711.1Sleo	} \
721.1Sleo	if ((ev)->ev_async) \
731.1Sleo		psignal((ev)->ev_io, SIGIO); \
741.1Sleo}
751.1Sleo
761.1Sleovoid	ev_init __P((struct evvar *));
771.1Sleovoid	ev_fini __P((struct evvar *));
781.1Sleoint	ev_read __P((struct evvar *, struct uio *, int));
791.2Sleoint	ev_poll __P((struct evvar *, int, struct proc *));
801.3Sjdolecekint	ev_kqfilter __P((struct evvar *, struct knote *));
811.1Sleo
821.1Sleo/*
831.1Sleo * PEVENT is set just above PSOCK, which is just above TTIPRI, on the
841.1Sleo * theory that mouse and keyboard `user' input should be quick.
851.1Sleo */
861.1Sleo#define	PEVENT	23
87