xref: /illumos-gate/usr/src/uts/common/sys/vuid_queue.h (revision 2d6eb4a5)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1985,1997-1998 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * This file describes a virtual user input device (vuid) event queue
29*7c478bd9Sstevel@tonic-gate  * maintainence package (see ../sundev/vuid_event.h for a description
30*7c478bd9Sstevel@tonic-gate  * of what vuid is).  This header file defines the interface that a
31*7c478bd9Sstevel@tonic-gate  * client of this package sees.	 This package is used to maintain queues
32*7c478bd9Sstevel@tonic-gate  * of firm events awaiting deliver to some consumer.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifndef _SYS_VUID_QUEUE_H
36*7c478bd9Sstevel@tonic-gate #define	_SYS_VUID_QUEUE_H
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Vuid input queue structure.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate typedef struct	vuid_queue {
46*7c478bd9Sstevel@tonic-gate 	struct	vuid_q_node *top;	/* input queue head (first in line) */
47*7c478bd9Sstevel@tonic-gate 	struct	vuid_q_node *bottom;	/* input queue head (last in line) */
48*7c478bd9Sstevel@tonic-gate 	struct	vuid_q_node *free;	/* input queue free list */
49*7c478bd9Sstevel@tonic-gate 	int	num;			/* number of items currently on queue */
50*7c478bd9Sstevel@tonic-gate 	int	size;			/* number of items allowed on queue */
51*7c478bd9Sstevel@tonic-gate } Vuid_queue;
52*7c478bd9Sstevel@tonic-gate #define	VUID_QUEUE_NULL ((Vuid_queue *)0)
53*7c478bd9Sstevel@tonic-gate #define	vq_used(vq) ((vq)->num)
54*7c478bd9Sstevel@tonic-gate #define	vq_avail(vq) ((vq)->size - (vq)->num)
55*7c478bd9Sstevel@tonic-gate #define	vq_size(vq) ((vq)->size)
56*7c478bd9Sstevel@tonic-gate #define	vq_is_empty(vq) ((vq)->top == VUID_Q_NODE_NULL)
57*7c478bd9Sstevel@tonic-gate #define	vq_is_full(vq) ((vq)->num == (vq)->size)
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * Vuid input queue node structure.
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate typedef struct	vuid_q_node {
63*7c478bd9Sstevel@tonic-gate 	struct	vuid_q_node *next;	/* Next item in queue */
64*7c478bd9Sstevel@tonic-gate 	struct	vuid_q_node *prev;	/* Previous item in queue */
65*7c478bd9Sstevel@tonic-gate 	Firm_event firm_event;		/* Firm event */
66*7c478bd9Sstevel@tonic-gate } Vuid_q_node;
67*7c478bd9Sstevel@tonic-gate #define	VUID_Q_NODE_NULL	((Vuid_q_node *)0)
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * Vuid input queue status codes.
71*7c478bd9Sstevel@tonic-gate  */
72*7c478bd9Sstevel@tonic-gate typedef enum	vuid_q_code {
73*7c478bd9Sstevel@tonic-gate 	VUID_Q_OK = 0,		/* OK */
74*7c478bd9Sstevel@tonic-gate 	VUID_Q_OVERFLOW = 1,	/* overflow */
75*7c478bd9Sstevel@tonic-gate 	VUID_Q_EMPTY = 2	/* empty */
76*7c478bd9Sstevel@tonic-gate } Vuid_q_code;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate extern	void vq_initialize(); /* (Vuid_queue *vq, caddr_t data, uint_t bytes) */
79*7c478bd9Sstevel@tonic-gate 				/* Client allocates bytes worth of storage */
80*7c478bd9Sstevel@tonic-gate 				/* and pass in a data. Client destroys the q */
81*7c478bd9Sstevel@tonic-gate 				/* simply by releasing data. */
82*7c478bd9Sstevel@tonic-gate extern	Vuid_q_code vq_put();	/* (Vuid_queue *vq, Firm_event *firm_event) */
83*7c478bd9Sstevel@tonic-gate 				/* Place firm_event on queue, position is */
84*7c478bd9Sstevel@tonic-gate 				/* dependent on the firm event's time.	Can */
85*7c478bd9Sstevel@tonic-gate 				/* return VUID_Q_OVERFLOW if no more room. */
86*7c478bd9Sstevel@tonic-gate extern	Vuid_q_code vq_get();	/* (Vuid_queue *vq, Firm_event *firm_event) */
87*7c478bd9Sstevel@tonic-gate 				/* Place event on top of queue in firm_event. */
88*7c478bd9Sstevel@tonic-gate 				/* Can return VUID_Q_EMPTY if no more events */
89*7c478bd9Sstevel@tonic-gate extern	Vuid_q_code vq_peek();	/* Like vq_get but doesn't remove from queue */
90*7c478bd9Sstevel@tonic-gate extern	Vuid_q_code vq_putback(); /* (Vuid_queue *vq, Firm_event *firm_event) */
91*7c478bd9Sstevel@tonic-gate 				/* Push firm_event on top of queue.  Can */
92*7c478bd9Sstevel@tonic-gate 				/* return VUID_Q_OVERFLOW if no more room. */
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate extern	int vq_compress();	/* (Vuid_queue *vq, factor)  Try to */
95*7c478bd9Sstevel@tonic-gate 				/* collapse the queue to a size of 1/factor */
96*7c478bd9Sstevel@tonic-gate 				/* by squeezing like valuator events together */
97*7c478bd9Sstevel@tonic-gate 				/* Returns number collapsed */
98*7c478bd9Sstevel@tonic-gate extern	int vq_is_valuator();	/* (Vuid_q_node *vqn) if value is not 0 or 1 */
99*7c478bd9Sstevel@tonic-gate 				/* || pair_type is FE_PAIR_DELTA or */
100*7c478bd9Sstevel@tonic-gate 				/* FE_PAIR_ABSOLUTE */
101*7c478bd9Sstevel@tonic-gate extern	void vq_delete_node();	/* (Vuid_queue *vq, Vuid_q_node *vqn) */
102*7c478bd9Sstevel@tonic-gate 				/* Deletes vqn from vq */
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
105*7c478bd9Sstevel@tonic-gate }
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_VUID_QUEUE_H */
109