xref: /illumos-gate/usr/src/uts/common/sys/conskbd.h (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_CONSKBD_H
28 #define	_SYS_CONSKBD_H
29 
30 #include <sys/types.h>
31 #include <sys/stream.h>
32 #include <sys/consdev.h>
33 #include <sys/kbd.h>
34 #include <sys/kbtrans.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Lower Queue State:
42  *
43  * Every physical keyboard has a corresponding STREAMS queue. We call this
44  * queue lower queue. To describe this kind of queue, we define a structure
45  * (refer conskbd_lower_queue_t). Every lower queue has a state, transform
46  * of the state describes the process from a keyborad attached to system to
47  * the keyboard is plumbed into conskbd or rejected.
48  *  Rule:
49  *
50  * 1) LQS_UNINITIALIZED 	--->	LQS_KIOCTYPE_ACK_PENDING;
51  * 	send a KIOCTYPE to lower queue, and then wait response;
52  *
53  * 2) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_INITIALIZED_LEGACY;
54  * 	receive nak to KIOCTYPE, the corresponding keyboard can not
55  * 	multiplexed with other keyboards. so the conskbd is bypassed,
56  * 	only one keyboard is supported.
57  *
58  * 3) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_KIOCTRANS_ACK_PENDING;
59  *	receive ack to KIOCTYPE, and send KIOCTRANS to lower queue,
60  *
61  * 4) LQS_KIOCTRANS_ACK_PENDING	--->	LQS_KIOCLAYOUT_ACK_PENDING;
62  * 	receive ack to KIOCTRANS, and send KIOCLAYOUT to lower queue
63  *
64  * 5) LQS_KIOCTRANS_ACK_PENDING --->	Destroy
65  * 	receive nak to KIOCTRANS, it is a fatal error so that this
66  * 	keyboard is not avilable. destroy the lower queue struct.
67  *
68  * 6) LQS_KIOCLAYOUT_ACK_PENDING --->	LQS_KIOCSLED_ACK_PENDING;
69  * 	receive ack/nak to KIOCLAYOUT, and send KIOCSLED/KIOCGLED to
70  *	lower queue.
71  *
72  * 7) LQS_KIOCSLED_ACK_PENDING	--->	LQS_INITIALIZED
73  * 	receive ack/nak, the keyboard is linked under conskbd, multiplexed
74  * 	with other keyboards.
75  *
76  * 8) when lower queue is in the state of LQS_INITIALIZED_LEGACY or
77  *    LQS_INITIALIZED, no state transform occures unless the lower
78  *    queue is destroyed.
79  */
80 enum conskbd_lqs_state {
81 	LQS_UNINITIALIZED = 0,
82 	LQS_KIOCTYPE_ACK_PENDING = 1,	/* waiting ACK for KIOCTYPE */
83 	LQS_KIOCTRANS_ACK_PENDING = 2, /* waiting ACK for KIOCTRANS */
84 	LQS_KIOCLAYOUT_ACK_PENDING = 3, /* waiting ACK for KIOCLAYOUT */
85 	LQS_KIOCSLED_ACK_PENDING = 4, /* waiting ACK for KIOCSLED/KIOCGLED */
86 	LQS_INITIALIZED_LEGACY = 5, /* only one lower legacy keyboard */
87 	LQS_INITIALIZED = 6 /* virtual keyboard initialized */
88 };
89 
90 struct conskbd_state;
91 struct conskbd_lower_queue;
92 
93 /*
94  * state of lower queue.
95  */
96 typedef struct conskbd_lower_queue	conskbd_lower_queue_t;
97 struct conskbd_lower_queue {
98 
99 	conskbd_lower_queue_t	*lqs_next;
100 
101 	queue_t		*lqs_queue; /* streams queue of lower driver */
102 
103 	queue_t		*lqs_pending_queue; /* queue of pending message from */
104 	mblk_t		*lqs_pending_plink; /* pending I_PLINK message */
105 
106 	/* state of lower queue */
107 	enum conskbd_lqs_state		lqs_state;
108 
109 	/* polled I/O interface structure of lower keyboard driver */
110 	struct cons_polledio	*lqs_polledio;
111 
112 	/* key status (key-down/key-up) of each key */
113 	enum keystate	lqs_key_state[KBTRANS_KEYNUMS_MAX];
114 };
115 
116 /*
117  * Pending message structure.
118  *
119  * Note:
120  *     When conskbd receives message from its upper module, it has to
121  * clone the message and send a copy to each of its lower queues. The
122  * conskbd_pending_msg structure is used to track the process of handling
123  * this kind of messages.
124  */
125 typedef struct conskbd_pending_msg	conskbd_pending_msg_t;
126 struct conskbd_pending_msg {
127 
128 	conskbd_pending_msg_t	*kpm_next;
129 
130 	/* the upper queue from which request message is sent out */
131 	queue_t	*kpm_upper_queue;
132 
133 	mblk_t	*kpm_req_msg;	/* the message block from upper */
134 
135 	/* message ID and Command Code of the message pointed by kpm_req_msg */
136 	uint_t	kpm_req_id;
137 	int	kpm_req_cmd;
138 
139 	/* number of request message's copies sent down to lower queues */
140 	int	kpm_req_nums;
141 
142 	/* number of responses to request message received from lower queues */
143 	int	kpm_resp_nums;
144 
145 	mblk_t	*kpm_resp_list;	/* chain of responses from lower */
146 
147 	kmutex_t kpm_lock;	/* lock for this structure */
148 };
149 
150 /*
151  * software state structure for virtual keyboard
152  */
153 struct conskbd_state {
154 
155 	/* kbtrans of virtual keyboard */
156 	struct kbtrans		*conskbd_kbtrans;
157 
158 	/* polled I/O interface structure of virutal keyboard */
159 	struct cons_polledio	conskbd_polledio;
160 
161 	/* chain of lower physical keyboard queues */
162 	conskbd_lower_queue_t	*conskbd_lqueue_list;
163 
164 	/* the number of lower physical keyboard queues */
165 	int	conskbd_lqueue_nums;
166 
167 	int	conskbd_layout;	 /* layout of virtual keyboard */
168 	int	conskbd_led_state; /* LED state of virtual keyboard */
169 
170 	boolean_t	conskbd_directio; /* upstream directory */
171 	boolean_t	conskbd_bypassed; /* is virtual keyboard disabled ? */
172 };
173 typedef struct conskbd_state	conskbd_state_t;
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif	/* _SYS_CONSKBD_H */
180