xref: /netbsd-src/sys/arch/amiga/dev/event_var.h (revision c6186face496111adff8392f10c5c54354f3287f)
1*c6186facSrmind /*	$NetBSD: event_var.h,v 1.9 2008/03/01 14:16:49 rmind Exp $	*/
2ec77f0b3Scgd 
3bdb2629dSmw /*
4bdb2629dSmw  * Copyright (c) 1992, 1993
5bdb2629dSmw  *	The Regents of the University of California.  All rights reserved.
6bdb2629dSmw  *
7bdb2629dSmw  * This software was developed by the Computer Systems Engineering group
8bdb2629dSmw  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9bdb2629dSmw  * contributed to Berkeley.
10bdb2629dSmw  *
11bdb2629dSmw  * All advertising materials mentioning features or use of this software
12bdb2629dSmw  * must display the following acknowledgement:
13bdb2629dSmw  *	This product includes software developed by the University of
14bdb2629dSmw  *	California, Lawrence Berkeley Laboratory.
15bdb2629dSmw  *
16bdb2629dSmw  * Redistribution and use in source and binary forms, with or without
17bdb2629dSmw  * modification, are permitted provided that the following conditions
18bdb2629dSmw  * are met:
19bdb2629dSmw  * 1. Redistributions of source code must retain the above copyright
20bdb2629dSmw  *    notice, this list of conditions and the following disclaimer.
21bdb2629dSmw  * 2. Redistributions in binary form must reproduce the above copyright
22bdb2629dSmw  *    notice, this list of conditions and the following disclaimer in the
23bdb2629dSmw  *    documentation and/or other materials provided with the distribution.
24aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
25bdb2629dSmw  *    may be used to endorse or promote products derived from this software
26bdb2629dSmw  *    without specific prior written permission.
27bdb2629dSmw  *
28bdb2629dSmw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29bdb2629dSmw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30bdb2629dSmw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31bdb2629dSmw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32bdb2629dSmw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33bdb2629dSmw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34bdb2629dSmw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35bdb2629dSmw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36bdb2629dSmw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37bdb2629dSmw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38bdb2629dSmw  * SUCH DAMAGE.
39bdb2629dSmw  *
40bdb2629dSmw  *	@(#)event_var.h	8.1 (Berkeley) 6/11/93
41bdb2629dSmw  *
42ec77f0b3Scgd  * Header: event_var.h,v 1.5 92/11/26 01:11:51 torek Exp  (LBL)
43bdb2629dSmw  */
44bdb2629dSmw 
45bdb2629dSmw /*
46bdb2629dSmw  * Internal `Firm_event' interface for the keyboard and mouse drivers.
47bdb2629dSmw  * The drivers are expected not to place events in the queue above spltty(),
48bdb2629dSmw  * i.e., are expected to run off serial ports.
49bdb2629dSmw  */
50bdb2629dSmw 
51bdb2629dSmw /* EV_QSIZE should be a power of two so that `%' is fast */
52bdb2629dSmw #define	EV_QSIZE	256	/* may need tuning; this uses 2k */
53bdb2629dSmw 
54bdb2629dSmw struct evvar {
55bdb2629dSmw 	u_int	ev_get;		/* get (read) index (modified synchronously) */
56bdb2629dSmw 	volatile u_int ev_put;	/* put (write) index (modified by interrupt) */
57bdb2629dSmw 	struct	selinfo ev_sel;	/* process selecting */
58bdb2629dSmw 	struct	proc *ev_io;	/* process that opened queue (can get SIGIO) */
59bdb2629dSmw 	char	ev_wanted;	/* wake up on input ready */
60bdb2629dSmw 	char	ev_async;	/* send SIGIO on input ready */
61bdb2629dSmw 	struct	firm_event *ev_q;/* circular buffer (queue) of events */
62bdb2629dSmw };
63bdb2629dSmw 
64bdb2629dSmw #define	splev()	spltty()
65bdb2629dSmw 
66bdb2629dSmw #define	EV_WAKEUP(ev) { \
67*c6186facSrmind 	selnotify(&(ev)->ev_sel, 0, 0); \
68bdb2629dSmw 	if ((ev)->ev_wanted) { \
69bdb2629dSmw 		(ev)->ev_wanted = 0; \
7053524e44Schristos 		wakeup((void *)(ev)); \
71bdb2629dSmw 	} \
72bdb2629dSmw 	if ((ev)->ev_async) \
73bdb2629dSmw 		psignal((ev)->ev_io, SIGIO); \
74bdb2629dSmw }
75bdb2629dSmw 
769382c873Saymeric void	ev_init(struct evvar *);
779382c873Saymeric void	ev_fini(struct evvar *);
789382c873Saymeric int	ev_read(struct evvar *, struct uio *, int);
7995e1ffb1Schristos int	ev_poll(struct evvar *, int, struct lwp *);
80e0cc03a0Sjdolecek int	ev_kqfilter(struct evvar *, struct knote *);
81bdb2629dSmw 
82bdb2629dSmw /*
83bdb2629dSmw  * PEVENT is set just above PSOCK, which is just above TTIPRI, on the
84bdb2629dSmw  * theory that mouse and keyboard `user' input should be quick.
85bdb2629dSmw  */
86bdb2629dSmw #define	PEVENT	23
87