xref: /illumos-gate/usr/src/uts/common/sys/vuid_store.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1985,1997-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * This file is used by the code of a virtual user input device
29  * (vuid) state maintainence package (see ../sundev/vuid_event.h for a
30  * description of what vuid is) and is private to that implementation.
31  * It implements the interface defined by ../sunwindowdev/vuid_state.h.
32  */
33 
34 #ifndef _SYS_VUID_STORE_H
35 #define	_SYS_VUID_STORE_H
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * The typical struct vuid_seg state list contains 2 segments:
43  *
44  *	First, the VKEY_FIRST segment with four values in its list,
45  *	    LOC_*_ABSOLUTE and LOC_*_DELTA.  The rest of the values are
46  *	    booleans.  The vuid storage package know to update the
47  *	    LOC_*_ABSOLUTE value when its gets a LOC_*_DELTA and visa
48  *	    versa.
49  *	The ascii/meta segment has all booleans.
50  *
51  * The implementation is skewed to optimize the space usage but
52  * still be efficient in terms of accessing short vuid_value lists
53  * (e.g., during high volume mouse tracking) and gang requests
54  * about the state of shift buttons.
55  */
56 
57 /*
58  * A component of virutal user input device (vuid) state storage.
59  * A struct vuid_value holds a single non-boolean value.
60  */
61 typedef	struct vuid_value {
62 	struct vuid_value	*next;	/* Next node in list */
63 	ushort_t		offset;	/* Offset of value from seg addr */
64 	int			value;	/* Value */
65 } Vuid_value;
66 #define	VUID_VALUE_NULL	((Vuid_value *)0)
67 
68 #define	BITSPERBYTE	8
69 #define	VUID_BIT_ARRAY_SIZE (VUID_SEG_SIZE/((sizeof (char))*BITSPERBYTE))
70 /*
71  * A component of virutal user input device (vuid) state storage.
72  * A struct vuid_seg contains all the values for a vuid segment.
73  * Neither the vuid_seg list or the vuid_value list will be sorted
74  * unless a performance problem is identified.  As a new event is
75  * sent to vuid_set_value, so the lists grow.
76  */
77 typedef	struct vuid_seg {
78 	struct vuid_seg		*next;	/* Next state segment in list */
79 	ushort_t		addr;	/* Starting address of segment */
80 	char			booleans[VUID_BIT_ARRAY_SIZE];
81 					/* Up/down value of boolean codes */
82 	char			ints[VUID_BIT_ARRAY_SIZE];
83 					/* In/not in list */
84 	struct vuid_value 	*list;	/* Linked list of values of */
85 					/* non-boolean codes.  If a code is */
86 					/* in this list, the boolean value is */
87 					/* ignored and the corresponding bit */
88 					/* in values is on. */
89 } Vuid_seg;
90 #define	VUID_SEG_NULL	((Vuid_seg *)0)
91 #define	vuid_cstate_to_state(cstate)	((Vuid_seg *)cstate)
92 
93 #define	vuid_set_boolean_bit(seg, offset) \
94 	(seg)->booleans[(offset)/BITSPERBYTE] |= \
95 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE)))
96 #define	vuid_clear_boolean_bit(seg, offset) \
97 	(seg)->booleans[(offset)/BITSPERBYTE] &= \
98 	    (~(1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
99 #define	vuid_get_boolean_bit(seg, offset) \
100 	((seg)->booleans[(offset)/BITSPERBYTE] & \
101 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
102 
103 #define	vuid_set_int_bit(seg, offset) \
104 	(seg)->ints[(offset)/BITSPERBYTE] |= \
105 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE)))
106 #define	vuid_clear_int_bit(seg, offset) \
107 	(seg)->ints[(offset)/BITSPERBYTE] &= \
108 	    (~(1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
109 #define	vuid_get_int_bit(seg, offset) \
110 	((seg)->ints[(offset)/BITSPERBYTE] & \
111 	    (1<<((BITSPERBYTE-1)-((offset)%BITSPERBYTE))))
112 
113 #ifdef	__cplusplus
114 }
115 #endif
116 
117 #endif	/* _SYS_VUID_STORE_H */
118