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