xref: /illumos-gate/usr/src/uts/common/sys/vuid_store.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 is used by the code of a virtual user input device
29*7c478bd9Sstevel@tonic-gate  * (vuid) state maintainence package (see ../sundev/vuid_event.h for a
30*7c478bd9Sstevel@tonic-gate  * description of what vuid is) and is private to that implementation.
31*7c478bd9Sstevel@tonic-gate  * It implements the interface defined by ../sunwindowdev/vuid_state.h.
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifndef _SYS_VUID_STORE_H
35*7c478bd9Sstevel@tonic-gate #define	_SYS_VUID_STORE_H
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * The typical struct vuid_seg state list contains 2 segments:
43*7c478bd9Sstevel@tonic-gate  *
44*7c478bd9Sstevel@tonic-gate  *	First, the VKEY_FIRST segment with four values in its list,
45*7c478bd9Sstevel@tonic-gate  *	    LOC_*_ABSOLUTE and LOC_*_DELTA.  The rest of the values are
46*7c478bd9Sstevel@tonic-gate  *	    booleans.  The vuid storage package know to update the
47*7c478bd9Sstevel@tonic-gate  *	    LOC_*_ABSOLUTE value when its gets a LOC_*_DELTA and visa
48*7c478bd9Sstevel@tonic-gate  *	    versa.
49*7c478bd9Sstevel@tonic-gate  *	The ascii/meta segment has all booleans.
50*7c478bd9Sstevel@tonic-gate  *
51*7c478bd9Sstevel@tonic-gate  * The implementation is skewed to optimize the space usage but
52*7c478bd9Sstevel@tonic-gate  * still be efficient in terms of accessing short vuid_value lists
53*7c478bd9Sstevel@tonic-gate  * (e.g., during high volume mouse tracking) and gang requests
54*7c478bd9Sstevel@tonic-gate  * about the state of shift buttons.
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * A component of virutal user input device (vuid) state storage.
59*7c478bd9Sstevel@tonic-gate  * A struct vuid_value holds a single non-boolean value.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate typedef	struct vuid_value {
62*7c478bd9Sstevel@tonic-gate 	struct vuid_value	*next;	/* Next node in list */
63*7c478bd9Sstevel@tonic-gate 	ushort_t		offset;	/* Offset of value from seg addr */
64*7c478bd9Sstevel@tonic-gate 	int			value;	/* Value */
65*7c478bd9Sstevel@tonic-gate } Vuid_value;
66*7c478bd9Sstevel@tonic-gate #define	VUID_VALUE_NULL	((Vuid_value *)0)
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	BITSPERBYTE	8
69*7c478bd9Sstevel@tonic-gate #define	VUID_BIT_ARRAY_SIZE (VUID_SEG_SIZE/((sizeof (char))*BITSPERBYTE))
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * A component of virutal user input device (vuid) state storage.
72*7c478bd9Sstevel@tonic-gate  * A struct vuid_seg contains all the values for a vuid segment.
73*7c478bd9Sstevel@tonic-gate  * Neither the vuid_seg list or the vuid_value list will be sorted
74*7c478bd9Sstevel@tonic-gate  * unless a performance problem is identified.  As a new event is
75*7c478bd9Sstevel@tonic-gate  * sent to vuid_set_value, so the lists grow.
76*7c478bd9Sstevel@tonic-gate  */
77*7c478bd9Sstevel@tonic-gate typedef	struct vuid_seg {
78*7c478bd9Sstevel@tonic-gate 	struct vuid_seg		*next;	/* Next state segment in list */
79*7c478bd9Sstevel@tonic-gate 	ushort_t		addr;	/* Starting address of segment */
80*7c478bd9Sstevel@tonic-gate 	char			booleans[VUID_BIT_ARRAY_SIZE];
81*7c478bd9Sstevel@tonic-gate 					/* Up/down value of boolean codes */
82*7c478bd9Sstevel@tonic-gate 	char			ints[VUID_BIT_ARRAY_SIZE];
83*7c478bd9Sstevel@tonic-gate 					/* In/not in list */
84*7c478bd9Sstevel@tonic-gate 	struct vuid_value 	*list;	/* Linked list of values of */
85*7c478bd9Sstevel@tonic-gate 					/* non-boolean codes.  If a code is */
86*7c478bd9Sstevel@tonic-gate 					/* in this list, the boolean value is */
87*7c478bd9Sstevel@tonic-gate 					/* ignored and the corresponding bit */
88*7c478bd9Sstevel@tonic-gate 					/* in values is on. */
89*7c478bd9Sstevel@tonic-gate } Vuid_seg;
90*7c478bd9Sstevel@tonic-gate #define	VUID_SEG_NULL	((Vuid_seg *)0)
91*7c478bd9Sstevel@tonic-gate #define	vuid_cstate_to_state(cstate)	((Vuid_seg *)cstate)
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate #define	vuid_set_boolean_bit(seg, offset) \
94*7c478bd9Sstevel@tonic-gate 	(seg)->booleans[(offset)/BITSPERBYTE] |= \
95*7c478bd9Sstevel@tonic-gate 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE)))
96*7c478bd9Sstevel@tonic-gate #define	vuid_clear_boolean_bit(seg, offset) \
97*7c478bd9Sstevel@tonic-gate 	(seg)->booleans[(offset)/BITSPERBYTE] &= \
98*7c478bd9Sstevel@tonic-gate 	    (~(1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
99*7c478bd9Sstevel@tonic-gate #define	vuid_get_boolean_bit(seg, offset) \
100*7c478bd9Sstevel@tonic-gate 	((seg)->booleans[(offset)/BITSPERBYTE] & \
101*7c478bd9Sstevel@tonic-gate 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate #define	vuid_set_int_bit(seg, offset) \
104*7c478bd9Sstevel@tonic-gate 	(seg)->ints[(offset)/BITSPERBYTE] |= \
105*7c478bd9Sstevel@tonic-gate 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE)))
106*7c478bd9Sstevel@tonic-gate #define	vuid_clear_int_bit(seg, offset) \
107*7c478bd9Sstevel@tonic-gate 	(seg)->ints[(offset)/BITSPERBYTE] &= \
108*7c478bd9Sstevel@tonic-gate 	    (~(1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
109*7c478bd9Sstevel@tonic-gate #define	vuid_get_int_bit(seg, offset) \
110*7c478bd9Sstevel@tonic-gate 	((seg)->ints[(offset)/BITSPERBYTE] & \
111*7c478bd9Sstevel@tonic-gate 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate #endif
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_VUID_STORE_H */
118